function room_enter($id) { eval(import_module('sys')); $id = (int) $id; $result = $db->query("SELECT status FROM {$gtablepre}rooms WHERE roomid = '{$id}'"); if (!$db->num_rows($result)) { gexit('房间编号不存在', __FILE__, __LINE__); die; } $zz = $db->fetch_array($result); if ($zz['status'] == 0) { gexit('房间编号不存在', __FILE__, __LINE__); die; } if (!file_exists(GAME_ROOT . './gamedata/tmp/rooms/' . $id . '.txt')) { gexit('房间编号不存在', __FILE__, __LINE__); die; } $roomdata = json_decode(mgzdecode(base64_decode(file_get_contents(GAME_ROOT . './gamedata/tmp/rooms/' . $id . '.txt'))), 1); global $cuser; room_new_chat($roomdata, "<span class=\"grey\">{$cuser}进入了房间</span><br>"); $db->query("UPDATE {$gtablepre}users SET roomid = 's{$id}' WHERE username = '******'"); room_save_broadcast($id, $roomdata); header('Location: index.php'); die; }
if ($room_prefix == '' || $room_prefix[0] != 's') { ob_clean(); header('Location: index.php'); $gamedata['url'] = 'index.php'; echo base64_encode(gzencode(compatible_json_encode($gamedata))); die; } $roomid = substr($room_prefix, 1); if (!file_exists(GAME_ROOT . './gamedata/tmp/rooms/' . $roomid . '.txt')) { ob_clean(); header('Location: index.php'); $gamedata['url'] = 'index.php'; echo base64_encode(gzencode(compatible_json_encode($gamedata))); die; } $roomdata = json_decode(mgzdecode(base64_decode(file_get_contents(GAME_ROOT . './gamedata/tmp/rooms/' . $roomid . '.txt'))), 1); $result = $db->query("SELECT status FROM {$gtablepre}rooms WHERE roomid = '{$roomid}'"); if (!$db->num_rows($result)) { ob_clean(); die; } //房间命令只对处于等待状态的房间有效,除了退出房间命令 $zz = $db->fetch_array($result); if ($zz['status'] != 1 && $command != 'leave') { ob_clean(); die; } //进入即将开始状态后,任何房间命令均无效,包括退出房间命令 if ($roomdata['roomstat'] == 2) { ob_clean(); die;
function post_gameover_events() { if (eval(__MAGIC__)) { return $___RET_VALUE; } $chprocess(); eval(import_module('replay', 'sys')); global $___MOD_SRV, $___MOD_CODE_ADV3; if (!$___MOD_SRV || !$___MOD_CODE_ADV3) { return; } //游戏准备时,保存上局的录像文件并清空目录准备下一局 $curdatalib = file_get_contents(GAME_ROOT . './gamedata/javascript/datalib.current.txt'); $result = $db->query("SELECT name,gstime,getime FROM {$wtablepre}winners WHERE gid={$gamenum}"); $data = $db->fetch_array($result); $gametimelen = (int) $data['getime'] - (int) $data['gstime']; $winname = $data['name']; $result = $db->query("SELECT name,pid FROM {$tablepre}players WHERE type = 0"); $plis = array(); $room_gprefix = ''; if ($room_prefix != '') { $room_gprefix = (string) $room_prefix[0] . '.'; } while ($data = $db->fetch_array($result)) { if (is_dir(GAME_ROOT . './gamedata/tmp/replay/' . $room_prefix . '_/' . $data['pid']) && file_exists(GAME_ROOT . './gamedata/tmp/replay/' . $room_prefix . '_/' . $data['pid'] . '/replay.txt')) { $totsz = 0; $arr = array(); $opdatalist = array(); $opreclist = array(); $arr['replay_gamenum'] = $room_gprefix . (string) $gamenum; $arr['replay_player'] = $data['name']; $arr['replay_timelen'] = $gametimelen; $arr['replay_optime'] = array(); $oplist = openfile(GAME_ROOT . './gamedata/tmp/replay/' . $room_prefix . '_/' . $data['pid'] . '/replay.txt'); $cnt = sizeof($oplist); $arr['replay_datapart'] = (int) floor($cnt / $partsize); if ($cnt % $partsize != 0) { $arr['replay_datapart']++; } for ($i = 0; $i < $cnt; $i++) { if (!empty($oplist[$i]) && strpos($oplist[$i], ',') !== false) { list($oprec, $optime, $opdata) = explode(',', $oplist[$i]); array_push($opreclist, json_decode(mgzdecode(base64_decode($oprec)))); array_push($arr['replay_optime'], round($optime * 10000) / 10000); array_push($opdatalist, $opdata); } } $jreplaydata = compatible_json_encode($arr); $jreplaydata = '___temp_s = new String(\'' . base64_encode(gzencode($jreplaydata, 9)) . '\'); replay_header = JSON.parse(JXG.decompress(___temp_s)); delete ___temp_s; replay_data = new Array(); replayload_progressbar(' . round(100 / ($arr['replay_datapart'] + 2)) . '); jQuery.cachedScript("gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.oprecord.js"); '; writeover(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.header.js', $jreplaydata); $totsz += strlen($jreplaydata); $jreplaydata = compatible_json_encode($opreclist); $jreplaydata = '___temp_s = new String(\'' . base64_encode(gzencode($jreplaydata, 9)) . '\'); replay_oprecord = JSON.parse(JXG.decompress(___temp_s)); delete ___temp_s; replay_data = new Array(); replayload_progressbar(' . round(100 / ($arr['replay_datapart'] + 2) * 2) . '); jQuery.cachedScript("gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.data.0.js"); '; writeover(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.oprecord.js', $jreplaydata); $totsz += strlen($jreplaydata); for ($i = 0; $i < $arr['replay_datapart']; $i++) { $i_start = $i * $partsize; $i_end = min($cnt - 1, $i_start + $partsize - 1); $xdata = array(); for ($k = $i_start; $k <= $i_end; $k++) { array_push($xdata, json_decode(mgzdecode(base64_decode(file_get_contents($opdatalist[$k]))), true)); } $jreplaydata = compatible_json_encode($xdata); $jreplaydata = '___temp_s = new String(\'' . base64_encode(gzencode($jreplaydata, 9)) . '\'); replay_part = JSON.parse(JXG.decompress(___temp_s)); replay_data = replay_data.concat(replay_part); delete replay_part; delete ___temp_s; replayload_progressbar(' . round(100 / ($arr['replay_datapart'] + 2) * ($i + 3)) . '); '; if ($i + 1 < $arr['replay_datapart']) { $jreplaydata .= 'jQuery.cachedScript("gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.data.' . ($i + 1) . '.js");'; } else { $jreplaydata .= 'replay_init();'; } writeover(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.replay.data.' . $i . '.js', $jreplaydata); $totsz += strlen($jreplaydata); } $totsz = round($totsz / 1024 * 10) / 10 . 'KB'; writeover(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.rep', base64_encode($curdatalib) . ',' . $gamenum . ',' . base64_encode($data['name']) . ',' . $totsz . ',' . $cnt . ','); //生成缩略图 $pic_len = 1000; $pix_time = $gametimelen / $pic_len; $cur = 0; $ca = count($arr['replay_optime']); $content = array(); for ($i = 0; $i < $pic_len * 4; $i++) { for ($j = 0; $j < 3; $j++) { $content[$i][$j] = 255; } } for ($i = 0; $i < $pic_len * 4; $i++) { $csz[$i] = 0; } for ($i = 0; $i < $pic_len; $i++) { $cz = 0; while ($cur < $ca && $arr['replay_optime'][$cur] <= $pix_time * ($i + 1)) { $cz++; $cur++; } //对相邻像素的渲染强度 if ($pix_time <= 1.2) { $render_strength = 0.6; } else { if ($pix_time <= 2) { $render_strength = 0.35; } else { if ($pix_time <= 3) { $render_strength = 0.15; } else { $render_strength = 0; } } } //单像素最高标准是0.3秒一次操作 $color = 255 * $cz / ($pix_time / 0.3); //对相邻像素渲染 $r = $render_strength; $cs = $i; while ($r > 0.1 && $cs + 1 < $pic_len) { $cs++; $csz[$cs] += $r * $color; $r *= $render_strength; } $r = $render_strength; $cs = $i; while ($r > 0.1 && $cs > 0) { $cs--; $csz[$cs] += $r * $color; $r *= $render_strength; } $csz[$i] += $color; } for ($i = 0; $i < $pic_len; $i++) { if ($csz[$i] >= 255) { $csz[$i] = 255; } $csz[$i] = (int) round($csz[$i]); $content[$i][1] = 255 - $csz[$i]; $content[$i][2] = 255 - $csz[$i]; } file_put_contents(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.' . $data['pid'] . '.rep.bmp', \bmp_util\gen_bmp($content, $pic_len, 1)); $data['opnum'] = -$cnt; if ($data['name'] == $winname) { $data['opnum'] = -2000000000; } array_push($plis, $data); } } $hs = array(); foreach ($plis as $key) { if (!isset($hs[$key['opnum']])) { $hs[$key['opnum']] = array(); } array_push($hs[$key['opnum']], $key); } ksort($hs); $sstr = ''; foreach ($hs as $key => $value) { foreach ($value as $wz) { $sstr .= $wz['pid'] . ','; } } file_put_contents(GAME_ROOT . './gamedata/replays/' . $room_gprefix . $gamenum . '.rep.index', $sstr); clear_dir(GAME_ROOT . './gamedata/tmp/replay/' . $room_prefix . '_/', 1); global $___MOD_TMP_FILE_DIRECTORY; clear_dir($___MOD_TMP_FILE_DIRECTORY . $room_prefix . '_/', 1); }