· 8 years ago · Jun 12, 2018, 06:36 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'];
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 );
175
176
177 // Now, we need to replace Data FOR EACH field within the new values used, as items.
178 $COPY_character['data'] = str_replace($MAIN_COPY_SUB_item_instance['guid'], $item, $COPY_character['data']);
179
180 $ARRAY_INCREMENT++; // TODO: We need to copy bags content into the right places .... Long process
181 }// END WHILE CHARACTER_INSTANCE
182
183
184
185
186
187 ####################### INSERT TO Database ########################
188 // Filter Item_instance + Character Inventory.
189 foreach($COPY_BAG_item_instance as $COPY_BAG_SUB_item_instance){
190
191 // Filter thrue all item_instance objects and replace in bags.
192 foreach($COPY_item_instance as $COPY_WORK_item_instance){
193
194 if (strstr($COPY_BAG_SUB_item_instance['owner_guid'], $COPY_WORK_item_instance['old_guid']) == TRUE){
195 $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']);
196 foreach($COPY_character_inventory as $i => $check){
197 if ($check['bag'] != 0){
198 if ($check['bag'] == $COPY_BAG_SUB_item_instance['old_guid']){
199 $COPY_character_inventory[$i]['bag'] = $COPY_BAG_SUB_item_instance['guid'];
200 }
201 }
202 }
203 }
204
205 }
206
207 $CHDB->query("INSERT INTO `item_instance` (
208 `guid`,
209 `itemEntry`,
210 `owner_guid`,
211 `creatorGuid`,
212 `giftCreatorGuid`,
213 `count`,
214 `duration`,
215 `charges`,
216 `flags`,
217 `enchantments`,
218 `randomPropertyId`,
219 `durability`,
220 `playedTime`,
221 `text`)
222 VALUES
223 ('".$COPY_BAG_SUB_item_instance['guid']."', '".$COPY_BAG_SUB_item_instance['itemEntry']."', '".$COPY_BAG_SUB_item_instance['owner_guid']."', '".$COPY_BAG_SUB_item_instance['creatorGuid']."', '".$COPY_BAG_SUB_item_instance['giftCreatorGuid']."', '".$COPY_BAG_SUB_item_instance['count']."', '".$COPY_BAG_SUB_item_instance['duration']."', '".$COPY_BAG_SUB_item_instance['charges']."', '".$COPY_BAG_SUB_item_instance['flags']."', '".$COPY_BAG_SUB_item_instance['enchantments']."', '".$COPY_BAG_SUB_item_instance['randomPropertyId']."', '".$COPY_BAG_SUB_item_instance['durability']."', '".$COPY_BAG_SUB_item_instance['playedTime']."', '".$COPY_BAG_SUB_item_instance['text']."')");
224
225 }
226
227 foreach($COPY_item_instance as $COPY_SUB_item_instance){
228 $CHDB->query("INSERT INTO `item_instance` (
229 `guid`,
230 `itemEntry`,
231 `owner_guid`,
232 `creatorGuid`,
233 `giftCreatorGuid`,
234 `count`,
235 `duration`,
236 `charges`,
237 `flags`,
238 `enchantments`,
239 `randomPropertyId`,
240 `durability`,
241 `playedTime`,
242 `text`)
243 VALUES
244 ('".$COPY_SUB_item_instance['guid']."', '".$COPY_SUB_item_instance['itemEntry']."', '".$COPY_SUB_item_instance['owner_guid']."', '".$COPY_SUB_item_instance['creatorGuid']."', '".$COPY_SUB_item_instance['giftCreatorGuid']."', '".$COPY_SUB_item_instance['count']."', '".$COPY_SUB_item_instance['duration']."', '".$COPY_SUB_item_instance['charges']."', '".$COPY_SUB_item_instance['flags']."', '".$COPY_SUB_item_instance['enchantments']."', '".$COPY_SUB_item_instance['randomPropertyId']."', '".$COPY_SUB_item_instance['durability']."', '".$COPY_SUB_item_instance['playedTime']."', '".$COPY_SUB_item_instance['text']."')");
245 }
246
247 foreach($COPY_character_inventory as $COPY_SUB_character_inventory){
248 $CHDB->query("INSERT INTO `character_inventory` (
249 `guid`,
250 `bag`,
251 `slot`,
252 `item`,
253 VALUES
254 ('".$COPY_SUB_character_inventory['guid']."', '".$COPY_SUB_character_inventory['bag']."', '".$COPY_SUB_character_inventory['slot']."', '".$COPY_SUB_character_inventory['item']."')");
255 }
256
257 /* character */
258 // Filters
259 # $COPY_character[data] == FILTERED!
260 $COPY_character['data'] = explode(' ', $COPY_character['data']);
261 $COPY_character['data']['0'] = $guid;
262 // NOT USE - Mangos changes field all time | $COPY_character['data']['1326'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Money;
263 // NOT USE - Mangos changes field all time | $COPY_character['data']['1420'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Level;
264 // NOT USE - Mangos changes field all time | $COPY_character['data']['1244'] = (int)$MW->getConfig->character_copy_config->general->Player_Start_Level-9;
265 $COPY_character['data'] = implode(' ', $COPY_character['data']);
266 $CHDB->query("INSERT INTO `characters` (
267 `guid`,
268 `account`,
269 `name`,
270 `race`,
271 `class`,
272 `gender`,
273 `level`,
274 `xp`,
275 `money`,
276 `playerBytes`,
277 `playerBytes2`,
278 `playerFlags`,
279 `position_x`,
280 `position_y`,
281 `position_z`,
282 `map`,
283 `instance_id`,
284 `instance_mode_mask`,
285 `orientation`,
286 `taximask`,
287 `online`,
288 `cinematic`,
289 `totaltime`,
290 `leveltime`,
291 `logout_time`,
292 `is_logout_resting`,
293 `rest_bonus`,
294 `resettalents_cost`,
295 `resettalents_time`,
296 `trans_x`,
297 `trans_y`,
298 `trans_z`,
299 `trans_o`,
300 `transguid`,
301 `extra_flags`,
302 `stable_slots`,
303 `at_login`,
304 `zone`,
305 `death_expire_time`,
306 `taxi_path`,
307 `arenaPoints`,
308 `totalHonorPoints`,
309 `todayHonorPoints`,
310 `yesterdayHonorPoints`,
311 `totalKills`,
312 `todayKills`,
313 `yesterdayKills`,
314 `chosenTitle`,
315 `knownCurrencies`,
316 `watchedFaction`,
317 `drunk`,
318 `health`,
319 `power1`,
320 `power2`,
321 `power3`,
322 `power4`,
323 `power5`,
324 `power6`,
325 `power7`,
326 `latency`,
327 `speccount`,
328 `activespec`,
329 `exploredZones`,
330 `equipmentCache`,
331 `ammoId`,
332 `knownTitles`,
333 `actionBars`,
334 `GrantableLevels`,
335 `deleteInfos_Account`,
336 `deleteInfos_Name`,
337 `deleteDate`)
338 VALUES
339 ('".$guid."', '".$account_id."', '".$name."', '".$COPY_character['race']."', '".$COPY_character['class']."', '".$COPTY_character['gender']."', '".$COPY_character['level']."',
340 '".$COPY_character['xp']."', '".$COPY_character['money']."', '".$COPY_character['playerBytes']."', '".$COPY_character['playerBytes2']."', '".$COPY_character['playerFlags']."', '".$COPY_character['position_x']."',
341 '".$COPY_character['position_y']."', '".$COPY_character['position_z']."', '".$COPY_character['map']."', '".$COPY_character['instance_id']."', '".$COPY_character['instance_orientation_mask']."', '".$COPY_character['orientation']."', '".$COPY_character['taximask']."', '".$COPY_character['online']."',
342 '".$COPY_character['cinematic']."', '".$COPY_character['totaltime']."', '".$COPY_character['leveltime']."', '".$COPY_character['logout_time']."', '".$COPY_character['is_logout_resting']."',
343 '".$COPY_character['rest_bonus']."', '".$COPY_character['resettalents_cost']."', '".$COPY_character['resettalents_time']."', '".$COPY_character['trans_x']."', '".$COPY_character['trans_y']."',
344 '".$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']."',
345 '".$COPY_character['taxi_path']."', '".$COPY_character['arenaPoints']."', '".$COPY_character['totalHonorPoints']."', '".$COPY_character['todayHonorPoints']."', '".$COPY_character['yesterdayHonorPoints']."', '".$COPY_character['totalKills']."', '".$COPY_character['todayKills']."',
346 '".$COPY_character['yesterdayKills']."', '".$COPY_character['chosenTitle']."', '".$COPY_character['knownCurrenies']."', '".$COPY_character['watchedFaction']."', '".$COPY_character['drunk']."', '".$COPY_character['health']."', '".$COPY_character['power1']."', '".$COPY_character['power2']."',
347 '".$COPY_character['power3']."', '".$COPY_character['power4']."', '".$COPY_character['power5']."', '".$COPY_character['power6']."', '".$COPY_character['power7']."', '".$COPY_character['latency']."', '".$COPY_character['speccount']."', '".$COPY_character['activespec']."', '".$COPY_character['exploredZones']."',
348 '".$COPY_character['equipmentCache']."', '".$COPY_character['ammoId']."', '".$COPY_character['knownTitles']."', '".$COPY_character['actionBars']."', '".$COPY_character['GrantableLevels']."', '".$COPY_character['deleteInfos_Account']."', '".$COPY_character['deleteInfos_Name']."', '".$COPY_character['deleteDate']."')");
349
350 /* Character_action */
351 foreach($COPY_character_action as $COPY_SUB_character_action){
352 $CHDB->query("INSERT INTO `character_action` (
353 `guid`,
354 `spec`,
355 `button`,
356 `action`,
357 `type`)
358 VALUES
359 ('".$guid."' , '".$COPY_SUB_character_action['spec']."', '".$COPY_SUB_character_action['button']."', '".$COPY_SUB_character_action['action']."', '".$COPY_SUB_character_action['type']."')");
360 }
361 /* Character_homebind */
362 foreach($COPY_character_homebind as $COPY_SUB_character_homebind){
363 $CHDB->query("INSERT INTO `character_homebind` (
364 `guid`,
365 `map`,
366 `zone`,
367 `position_x`,
368 `position_y`,
369 `position_z`)
370 VALUES
371 ('".$guid."' , '".$COPY_SUB_character_homebind['map']."', '".$COPY_SUB_character_homebind['zone']."',
372 '".$COPY_SUB_character_homebind['position_x']."', '".$COPY_SUB_character_homebind['position_y']."', '".$COPY_SUB_character_homebind['position_z']."')");
373 }
374
375 /* Character_reputation */
376 foreach($COPY_character_reputation as $COPY_SUB_character_reputation){
377 $CHDB->query("INSERT INTO `character_reputation` (
378 `guid`,
379 `faction`,
380 `standing`,
381 `flags`)
382 VALUES
383 ('".$guid."', '".$COPY_SUB_character_reputation['faction']."', '".$COPY_SUB_character_reputation['standing'].", '".$COPY_SUB_character_reputation['flags']."')");
384 }
385 /* Character_spell */
386 foreach($COPY_character_spell as $COPY_SUB_character_spell){
387 $CHDB->query("INSERT INTO `character_spell` (
388 `guid`,
389 `spell`,
390 `active`,
391 `disabled`)
392 VALUES
393 ('".$guid."', '".$COPY_SUB_character_spell['spell']."', '".$COPY_SUB_character_spell['active']."', '".$COPY_SUB_character_spell['disabled']."')");
394 }
395
396 // update points
397 $query = $DB->query("UPDATE `voting_points` SET `points`=(`points` - ".$char_points."), `points_spent`=(`points_spent` + ".$char_points.")
398 WHERE id=?d",$account_id);
399
400 //Gogo message
401 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">');
402
403 }//Stops if all cases returns false, then apply data fields.
404 unset($MANG);
405}
406/*************** STOP LEVLEUP ACTION ****************/
407}
408?>