Advertisement
Guest User

[FusionCMS] Item Store Sending Item Error!

a guest
Mar 26th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.65 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Abstraction layer for supporting different emulators
  5. */
  6.  
  7. class Trinity_soap implements Emulator
  8. {
  9. protected $config;
  10.  
  11. /**
  12. * Whether or not this emulator supports remote console
  13. */
  14. protected $hasConsole = true;
  15.  
  16. /**
  17. * Whether or not this emulator supports character stats
  18. */
  19. protected $hasStats = true;
  20.  
  21. /**
  22. * Console object
  23. */
  24. protected $console;
  25.  
  26. /**
  27. * Array of expansion ids and their corresponding names
  28. */
  29. protected $expansions = array(
  30. 3 => "Cataclysm",
  31. 2 => "WotLK",
  32. 1 => "TBC",
  33. 0 => "None"
  34. );
  35.  
  36. /**
  37. * Array of table names
  38. */
  39. protected $tables = array(
  40. "account" => "account",
  41. "account_access" => "account_access",
  42. "account_banned" => "account_banned",
  43. "characters" => "characters",
  44. "item_template" => "item_template",
  45. "character_stats" => "character_stats",
  46. "guild_member" => "guild_member",
  47. "guild" => "guild",
  48. "gm_tickets" => "gm_tickets"
  49. );
  50.  
  51. /**
  52. * Array of column names
  53. */
  54. protected $columns = array(
  55.  
  56. "account" => array(
  57. "id" => "id",
  58. "username" => "username",
  59. "password" => "sha_pass_hash",
  60. "email" => "email",
  61. "joindate" => "joindate",
  62. "last_ip" => "last_ip",
  63. "last_login" => "last_login",
  64. "expansion" => "expansion",
  65. "v" => "v",
  66. "s" => "s",
  67. "sessionkey" => "sessionkey"
  68. ),
  69.  
  70. "account_access" => array(
  71. "id" => "id",
  72. "gmlevel" => "gmlevel"
  73. ),
  74.  
  75. "account_banned" => array(
  76. "id" => "id",
  77. "banreason" => "banreason",
  78. "active" => "active",
  79. "bandate" => "bandate",
  80. "unbandate" => "unbandate",
  81. "bannedby" => "bannedby"
  82. ),
  83.  
  84. "characters" => array(
  85. "guid" => "guid",
  86. "account" => "account",
  87. "name" => "name",
  88. "race" => "race",
  89. "class" => "class",
  90. "gender" => "gender",
  91. "level" => "level",
  92. "zone" => "zone",
  93. "online" => "online",
  94. "money" => "money",
  95. "totalKills" => "totalKills",
  96. "arenaPoints" => "arenaPoints",
  97. "totalHonorPoints" => "totalHonorPoints",
  98. "position_x" => "position_x",
  99. "position_y" => "position_y",
  100. "position_z" => "position_z",
  101. "orientation" => "orientation",
  102. "map" => "map"
  103. ),
  104.  
  105. "item_template" => array(
  106. "entry" => "entry",
  107. "name" => "name",
  108. "Quality" => "Quality",
  109. "InventoryType" => "InventoryType",
  110. "RequiredLevel" => "RequiredLevel",
  111. "ItemLevel" => "ItemLevel",
  112. "class" => "class",
  113. "subclass" => "subclass"
  114. ),
  115.  
  116. "character_stats" => array(
  117. "guid" => "guid",
  118. "maxhealth" => "maxhealth",
  119. "maxpower1" => "maxpower1",
  120. "maxpower2" => "maxpower2",
  121. "maxpower3" => "maxpower3",
  122. "maxpower4" => "maxpower4",
  123. "maxpower5" => "maxpower5",
  124. "maxpower6" => "maxpower6",
  125. "maxpower7" => "maxpower7",
  126. "strength" => "strength",
  127. "agility" => "agility",
  128. "stamina" => "stamina",
  129. "intellect" => "intellect",
  130. "spirit" => "spirit",
  131. "armor" => "armor",
  132. "blockPct" => "blockPct",
  133. "dodgePct" => "dodgePct",
  134. "parryPct" => "parryPct",
  135. "critPct" => "critPct",
  136. "rangedCritPct" => "rangedCritPct",
  137. "spellCritPct" => "spellCritPct",
  138. "attackPower" => "attackPower",
  139. "spellPower" => "spellPower",
  140. "resilience" => "resilience"
  141. ),
  142.  
  143. "guild" => array(
  144. "guildid" => "guildid",
  145. "name" => "name",
  146. "leaderguid" => "leaderguid"
  147. ),
  148.  
  149. "guild_member" => array(
  150. "guildid" => "guildid",
  151. "guid" => "guid"
  152. ),
  153.  
  154. "gm_tickets" => array(
  155. "ticketId" => "ticketId",
  156. "guid" => "guid",
  157. "message" => "message",
  158. "createTime" => "createTime",
  159. "completed" => "completed",
  160. "closedBy" => "closedBy"
  161. )
  162. );
  163.  
  164. /**
  165. * Array of queries
  166. */
  167. protected $queries = array(
  168. "get_ip_banned" => "SELECT ip, bandate, bannedby, banreason, unbandate FROM ip_banned WHERE ip=? AND unbandate > ?",
  169. "get_character" => "SELECT * FROM characters WHERE guid=?",
  170. "get_item" => "SELECT entry, Flags, name, Quality, bonding, InventoryType, MaxDurability, armor, RequiredLevel, ItemLevel, class, subclass, dmg_min1, dmg_max1, dmg_type1, holy_res, fire_res, nature_res, frost_res, shadow_res, arcane_res, delay, socketColor_1, socketColor_2, socketColor_3, spellid_1, spellid_2, spellid_3, spellid_4, spellid_5, spelltrigger_1, spelltrigger_2, spelltrigger_3, spelltrigger_4, spelltrigger_5, displayid, stat_type1, stat_value1, stat_type2, stat_value2, stat_type3, stat_value3, stat_type4, stat_value4, stat_type5, stat_value5, stat_type6, stat_value6, stat_type7, stat_value7, stat_type8, stat_value8, stat_type9, stat_value9, stat_type10, stat_value10, stackable FROM item_template WHERE entry=?",
  171. "get_rank" => "SELECT id id, gmlevel gmlevel, RealmID RealmID FROM account_access WHERE id=?",
  172. "get_banned" => "SELECT id id, bandate bandate, bannedby bannedby, banreason banreason, active active FROM account_banned WHERE id=? AND active=1",
  173. "get_account_id" => "SELECT id id, username username, sha_pass_hash password, email email, joindate joindate, last_ip last_ip, last_login last_login, expansion expansion FROM account WHERE id = ?",
  174. "get_account" => "SELECT id id, username username, sha_pass_hash password, email email, joindate joindate, last_ip last_ip, last_login last_login, expansion expansion FROM account WHERE username = ?",
  175. "get_charactername_by_guid" => "SELECT name name FROM characters WHERE guid = ?",
  176. "find_guilds" => "SELECT g.guildid guildid, g.name name, COUNT(g_m.guid) GuildMemberCount, g.leaderguid leaderguid, c.name leaderName FROM guild g, guild_member g_m, characters c WHERE g.leaderguid = c.guid AND g_m.guildid = g.guildid AND g.name LIKE ? GROUP BY g.guildid",
  177. "get_inventory_item" => "SELECT slot slot, item item, itemEntry itemEntry FROM character_inventory, item_instance WHERE character_inventory.item = item_instance.guid AND character_inventory.slot >= 0 AND character_inventory.slot <= 18 AND character_inventory.guid=? AND character_inventory.bag=0",
  178. "get_guild_members" => "SELECT m.guildid guildid, m.guid guid, c.name name, c.race race, c.class class, c.gender gender, c.level level, m.rank rank, r.rname rname, r.rights rights FROM guild_member m, guild_rank r, characters c WHERE m.guildid = r.guildid AND m.rank = r.rid AND c.guid = m.guid AND m.guildid = ? ORDER BY r.rights DESC",
  179. "get_guild" => "SELECT guildid guildid, name guildName, leaderguid leaderguid, motd motd, createdate createdate FROM guild WHERE guildid = ?"
  180. );
  181.  
  182. public function __construct($config)
  183. {
  184. $this->config = $config;
  185. }
  186.  
  187. /**
  188. * Get the name of a table
  189. * @param String $name
  190. * @return String
  191. */
  192. public function getTable($name)
  193. {
  194. if(array_key_exists($name, $this->tables))
  195. {
  196. return $this->tables[$name];
  197. }
  198. }
  199.  
  200. /**
  201. * Get the name of a column
  202. * @param String $table
  203. * @param String $name
  204. * @return String
  205. */
  206. public function getColumn($table, $name)
  207. {
  208. if(array_key_exists($table, $this->columns) && array_key_exists($name, $this->columns[$table]))
  209. {
  210. return $this->columns[$table][$name];
  211. }
  212. }
  213.  
  214. /**
  215. * Get a set of all columns
  216. * @param String $name
  217. * @return String
  218. */
  219. public function getAllColumns($table)
  220. {
  221. if(array_key_exists($table, $this->columns))
  222. {
  223. return $this->columns[$table];
  224. }
  225. }
  226.  
  227. /**
  228. * Get a pre-defined query
  229. * @param String $name
  230. * @return String
  231. */
  232. public function getQuery($name)
  233. {
  234. if(array_key_exists($name, $this->queries))
  235. {
  236. return $this->queries[$name];
  237. }
  238. }
  239.  
  240. /**
  241. * Password encryption
  242. */
  243. public function encrypt($username, $password)
  244. {
  245. if(!is_string($username)) { $username = ""; }
  246. if(!is_string($password)) { $password = ""; }
  247. $sha_pass_hash = sha1(strtoupper($username).':'.strtoupper($password));
  248.  
  249. return $sha_pass_hash;
  250. }
  251.  
  252. /**
  253. * Expansion getter
  254. * @return Array
  255. */
  256. public function getExpansions()
  257. {
  258. return $this->expansions;
  259. }
  260.  
  261. /**
  262. * Get the name of an expansion by the id
  263. * @param Int $id
  264. * @return String
  265. */
  266. public function getExpansionName($id)
  267. {
  268. if(array_key_exists($id, $this->expansions))
  269. {
  270. return $this->expansions[$id];
  271. }
  272. }
  273.  
  274. /**
  275. * Get the name of an expansion by the name
  276. * @param String $name
  277. * @return Int
  278. */
  279. public function getExpansionId($name)
  280. {
  281. if(in_array($name, $this->expansions))
  282. {
  283. return array_search($name, $this->expansions);
  284. }
  285. }
  286.  
  287. /**
  288. * Send mail via ingame mail to a specific character
  289. * @param String $character
  290. * @param String $subject
  291. * @param String $body
  292. */
  293. public function sendMail($character, $subject, $body)
  294. {
  295. $this->send(".send mail ".$character." \"".$subject."\" \"".$body."\"");
  296. }
  297.  
  298. /**
  299. * Send console command
  300. * @param String $command
  301. */
  302. public function sendCommand($command)
  303. {
  304. $this->send($command);
  305. }
  306.  
  307. /**
  308. * Whether or not console actions are enabled for this emulator
  309. * @return Boolean
  310. */
  311. public function hasConsole()
  312. {
  313. return $this->hasConsole;
  314. }
  315.  
  316. /**
  317. * Whether or not character stats are logged in the database
  318. * @return Boolean
  319. */
  320. public function hasStats()
  321. {
  322. return $this->hasStats;
  323. }
  324.  
  325. /**
  326. * Send items via ingame mail to a specific character
  327. * @param String $character
  328. * @param String $subject
  329. * @param String $body
  330. * @param Array $items
  331. */
  332. public function sendItems($character, $subject, $body, $items)
  333. {
  334. $item_command = array();
  335. $mail_id = 0;
  336. $item_count = 0;
  337. $item_stacks = array();
  338.  
  339. foreach($items as $i)
  340. {
  341. // Check if item has been added
  342. if(array_key_exists($i['id'], $item_stacks))
  343. {
  344. // If stack is full
  345. if($item_stacks[$i['id']]['max_count'] == $item_stacks[$i['id']]['count'][$item_stacks[$i['id']]['stack_id']])
  346. {
  347. // Create a new stack
  348. $item_stacks[$i['id']]['stack_id']++;
  349. $item_stacks[$i['id']]['count'][$item_stacks[$i['id']]['stack_id']] = 0;
  350. }
  351.  
  352. // Add one to the currently active stack
  353. $item_stacks[$i['id']]['count'][$item_stacks[$i['id']]['stack_id']]++;
  354. }
  355. else
  356. {
  357. // Load the item row
  358. $item_row = get_instance()->realms->getRealm($this->config['id'])->getWorld()->getItem($i['id']);
  359.  
  360. // Add the item to the stacks array
  361. $item_stacks[$i['id']] = array(
  362. 'id' => $i['id'],
  363. 'count' => array(1),
  364. 'stack_id' => 0,
  365. 'max_count' => $item_row['stackable']
  366. );
  367. }
  368. }
  369.  
  370. // Loop through all items
  371. foreach($item_stacks as $item)
  372. {
  373. foreach($item['count'] as $count)
  374. {
  375. // Limit to 8 items per mail
  376. if($item_count > 8)
  377. {
  378. // Reset item count
  379. $item_count = 0;
  380.  
  381. // Queue a new mail
  382. $mail_id++;
  383. }
  384.  
  385. // Increase the item count
  386. $item_count++;
  387.  
  388. if(!isset($item_command[$mail_id]))
  389. {
  390. $item_command[$mail_id] = "";
  391. }
  392.  
  393. // Append the command
  394. $item_command[$mail_id] .= " ".$item['id'].":".$count;
  395. }
  396. }
  397.  
  398. // Send all the queued mails
  399. for($i = 0; $i <= $mail_id; $i++)
  400. {
  401. // .send item
  402. $this->send("send items ".$character." \"".$subject."\" \"".$body."\"".$item_command[$i]);
  403. }
  404. }
  405.  
  406. /**
  407. * Send a console command
  408. * @param String $command
  409. * @return Array
  410. */
  411. public function send($command)
  412. {
  413. $client = new SoapClient(NULL,
  414. array(
  415. "location" => "http://".$this->config['hostname'].":".$this->config['console_port'],
  416. "uri" => "urn:TC",
  417. 'login' => $this->config['console_username'],
  418. 'password' => $this->config['console_password']
  419. )
  420. );
  421.  
  422. try
  423. {
  424. $result = $client->executeCommand(new SoapParam($command, "command"));
  425. }
  426. catch (Exception $e)
  427. {
  428. die("Something went wrong! An administrator has been noticed and will send your order as soon as possible.<br /><br /><b>Error:</b> <br />".$e->getMessage());
  429. }
  430. }
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement