function room_save_broadcast($roomid, &$roomdata) { //保存数据并广播 eval(import_module('sys')); $result = $db->query("SELECT status FROM {$gtablepre}rooms WHERE roomid = '{$roomid}'"); $runflag = 0; if ($db->num_rows($result)) { $zz = $db->fetch_array($result); if ($zz['status'] == 2) { $runflag = 1; } } update_roomstate($roomdata, $runflag); writeover(GAME_ROOT . './gamedata/tmp/rooms/' . $roomid . '.txt', base64_encode(gzencode(compatible_json_encode($roomdata)))); $result = $db->query("SELECT * FROM {$gtablepre}roomlisteners WHERE roomid = '{$roomid}' AND timestamp < '{$roomdata['timestamp']}'"); if ($db->num_rows($result)) { $str = '('; $lis = array(); while ($data = $db->fetch_array($result)) { $str .= "('" . $data['port'] . "','" . $data['roomid'] . "','" . $data['timestamp'] . "','" . $data['uniqid'] . "'),"; array_push($lis, $data['port']); } $str = substr($str, 0, -1) . ')'; $db->query("DELETE FROM {$gtablepre}roomlisteners WHERE (port,roomid,timestamp,uniqid) IN {$str}"); foreach ($lis as $port) { $___TEMP_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($___TEMP_socket === false) { continue; } $___TEMP_connected = socket_connect($___TEMP_socket, '127.0.0.1', $port); if (!$___TEMP_connected) { continue; } socket_shutdown($___TEMP_socket); } } }
$zz = $db->fetch_array($result); if ($zz['status'] != 1 && $command != 'leave') { ob_clean(); die; } //进入即将开始状态后,任何房间命令均无效,包括退出房间命令 if ($roomdata['roomstat'] == 2) { ob_clean(); die; } if ($zz['status'] == 2) { $runflag = 1; } else { $runflag = 0; } update_roomstate($roomdata, $runflag); //更新踢人状态 if ($roomdata['roomstat'] == 1 && time() >= $roomdata['kicktime']) { for ($i = 0; $i < $roomtypelist[$roomdata['roomtype']]['pnum']; $i++) { if (!$roomdata['player'][$i]['forbidden'] && !$roomdata['player'][$i]['ready'] && $roomdata['player'][$i]['name'] != '') { room_new_chat($roomdata, "<span class=\"grey\">{$roomdata['player'][$i]['name']}因为长时间未准备,被系统踢出了房间。</span><br>"); $roomdata['player'][$i]['name'] = ''; } } room_save_broadcast($roomid, $roomdata); } if ($command == 'newchat') { room_new_chat($roomdata, "<span class=\"white\"><span class=\"yellow\">{$cuser}:</span> {$para1}</span><br>"); room_save_broadcast($roomid, $roomdata); die; }
$db->query("UPDATE {$gtablepre}rooms SET status = 0 WHERE roomid='{$data['roomid']}'"); unlink(GAME_ROOT . './gamedata/tmp/rooms/' . $data['roomid'] . '.txt'); $data['status'] = 0; } else { $roomlist[$data['roomid']]['id'] = $data['roomid']; $roomlist[$data['roomid']]['status'] = $data['status']; $roomlist[$data['roomid']]['nowplayer'] = $cnt; $roomlist[$data['roomid']]['maxplayer'] = $roomtypelist[$roomdata['roomtype']]['pnum']; $roomlist[$data['roomid']]['roomtype'] = $roomdata['roomtype']; $roomlist[$data['roomid']]['roomdata'] = $roomdata; } } else { if ($data['status'] == 2) { if (file_exists(GAME_ROOT . './gamedata/tmp/rooms/' . $data['roomid'] . '.txt')) { $roomdata = json_decode(mgzdecode(base64_decode(file_get_contents(GAME_ROOT . './gamedata/tmp/rooms/' . $data['roomid'] . '.txt'))), 1); if (update_roomstate($roomdata, 1)) { room_save_broadcast($data['roomid'], $roomdata); } $roomlist[$data['roomid']]['id'] = $data['roomid']; $roomlist[$data['roomid']]['status'] = $data['status']; $roomlist[$data['roomid']]['roomtype'] = $roomdata['roomtype']; $roomlist[$data['roomid']]['roomdata'] = $roomdata; } else { $db->query("UPDATE {$gtablepre}rooms SET status = 0 WHERE roomid='{$data['roomid']}'"); $data['status'] = 0; } } } } //var_dump($roomlist); //die();