1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Gorlum |
5
|
|
|
* Date: 17.04.2015 |
6
|
|
|
* Time: 6:37 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
function sys_user_vacation($user) { |
10
|
|
|
global $config; |
|
|
|
|
11
|
|
|
|
12
|
|
|
if(sys_get_param_str('vacation') == 'leave') { |
13
|
|
|
if ($user['vacation'] < SN_TIME_NOW) { |
14
|
|
|
$user['vacation'] = 0; |
15
|
|
|
$user['vacation_next'] = SN_TIME_NOW + $config->player_vacation_timeout; |
16
|
|
|
db_user_set_by_id($user['id'], "`vacation` = {$user['vacation']}, `vacation_next` = {$user['vacation_next']}"); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
if($user['vacation']) { |
21
|
|
|
// sn_sys_logout(false, true); |
|
|
|
|
22
|
|
|
// core_auth::logout(false, true); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$template = gettemplate('vacation', true); |
|
|
|
|
25
|
|
|
|
26
|
|
|
$template->assign_vars(array( |
27
|
|
|
'MENU' => false, |
28
|
|
|
'NAVBAR' => false, |
29
|
|
|
|
30
|
|
|
'NAME' => $user['username'], |
31
|
|
|
'VACATION_END' => date(FMT_DATE_TIME, $user['vacation']), |
32
|
|
|
'CAN_LEAVE' => $user['vacation'] <= SN_TIME_NOW, |
33
|
|
|
'RANDOM' => mt_rand(1, 2), |
34
|
|
|
)); |
35
|
|
|
|
36
|
|
|
display($template); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return false; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function sys_is_multiaccount($user1, $user2) { |
43
|
|
|
global $config; |
|
|
|
|
44
|
|
|
|
45
|
|
|
return $user1['user_lastip'] == $user2['user_lastip'] && !$config->game_multiaccount_enabled; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $banner |
50
|
|
|
* @param $banned |
51
|
|
|
* @param $term |
52
|
|
|
* @param bool $is_vacation |
53
|
|
|
* @param string $reason |
54
|
|
|
*/ |
55
|
|
|
function sys_admin_player_ban($banner, $banned, $term, $is_vacation = true, $reason = '') { |
56
|
|
|
$ban_current = db_user_by_id($banned['id'], false, 'banaday'); |
|
|
|
|
57
|
|
|
$ban_until = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term; |
58
|
|
|
|
59
|
|
|
db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : '')); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$banned['username'] = db_escape($banned['username']); |
62
|
|
|
$banner['username'] = db_escape($banner['username']); |
63
|
|
|
doquery( |
64
|
|
|
"INSERT INTO |
65
|
|
|
{{banned}} |
66
|
|
|
SET |
67
|
|
|
`ban_user_id` = '{$banned['id']}', |
68
|
|
|
`ban_user_name` = '{$banned['username']}', |
69
|
|
|
`ban_reason` = '{$reason}', |
70
|
|
|
`ban_time` = " . SN_TIME_NOW . ", |
71
|
|
|
`ban_until` = {$ban_until}, |
72
|
|
|
`ban_issuer_id` = '{$banner['id']}', |
73
|
|
|
`ban_issuer_name` = '{$banner['username']}', |
74
|
|
|
`ban_issuer_email` = '{$banner['email']}' |
75
|
|
|
"); |
76
|
|
|
|
77
|
|
|
DBStaticPlanet::db_planet_set_by_owner($banned['id'], |
78
|
|
|
"`metal_mine_porcent` = 0, `crystal_mine_porcent` = 0, `deuterium_sintetizer_porcent` = 0, `solar_plant_porcent` = 0, |
79
|
|
|
`fusion_plant_porcent` = 0, `solar_satelit_porcent` = 0, `ship_sattelite_sloth_porcent` = 0" |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param $banner |
85
|
|
|
* @param $banned |
86
|
|
|
* @param string $reason |
87
|
|
|
*/ |
88
|
|
|
function sys_admin_player_ban_unset($banner, $banned, $reason = '') { |
89
|
|
|
db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . ""); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$banned['username'] = db_escape($banned['username']); |
92
|
|
|
$banner['username'] = db_escape($banner['username']); |
93
|
|
|
$reason = db_escape($reason); |
94
|
|
|
doquery( |
95
|
|
|
"INSERT INTO {{banned}} |
96
|
|
|
SET |
97
|
|
|
`ban_user_id` = '{$banned['id']}', |
98
|
|
|
`ban_user_name` = '{$banned['username']}', |
99
|
|
|
`ban_reason` = '{$reason}', |
100
|
|
|
`ban_time` = 0, |
101
|
|
|
`ban_until` = " . SN_TIME_NOW . ", |
102
|
|
|
`ban_issuer_id` = '{$banner['id']}', |
103
|
|
|
`ban_issuer_name` = '{$banner['username']}', |
104
|
|
|
`ban_issuer_email` = '{$banner['email']}' |
105
|
|
|
"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function player_create($username_unsafe, $email_unsafe, $options) { |
109
|
|
|
sn_db_transaction_check(true); |
110
|
|
|
|
111
|
|
|
global $config, $lang; |
|
|
|
|
112
|
|
|
|
113
|
|
|
static $player_options_string = 'opt_mnl_spy^1|opt_email_mnl_spy^0|opt_email_mnl_joueur^0|opt_email_mnl_alliance^0|opt_mnl_attaque^1|opt_email_mnl_attaque^0|opt_mnl_exploit^1|opt_email_mnl_exploit^0|opt_mnl_transport^1|opt_email_mnl_transport^0|opt_email_msg_admin^1|opt_mnl_expedition^1|opt_email_mnl_expedition^0|opt_mnl_buildlist^1|opt_email_mnl_buildlist^0|opt_int_navbar_resource_force^1|'; |
114
|
|
|
|
115
|
|
|
empty($options['planet_options']) ? $options['planet_options'] = array() : false; |
116
|
|
|
|
117
|
|
|
$field_set = array( |
118
|
|
|
'server_name' => SN_ROOT_VIRTUAL, |
119
|
|
|
'register_time' => SN_TIME_NOW, |
120
|
|
|
'news_lastread' => SN_TIME_NOW, |
121
|
|
|
'user_bot' => $options['user_bot'] = empty($options['user_bot']) ? USER_BOT_PLAYER : $options['total_points'], |
122
|
|
|
|
123
|
|
|
'username' => $username_unsafe, |
124
|
|
|
'email' => $email_unsafe, |
125
|
|
|
'email_2' => $email_unsafe, |
126
|
|
|
|
127
|
|
|
'lang' => $options['language_iso'] ? $options['language_iso'] : DEFAULT_LANG, |
128
|
|
|
'skin' => DEFAULT_SKIN_NAME, |
129
|
|
|
|
130
|
|
|
'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'], |
131
|
|
|
|
132
|
|
|
'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']), |
133
|
|
|
|
134
|
|
|
'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0), |
135
|
|
|
'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0), |
136
|
|
|
'planet' => $options['planet'] = intval($options['planet'] ? $options['planet'] : 0), |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
!empty($options['salt']) ? $field_set['salt'] = $options['salt'] : false; |
140
|
|
|
!empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; |
141
|
|
|
\DBAL\DbQuery::build()->setTable('users')->setValues($field_set)->doInsert(); |
142
|
|
|
$user_new = db_user_by_id(db_insert_id()); |
|
|
|
|
143
|
|
|
|
144
|
|
|
if(!($options['galaxy'] && $options['system'] && $options['planet'])) { |
145
|
|
|
$options['galaxy'] = $config->LastSettedGalaxyPos; |
146
|
|
|
$options['system'] = $config->LastSettedSystemPos; |
147
|
|
|
$segment_size = floor($config->game_maxPlanet / 3); |
148
|
|
|
$segment = floor($config->LastSettedPlanetPos / $segment_size); |
149
|
|
|
$segment++; |
150
|
|
|
$options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
151
|
|
|
|
152
|
|
|
while(true) { |
153
|
|
|
if($options['planet'] > $config->game_maxPlanet) { |
154
|
|
|
$options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
155
|
|
|
$options['system']++; |
156
|
|
|
} |
157
|
|
|
if($options['system'] > $config->game_maxSystem) { |
158
|
|
|
$options['system'] = 1; |
159
|
|
|
$options['galaxy']++; |
160
|
|
|
} |
161
|
|
|
$options['galaxy'] > $config->game_maxGalaxy ? $options['galaxy'] = 1 : false; |
162
|
|
|
|
163
|
|
|
$galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); |
164
|
|
|
if(!$galaxy_row['id']) { |
165
|
|
|
$config->db_saveItem(array( |
166
|
|
|
'LastSettedGalaxyPos' => $options['galaxy'], |
167
|
|
|
'LastSettedSystemPos' => $options['system'], |
168
|
|
|
'LastSettedPlanetPos' => $options['planet'], |
169
|
|
|
)); |
170
|
|
|
break; |
171
|
|
|
} |
172
|
|
|
$options['planet'] += 3; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
$new_planet_id = uni_create_planet($options['galaxy'], $options['system'], $options['planet'], $user_new['id'], '', true, $options['planet_options']); |
176
|
|
|
|
177
|
|
|
db_user_set_by_id($user_new['id'], |
|
|
|
|
178
|
|
|
"`id_planet` = '{$new_planet_id}', `current_planet` = '{$new_planet_id}', |
179
|
|
|
`galaxy` = '{$options['galaxy']}', `system` = '{$options['system']}', `planet` = '{$options['planet']}'" |
180
|
|
|
); |
181
|
|
|
|
182
|
|
|
$config->db_saveItem('users_amount', $config->users_amount + 1); |
183
|
|
|
|
184
|
|
|
$username_safe = db_escape($username_unsafe); |
185
|
|
|
doquery("REPLACE INTO {{player_name_history}} SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'"); |
186
|
|
|
|
187
|
|
|
if(!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
|
|
|
188
|
|
|
doquery("INSERT INTO {{referrals}} SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}"); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
sys_player_new_adjust($user_new['id'], $new_planet_id); |
192
|
|
|
|
193
|
|
|
return $result = db_user_by_id($user_new['id']); |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state