diff --git a/webapp/controller/MatchController.class.php b/webapp/controller/MatchController.class.php index 8c66be3..fbcdfa2 100644 --- a/webapp/controller/MatchController.class.php +++ b/webapp/controller/MatchController.class.php @@ -58,6 +58,8 @@ class MatchController{ $join_time = 5; $room_state = 0; $downtime = 0; + $tank_id = $this->getTankid($_REQUEST['account_id']); + $tank_skin = $this->getTankSkinid($_REQUEST['account_id']); $room = $this->getRedis($room_uuid); $room_db_str = $room->get($room_uuid); if (empty($room_db_str)) { @@ -71,6 +73,8 @@ class MatchController{ 'account_id' => $_REQUEST['account_id'], 'name' => $_REQUEST['name'], 'avatar_url' => $_REQUEST['avatar_url'], + 'tank_id' => $tank_id, + 'tankskin_id' => $tank_skin ) )); $room -> set($room_uuid, json_encode($room_db)); @@ -104,6 +108,8 @@ class MatchController{ 'account_id' => $_REQUEST['account_id'], 'name' => $_REQUEST['name'], 'avatar_url' => $_REQUEST['avatar_url'], + 'tank_id' => $tank_id, + 'tankskin_id' => $tank_skin ) )); $room -> set($room_uuid, json_encode($room_db)); @@ -122,10 +128,13 @@ class MatchController{ $random = Rand(1, 100); $robot_id = 1000 + ($num - 1) * 100 + $random; $rob = $this->getRobot($robot_id, $num); + $tank_id = Rand(1, 9) + 15000; array_push ($room_db['member_list'], array( 'account_id' => $rob['id'], 'name' => $rob['name'], 'avatar_url' => $rob['avatar_url'], + 'tank_id' => $tank_id, + 'tankskin_id' => 0 )); $room_db['last_join_time'] = time(); } @@ -135,6 +144,8 @@ class MatchController{ 'account_id' => $_REQUEST['account_id'], 'name' => $_REQUEST['name'], 'avatar_url' => $_REQUEST['avatar_url'], + 'tank_id' => $tank_id, + 'tankskin_id' => $tank_skin )); $room_db['last_join_time'] = time(); } @@ -173,6 +184,8 @@ class MatchController{ 'account_id' => $member['account_id'], 'name' => $member['name'], 'avatar_url' => $member['avatar_url'], + 'tank_id' => $member['tank_id'], + 'tankskin_id' => $member['tankskin_id'], )); } @@ -236,5 +249,38 @@ class MatchController{ 'errmsg'=> '', )); } + + protected function getTankid($accountid) + { + $conn = $this->getMysql($accountid); + $row = $conn->execQueryOne('SELECT tank_id FROM tank WHERE accountid=:account_id AND tank_status=0;', + array( + ':account_id' => $accountid, + )); + return $row['tank_id']; + } + + protected function getTankSkinid($accountid) + { + $conn = $this->getMysql($accountid); + $row = $conn->execQueryOne('SELECT skin_id FROM skin WHERE accountid=:account_id AND skin_status=0;', + array( + ':account_id' => $accountid, + )); + return $row['skin_id']; + } + + protected function getMysql($account_id) + { + $mysql_conf = getMysqlConfig(crc32($account_id)); + $conn = new phpcommon\Mysql(array( + 'host' => $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2002_' . $mysql_conf['instance_id'] + )); + return $conn; + } } ?>