Merge lp:~mcflypl/vallheru/vallheru into lp:vallheru

Proposed by McFly on 2012-09-08
Status: Needs review
Proposed branch: lp:~mcflypl/vallheru/vallheru
Merge into: lp:vallheru
Diff against target: 419 lines (+215/-183)
1 file modified
class/player_class.php (+215/-183)
To merge this branch: bzr merge lp:~mcflypl/vallheru/vallheru
Reviewer Review Type Date Requested Status
Bartek Jasicki 2012-09-08 Needs Fixing on 2012-09-10
Review via email: mp+123408@code.launchpad.net

This proposal supersedes a proposal from 2012-09-07.

Description of the change

Poprawiłem błąd z kategoriami forum (kolejna niezgodność nazw forumtime w kodzie i forum_time w bazie - będzie trzeba te wszystkie konflikty popoprawiać). Zmieniłem także komentarze na angielskie.

To post a comment you must log in.
Bartek Jasicki (thindil) wrote : Posted in a previous version of this proposal

Na razie pojawia się problem z kompatybilnością:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND `cat_id` IN(1,2,3)' at line 1

Błąd dotyczy braku odczytu ustawień dotyczących śledzenia forum (z tego co pamiętam). Plus nie jestem pewien czy ta zmienna dotycząca możliwości edycji jest wymagana. Nie prościej zrobić taką zmienną typu protected (czy jak to tam się nazywa w PHP :) ).

review: Needs Fixing
Bartek Jasicki (thindil) wrote :

Znowu wyskakuje gdzieś błąd z zapytaniem do bazy danych. Tym razem już bez konkretnych informacji, obawiam się, że samemu trzeba to przeszukać :(

review: Needs Fixing
McFly (mcflypl) wrote :

w jakim miejscu, w jakiej sytuacji?

Bartek Jasicki (thindil) wrote :

W dniu 10 września 2012 12:24 użytkownik McFly <email address hidden> napisał:
> w jakim miejscu, w jakiej sytuacji?
> --
> https://code.launchpad.net/~mcflypl/vallheru/vallheru/+merge/123408
> You are reviewing the proposed merge of lp:~mcflypl/vallheru/vallheru into lp:vallheru.

No właśnie nie przyglądałem się temu. Mi to wyskakuje podczas
logowania, dalej nie idzie wszystko. Czyli pewnie znowu coś w pliku
head.php (pewnie jeszcze jakaś zmienna do naprawy). Najlepiej
przeszukać zapytania z die($db->ErrorMsg());

Unmerged revisions

1322. By McFly on 2012-09-08

rebuild player class

1321. By McFly on 2012-09-07

Rebuild player class

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'class/player_class.php'
2--- class/player_class.php 2012-09-04 09:19:29 +0000
3+++ class/player_class.php 2012-09-08 10:15:23 +0000
4@@ -6,8 +6,9 @@
5 * @name : player_class.php
6 * @copyright : (C) 2004,2005,2006,2007,2011,2012 Vallheru Team based on Gamers-Fusion ver 2.5
7 * @author : thindil <thindil@vallheru.net>
8+ * @author : McFly <http://mcfly.com.pl/>
9 * @version : 1.6
10- * @since : 04.09.2012
11+ * @since : 08.09.2012
12 *
13 */
14
15@@ -31,191 +32,222 @@
16
17 class Player
18 {
19- var $user;
20- var $id;
21- var $level;
22- var $exp;
23- var $hp;
24- var $max_hp;
25- var $mana;
26- var $energy;
27- var $max_energy;
28- var $credits;
29- var $bank;
30- var $platinum;
31- var $tribe;
32- var $rank;
33- var $location;
34- var $ap;
35- var $race;
36- var $clas;
37- var $agility;
38- var $strength;
39- var $inteli;
40- var $pw;
41- var $wins;
42- var $losses;
43- var $lastkilled;
44- var $lastkilledby;
45- var $age;
46- var $logins;
47- var $smith;
48- var $attack;
49- var $miss;
50- var $magic;
51- var $ip;
52- var $speed;
53- var $cond;
54- var $alchemy;
55- var $gg;
56- var $avatar;
57- var $wisdom;
58- var $shoot;
59- var $tribe_rank;
60- var $fletcher;
61- var $immunited;
62- var $corepass;
63- var $trains;
64- var $fight;
65- var $deity;
66- var $maps;
67- var $rest;
68- var $page;
69- var $profile;
70- var $crime;
71- var $gender;
72- var $leadership;
73- var $antidote;
74- var $breeding;
75- var $poll;
76- var $mining;
77- var $lumberjack;
78- var $herbalist;
79- var $jeweller;
80- var $vallars;
81- var $newbie;
82- var $thievery;
83- var $perception;
84- var $forumtime;
85- var $tforumtime;
86- var $metallurgy;
87- var $revent;
88- var $room;
89- var $oldstats;
90- var $settings;
91- var $changed;
92- var $chattimes;
93- /**
94- * Player equipment
95- */
96- var $equip;
97-/**
98-* Class constructor - get data from database and write it to variables
99-*/
100- function Player($pid)
101- {
102+ // 'field name' => (editing, type)
103+ private $_fields = array(
104+ 'id' => array(0, 'int'),
105+ 'user' => array(1, 'string'),
106+ 'email' => array(1, 'string'),
107+ 'rank' => array(1, 'string'),
108+ 'level' => array(1, 'int'),
109+ 'exp' => array(1, 'int'),
110+ 'credits' => array(1, 'int'),
111+ 'energy' => array(1, 'int'),
112+ 'max_energy' => array(1, 'int'),
113+ 'strength' => array(1, 'int'),
114+ 'agility' => array(1, 'int'),
115+ 'ap' => array(1, 'int'),
116+ 'wins' => array(1, 'int'),
117+ 'losses' => array(1, 'int'),
118+ 'lastkilled' => array(1, 'string'),
119+ 'lastkilledby' => array(1, 'string'),
120+ 'platinum' => array(1, 'int'),
121+ 'age' => array(1, 'int'),
122+ 'logins' => array(1, 'int'),
123+ 'hp' => array(1, 'int'),
124+ 'max_hp' => array(1, 'int'),
125+ 'bank' => array(1, 'int'),
126+ 'lpv' => array(1, 'int'),
127+ 'page' => array(1, 'string'),
128+ 'ip' => array(1, 'string'),
129+ 'ability' => array(1, 'int'),
130+ 'tribe' => array(1, 'int'),
131+ 'profile' => array(1, 'html'),
132+ 'refs' => array(1, 'int'),
133+ 'corepass' => array(1, 'string'),
134+ 'fight' => array(1, 'int'),
135+ 'trains' => array(1, 'int'),
136+ 'rasa' => array(1, 'string'),
137+ 'klasa' => array(1, 'string'),
138+ 'inteli' => array(1, 'int'),
139+ 'pw' => array(1, 'int'),
140+ 'atak' => array(1, 'int'),
141+ 'unik' => array(1, 'int'),
142+ 'magia' => array(1, 'int'),
143+ 'immu' => array(1, 'string'),
144+ 'pm' => array(1, 'int'),
145+ 'miejsce' => array(1, 'string'),
146+ 'szyb' => array(1, 'int'),
147+ 'wytrz' => array(1, 'int'),
148+ 'alchemia' => array(1, 'int'),
149+ 'gg' => array(1, 'string'),
150+ 'avatar' => array(1, 'string'),
151+ 'wisdom' => array(1, 'int'),
152+ 'shoot' => array(1, 'int'),
153+ 'tribe_rank' => array(1, 'string'),
154+ 'fletcher' => array(1, 'int'),
155+ 'deity' => array(1, 'string'),
156+ 'maps' => array(1, 'int'),
157+ 'rest' => array(1, 'string'),
158+ 'crime' => array(1, 'int'),
159+ 'gender' => array(1, 'string'),
160+ 'bridge' => array(1, 'string'),
161+ 'temp' => array(1, 'int'),
162+ 'leadership' => array(1, 'int'),
163+ 'forum_time' => array(1, 'int'),
164+ 'tforum_time' => array(1, 'int'),
165+ 'bless' => array(1, 'string'),
166+ 'blessval' => array(1, 'int'),
167+ 'antidote' => array(1, 'string'),
168+ 'freeze' => array(1, 'int'),
169+ 'breeding' => array(1, 'int'),
170+ 'houserest' => array(1, 'string'),
171+ 'poll' => array(1, 'string'),
172+ 'mining' => array(1, 'int'),
173+ 'lumberjack' => array(1, 'int'),
174+ 'herbalist' => array(1, 'int'),
175+ 'astralcrime' => array(1, 'string'),
176+ 'changedeity' => array(1, 'int'),
177+ 'jeweller' => array(1, 'int'),
178+ 'vallars' => array(1, 'int'),
179+ 'metallurgy' => array(1, 'int'),
180+ 'newbie' => array(1, 'int'),
181+ 'thievery' => array(1, 'int'),
182+ 'perception' => array(1, 'int'),
183+ 'roleplay' => array(1, 'string'),
184+ 'ooc' => array(1, 'string'),
185+ 'shortrpg' => array(1, 'string'),
186+ 'room' => array(1, 'string'),
187+ 'chattimes' => array(1, 'int'),
188+ 'settings' => array(1, 'string')
189+ );
190+
191+ /**
192+ * Class constructor - get data from database and write it to variables
193+ *
194+ * @param int $pid Player ID
195+ * @param array $fields Fields to get
196+ */
197+ public function __construct($pid, $fields=array()) {
198 global $db;
199- $pid = intval($pid);
200- $stats = $db -> Execute("SELECT * FROM `players` WHERE `id`=".$pid);
201- if ($stats -> fields['id'] != $pid)
202- {
203- return FALSE;
204- }
205- $this -> user = $stats -> fields['user'];
206- $this -> id = $stats -> fields['id'];
207- $this -> level = $stats -> fields['level'];
208- $this -> exp = $stats -> fields['exp'];
209- $this -> hp = $stats -> fields['hp'];
210- $this -> max_hp = $stats -> fields['max_hp'];
211- $this -> mana = $stats -> fields['pm'];
212- $this -> energy = $stats -> fields['energy'];
213- $this -> max_energy = $stats -> fields['max_energy'];
214- $this -> credits = $stats -> fields['credits'];
215- $this -> bank = $stats -> fields['bank'];
216- $this -> platinum = $stats -> fields['platinum'];
217- $this -> tribe = $stats -> fields['tribe'];
218- $this -> rank = $stats -> fields['rank'];
219- $this -> location = $stats -> fields['miejsce'];
220- $this -> ap = $stats -> fields['ap'];
221- $this -> race = $stats -> fields['rasa'];
222- $this -> clas = $stats -> fields['klasa'];
223- $this -> agility = $stats -> fields['agility'];
224- $this -> strength = $stats -> fields['strength'];
225- $this -> inteli = $stats -> fields['inteli'];
226- $this -> pw = $stats -> fields['pw'];
227- $this -> wins = $stats -> fields['wins'];
228- $this -> losses = $stats -> fields['losses'];
229- $this -> lastkilled = $stats -> fields['lastkilled'];
230- $this -> lastkilledby = $stats -> fields['lastkilledby'];
231- $this -> age = $stats -> fields['age'];
232- $this -> logins = $stats -> fields['logins'];
233- $this -> smith = $stats -> fields['ability'];
234- $this -> attack = $stats -> fields['atak'];
235- $this -> miss = $stats -> fields['unik'];
236- $this -> magic = $stats -> fields['magia'];
237- $this -> ip = $stats -> fields['ip'];
238- $this -> speed = $stats -> fields['szyb'];
239- $this -> cond = $stats -> fields['wytrz'];
240- $this -> alchemy = $stats -> fields['alchemia'];
241- $this -> gg = $stats -> fields['gg'];
242- $this -> avatar = $stats -> fields['avatar'];
243- $this -> wisdom = $stats -> fields['wisdom'];
244- $this -> shoot = $stats -> fields['shoot'];
245- $this -> tribe_rank = $stats -> fields['tribe_rank'];
246- $this -> fletcher = $stats -> fields['fletcher'];
247- $this -> immunited = $stats -> fields['immu'];
248- $this -> corepass = $stats -> fields['corepass'];
249- $this -> trains = $stats -> fields['trains'];
250- $this -> fight = $stats -> fields['fight'];
251- $this -> deity = $stats -> fields['deity'];
252- $this -> maps = $stats -> fields['maps'];
253- $this -> rest = $stats -> fields['rest'];
254- $this -> page = $stats -> fields['page'];
255- $this -> profile = $stats -> fields['profile'];
256- $this -> crime = $stats -> fields['crime'];
257- $this -> gender = $stats -> fields['gender'];
258- $this -> leadership = $stats -> fields['leadership'];
259- if (!empty($stats -> fields['antidote']))
260- {
261- $this -> antidote = $stats -> fields['antidote']{0};
262- }
263- else
264- {
265- $this -> antidote = '';
266- }
267- $this -> breeding = $stats -> fields['breeding'];
268- $this -> poll = $stats -> fields['poll'];
269- $this -> mining = $stats -> fields['mining'];
270- $this -> lumberjack = $stats -> fields['lumberjack'];
271- $this -> herbalist = $stats -> fields['herbalist'];
272- $this -> jeweller = $stats -> fields['jeweller'];
273- $this->vallars = $stats->fields['vallars'];
274- $this->newbie = $stats->fields['newbie'];
275- $this->thievery = $stats->fields['thievery'];
276- $this->perception = $stats->fields['perception'];
277- $this->forumtime = $stats->fields['forum_time'];
278- $this->tforumtime = $stats->fields['tforum_time'];
279- $this->metallurgy = $stats->fields['metallurgy'];
280- $stats -> Close();
281- $objRevent = $db->Execute("SELECT `state` FROM `revent` WHERE `pid`=".$pid);
282- if (!$objRevent->fields['state'])
283- {
284- $this->revent = 0;
285- }
286- else
287- {
288- $this->revent = $objRevent->fields['state'];
289- }
290- $objRevent->Close();
291- $this->room = $stats->fields['room'];
292- $this->chattimes = $stats->fields['chattimes'];
293- $this->oldstats = array($this->agility, $this->strength, $this->inteli, $this->wisdom, $this->speed, $this->cond);
294- $this->settings = $this->toarray($stats->fields['settings']);
295- $this->equip = $this->equipment();
296- $this->curstats();
297+
298+ $arrFields = (is_array($fields) && !empty($fields)) ? $fields : $this->_fields;
299+ $strFields = '';
300+ foreach ($arrFields as $field => $value) {
301+ $strFields .= $field.', ';
302+ }
303+ if (empty($strFields))
304+ return false;
305+ $strFields = substr($strFields,0,-2); //delete last comma
306+
307+ $pid = intval($pid);
308+ $stats = $db->Execute('SELECT '.$strFields.' FROM `players` WHERE `id`='.$pid) or die($db->ErrorMsg());
309+ if (empty($stats->fields))
310+ return false;
311+
312+ foreach ($stats->fields as $field => $value) {
313+ switch ($this->_fields[$field][1]) {
314+ case 'int':
315+ $this->$field = (float)$value;
316+ break;
317+ case 'string':
318+ $this->$field = $value;
319+ break;
320+ case 'html':
321+ $this->$field = $value;
322+ break;
323+ case 'json':
324+ $this->$field = json_decode($value);
325+ break;
326+ }
327+ }
328+ $stats->Close();
329+
330+ /**
331+ * Compatibility
332+ */
333+ $this->mana = $this->pm;
334+ $this->location = $this->miejsce;
335+ $this->race = $this->rasa;
336+ $this->clas = $this->klasa;
337+ $this->smith = $this->ability;
338+ $this->miss = $this->unik;
339+ $this->magic = $this->magia;
340+ $this->speed = $this->szyb;
341+ $this->cond = $this->wytrz;
342+ $this->alchemy = $this->alchemia;
343+ $this->immunited = $this->immu;
344+ $this->antidote = (!empty($this->antidote)) ? $this->antidote{0} : NULL;
345+ $this->oldstats = array($this->agility, $this->strength, $this->inteli, $this->wisdom, $this->speed, $this->cond);
346+ $this->settings = $this->toarray($stats->fields['settings']);
347+ $this->forumtime = $this->forum_time;
348+
349+ $objRevent = $db->Execute('SELECT `state` FROM `revent` WHERE `pid`='.$pid);
350+ $this->revent = ($objRevent->fields['state']) ? $objRevent->fields['state'] : 0;
351+ $objRevent->Close();
352+
353+ /**
354+ * Player equipment
355+ */
356+ $this->equip = $this->equipment();
357+
358+ $this->curstats();
359 }
360+
361+ /**
362+ * Method to update fields in database
363+ *
364+ * @param array $fields
365+ * @param int $pid
366+ * @return bool
367+ */
368+ public function Update($fields, $pid=NULL)
369+ {
370+ global $db;
371+
372+ if (!is_array($fields))
373+ return false;
374+ $pid = (!empty($pid)) ? (int)$pid : $this->id;
375+
376+ $strUpdate = '';
377+ $i = 0;
378+ foreach ($fields as $field => $value)
379+ {
380+ if (isset($this->_fields[$field]) && $this->_fields[$field][0]) {
381+ switch ($this->_fields[$field][1])
382+ {
383+ case 'int':
384+ $value = (int)$value;
385+ $strUpdate .= '`'.$field.'`='.$value.', ';
386+ break;
387+ case 'string':
388+ $value = htmlspecialchars($value);
389+ $strUpdate .= '`'.$field.'`=\''.$value.'\', ';
390+ break;
391+ case 'html':
392+ $value = addslashes($value);
393+ $strUpdate .= '`'.$field.'`=\''.$value.'\', ';
394+ break;
395+ case 'json':
396+ $value = json_encode($value);
397+ $strUpdate .= '`'.$field.'`=\''.$value.'\', ';
398+ break;
399+ }
400+ $this->$field = $value;
401+ $i++;
402+ }
403+ }
404+ if (!empty($strUpdate))
405+ {
406+ $strUpdate = substr($strUpdate,0,-2); //usuwa ostatni przecinek
407+ $db->Execute('UPDATE `players` SET '.$strUpdate.' WHERE `id`='.$pid) or die($db->ErrorMsg());
408+
409+ return true;
410+ }
411+ else
412+ return false;
413+ }
414
415- /**
416+ /**
417 * Function convert string value to array
418 */
419 function toarray($strValue)

Subscribers

People subscribed via source and target branches

to status/vote changes: