Issues (1369)

includes/functions/sys_user.php (13 issues)

1
<?php
2
3
use DBAL\db_mysql;
4
use Planet\DBStaticPlanet;
5
6
/**
7
 * Created by PhpStorm.
8
 * User: Gorlum
9
 * Date: 17.04.2015
10
 * Time: 6:37
11
 */
12
13
function sys_user_vacation($user) {
14
  global $config;
15
16
  if (sys_get_param_str('vacation') == 'leave') {
17
    if ($user['vacation'] < SN_TIME_NOW) {
18
      $user['vacation']      = 0;
19
      $user['vacation_next'] = SN_TIME_NOW + $config->player_vacation_timeout;
20
      db_user_set_by_id($user['id'], "`vacation` = {$user['vacation']}, `vacation_next` = {$user['vacation_next']}");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

20
      /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], "`vacation` = {$user['vacation']}, `vacation_next` = {$user['vacation_next']}");
Loading history...
21
    }
22
  }
23
24
  if ($user['vacation']) {
25
    // sn_sys_logout(false, true);
26
    // core_auth::logout(false, true);
27
28
    $template = SnTemplate::gettemplate('vacation', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
    $template = SnTemplate::gettemplate('vacation', /** @scrutinizer ignore-type */ true);
Loading history...
29
30
    $template->assign_vars(array(
31
      'MENU'   => false,
32
      'NAVBAR' => false,
33
34
      'NAME'         => $user['username'],
35
      'VACATION_END' => date(FMT_DATE_TIME, $user['vacation']),
36
      'CAN_LEAVE'    => $user['vacation'] <= SN_TIME_NOW,
37
      'RANDOM'       => mt_rand(1, 2),
38
    ));
39
40
    SnTemplate::display($template);
41
  }
42
43
  return false;
44
}
45
46
function sys_is_multiaccount($user1, $user2) {
47
  global $config;
48
49
  return $user1['user_lastip'] == $user2['user_lastip'] && !$config->game_multiaccount_enabled;
50
}
51
52
/**
53
 * @param        $banner
54
 * @param        $banned
55
 * @param        $term
56
 * @param bool   $is_vacation
57
 * @param string $reason
58
 */
59
function sys_admin_player_ban($banner, $banned, $term, $is_vacation = true, $reason = '') {
60
  $ban_current = db_user_by_id($banned['id'], false);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

60
  $ban_current = /** @scrutinizer ignore-deprecated */ db_user_by_id($banned['id'], false);
Loading history...
61
  $ban_until   = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term;
62
63
  db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

63
  /** @scrutinizer ignore-deprecated */ db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
Loading history...
64
65
  $banned['username'] = SN::$db->db_escape($banned['username']);
66
  $banner['username'] = SN::$db->db_escape($banner['username']);
67
  doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

67
  /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
68
    "INSERT INTO
69
      `{{banned}}`
70
    SET
71
      `ban_user_id` = '{$banned['id']}',
72
      `ban_user_name` = '{$banned['username']}',
73
      `ban_reason` = '{$reason}',
74
      `ban_time` = " . SN_TIME_NOW . ",
75
      `ban_until` = {$ban_until},
76
      `ban_issuer_id` = '{$banner['id']}',
77
      `ban_issuer_name` = '{$banner['username']}',
78
      `ban_issuer_email` = '{$banner['email']}'
79
  ");
80
81
  DBStaticPlanet::db_planet_set_by_owner($banned['id'],
82
    "`metal_mine_porcent` = 0, `crystal_mine_porcent` = 0, `deuterium_sintetizer_porcent` = 0, `solar_plant_porcent` = 0,
83
    `fusion_plant_porcent` = 0, `solar_satelit_porcent` = 0, `ship_sattelite_sloth_porcent` = 0"
84
  );
85
}
86
87
/**
88
 * @param        $banner
89
 * @param        $banned
90
 * @param string $reason
91
 */
92
function sys_admin_player_ban_unset($banner, $banned, $reason = '') {
93
  db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . "");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

93
  /** @scrutinizer ignore-deprecated */ db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . "");
Loading history...
94
95
  $banned['username'] = SN::$db->db_escape($banned['username']);
96
  $banner['username'] = SN::$db->db_escape($banner['username']);
97
  $reason             = SN::$db->db_escape($reason);
98
  doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
  /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
99
    "INSERT INTO `{{banned}}`
100
    SET
101
      `ban_user_id` = '{$banned['id']}',
102
      `ban_user_name` = '{$banned['username']}',
103
      `ban_reason` = '{$reason}',
104
      `ban_time` = 0,
105
      `ban_until` = " . SN_TIME_NOW . ",
106
      `ban_issuer_id` = '{$banner['id']}',
107
      `ban_issuer_name` = '{$banner['username']}',
108
      `ban_issuer_email` = '{$banner['email']}'
109
  ");
110
}
111
112
/**
113
 * @param string $username_unsafe
114
 * @param string $email_unsafe
115
 * @param array  $options
116
 *   [
117
 *   'user_bot'                 => (int),
118
 *   'total_points'             => (float),
119
 *   'language_iso'             => (string),
120
 *   'options'                  => (string),
121
 *   'options_extra'            => (string),
122
 *   'salt'                     => (string),
123
 *   'password_encoded_unsafe'  => md5(string),
124
 *   'partner_id'               => (id),
125
 *   'galaxy'                   => (int),
126
 *   'system'                   => (int),
127
 *   'planet'                   => (int),
128
 *   'planet_options'           => (array),
129
 *   ]
130
 *
131
 * @return array|false
132
 */
133
function player_create($username_unsafe, $email_unsafe, $options) {
134
  db_mysql::db_transaction_check(true);
135
136
  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|';
137
138
  empty($options['planet_options']) ? $options['planet_options'] = [] : false;
139
140
  $field_set = array(
141
    'server_name'   => SN_ROOT_VIRTUAL,
142
    'register_time' => SN_TIME_NOW,
143
    'news_lastread' => SN_TIME_NOW,
144
    'user_bot'      => $options['user_bot'] = empty($options['user_bot']) ? USER_BOT_PLAYER : $options['user_bot'],
145
146
    'username' => $username_unsafe,
147
    'email'    => $email_unsafe,
148
    'email_2'  => $email_unsafe,
149
150
    'lang' => $options['language_iso'] ? $options['language_iso'] : DEFAULT_LANG,
151
    'skin' => DEFAULT_SKIN_NAME,
152
153
    'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'],
154
155
    'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']),
156
157
    'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0),
158
    'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0),
159
    'planet' => $options['planet'] = intval($options['planet'] ? $options['planet'] : 0),
160
  );
161
162
  !empty($options['salt']) ? $field_set['salt'] = $options['salt'] : false;
163
  !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false;
164
  \DBAL\DbQuery::build()->setTable('users')->setValues($field_set)->doInsert();
165
  $user_new = db_user_by_id(SN::$db->db_insert_id());
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

165
  $user_new = /** @scrutinizer ignore-deprecated */ db_user_by_id(SN::$db->db_insert_id());
Loading history...
166
167
  if (!($options['galaxy'] && $options['system'] && $options['planet'])) {
168
    $options['galaxy'] = SN::$config->LastSettedGalaxyPos;
169
    $options['system'] = SN::$config->LastSettedSystemPos;
170
    $segment_size      = floor(SN::$config->game_maxPlanet / 3);
171
    $segment           = floor(SN::$config->LastSettedPlanetPos / $segment_size);
172
    $segment++;
173
    $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size);
174
175
    while (true) {
176
      if ($options['planet'] > SN::$config->game_maxPlanet) {
177
        $options['planet'] = mt_rand(0, $segment_size - 1) + 1;
178
        $options['system']++;
179
      }
180
      if ($options['system'] > SN::$config->game_maxSystem) {
181
        $options['system'] = 1;
182
        $options['galaxy']++;
183
      }
184
      $options['galaxy'] > SN::$config->game_maxGalaxy ? $options['galaxy'] = 1 : false;
185
186
      $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET);
187
      if (!$galaxy_row['id']) {
188
        SN::$config->db_saveItem(array(
189
          'LastSettedGalaxyPos' => $options['galaxy'],
190
          'LastSettedSystemPos' => $options['system'],
191
          'LastSettedPlanetPos' => $options['planet'],
192
        ));
193
        break;
194
      }
195
      $options['planet'] += 3;
196
    }
197
  }
198
  $new_planet_id = uni_create_planet($options['galaxy'], $options['system'], $options['planet'], $user_new['id'], '', true, $options['planet_options']);
199
200
  db_user_set_by_id($user_new['id'],
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

200
  /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user_new['id'],
Loading history...
201
    "`id_planet` = '{$new_planet_id}', `current_planet` = '{$new_planet_id}',
202
    `galaxy` = '{$options['galaxy']}', `system` = '{$options['system']}', `planet` = '{$options['planet']}'"
203
  );
204
205
  $username_safe = SN::$db->db_escape($username_unsafe);
206
  doquery("REPLACE INTO `{{player_name_history}}` SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

206
  /** @scrutinizer ignore-deprecated */ doquery("REPLACE INTO `{{player_name_history}}` SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'");
Loading history...
207
208
  if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) {
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

208
  if (!empty($options['partner_id']) && ($referral_row = /** @scrutinizer ignore-deprecated */ db_user_by_id($options['partner_id'], true))) {
Loading history...
209
    doquery("INSERT INTO `{{referrals}}` SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

209
    /** @scrutinizer ignore-deprecated */ doquery("INSERT INTO `{{referrals}}` SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}");
Loading history...
210
  }
211
212
  sys_player_new_adjust($user_new['id'], $new_planet_id);
213
214
  dbUpdateUsersCount(SN::$config->pass()->users_amount + 1);
215
216
  return $result = db_user_by_id($user_new['id']);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

216
  return $result = /** @scrutinizer ignore-deprecated */ db_user_by_id($user_new['id']);
Loading history...
217
}
218