-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_table_games.php
361 lines (342 loc) · 12.3 KB
/
show_table_games.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
require_once("global.php");
require_once("init_game.php");
require_once("modules/mysql.php");
function print_result($result,$button)
{
$mysql = new MySQL;
?>
<tr>
<td align="center" width="120px" valign="top">
<b>Имя стола</b>
</td>
<td align="center" width="250px" valign="top">
<b>Игроки</b>
</td>
<td align="center" width="40px" valign="top">
<b>Кол-во игроков</b>
</td>
<td align="center" width="80px" valign="top">
<b>Ограничение по игрокам</b>
</td>
<td align="center" width="150px" valign="top">
<b>Статус игры</b>
</td>
<td align="center" valign="top">
<b>Команда</b>
</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
$rowuser = mysql_fetch_assoc($mysql->sql_query("SELECT * FROM users WHERE login='".$row['creator']."'"));
$createuserid = $rowuser["id_user"];
$userlevel = $rowuser["level"];
$gamer = "<a title=\"Профиль игрока\" class=\"clickablelogin\" href=\"javascript:showuser(".$createuserid.")\" >".$row['creator']."($userlevel)</a>";
//Кто присоединился к столу
$link_usrnotcr = $mysql->sql_query('SELECT * FROM users WHERE ((id_gt='.$row['id_gt'].') AND (login<>"'.$row['creator'].'"))');
if(mysql_num_rows($link_usrnotcr)!=0)
{
while ($row1 = mysql_fetch_array($link_usrnotcr))
{
$gamer = $gamer.", <a style=\"font-weight:normal;\" title=\"Профиль игрока\" class=\"clickablelogin\" href=\"javascript:showuser(".$row1['id_user'].")\" >".$row1['login'] ."(".$row1['level'].")</a>";
}
}
if ( ($row['gt_status']==0) || ($row['gt_status']==2) )
{
$gt_status="Игра еще не начата!<br/>До начала игры:".($row['start_game']-time())." сек.";
}
else
{
$lastacttime = "";
$differencetime = time() - $row['timestamp'];
if($differencetime<24*3600)
{
if($differencetime<60*60)
{
$lastacttime = ceil($differencetime / 60) . " минут назад";
}
else
{
$lastacttime = ceil($differencetime / 3600) . " часов ";
$lastacttime .= ceil((ceil($differencetime / 3600)*3600 - $differencetime) / 60) . " минут назад ";
}
}
else
{
if(date("d",$row['timestamp']) == date("d"))
{
$lastacttime = "Сегодня в ";
}
elseif(date("d",$row['timestamp']) == date("d")-1)
{
$lastacttime = "Вчера в ";
}
else
{
$lastacttime .= date("d.m",$row['timestamp'])." в ";
}
$lastacttime .= date("H:i:s",$row['timestamp']);
}
$gt_status="Игра уже началась. <br/><small>Последняя активность:<br/>$lastacttime</small>";
}
?>
<tr>
<td align="center" valign="top">
<?=$row['name'] ?>
</td>
<td align="center" valign="top">
<?=$gamer ?>
</td>
<td align="center" valign="top">
<?=$row['num_user'] ?>
</td>
<td align="center" valign="top">
<?=$row['limit_user'] ?>
</td>
<td align="center" valign="top">
<?=$gt_status ?>
</td>
<td align="center" valign="top">
<?php
if ($button==1)
{
if ( (($row['gt_status']==0) || ($row['gt_status']==2) || ($row['gt_status']==3)) && ($row['num_user']<$row['limit_user']) )
{
?><span class="join_game" value="<?=$row['id_gt'] ?>" title="Присоединиться"><img alt="Присоединиться" width="32px" src="picture/joingame.png" /></span>
<span class="spectatemode" onClick="location.href='spectate.php?id=<?=$row['id_gt'] ?>'" title="Режим наблюдателя"><img alt="Режим наблюдателя" width="32px" src="picture/binoculars_big.png" /></span>
<?php
}
else
{
?><span class="spectatemode" onClick="location.href='spectate.php?id=<?=$row['id_gt'] ?>'" title="Режим наблюдателя"><img alt="Режим наблюдателя" width="32px" src="picture/binoculars_big.png" /></span><?php
}
}
elseif ($button==2)
{
if ($row['num_user']>=1)
{
//ТЕСТ может играть 1 игрок
?><span class="start_game" value="<?=$row['id_gt'] ?>" title="Начать игру"><img alt="Начать игру" width="32px" src="picture/startgame.png" /></span><?php
}
?> <span class="destroy_table" value="<?=$row['id_gt'] ?>" title="Удалить стол"><img alt="Удалить стол" width="32px" src="picture/deletetable.png" /></span><?php
}
elseif ($button==3)
{
?><span class="spectatemode" onClick="location.href='spectate.php?id=<?=$row['id_gt'] ?>'" title="Режим наблюдателя"><img alt="Режим наблюдателя" width="32px" src="picture/binoculars_big.png" /></span><?php
}
elseif ($button==4)
{
?><span class="leave_table" value="<?=$row['id_gt'] ?>"title="Выйти из-за стола"><img alt="Выйти из-за стола" width="32px" src="picture/exitgame.png" /></span><?php
}
elseif ($button==5)
{
?><span style="width:33px;" class="return_game" value="<?=$row['id_gt'] ?>" title="Войти в игру" ><img alt="Войти в игру" width="32px" src="picture/entergame.png" /></span><?php
?> <span style="width:33px;" class="destroy_table_whole" value="<?=$row['id_gt'] ?>" title="Удалить стол. Игра оборвется для всех игроков!"><img alt="Удалить стол" width="32px" src="picture/deletetable.png" /></span><?php
}
elseif ($button==6)
{
?><span class="return_game" value="<?=$row['id_gt'] ?>" title="Войти в игру"><img alt="Войти в игру" width="32px" src="picture/entergame.png" /></span>
<span class="leave_table" value="<?=$row['id_gt'] ?>" title="Выйти из-за стола"><img alt="Выйти из-за стола" width="32px" src="picture/exitgame.png" /></span><?php
}
?>
</td>
</tr>
<?php
}
}
function your_table()
{
$mysql = new MySQL;
$link_gt = $mysql->sql_query("SELECT * FROM users JOIN game_tables ON (users.id_gt=game_tables.id_gt) WHERE users.id_user=".$_SESSION['id_user']."");
//Вот с этой хренью нужно что-то сделать!
$link_gt_double = $mysql->sql_query("SELECT * FROM users JOIN game_tables ON (users.id_gt=game_tables.id_gt) WHERE users.id_user=".$_SESSION['id_user']."");
$row_gt = mysql_fetch_array($link_gt_double);
if ($row_gt['id_gt']==0)
{
?>
<script>
function trycreate_table()
{
if(document.form_create_table.table_name.value=='')
{
alert('Вы не ввели имя стола');
return false;
}
else
{
document.form_create_table.submit();
}
}
</script>
<h2>Создать новый игровой стол.</h2>
<table class="newdtable" border="0" />
<form name="form_create_table" id="form_create_table" action="create_table.php" method="post">
<tr>
<td>
<b>Имя стола:</b>
</td>
<td>
<input name="table_name" type="text" size="20" maxlength="15" value="" />
</td>
</tr>
<tr>
<td>
<b>Количество игроков:</b>
</td>
<td>
<select name="num_user">
<option value="3"> 3 </option>
<option value="4"> 4 </option>
<option value="5"> 5 </option>
<option value="6"> 6 </option>
</select>
</td>
</tr>
<tr>
<td>
<b>Время ожидания игроков:</b>
</td>
<td>
<select name="num_time">
<option value="180"> 3 мин.</option>
<option value="300"> 5 мин.</option>
<option value="600"> 10 мин.</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="allow_join" type="checkbox" value="1" checked /> <b style="cursor:pointer; border-bottom:1px #656565 dotted;" disabled="true" onClick="if(document.form_create_table.allow_join.checked == true){document.form_create_table.allow_join.checked = false; } else {document.form_create_table.allow_join.checked = true; }" >Разрешить присоединяться к уже начатой игре</b>
</td>
</tr>
</form>
<tr>
<td colspan="2" align="center">
<button class="submit" OnClick="trycreate_table()" >Создать</button>
</td>
</tr>
<tr>
<td colspan="2">
<small class="hint">(Игра находится в тестовом режиме. Можно играть даже с одним игроком за столом)</small>
</td>
</tr>
</table>
<?php
}
else
{
//Если стол создали вы
if ($row_gt['creator']==$row_gt['login'])
{
//Если стол еще не инициализирован
if (($row_gt['gt_status']==0) || ($row_gt['gt_status']==2))
{
?>
<h2>Созданный вами игровой стол</h2>
<table width="100%" align="center" border="1" style="border-collapse:collapse;" cellpadding="5" cellspacing="2">
<tbody>
<?php print_result($link_gt,2); ?>
</tbody>
</table>
<?php
if(($row_gt['start_game']-time()) <= 0)
{
init_game();
}
}
else
//Стол уже инициализирован
{
?>
<h2>Созданный вами игровой стол</h2>
<table width="100%" align="center" border="1" style="border-collapse:collapse;" cellpadding="5" cellspacing="2">
<tbody>
<?php print_result($link_gt,5); ?>
</tbody>
</table>
<?php
}
}
else
{
//Если стол создали не вы, а вы только к нему присоединились
//Если стол еще не инициализирован
if (($row_gt['gt_status']==0) || ($row_gt['gt_status']==2))
{
$auth = "<h2>Стол к которому вы присоединились</h2>\n";
echo $auth;
echo '<table width="100%" align="center" border="1" style="border-collapse:collapse;" cellpadding="5" cellspacing="2">
<tbody>';
print_result($link_gt,4);
echo '</tbody>
</table> ';
//Стол уже инециализирован
}
else
{
$auth = "<h2>Стол к которому вы присоединились</h2>\n";
echo $auth;
echo '<table width="100%" align="center" border="1" style="border-collapse:collapse;" cellpadding="5" cellspacing="2">
<tbody>';
print_result($link_gt,6);
echo '</tbody>
</table> ';
}
}
}
}
function show_table()
{
$mysql = new MySQL;
?>
<h2>Присоединиться к игровому столу.</h2>
<table width="100%" align="center" border="1" style="border-collapse:collapse;" cellpadding="5" cellspacing="2">
<tbody>
<?php
$link_users = $mysql->sql_query('SELECT * FROM users WHERE ((id_user='.$_SESSION['id_user'].'))');
$row_user = mysql_fetch_array($link_users);
$result = $mysql->sql_query('SELECT * FROM game_tables WHERE (id_gt<>"'.$row_user["id_gt"].'") AND (start_game > '.time().' OR (gt_status=1 OR gt_status=3)) ORDER BY timestamp DESC LIMIT 20');
if (mysql_num_rows($result)==0)
{
?>
<tr>
<td align="center" valign="top">
Нету ни одного свободного игрового стола.<br/> Создайте сами новый игровой стол, к вам обязательно кто нибудь присоединится.
</td>
</tr>
<?php
}
else
{
if ($row_user['id_gt']==0)
{
print_result($result,1);
}
else
{
print_result($result,3);
}
}
?>
</tbody>
</table>
<?php
}
if (isset($_REQUEST['send_com']))
{
if(!isset($_SESSION)){session_start();}
if (isset($_SESSION['id_user']))
{
if ($_REQUEST['send_com']==1)
{
show_table();
}
elseif($_REQUEST['send_com']==2)
{
your_table();
}
}
}
?>