Completed
Push — work-fleets ( c94fa6...bf14b2 )
by SuperNova.WS
06:23
created

sys_user.php ➔ sys_admin_player_ban()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 3
eloc 23
c 3
b 1
f 0
nc 2
nop 5
dl 0
loc 30
rs 8.8571
1
<?php
2
3
/**
4
 * Created by Gorlum 17.04.2015 6:37
5
 */
6
7
use Vector\Vector;
8
9
function sys_user_vacation($user) {
10
  if(sys_get_param_str('vacation') == 'leave') {
11
    if ($user['vacation'] < SN_TIME_NOW) {
12
      $user['vacation'] = 0;
13
      $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout;
14
      DBStaticUser::db_user_set_by_id_DEPRECATED($user['id'], "`vacation` = {$user['vacation']}, `vacation_next` = {$user['vacation_next']}");
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
15
    }
16
  }
17
18
  if($user['vacation']) {
19
    // sn_sys_logout(false, true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
    // core_auth::logout(false, true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
22
    $template = gettemplate('vacation', true);
23
24
    $template->assign_vars(array(
25
      'NAME' => $user['username'],
26
      'VACATION_END' => date(FMT_DATE_TIME, $user['vacation']),
27
      'CAN_LEAVE' => $user['vacation'] <= SN_TIME_NOW,
28
      'RANDOM' => mt_rand(1, 2),
29
    ));
30
31
    display(parsetemplate($template), '', false, '', false, false);
32
  }
33
34
  return false;
35
}
36
37
function sys_is_multiaccount($user1, $user2) {
38
  return $user1['id'] != $user2['id'] && $user1['user_lastip'] == $user2['user_lastip'] && !classSupernova::$config->game_multiaccount_enabled;
39
}
40
41
/**
42
 * @param $UserID
43
 */
44
function DeleteSelectedUser($UserID) {
45
  // TODO: Full rewrite
46
  sn_db_transaction_start();
47
  $TheUser = DBStaticUser::db_user_by_id($UserID);
48
  if ( $TheUser['ally_id'] != 0 ) {
49
    $TheAlly = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';");
50
    $TheAlly['ally_members'] -= 1;
51
    if ( $TheAlly['ally_members'] > 0 ) {
52
      classSupernova::$db->doUpdateRowSet(
53
        TABLE_ALLIANCE,
54
        array(
55
          'ally_members' => $TheAlly['ally_members'],
56
        ),
57
        array(
58
          'id' => $TheAlly['id'],
59
        )
60
      );
61
    } else {
62
      classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE, array('id' => $TheAlly['id'],));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
63
      classSupernova::$gc->db->doDeleteWhere(TABLE_STAT_POINTS, array('stat_type' => STAT_TYPE_ALLY, 'id_owner' => $TheAlly['id'],));
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
64
    }
65
  }
66
  classSupernova::$gc->db->doDeleteWhere(TABLE_STAT_POINTS, array('stat_type' => STAT_TYPE_USER, 'id_owner' => $UserID,));
67
68
  DBStaticPlanet::db_planet_list_delete_by_owner($UserID);
69
70
  classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_owner' => $UserID,));
71
  classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_sender' => $UserID,));
72
  classSupernova::$gc->db->doDeleteWhere(TABLE_NOTES, array('owner' => $UserID ,));
73
  FleetList::db_fleet_list_delete_by_owner($UserID);
74
  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_SENDER_ID' => $UserID ,));
75
  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_OWNER_ID' => $UserID ,));
76
77
78
  classSupernova::$gc->cacheOperator->db_del_record_by_id(LOC_USER, $UserID);
0 ignored issues
show
Bug introduced by
The method db_del_record_by_id does only exist in SnDbCachedOperator, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
79
  classSupernova::$db->doDeleteWhere(TABLE_REFERRALS, array('id' => $UserID));
80
  classSupernova::$db->doDeleteWhere(TABLE_REFERRALS, array('id_partner' => $UserID));
81
  classSupernova::$config->db_saveItem('users_amount', classSupernova::$config->db_loadItem('users_amount') - 1);
82
  sn_db_transaction_commit();
83
}
84
85
/**
86
 * @param        $banner
87
 * @param        $banned
88
 * @param        $term
89
 * @param bool   $is_vacation
90
 * @param string $reason_unsafe
91
 */
92
function sys_admin_player_ban($banner, $banned, $term, $is_vacation = true, $reason_unsafe = '') {
93
  $ban_current = DBStaticUser::db_user_by_id($banned['id'], false, 'banaday');
94
  $ban_until = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term;
95
96
  DBStaticUser::db_user_set_by_id_DEPRECATED($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
97
98
  classSupernova::$db->doInsertSet(TABLE_BANNED, array(
99
    'ban_user_id'      => $banned['id'],
100
    'ban_user_name'    => $banned['username'],
101
    'ban_reason'       => $reason_unsafe,
102
    'ban_time'         => SN_TIME_NOW,
103
    'ban_until'        => $ban_until,
104
    'ban_issuer_id'    => $banner['id'],
105
    'ban_issuer_name'  => $banner['username'],
106
    'ban_issuer_email' => $banner['email'],
107
  ));
108
109
  DBStaticPlanet::db_planet_set_by_owner(
110
    $banned['id'],
111
    array(
112
      'metal_mine_porcent'           => 0,
113
      'crystal_mine_porcent'         => 0,
114
      'deuterium_sintetizer_porcent' => 0,
115
      'solar_plant_porcent'          => 0,
116
      'fusion_plant_porcent'         => 0,
117
      'solar_satelit_porcent'        => 0,
118
      'ship_sattelite_sloth_porcent' => 0,
119
    )
120
  );
121
}
122
123
/**
124
 * @param        $banner
125
 * @param        $banned
126
 * @param string $reasonUnsafe
127
 */
128
function sys_admin_player_ban_unset($banner, $banned, $reasonUnsafe = '') {
129
  DBStaticUser::db_user_set_by_id_DEPRECATED($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . "");
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
130
131
  return classSupernova::$db->doInsertSet(TABLE_BANNED, array(
132
    'ban_user_id'      => $banned['id'],
133
    'ban_user_name'    => $banned['username'],
134
    'ban_reason'       => $reasonUnsafe,
135
    'ban_time'         => 0,
136
    'ban_until'        => SN_TIME_NOW,
137
    'ban_issuer_id'    => $banner['id'],
138
    'ban_issuer_name'  => $banner['username'],
139
    'ban_issuer_email' => $banner['email'],
140
  ));
141
}
142
143
function player_create($username_unsafe, $email_unsafe, $options) {
144
  sn_db_transaction_check(true);
145
146
  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|';
147
148
  empty($options['planet_options']) ? $options['planet_options'] = array() : false;
149
150
  $field_set = array(
151
    'server_name' => SN_ROOT_VIRTUAL,
152
    'register_time' => SN_TIME_NOW,
153
    'user_bot' => $options['user_bot'] = empty($options['user_bot']) ? USER_BOT_PLAYER : $options['total_points'],
154
155
    'username' => $username_unsafe,
156
    'email' => $email_unsafe,
157
    'email_2' => $email_unsafe,
158
159
    'lang' => $options['language_iso'] ? $options['language_iso'] : DEFAULT_LANG,
160
    'dpath' => DEFAULT_SKINPATH,
161
162
    'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'],
163
164
    'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']),
165
166
    'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0),
167
    'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0),
168
    'planet' => $options['planet'] = intval($options['planet'] ? $options['planet'] : 0),
169
  );
170
171
  !empty($options['salt']) ? $field_set['salt'] = $options['salt'] : false;
172
  !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false;
173
174
  $user_new = classSupernova::$gc->cacheOperator->db_ins_field_set(LOC_USER, $field_set);
0 ignored issues
show
Bug introduced by
The method db_ins_field_set does only exist in SnDbCachedOperator, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
175
  if(!($options['galaxy'] && $options['system'] && $options['planet'])) {
176
    $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos;
177
    $options['system'] = classSupernova::$config->LastSettedSystemPos;
178
    $segment_size = floor(Vector::$knownPlanets/ 3);
179
    $segment = floor(classSupernova::$config->LastSettedPlanetPos / $segment_size);
180
    $segment++;
181
    $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size);
182
183
    // $new_planet_id = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
184
    while(true) {
185
      if($options['planet'] > Vector::$knownPlanets) {
186
        $options['planet'] = mt_rand(0, $segment_size - 1) + 1;
187
        $options['system']++;
188
      }
189
      if($options['system'] > Vector::$knownSystems) {
190
        $options['system'] = 1;
191
        $options['galaxy']++;
192
      }
193
      $options['galaxy'] > Vector::$knownGalaxies? $options['galaxy'] = 1 : false;
194
195
      $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id');
196
      if(!$galaxy_row['id']) {
197
        classSupernova::$config->db_saveItem(array(
198
          'LastSettedGalaxyPos' => $options['galaxy'],
199
          'LastSettedSystemPos' => $options['system'],
200
          'LastSettedPlanetPos' => $options['planet'],
201
        ));
202
        break;
203
      }
204
      $options['planet'] += 3;
205
    }
206
  }
207
  $new_planet_id = uni_create_planet($options['galaxy'], $options['system'], $options['planet'], $user_new['id'], classLocale::$lang['sys_capital'], true, $options['planet_options']);
208
209
  DBStaticUser::db_user_set_by_id_DEPRECATED($user_new['id'],
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
210
    "`id_planet` = '{$new_planet_id}', `current_planet` = '{$new_planet_id}',
211
    `galaxy` = '{$options['galaxy']}', `system` = '{$options['system']}', `planet` = '{$options['planet']}'"
212
  );
213
214
  classSupernova::$config->db_saveItem('users_amount', classSupernova::$config->users_amount + 1);
215
216
  db_player_name_history_replace($user_new['id'], $username_unsafe);
217
218
  if(!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) {
219
    db_referral_insert($options['partner_id'], $user_new['id']);
220
  }
221
222
  sys_player_new_adjust($user_new['id'], $new_planet_id);
223
224
  return $result = DBStaticUser::db_user_by_id($user_new['id']);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
225
}
226