Tokiwa Battle Royale  GE777
A PHP Battle Royale inspired game
 All Data Structures Namespaces Files Functions Variables Pages
common.inc.php
Go to the documentation of this file.
1 <?php
2 
3 //set_magic_quotes_runtime(0);
4 
5 define('IN_GAME', TRUE);
6 define('GAME_ROOT', substr(dirname(__FILE__), 0, -7));
7 define('GAMENAME', 'bra');
8 
9 if(PHP_VERSION < '4.3.0') {
10  exit('PHP version must >= 4.3.0!');
11 }
12 require GAME_ROOT.'./include/global.func.php';
13 error_reporting(E_ALL);
14 set_error_handler('gameerrorhandler');
15 $magic_quotes_gpc = get_magic_quotes_gpc();
16 extract(gstrfilter($_COOKIE));
17 extract(gstrfilter($_POST));
18 extract(gstrfilter($_GET));
19 //$_GET = gstrfilter($_GET);
22 
23 require GAME_ROOT.'./config.inc.php';
24 
25 
26 
27 //$errorinfo ? error_reporting(E_ALL) : error_reporting(0);
28 date_default_timezone_set('Etc/GMT');
29 //$now = time() + $moveutmin*60;
30 $now = time() + $moveut*3600 + $moveutmin*60;
31 list($sec,$min,$hour,$day,$month,$year,$wday) = explode(',',date("s,i,H,j,n,Y,w",$now));
32 
33 
34 //if($attackevasive) {
35 // include_once GAME_ROOT.'./include/security.inc.php';
36 //}
37 
38 require GAME_ROOT.'./include/db_'.$database.'.class.php';
39 $db = new dbstuff;
41 //$db->select_db($dbname);
43 
44 require GAME_ROOT.'./gamedata/system.php';
45 require config('resources',$gamecfg);
46 require config('gamecfg',$gamecfg);
47 
48 include GAME_ROOT.'./gamedata/combatinfo.php';
49 
50 ob_start();
51 
52 if(CURSCRIPT !== 'chat'){
53  //if($gzipcompress && function_exists('ob_gzhandler') && CURSCRIPT != 'wap') {
54  // ob_start('ob_gzhandler');
55  //} else {
56  // $gzipcompress = 0;
57  // ob_start();
58  //}
59 
60  //$gamestate状态:0-上局游戏结束;10-新游戏准备阶段;20-游戏开放激活;30-游戏停止激活;40-游戏连斗;50-游戏死斗。
61  //$pt = getmicrotime();
62 
63  $plock=fopen(GAME_ROOT.'./gamedata/process.lock','ab');
64  flock($plock,LOCK_EX);
65  load_gameinfo();
66  $lostfocus = false;
67 
68 // $losttime = $now - $lastupdate;
69 // if($losttime >= $lostfocusmin * 60){
70 // $result = $db->query("SELECT pid FROM {$tablepre}players WHERE endtime > '$lastupdate' AND type = '0'");
71 // if(!$db->num_rows($result)){//满足失去焦点的判定条件
72 // $lostfocus = true;
73 // echo 'LOST FOCUS:'.$losttime;
74 // if($now - $afktime > $losttime){
75 // $afktime = $now;
76 // addnews();
77 // }
78 // }
79 // }
80 
81  //include GAME_ROOT.'./gamedata/gameinfo.php';
82  $ginfochange = false;
83 // $old_gamestate = $gamestate;
84 // $old_areanum = $areanum;
85  if(!$gamestate) { //判定游戏准备
86  if(($starttime)&&($now > $starttime - $startmin*60)) {
87  $gamenum++;
88  $gamestate = 10;
89  $hdamage = 0;
90  $hplayer = '';
91  $noisemode = '';
92  //save_gameinfo();
93  include_once GAME_ROOT.'./include/system.func.php';
94  rs_game(1+2+4+8+16+32);
95  //save_gameinfo();
96  $ginfochange = true;
97  }
98  }
99  if($gamestate == 10) {//判定游戏开始
100  if($now >= $starttime) {
101  $gamestate = 20;
102  //save_gameinfo();
103  //addnews($starttime,'newgame',$gamenum);
104  addnews($starttime,'newgame',$gamenum);
105  systemputchat($starttime,'newgame');
106  $ginfochange = true;
107  }
108  }
109  //if (($gamestate > 10)&&($now > $areatime)) {
110  // include_once GAME_ROOT.'./include/system.func.php';
111  // addarea($areatime);
112  // save_gameinfo();
113  //}
114  //$combatinfo = file_get_contents(GAME_ROOT.'./gamedata/combatinfo.php');
115  //list($hdamage,$hplayer,$noisetime,$noisepls,$noiseid,$noiseid2,$noisemode) = explode(',',$combatinfo);
116  if (($gamestate > 10)&&($now > $areatime)) {//判定增加禁区
117  include_once GAME_ROOT.'./include/system.func.php';
118  while($now>$areatime){
119  $o_areatime = $areatime;
120  $areatime += $areahour*60;
121  //save_gameinfo();
122  add_once_area($o_areatime);
123  $areawarn = 0;
124  //save_gameinfo();
125  $ginfochange = true;
126  // testlog('禁区增加');
127  }
128  //addarea($areatime);
129  }elseif(($gamestate > 10)&&($now > $areatime - $areawarntime)&&(!$areawarn)){//判定警告增加禁区
130  include_once GAME_ROOT.'./include/system.func.php';
131  areawarn();
132  //save_gameinfo();
133  $ginfochange = true;
134  }
135 
136  if($gamestate == 20) {
137  $arealimit = $arealimit > 0 ? $arealimit : 1;
138  if(($validnum <= 0)&&($areanum >= $arealimit*$areaadd)) {//判定无人参加并结束游戏
139  gameover($areatime-3599,'end4');
140  } elseif(($areanum >= $arealimit*$areaadd) || ($validnum >= $validlimit)) {//判定游戏停止激活
141  $gamestate = 30;
142  //save_gameinfo();
143  $ginfochange = true;
144  }
145  }
146 
147  if($gamestate < 40 && $gamestate > 20 && $alivenum <= $combolimit) {//判定进入连斗条件1:停止激活时玩家数少于特定值
148  $gamestate = 40;
149  addnews($now,'combo');
150  systemputchat($now,'combo');
151  $ginfochange = true;
152  }elseif($gamestate < 40 && $gamestate >= 20 && $combonum && $deathnum >= $combonum){//判定进入连斗条件2:死亡人数超过特定公式计算出的值
153  $real_combonum = $deathlimit + ceil($validnum/$deathdeno) * $deathnume;
154  if($deathnum >= $real_combonum){
155  $gamestate = 40;
156  addnews($now,'combo');
157  systemputchat($now,'combo');
158  }else{
159  $combonum = $real_combonum;
160  addnews($now,'comboupdate',$combonum,$deathnum);
161  systemputchat($now,'comboupdate',$combonum);
162  }
163  $ginfochange = true;
164  }
165 
166 // if((($gamestate == 30)&&($alivenum <= $combolimit))||($deathlimit&&($gamestate < 40)&&($gamestate >= 20)&&($deathnum >= $deathlimit))) {//判定进入连斗
167 // $gamestate = 40;
168 // //save_gameinfo();
169 // //$db->query("UPDATE {$tablepre}players SET teamID='',teamPass='' WHERE type=0 ");
170 // addnews($now,'combo');
171 // systemputchat($now,'combo');
172 // $ginfochange = true;
173 // }
174 
175  if (($gamestate >= 40)&&($now > $afktime + $antiAFKertime * 60)) {//判定自动反挂机
176  include_once GAME_ROOT.'./include/system.func.php';
177  antiAFK();
178  $afktime = $now;
179  //echo 'afk';
180  //save_gameinfo();
181  $ginfochange = true;
182  }
183 
184  if($gamestate >= 40) {
185  if($alivenum <= 1) {
186  include_once GAME_ROOT.'./include/system.func.php';
187  gameover();
188  // testlog('游戏结束');
189  }
190  }
191 
192  if($ginfochange || $lostfocus){
193  save_gameinfo();
194  }
195 
196  fclose($plock);
197 }
198 
199 if (CURSCRIPT == 'botservice')
200 {
201  $cuser = $botname;
202  $cpass = $botpass;
203 }
204 else
205 {
206  $cuser = & ${$tablepre.'user'};
207  $cpass = & ${$tablepre.'pass'};
208 }
209 
210 //function testlog($name){
211 // global $month,$day,$hour,$min,$sec,$old_gamestate,$gamestate,$old_areanum,$areanum,$pt;
212 // //$a = file_get_contents(GAME_ROOT.'./gamedata/gameinfo.php');
213 // $pt2 = getmicrotime();
214 // $nowtime = "{$month}月{$day}日{$hour}时{$min}分{$sec}秒;{$pt} {$pt2}";
215 // $a = "{$nowtime}\n {$name}\n 『旧游戏状态:{$old_gamestate};新游戏状态:{$gamestate}』\n 『旧禁区数目:{$old_areanum};新禁区数目:{$areanum}』\n\n";
216 // $filec = file_get_contents(GAME_ROOT.'./log.txt');
217 // $a = $a.$filec;
218 // file_put_contents(GAME_ROOT.'./log.txt',$a);
219 // return;
220 //}
221 ?>
$_REQUEST
Definition: common.inc.php:20
$hplayer
Definition: combatinfo.php:6
$tablepre
Definition: config.inc.php:58
$areawarntime
Definition: gamecfg_1.php:9
systemputchat($time, $type, $msg= '')
const GAME_ROOT
Definition: common.inc.php:6
$database
Definition: config.inc.php:67
$gamecfg
Definition: system.php:22
$areanum
Definition: gameinfo.php:9
if(!defined('IN_GAME')) $hdamage
Definition: combatinfo.php:5
$validnum
Definition: gameinfo.php:13
$validlimit
Definition: gamecfg_1.php:44
$deathdeno
Definition: gamecfg_1.php:50
$arealimit
Definition: gamecfg_1.php:11
$moveutmin
Definition: config.inc.php:52
$magic_quotes_gpc
Definition: common.inc.php:15
$dbpw
Definition: config.inc.php:12
areawarn()
gstrfilter($str)
Definition: global.func.php:48
gameover($time=0, $mode= '', $winname= '')
$noisemode
Definition: combatinfo.php:11
addnews($t=0, $n= '', $a='', $b='', $c= '', $d= '', $e= '')
$antiAFKertime
Definition: gamecfg_1.php:24
$moveut
Definition: config.inc.php:49
$combolimit
Definition: gamecfg_1.php:46
$deathnum
Definition: gameinfo.php:15
【生存者数:<?php echo $alivenum?> 人】< input type="button"value="显示全部幸存者"onClick="$('alivemode').value='all';$('gbmode').value='none';postCmd('alive','alive.php');"></p > if($gamblingon &&$gamestate >=20) elseif($gamblingon &&$gamestate<=10)
Definition: 1_alive.tpl.php:18
add_once_area($atime)
$alivenum
Definition: gameinfo.php:14
if(!defined('IN_GAME')) rs_game($mode=0)
Definition: system.func.php:7
load_gameinfo()
$deathnume
Definition: gamecfg_1.php:52
antiAFK($timelimit=0)
$db
Definition: common.inc.php:39
$gamestate
Definition: gameinfo.php:4
const CURSCRIPT
Definition: admin.php:3
config($file= '', $cfg=1)
$startmin
Definition: system.php:20
$dbhost
Definition: config.inc.php:6
$deathlimit
Definition: gamecfg_1.php:48
$gamenum
Definition: gameinfo.php:3
$dbuser
Definition: config.inc.php:9
$areahour
Definition: gamecfg_1.php:5
$now
Definition: common.inc.php:30
$pconnect
Definition: config.inc.php:40
$areatime
Definition: gameinfo.php:10
$dbname
Definition: config.inc.php:15
$starttime
Definition: gameinfo.php:5
$cpass
Definition: common.inc.php:207
$areaadd
Definition: gamecfg_1.php:7
$_FILES
Definition: common.inc.php:21
save_gameinfo()