· 8 years ago · Jun 12, 2018, 03:52 PM
1<?php
2if(INCLUDED!==true)exit;
3
4// ==================== //
5$pathway_info[] = array('title'=>$lang['charcreate'],'link'=>'');
6// ==================== //
7
8$account_id = $user['id'];
9$rid = $user['cur_selected_realmd'];
10$char_points = (int)$MW->getConfig->character_copy_config->points;
11$get_your_points = $DB->select("SELECT `points_earned`, `points_spent` FROM `voting_points` WHERE id=?d",$account_id);
12foreach ($get_your_points as $row)
13 {
14 $your_points = ($row["points_earned"] - $row["points_spent"]);
15 }
16
17if($user['id'] > 0){
18/*************** START LEVLEUP ACTION ****************/
19 if(!$_GET['action'])
20 {
21 $profile = $auth->getprofile($user['id']);
22 $profile['signature'] = str_replace('<br />','',$profile['signature']);
23 }
24 elseif($_GET['action']=='createchar'){
25 $MANG = new Mangos;
26 //Post declare:
27 $class =& $_POST["createchar_class"]; //used only as a check to see if it exists
28 $faction =& $_POST["createchar_faction"]; //used only as a check to see if it exists
29 $character_copy_to = $_POST["character_copy_char"];
30 //Main Declare.....
31 $name = $checknamestring = ucfirst(strtolower(escape_string($_POST['createchar_name'])));
32 $loggedin = 0;
33
34 // Current ID + 1
35
36 $new_guid = $MANG->mangos_newguid('character');
37 $guid = $new_guid['new_guid'];
38 $WE_DID_OFFSET_ID = $new_guid['incr'];
39
40 //Checks if wanted name exsits.
41 $name_check = $CHDB->selectCell("SELECT guid from `characters` WHERE name='".$name."'");
42 if ($name_check == FALSE){
43 $classexists = false;
44 }else{
45 $classexists = true;
46 }
47
48
49 //Checks if user is logged on
50 $loggedin = $DB->selectCell("SELECT online FROM account WHERE id=?d",$account_id);
51 //Another check if user is logged on.
52 if ($loggedin == '0'){
53 $loggedin = $CHDB->selectCell("SELECT online FROM `characters` WHERE account=?d",$account_id);
54 }
55 //Checks if user has MAX players.
56 $numchars = $DB->selectCell("SELECT numchars FROM realmcharacters WHERE acctid=?d AND realmid=?d",$account_id,$rid);
57
58
59 /******** FORM CHECKS ********/
60 if ($class == false){}
61 elseif ($faction == false){}
62 elseif ($classexists == true)
63 {
64 output_message('alert','<b>'.$lang['charcreate_nameinuse'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="3;url=index.php?n=account&sub=charcreate">');
65 }
66 elseif ($name == false)
67 {
68 output_message('alert','<b>'.$lang['charcreate_invalidname'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="3;url=index.php?n=account&sub=charcreate">');
69 }
70 elseif ($loggedin == 1)
71 {
72 output_message('alert','<b>'.$lang['charcreate_loggedin'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="3;url=index.php?n=account&sub=charcreate">');
73 }
74 elseif(check_for_symbols($checknamestring,1) == TRUE)
75 {
76 output_message('alert','<b>'.$lang['charcreate_nameissymbols'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="3;url=index.php?n=account&sub=charcreate">');
77 }
78 elseif($numchars == 9)
79 {
80 output_message('alert','<b>'.$lang['charcreate_tomanychars'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="3;url=index.php?n=account&sub=charcreate">');
81 }
82 else
83 {
84 //Here is the main section for character creation. You define your values.
85 // You create a character in-game, look up the ID in character table.
86
87 /******************* MAIN COPY ******************/
88 // Tables wich is going to be copied.
89 #character
90 #character_action
91 #character_homebind
92 #character_inventory
93 #character_reputation
94 #character_skills
95 #character_spell
96 #item_instance
97
98
99 /* Make array's From copy char */
100 /*Character*/
101 $COPY_character = $CHDB->selectRow("SELECT * FROM `characters` WHERE guid=?d",$character_copy_to);
102 /*`character_action` */
103 $COPY_character_action = $CHDB->select("SELECT * FROM `character_action` WHERE guid=?d",$character_copy_to);
104 /*`character_homebind` */
105 $COPY_character_homebind = $CHDB->select("SELECT * FROM `character_homebind` WHERE guid=?d",$character_copy_to);
106 /*`character_reputation` */
107 $COPY_character_reputation = $CHDB->select("SELECT * FROM `character_reputation` WHERE guid=?d",$character_copy_to);
108 /*`character_skills` */
109 $COPY_character_skills = $CHDB->select("SELECT * FROM `character_skills` WHERE guid=?d",$character_copy_to);
110 /*`character_spell` */
111 $COPY_character_spell = $CHDB->select("SELECT * FROM `character_spell` WHERE guid=?d",$character_copy_to);
112
113 /*``character_inventory` ` */ /* Also ``item_instance``*/
114 $MAIN_COPY_item_instance = $CHDB->select("SELECT * FROM `item_instance` WHERE owner_guid=?d",$character_copy_to);
115 $ROUNDS = 0;
116 $ARRAY_INCREMENT = 0;
117 $ARRAY_BAG_INCREMENT = 0;
118 foreach($MAIN_COPY_item_instance as $MAIN_COPY_SUB_item_instance){
119
120 $character_inventory = $CHDB->selectRow("SELECT * FROM `character_inventory` WHERE item=?d",$MAIN_COPY_SUB_item_instance['guid']);
121 $bag = $character_inventory['bag'];
122 $slot = $character_inventory['slot'];
123 $item_template = $character_inventory['item_template'];
124
125 // First we need to check what is the lastest id
126 // We use standard query SAME AS DONATION system uses.
127 $ROUNDS++;
128 // If this is the first loop we must check if we MUST increment with offset or if we can just apply id +1
129 if ($ROUNDS == 1){
130 $new_guid = $MANG->mangos_newguid('item_instance');
131 $item = $new_guid['new_guid'];
132 $WE_DID_OFFSET_ID = $new_guid['incr'];
133
134 }else{
135 // In this point we must incre, since we dont INSERT after each loop therefor we must take current + 1
136 $item = $item+1;
137 }
138 // Start modify data fields to what it should be.
139 $data = explode(" ", $MAIN_COPY_SUB_item_instance['data']);
140 $data['0'] = $item;
141 $data['6'] = $guid;
142 $data['8'] = $guid;
143 $update_implode_data_field = implode(" ", $data);
144
145
146
147 // Make a check if this is a bag. If it is we make an array with the bag.
148 // If its NOT a bag.. we will define it in our NOT bag array.
149 if (count($data) > 90){
150 $COPY_BAG_item_instance[$ARRAY_BAG_INCREMENT] = array(
151 'guid' => $item,
152 'owner_guid' => $guid,
153 'data' => $update_implode_data_field,
154 'old_guid' => $MAIN_COPY_SUB_item_instance['guid'],
155 );
156 $ARRAY_BAG_INCREMENT++;
157 }else{
158
159 // Ok this was not an bag well.. We must now basicly make the sql array's.
160 $COPY_item_instance[$ARRAY_INCREMENT] = array(
161 'guid' => $item,
162 'owner_guid' => $guid,
163 'data' => $update_implode_data_field,
164 'old_guid' => $MAIN_COPY_SUB_item_instance['guid'],
165 );
166 }
167
168
169 $COPY_character_inventory[$ARRAY_INCREMENT] = array(
170 'guid' => $guid,
171 'bag' => $bag,
172 'slot' => $slot,
173 'item' => $item,
174 'item_template' => $item_template,
175 );
176
177
178 // Now, we need to replace Data FOR EACH field within the new values used, as items.
179 $COPY_character['data'] = str_replace($MAIN_COPY_SUB_item_instance['guid'], $item, $COPY_character['data']);
180
181 $ARRAY_INCREMENT++; // TODO: We need to copy bags content into the right places .... Long process
182 }// END WHILE CHARACTER_INSTANCE
183
184
185
186
187
188 ####################### INSERT TO Database ########################
189 // Filter Item_instance + Character Inventory.
190 foreach($COPY_BAG_item_instance as $COPY_BAG_SUB_item_instance){
191
192 // Filter thrue all item_instance objects and replace in bags.
193 foreach($COPY_item_instance as $COPY_WORK_item_instance){
194
195 if (strstr($COPY_BAG_SUB_item_instance['data'], $COPY_WORK_item_instance['old_guid']) == TRUE){
196 $COPY_BAG_SUB_item_instance['data'] = str_replace(" ".$COPY_WORK_item_instance['old_guid']." ", " ".$COPY_WORK_item_instance['guid']." ", $COPY_BAG_SUB_item_instance['data']);
197 foreach($COPY_character_inventory as $i => $check){
198 if ($check['bag'] != 0){
199 if ($check['bag'] == $COPY_BAG_SUB_item_instance['old_guid']){
200 $COPY_character_inventory[$i]['bag'] = $COPY_BAG_SUB_item_instance['guid'];
201 }
202 }
203 }
204 }
205
206 }
207
208 $CHDB->query("INSERT INTO `item_instance` (
209 `guid`,
210 `owner_guid`,
211 `data`)
212 VALUES
213 ('".$COPY_BAG_SUB_item_instance['guid']."', '".$COPY_BAG_SUB_item_instance['owner_guid']."', '".$COPY_BAG_SUB_item_instance['data']."')");
214
215 }
216
217 foreach($COPY_item_instance as $COPY_SUB_item_instance){
218 $CHDB->query("INSERT INTO `item_instance` (
219 `guid`,
220 `owner_guid`,
221 `data`)
222 VALUES
223 ('".$COPY_SUB_item_instance['guid']."', '".$COPY_SUB_item_instance['owner_guid']."', '".$COPY_SUB_item_instance['data']."')");
224 }
225
226 foreach($COPY_character_inventory as $COPY_SUB_character_inventory){
227 $CHDB->query("INSERT INTO `character_inventory` (
228 `guid`,
229 `bag`,
230 `slot`,
231 `item`,
232 `item_template`)
233 VALUES
234 ('".$COPY_SUB_character_inventory['guid']."', '".$COPY_SUB_character_inventory['bag']."', '".$COPY_SUB_character_inventory['slot']."', '".$COPY_SUB_character_inventory['item']."', '".$COPY_SUB_character_inventory['item_template']."')");
235 }
236
237 /* character */
238 // Filters
239 # $COPY_character[data] == FILTERED!
240 $COPY_character['data'] = explode(' ', $COPY_character['data']);
241 $COPY_character['data']['0'] = $guid;
242 // NOT USE - Mangos changes field all time | $COPY_character['data']['1326'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Money;
243 // NOT USE - Mangos changes field all time | $COPY_character['data']['1420'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Level;
244 // NOT USE - Mangos changes field all time | $COPY_character['data']['1244'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Level-9;
245 $COPY_character['data'] = implode(' ', $COPY_character['data']);
246 $CHDB->query("INSERT INTO `characters` (
247 `guid`,
248 `account`,
249 `name`,
250 `race`,
251 `class`,
252 `gender`,
253 `level`,
254 `xp`,
255 `money`,
256 `playerBytes`,
257 `playerBytes2`,
258 `playerFlags`,
259 `position_x`,
260 `position_y`,
261 `position_z`,
262 `map`,
263 `instance_id`,
264 `dungeon_difficulty`,
265 `orientation`,
266 `taximask`,
267 `online`,
268 `cinematic`,
269 `totaltime`,
270 `leveltime`,
271 `logout_time`,
272 `is_logout_resting`,
273 `rest_bonus`,
274 `resettalents_cost`,
275 `resettalents_time`,
276 `trans_x`,
277 `trans_y`,
278 `trans_z`,
279 `trans_o`,
280 `transguid`,
281 `extra_flags`,
282 `stable_slots`,
283 `at_login`,
284 `zone`,
285 `death_expire_time`,
286 `taxi_path`,
287 `arenaPoints`,
288 `totalHonorPoints`,
289 `todayHonorPoints`,
290 `yesterdayHonorPoints`,
291 `totalKills`,
292 `todayKills`,
293 `yesterdayKills`,
294 `chosenTitle`,
295 `knownCurrencies`,
296 `watchedFaction`,
297 `drunk`,
298 `health`,
299 `power1`,
300 `power2`,
301 `power3`,
302 `power4`,
303 `power5`,
304 `power6`,
305 `power7`,
306 `speccount`,
307 `activespec`,
308 `exploredZones`,
309 `equipmentCache`,
310 `ammoId`,
311 `knownTitles`,
312 `actionBars`,
313 `latency`)
314 VALUES
315 ('".$guid."', '".$account_id."', '".$name."', '".$COPY_character['race']."', '".$COPY_character['class']."', '".$COPTY_character['gender']."', '".$COPY_character['level']."',
316 '".$COPY_character['xp']."', '".$COPY_character['money']."', '".$COPY_character['playerBytes']."', '".$COPY_character['playerBytes2']."', '".$COPY_character['playerFlags']."', '".$COPY_character['position_x']."',
317 '".$COPY_character['position_y']."', '".$COPY_character['position_z']."', '".$COPY_character['map']."', '".$COPY_character['instance_id']."', '".$COPY_character['dungeon_difficulty']."', '".$COPY_character['orientation']."', '".$COPY_character['taximask']."', '".$COPY_character['online']."',
318 '".$COPY_character['cinematic']."', '".$COPY_character['totaltime']."', '".$COPY_character['leveltime']."', '".$COPY_character['logout_time']."', '".$COPY_character['is_logout_resting']."',
319 '".$COPY_character['rest_bonus']."', '".$COPY_character['resettalents_cost']."', '".$COPY_character['resettalents_time']."', '".$COPY_character['trans_x']."', '".$COPY_character['trans_y']."',
320 '".$COPY_character['trans_z']."', '".$COPY_character['trans_o']."', '".$COPY_character['transguid']."', '".$COPY_character['extra_flags']."', '".$COPY_character['stable_slots']."', '".$COPY_character['at_login']."', '".$COPY_character['zone']."', '".$COPY_character['death_expire_time']."',
321 '".$COPY_character['taxi_path']."', '".$COPY_character['arenaPoints']."', '".$COPY_character['totalHonorPoints']."', '".$COPY_character['todayHonorPoints']."', '".$COPY_character['yesterdayHonorPoints']."', '".$COPY_character['totalKills']."', '".$COPY_character['todayKills']."',
322 '".$COPY_character['yesterdayKills']."', '".$COPY_character['chosenTitle']."', '".$COPY_character['knownCurrenies']."', '".$COPY_character['watchedFaction']."', '".$COPY_character['drunk']."', '".$COPY_character['health']."', '".$COPY_character['power1']."', '".$COPY_character['power2']."',
323 '".$COPY_character['power3']."', '".$COPY_character['power4']."', '".$COPY_character['power5']."', '".$COPY_character['power6']."', '".$COPY_character['power7']."', '".$COPY_character['speccount']."', '".$COPY_character['activespec']."', '".$COPY_character['exploredZones']."',
324 '".$COPY_character['equipmentCache']."', '".$COPY_character['ammoId']."', '".$COPY_character['knownTitles']."', '".$COPY_character['actionBars']."', '".$COPY_character['latency']."')");
325
326 /* Character_action */
327 foreach($COPY_character_action as $COPY_SUB_character_action){
328 $CHDB->query("INSERT INTO `character_action` (
329 `guid`,
330 `spec`,
331 `button`,
332 `action`,
333 `type`)
334 VALUES
335 ('".$guid."' , '".$COPY_SUB_character_action['spec']."', '".$COPY_SUB_character_action['button']."', '".$COPY_SUB_character_action['action']."', '".$COPY_SUB_character_action['type']."')");
336 }
337 /* Character_homebind */
338 foreach($COPY_character_homebind as $COPY_SUB_character_homebind){
339 $CHDB->query("INSERT INTO `character_homebind` (
340 `guid`,
341 `map`,
342 `zone`,
343 `position_x`,
344 `position_y`,
345 `position_z`)
346 VALUES
347 ('".$guid."' , '".$COPY_SUB_character_homebind['map']."', '".$COPY_SUB_character_homebind['zone']."',
348 '".$COPY_SUB_character_homebind['position_x']."', '".$COPY_SUB_character_homebind['position_y']."', '".$COPY_SUB_character_homebind['position_z']."')");
349 }
350
351 /* Character_reputation */
352 foreach($COPY_character_reputation as $COPY_SUB_character_reputation){
353 $CHDB->query("INSERT INTO `character_reputation` (
354 `guid`,
355 `faction`,
356 `standing`,
357 `flags`)
358 VALUES
359 ('".$guid."', '".$COPY_SUB_character_reputation['faction']."', '".$COPY_SUB_character_reputation['standing'].", '".$COPY_SUB_character_reputation['flags']."')");
360 }
361 /* Character_spell */
362 foreach($COPY_character_spell as $COPY_SUB_character_spell){
363 $CHDB->query("INSERT INTO `character_spell` (
364 `guid`,
365 `spell`,
366 `active`,
367 `disabled`)
368 VALUES
369 ('".$guid."', '".$COPY_SUB_character_spell['spell']."', '".$COPY_SUB_character_spell['active']."', '".$COPY_SUB_character_spell['disabled']."')");
370 }
371
372 // update points
373 $query = $DB->query("UPDATE `voting_points` SET `points`=(`points` - ".$char_points."), `points_spent`=(`points_spent` + ".$char_points.")
374 WHERE id=?d",$account_id);
375
376 //Gogo message
377 output_message('notice','<b><h1>'.$lang['congratulations'].'</h1>, '.$lang['charcreate_charcreated'].'<br/>'.$lang['redirecting_wait'].'</b><meta http-equiv=refresh content="5;url=index.php?n=account&sub=charcreate">');
378
379 }//Stops if all cases returns false, then apply data fields.
380 unset($MANG);
381}
382/*************** STOP LEVLEUP ACTION ****************/
383}
384?>