1
|
|
|
<?php |
2
|
|
|
class GameController extends Controller |
3
|
|
|
{ |
4
|
|
|
public $pageID; |
5
|
|
|
public $contentClass; |
6
|
|
|
public $layout='//layouts/column1'; |
|
|
|
|
7
|
|
|
private $lastRefresh = 0; |
8
|
|
|
|
9
|
|
|
protected function beforeAction($action) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$this->checkCookie(); |
12
|
|
|
|
13
|
|
|
if (!Yii::app()->player->uid) { |
14
|
|
|
if (Yii::app()->params['isPartOfWline'] === true) { |
15
|
|
|
throw new CHttpException(403, 'Regisztráció nélkül a játék nem használható.'); //own nick |
16
|
|
|
} else { |
17
|
|
|
if (isset($_SESSION['uid'])) { |
18
|
|
|
unset($_SESSION['uid']); |
19
|
|
|
} |
20
|
|
|
Yii::app()->user->logout(); |
21
|
|
|
$this->redirect(['/?ba']); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if (Yii::app()->params['isPartOfWline'] === true) { |
26
|
|
|
$this->updateInternals(); |
27
|
|
|
$this->autoLogout(); |
28
|
|
|
$this->setTimers(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
//init Player component, increase energy |
32
|
|
|
Yii::app()->player->rest(); |
33
|
|
|
|
34
|
|
|
return true; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function checkCookie() |
38
|
|
|
{ |
39
|
|
|
$missingGameVar = true; |
40
|
|
|
$enabledCookie = isset(Yii::app()->request->cookies['PHPSESSID']->value); |
|
|
|
|
41
|
|
|
if ($enabledCookie) { |
42
|
|
|
$session = Yii::app()->session; |
43
|
|
|
$session->open(); |
44
|
|
|
if ($session->get('fish_game') == 1) { |
45
|
|
|
$missingGameVar = false; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (Yii::app()->params['isPartOfWline'] === true && $missingGameVar) { |
50
|
|
|
$this->redirect(['gate/cookie']); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function updateInternals() |
55
|
|
|
{ |
56
|
|
|
$session = Yii::app()->session; |
57
|
|
|
|
58
|
|
|
$lastRefresh = Yii::app()->dbWline->createCommand() |
59
|
|
|
->select(Yii::app()->params['wlineRefreshAttribute']) |
60
|
|
|
->from(Yii::app()->params['wlineUsersTable']) |
61
|
|
|
->where('uid=' . Yii::app()->player->uid) |
62
|
|
|
->queryScalar(); |
63
|
|
|
|
64
|
|
|
if (!isset($session['r_time'])) { |
65
|
|
|
$session['r_time'] = time(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->lastRefresh = $lastRefresh; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function autoLogout() |
72
|
|
|
{ |
73
|
|
|
$session = Yii::app()->session; |
74
|
|
|
|
75
|
|
|
if (time() - $session['r_time'] > Yii::app()->params['maxtime']) { |
76
|
|
|
$wid = @Yii::app()->request->cookies['PHPSESSID']->value; |
77
|
|
|
header('Location: ' . Yii::app()->params['wlineHost'] . "menu.php?wid=$wid#autoLogout"); |
|
|
|
|
78
|
|
|
Yii::app()->end(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function setTimers() |
83
|
|
|
{ |
84
|
|
|
if (Yii::app()->request->getParam('auto', 0) == 1) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//set r_time |
89
|
|
|
Yii::app()->session['r_time'] = time(); |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
if (time() - $this->lastRefresh < 30) { |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
Yii::app()->dbWline->createCommand()->update(Yii::app()->params['wlineUsersTable'], [ |
97
|
|
|
Yii::app()->params['wlineRefreshAttribute'] => time(), |
98
|
|
|
], 'uid=' . Yii::app()->player->uid); |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
|
|
|
|
102
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.