php session_start ping microtime Создаем константы -- class define htt

  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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<?php
session_start();
$ping = microtime('1');
# Создаем константы <!-- <class>
define('H', 'http://'.$_SERVER['HTTP_HOST']);
define('TIME', $_SERVER['REQUEST_TIME']);
# Создаем константы </class> --!>
# Проверяем _GET* <!-- <class>
foreach ($_GET as $links) {
if (!is_string($links) || !preg_match('#^(?:[a-z0-9_\-/]+|\.+(?!/))*$#i', $links)) {
header ('Location: '.H);
exit;
}
}
unset($links);
# Проверяем _GET* </class> --!>
# Подключаем класс <!-- <class>
$DBH = new PDO('mysql:host=localhost;dbname=jgday', 'root', '');
$DBH->query('SET NAMES "utf8"');
/*--- ДЛЯ ХОСТИНГА ННАДА, А на вдске я потом просто кфг сменю, и заебца будет аще.
*/
# Подключаем класс </class> --!>
# Класс защитных функций <!-- <class>
class sys{
function number($id){
$id = trim(abs(intval($id)));
return $id;
}
function xss($text){
$text = trim(htmlspecialchars($text));
return $text;
}
function html($msg){
$msg = nl2br(stripslashes($msg));
return $msg;
}
}
$sys = new sys();
# Класс защитных функций </class> --!>
# Куки пользователя <!-- <class>
if(isset($_COOKIE['login']) AND isset($_COOKIE['pass'])){
$login = $sys->xss($_COOKIE['login']);
$pass = $sys->xss($_COOKIE['pass']);
if(empty($login) or empty($pass)){
setcookie('login', '', time()-((60*60)*24), '/');
setcookie('pass', '', time()-((60*60)*24), '/');
}
$_user = $DBH -> prepare('SELECT * FROM `user` WHERE `login` = ? AND `pass` = ? LIMIT 1');
$_user -> execute(array($login, $pass));
$user = $_user -> fetch();
$__user = $DBH->prepare('UPDATE `user` SET `self` = ?, `last` = ? WHERE `id` = ? LIMIT 1');
$__user->execute(array($sys->xss($_SERVER['PHP_SELF']),TIME,$user['id']));
if(isset($user['id']) && $user['login'] != $login || $user['pass'] != $pass){
setcookie('login', '', time()-((60*60)*24), '/');
setcookie('pass', '', time()-((60*60)*24), '/');
}
}
# Куки пользователя </class> --!>
# Класс основных методов <!-- <class>
class func{
function verh($title = NULL){
global $sys,$user,$func,$DBH;
ob_start();
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s").'GMT');
header('Content-type:text/html; charset=utf-8');
$last_attack = floor((TIME - $user['last'])/3) < 1 ? 1 : floor((TIME - $user['last_attack'])/3);
echo '<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="author" content="Pavel228VseDela" />
<meta name="description" content="Судный день" />
<meta name="keywords" content="Судный день" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="'.H.'/favicon.ico" />
<link rel="stylesheet" href="'.H.'/templates/themes/styles.css" type="text/css" />
<title>
'.$title.'
</title>
'.($_SERVER['SCRIPT_NAME'] == '/includes/anketa.php' ? "
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script>
<script type='text/javascript'>
$(
function(){
$('a.linkul').click(
function(){
$(
'a.linkul-active'
).removeClass(
'linkul-active'
).addClass(
'linkul'
);
$(
this
).removeClass(
'linkul'
).addClass(
'linkul-active'
);
$(this).removeClass('offset').addClass('inset');
}
);
}
);
$(
function(){
$('#offsets').click(
function () {
$('#offset').toggle();
}
);
}
);
</script>
" : '').'
</head>
<body>
';
if($user['id'] == TRUE) echo '
<div class="top">
<div class="top-span">
<div class="j2">
<div class="j2-text">
'.ceil($user['xp']/$user['max_xp']*100).'%
</div>
<div class="j2-bot" style="width:'.ceil($user['xp']/$user['max_xp']*100).'%;">
</div>
</div>
</div>
<div class="top-span">
<div class="e2">
<div class="e2-text">
'.ceil($user['energy']/$user['max_energy']*100).'%
</div>
<div class="e2-bot" style="width:'.ceil($user['energy']/$user['max_energy']*100).'%;">
</div>
</div>
</div>
<div class="top-span">
<div class="r2">
<div class="r2-text">
'.$user['money'].'
</div>
</div>
</div>
<div class="top-span">
<div class="m2">
<div class="m2-text">
28/100
</div>
<div class="m2-bot" style="width:'.ceil(28/100*100).'%;">
</div>
</div>
</div>
</div>
';
$_temp_inventory = $DBH->prepare('SELECT * FROM `temp_inventory` WHERE `user` = ? AND `status` = ?');
$_temp_inventory->execute(array($user['id'],0));
while($temp_inventory = $_temp_inventory -> fetch()){
$_items = $DBH -> prepare('SELECT `name` FROM `items` WHERE `id` = ? LIMIT 1');
$_items -> execute(array($temp_inventory ['predmet']));
$item = $_items -> fetch();
echo '
<div class="link707">
<div class="info" style="background: #6f5125;border-top: 1px solid #573e1a;border-bottom: 1px solid #ae813d;">
Вам выпал предмет
<b>
<a href="#">
'.$item['name'].'
</a>
</b>
<br />
<a href="'.H.'/bag/temp/'.$temp_inventory['id'].'/" class="but">
Положить в сумку
</a>
<a href="'.H.'/bag/untemp/'.$temp_inventory['id'].'/" class="but">
Выкинуть
</a>
</div>
</div>
';
}
if($user['xp'] <= 0 and $user) {
$__log2 = $DBH -> prepare('DELETE FROM `raids_user` WHERE `user` = ?');
$__log2 -> execute(array($user['id']));
$__log2 = $DBH -> prepare('DELETE FROM `raids_log` WHERE `user` = ?');
$__log2 -> execute(array($user['id']));
if(isset($_GET['ressurection'])){
$__user = $DBH->prepare('UPDATE `user` SET `xp` = ? WHERE `id` = ? LIMIT 1');
$__user->execute(array(ceil($user['max_xp']/2),$user['id']));
header('Location:/menu');
exit;
}
echo '
<div class="link707">
Ебать ты лох, но ты подох.
<br />
<a href="?ressurection">
Возродиться
<a/>
</div>
';
$func->niz('true');
}
if($_SERVER['PHP_SELF'] !== '/includes/raids.php' and $_SERVER['PHP_SELF'] !== '/includes/anketa.php' and $_SERVER['PHP_SELF'] !== '/includes/bag.php' || $user['xp'] <= 0){
$__raid_log = $DBH->prepare('DELETE FROM `raids_user` WHERE `user` = ?');
$__raid_log->execute(array($user['id']));
}
if($_SERVER['PHP_SELF'] == '/includes/menu.php' || $user['xp'] <= 0){
$__raid_log = $DBH->prepare('DELETE FROM `quest_boi` WHERE `user` = ?');
$__raid_log->execute(array($user['id']));
$__raid_log = $DBH->prepare('DELETE FROM `quest_monsters_attack` WHERE `user` = ?');
$__raid_log->execute(array($user['id']));
}
$_raids_user = $DBH -> prepare('SELECT * FROM `raids_user` WHERE `user` = ?');
$_raids_user -> execute(array($user['id']));
$raids_user = $_raids_user -> fetch();
if($user['last'] and $raids_user and $last_attack >= 1){
for($i = 0; $i < $last_attack; ++$i){
////////`raids`//////////////////
$_boss = $DBH -> prepare('SELECT `atk`,`crit`,`hp`,`def` FROM `raids` WHERE `id` = ? LIMIT 1');
$_boss -> execute(array($raids_user['raid']));
$boss = $_boss -> fetch();
if($user['xp'] > 0 and $boss['hp'] > 0){
$boss_crit = rand(1, 100);
$par = rand(1, 100);
$evasion = rand(1, 100);
$boss_dmg = ceil($boss['atk'] * 70 /$user['def']);
if($boss_crit < $boss['crit']) $boss_dmg = $boss_dmg * 2;
if($user['xp'] - $boss_dmg * 2 < 0) $boss_dmg = $user['xp'];
if($par < $user['par']){
$dmg_par = ceil($boss['atk'] * 70 /$boss['def']);
if($boss_crit < $boss['crit']) $dmg_par = $dmg_par*2;
if($boss['hp'] - $dmg_par >0){
$__raid_log = $DBH->prepare('INSERT INTO `raids_log` SET `raid` = ?, `user` = ?, `time` = ?, `dmg` = ?, `par` = ?'.($boss_crit < $boss['crit'] ? ',`crit` = "1"' : '').'');
$__raid_log->execute(array($raids_user['raid'],$raids_user['user'],TIME,$dmg_par,1));
$__raids = $DBH->prepare('UPDATE `raids` SET `hp` = `hp` - ? WHERE `id` = ? LIMIT 1');
$__raids->execute(array($dmg_par,$raids_user['raid']));
}
}
elseif($evasion < $user['evasion']){
$__raid_log = $DBH->prepare('INSERT INTO `raids_log` SET `raid` = ?, `user` = ?, `time` = ?, `usery` = ?, `evasion` = ?');
$__raid_log->execute(array($raids_user['raid'],$raids_user['user'],TIME,1,1));
}
else{
$__raid_log = $DBH->prepare('INSERT INTO `raids_log` SET `raid` = ?, `user` = ?, `time` = ?, `usery` = ? '.($boss_crit < $boss['crit'] ? ',`crit` = "1"' : '').'');
$__raid_log->execute(array($raids_user['raid'],$raids_user['user'],TIME,$boss_dmg));
$__raids = $DBH->prepare('UPDATE `user` SET `xp` = `xp` - ? WHERE `id` = ? LIMIT 1');
$__raids->execute(array($boss_dmg,$raids_user['user']));
}
}
}
}
$_quest_boi = $DBH -> prepare('SELECT `quest`,`hash` FROM `quest_boi` WHERE `user` = ?');
$_quest_boi -> execute(array($user['id']));
$quest_boi = $_quest_boi -> fetch();
if($user['last'] and $quest_boi and $last_attack >= 1){
for($i = 0; $i < $last_attack; ++$i){
$_quest_monsters_attack = $DBH -> prepare('SELECT * FROM `quest_monsters_attack` WHERE `user` = ? and `quest` = ?');
$_quest_monsters_attack -> execute(array($user['id'],$quest_boi['quest']));
while($quest_monster_attack = $_quest_monsters_attack -> fetch()){
$_quest_monsters = $DBH -> prepare('SELECT * FROM `quest_monsters` WHERE `id` = ?');
$_quest_monsters -> execute(array($quest_monster_attack['monster']));
$quest_monster = $_quest_monsters -> fetch();
if($user['xp'] > 0 and $quest_monster_attack['hp'] > 0 and $quest_monster_attack['dead'] !== 1){
$monster_crit = rand(1, 100);
$par = rand(1, 100);
$evasion = rand(1, 100);
$monster_dmg = ceil($quest_monster['atk'] * 70 /$user['def']);
if($monster_crit < $quest_monster['crit']) $monster_dmg = $monster_dmg * 2;
if($user['xp'] - $monster_dmg * 2 < 0) $monster_dmg = $user['xp'];
if($par < $user['par']){
$dmg_par = ceil($quest_monster['atk'] * 70 /$quest_monster['def']);
if($monster_crit < $quest_monster['crit']) $dmg_par = $dmg_par*2;
if($quest_monster_attack['hp'] - $dmg_par >0){
$__quest_par_log = $DBH->prepare('INSERT INTO `quest_log` SET `quest` = ?, `monster` = ?, `user` = ?, `time` = ?, `dmg` = ?, `par` = ?'.($monster_crit < $quest_monster['crit'] ? ',`crit` = "1"' : '').'');
$__quest_par_log->execute(array($quest_boi['quest'],$quest_monster_attack['monster'],$user['id'],time(),$dmg_par,1));
$__quest_monster = $DBH->prepare('UPDATE `quest_monsters_attack` SET `hp` = `hp` - ? WHERE `monster` = ? AND `hash` = ? LIMIT 1');
$__quest_monster->execute(array($dmg_par,$quest_monster_attack['monster'],$quest_boi['hash']));
}
}
elseif($evasion < $user['evasion']){
$__raid_log = $DBH->prepare('INSERT INTO `quest_log` SET `quest` = ?, `monster` = ?, `user` = ?, `time` = ?, `usery` = ?, `evasion` = ?');
$__raid_log->execute(array($quest_boi['quest'],$quest_monster_attack['monster'],$user['id'],time(),1,1));
}
else{
$__raid_log = $DBH->prepare('INSERT INTO `quest_log` SET `quest` = ?, `monster` = ?, `user` = ?, `dmg` = ?, `time` = ?, `usery` = ?'.($monster_crit < $quest_monster['crit'] ? ',`crit` = "1"' : '').'');
$__raid_log->execute(array($quest_boi['quest'],$quest_monster_attack['monster'],$user['id'],$monster_dmg,time(),1));
$__raids = $DBH->prepare('UPDATE `user` SET `xp` = `xp` - ? WHERE `id` = ? LIMIT 1');
$__raids->execute(array($monster_dmg,$user['id']));
}
}
}
}
}
$_back = $DBH -> prepare('SELECT `hash` FROM `quest_boi` WHERE `user` = ? LIMIT 1');
$_back -> execute(array($user['id']));
$back = $_back -> fetch();
if($_SERVER['PHP_SELF'] !== '/includes/quests.php' and $_SERVER['PHP_SELF'] !== '/includes/menu.php' || $user['xp'] <= 0 and $back){
echo '
<div class="ancet-box">
<a href="/action/'.$back['hash'].'/">
Назад, йобана
</a>
</div>
';
}
}
function niz($ok = NULL){
global $sys,$user,$ping,$DBH;
if($user['level'] < 99 and $user['exp'] >= $user['max_exp']) {
$__user = $DBH->prepare('UPDATE `user` SET `level` = `level` + ?, `max_exp` = `max_exp` * `level` WHERE `id` = ? LIMIT 1');
$__user->execute(array(1,$user['id']));
}
if($user['id'] == TRUE) echo '
<div class="foot">
<a href="#">
Информация
</a>
<a href="#">
<font color="#8ec441">
On:184
</font>
</a>
<a href="#">
'.(round(microtime(1) - $ping, 6) > 0.01 ? '
<font color="red">
'.round(microtime(1) - $ping, 6).'
</font>
':'
<font color="#8ec441">
'.round(microtime(1) - $ping, 6).'
</font>
').'
</a>
<br />
<span>
© Судный день 16+
</span>
</div>
</body>
</html>
';
elseif($_SERVER['QUERY_STRING']) echo '
<div class="otstup">
© Судный день 16+
'.round(microtime(1) - $ping, 6).'
</div>
</body>
</html>
';
else echo '
<div class="otstup">
На местности 184 человека
<br />
© Судный день 16+
'.round(microtime(1) - $ping, 6).'
</div>
</body>
</html>
';
ob_end_flush();
exit;
}
function users($id){
global $user,$DBH;
$_us = $DBH -> prepare('SELECT `id`,`login` FROM `user` WHERE `id` = ? LIMIT 1');
$_us -> execute(array($id));
$us = $_us -> fetch();
return (empty($us)?'
<b>
[Изгнан]
</b>
'
:
'
<a href="'.H.'/id'.$us['id'].'">
<b>
'.$us['login'].'
</b>
</a>
');
}
function times($time = NULL) {
if(!$time) $time = time();
$data = date('j.n.y', $time);
if($data == date('j.n.y')) $res = 'Днем в '. date('G:i', $time);
elseif($data == date('j.n.y', time() - 86400)) $res = 'Вчера в '. date('G:i', $time);
else{
$m = array('0',
'Янв', 'Фев',
'Мар', 'Апр', 'Май',
'Июн', 'Июл', 'Авг',
'Сен', 'Окт', 'Ноя',
'Дек');
$res = date('j '. $m[date('n', $time)] .' Y', $time);
}
return $res;
}
function time_last($time) {
$h = floor((time() - $time)/3600);
$m = floor(((time() - $time) % 3600)/60);
$s = ((time() - $time) % 3600) % 60;
return $h.':'.$m.':'.$s;
}
function headr($url = NULL){
global $user;
if($user['id'] == FALSE) {
header('Location:'.H.($url ? $url : ''));
exit();
}
}
}
$func = new func();
# Класс основных методов </class> --!>
# Класс навигации <!-- <class>
$on_page = 5;
class nav{
public $pages,$page,$start;
function __construct($count,$on_page, $path = NULL){
global $on_page;
if(!$_GET['page']) $_GET['page']=1;
$this->pages = ceil($count/$on_page);
$this->page = !$_GET['page'] || $_GET['page'] < 1 ? 1:$_GET['page'] > $this->pages ? $this->pages: (int) $_GET['page'];
$this->start = $this->page*$on_page-$on_page;
if($_GET['page'] > ceil($count/$on_page)){
header('Location: '.ceil($count/$on_page));
exit;
}
}
function listing($path,$count){
global $on_page;
echo '
<div class="link707" style="text-align:center;">';
if($this->page > 2) echo '
<a class="nav7" href="'.$path.'1">
<span class="l">
&#171
</span>
</a>
';
if($this->page > 2) echo '
<a class="nav5" href="'.$path.($this->page-2).'">
<span class="ll">
'.($this->page-2).'
</span>
</a>
';
if($this->page > 1) echo '
<a class="nav5" href="'.$path.($this->page-1).'">
<span class="ll">
'.($this->page-1).'
</span>
</a>
';
echo '
<span class="nav2">
'.$this->page.'
</span>
';
if(($this->page + 1) <= $this->pages) echo '
<a class="nav5" href="'.$path.($this->page+1).'">
<span class="ll">
'.($this->page+1).'
</span>
</a>
';
if(($this->page + 2) <= $this->pages) echo '
<a class="nav5" href="'.$path.($this->page+2).'">
<span class="ll">
'.($this->page+2).'
</span>
</a>
';
if(($this->page + 2) <= $this->pages) echo '
<a class="nav7" href="'.$path.ceil($count/$on_page).'">
<span class="l">
&#187;
</span>
</a>
';
echo '
</div>
';
}
}
# Класс навигации </class> --!>
?>