Issues (1020)

Security Analysis    no vulnerabilities found

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

models/Item.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @property integer $id
4
 * @property string $item_type
5
 * @property integer $skill
6
 * @property integer $level
7
 * @property string $title
8
 * @property integer $price
9
 * @property integer $price_sell
10
 * @property integer $owned
11
 * @property integer $buy_amount
12
 * @property integer $sell_amount
13
 * @property array $errors
14
 * @property boolean $success
15
 */
16
class Item extends CModel
17
{
18
    const TYPE_BAIT = 'bait';
19
    const TYPE_ITEM = 'item';
20
    const TYPE_ITEMSET = 'itemset';
21
    const TYPE_PART = 'part';
22
23
    private $id;
24
    private $item_type;
25
    private $skill;
26
    private $level;
27
    private $title;
28
    private $price;
29
    private $parts;
30
    private $owned;
31
    private $buy_amount = [];
32
    private $sell_amount = [];
33
34
    private $errors = ['dollar'=>false, 'amount'=>false, 'owned'=>false, 'isLast'=>false, 'freeSlots'=>false];
35
    private $success;
36
37
    public function attributeNames()
38
    {
39
        return [];
40
    }
41
42
    public function getId()
43
    {
44
        return $this->id;
45
    }
46
47
    public function getItem_type()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
48
    {
49
        return $this->item_type;
50
    }
51
52
    public function getSkill()
53
    {
54
        return $this->skill;
55
    }
56
57
    public function getLevel()
58
    {
59
        return $this->level;
60
    }
61
62
    public function getTitle()
63
    {
64
        return $this->title;
65
    }
66
67
    public function getPrice()
68
    {
69
        return $this->price;
70
    }
71
72
    public function getPrice_sell()
73
    {
74
        return floor($this->price / 2);
75
    }
76
77
    public function getOwned()
78
    {
79
        return $this->owned;
80
    }
81
82
    public function getBuy_amount()
83
    {
84
        return $this->buy_amount;
85
    }
86
87
    public function getSell_amount()
88
    {
89
        return $this->sell_amount;
90
    }
91
92
    public function getErrors($attribute = NULL)
93
    {
94
        return $this->errors;
95
    }
96
97
    public function getSuccess()
98
    {
99
        return $this->success;
100
    }
101
102
    public function setId($id)
103
    {
104
        $this->id = (int)$id;
105
    }
106
107
    public function setItem_type($type)
108
    {
109
        $this->item_type = $type;
110
    }
111
112
    public function setOwned($owned)
113
    {
114
        $this->owned = (int)$owned;
115
    }
116
117
    public function fetch()
118
    {
119
        if (!$this->id) {
120
            return false;
121
        }
122
123
        $uid = Yii::app()->player->uid;
124
125
        //read all from db
126
        $dependency = new CExpressionDependency("Yii::app()->params['{$this->item_type}s_version']");
127
        $res = Yii::app()->db->cache(Yii::app()->params['cacheDuration'], $dependency)->createCommand()
128
            ->select('*')
129
            ->from($this->item_type.'s')
130
            ->where('id=:id', [':id'=>$this->id])
131
            ->queryRow();
132
133
        if (!$res) {
134
            return false;
135
        }
136
137
        foreach ($res as $k => $v) {
138
            if ($k == 'id') {
139
                continue;
140
            }
141
142
            $this->$k = $v;
143
        }
144
145
        $own = Yii::app()->db->createCommand()
146
            ->select('item_count')
147
            ->from('users_'.$this->item_type.'s')
148
            ->where('uid=:uid and item_id=:item_id', [':uid'=>$uid, ':item_id'=>$this->id])
149
            ->queryRow();
150
        $this->owned = (int)$own['item_count'];
151
152
        $this->setBuyAmount();
153
        $this->setSellAmount();
154
    }
155
156
    public function fetchSet()
157
    {
158
        if (!$this->id) {
159
            return false;
160
        }
161
162
        $uid = Yii::app()->player->uid;
163
164
        $combinedId = (string)$this->id;
165
        $setId = (int)substr($combinedId, 0, -3);
166
        $this->level = (int)substr($combinedId, -3);
167
168
169
        //read all from db
170
        $dependency = new CExpressionDependency("Yii::app()->params['{$this->item_type}s_version']");
171
        $res = Yii::app()->db->cache(Yii::app()->params['cacheDuration'], $dependency)->createCommand()
172
            ->select('*')
173
            ->from('itemsets')
174
            ->where('id=:id', [':id'=>$setId])
175
            ->queryRow();
176
177
        if (!$res) {
178
            return false;
179
        }
180
181
        foreach ($res as $k => $v) {
182
            if ($k == 'id') {
183
                continue;
184
            }
185
186
            $this->$k = $v;
187
        }
188
189
        $own = Yii::app()->db->createCommand()
190
            ->select('skill, item_count, price')
191
            ->from('users_items')
192
            ->where('uid=:uid and item_id=:item_id', [':uid'=>$uid, ':item_id'=>$this->id])
193
            ->queryRow();
194
        $this->owned = (int)$own['item_count'];
195
196
        //read skill from users tbl
197
        $this->title = $this->level . '. szintű ' . $this->title;
198
        $this->skill = (int)$own['skill'];
199
        $this->price = (int)$own['price'];
200
        $this->level = 1;
201
202
        $this->setBuyAmount();
203
        $this->setSellAmount();
204
    }
205
206
    /**
207
     * @param integer $amount
208
     */
209
    public function buy($amount)
210
    {
211
        $decr = [];
212
        $amount = (int)$amount;
213
        if ($amount < 1) {
214
            $this->errors['amount'] = true;
215
            return false;
216
        }
217
218 View Code Duplication
        if ($this->price * $amount > Yii::app()->player->model->dollar) {
219
            $this->errors['dollar'] = true;
220
            return false;
221
        }
222
223 View Code Duplication
        if ($this->item_type !== self::TYPE_PART) {
224
            if ($amount > Yii::app()->player->model->freeSlots) {
225
                $this->errors['freeSlots'] = true;
226
                return false;
227
            }
228
        }
229
230
        $uid = Yii::app()->player->uid;
231
232
        //add to inventory
233
        $update = Yii::app()->db
234
            ->createCommand("UPDATE users_{$this->item_type}s SET item_count=item_count+:amount WHERE uid=:uid AND item_id=:item_id")
235
            ->bindValues([':uid'=>$uid, ':item_id'=>(int)$this->id, ':amount'=>$amount])
236
            ->execute();
237
238 View Code Duplication
        if (!$update) {
239
            Yii::app()->db->createCommand()
240
                ->insert('users_'.$this->item_type.'s', [
241
                'uid'=>$uid,
242
                'item_id'=>(int)$this->id,
243
                'item_count'=>$amount,
244
                'skill'=>(int)$this->skill,
245
                ]);
246
        }
247
248
        //pay for it
249
        if ($this->price > 0) {
250
            $decr['dollar'] = $amount * $this->price;
251
            Yii::app()->player->model->updateAttributes([], $decr);
252
        }
253
254
        $this->success = true;
255
        $this->owned += $amount;
256
        $this->setBuyAmount();
257
    }
258
259
    public function sell($amount)
260
    {
261
        $incr = [];
262
        $amount = (int)$amount;
263
        if ($amount < 1) {
264
            $this->errors['amount'] = true;
265
            return false;
266
        }
267
268
        if ($this->owned < $amount) {
269
            $this->errors['owned'] = true;
270
            return false;
271
        }
272
273
        $player = Yii::app()->player->model;
274
275
        $owned = $this->item_type == self::TYPE_BAIT ? $player->owned_baits : $player->owned_items;
276
        if ($owned == 1) {
277
            $this->errors['isLast'] = true;
278
            return false;
279
        }
280
281
        //remove from inventory
282
        Yii::app()->db
283
            ->createCommand("UPDATE users_{$this->item_type}s SET item_count=item_count-:amount WHERE uid=:uid AND item_id=:item_id")
284
            ->bindValues([':uid'=>$player->uid, 'item_id'=>(int)$this->id, ':amount'=>$amount])
285
            ->execute();
286
287
        //give money for it
288
        $incr['dollar'] = $amount * $this->price_sell;
289
        Yii::app()->player->model->updateAttributes($incr, []);
290
291
        $this->success = true;
292
        $this->owned -= $amount;
293
        $this->setSellAmount();
294
295
    }
296
297
    private function setBuyAmount()
298
    {
299
        foreach ([1,5,10] as $amount) {
300
            $this->buy_amount[$amount] = (bool)($this->price * $amount <= Yii::app()->player->model->dollar);
301
        }
302
    }
303
304
    private function setSellAmount()
305
    {
306
        foreach ([1,5,10] as $amount) {
307
            $this->sell_amount[$amount] = (bool)($this->owned >= $amount);
308
        }
309
    }
310
311
    public function __toString()
312
    {
313
        $attributes = ['id','item_type','skill','level','price','title','owned'];
314
        $ret = '';
315
        foreach ($attributes as $attribute) {
316
            $ret .= $attribute . ': ' . $this->$attribute . "\n";
317
        }
318
        return $ret;
319
    }
320
}
321