Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.27 KB | None | 0 0
  1. <?php
  2. class PacketParser {
  3.  
  4.     public $DB, $Room, $Items, $Maps, $Skills, $Passives, $ClientData;
  5.  
  6.     public function __construct() {
  7.         try {
  8.             $this->DB = new DB(Config::get('User'), Config::get('Pass'), Config::get('DB'));
  9.         } catch (PDOException $e) {
  10.             echo $e->getMessage();
  11.         }
  12.         if ($this->DB != null) {
  13.             $this->write("MySQL server started!", "MYSQL");
  14.  
  15.             $this->ClientData = new Map();
  16.             $this->Maps = new Map();
  17.             $this->Items = new Map();
  18.             $this->Skills = new Map();
  19.             $this->Passives = new Map();
  20.  
  21.             $this->Room = new Room();
  22.  
  23.             $this->cacheAll();
  24.         }
  25.     }
  26.  
  27.     public function cacheAll() {
  28.         $maps = $this->DB->query('SELECT * FROM maps')->resultset();
  29.  
  30.         foreach($maps as $map) {
  31.             $this->Maps->set($map->Name, $map);
  32.         }
  33.  
  34.         $this->write("Cached {$this->Maps->size()} maps", "CACHE");
  35.         unset($maps);
  36.  
  37.         $items = $this->DB->query('SELECT * FROM items')->resultset();
  38.  
  39.         foreach($items as $item) {
  40.             $this->Items->set($item->id, $item);
  41.         }
  42.  
  43.         $this->write("Cached {$this->Items->size()} items", "CACHE");
  44.         unset($items);
  45.  
  46.         $skills = $this->DB->query('SELECT * FROM skills')->resultset();
  47.  
  48.         foreach($skills as $skill) {
  49.             $this->Skills->set($skill->id, $skill);
  50.         }
  51.  
  52.         $this->write("Cached {$this->Skills->size()} skills", "CACHE");
  53.         unset($skills);
  54.  
  55.         $passives = $this->DB->query('SELECT * FROM passives')->resultset();
  56.        
  57.         foreach($passives as $passive) {
  58.             $this->Passives->set($passive->auraid, $passive);
  59.         }
  60.        
  61.         $this->write("Cached {$this->Passives->size()} passives", "CACHE");
  62.         unset($passives);
  63.     }
  64.  
  65.     public function GetSettingsObject() {
  66.         return $this->DB->query('SELECT * FROM settings_server WHERE id = 1')->single();
  67.     }
  68.  
  69.     public function GetClientData($client) {
  70.         if ($this->ClientData->containsKey((int)$client) && !$this->ClientData->isEmpty()) {
  71.             return $this->ClientData->get((int)$client);
  72.         }
  73.         return null;
  74.     }
  75.  
  76.     public function AddClientData($socket, $data) {
  77.         $this->ClientData->set((int)$socket, $data);
  78.     }
  79.  
  80.     public function write($msg, $type = 'INFO') {
  81.         printf('%s%s %s  <%s> %s  %s',"\n",@date('m/d/y'),@date('g:i A'),$type, $msg, chr(10));
  82.     }
  83.  
  84.     public function send($client, $packet) {
  85.         $packet .= "\0";
  86.         socket_write($client, $packet);
  87.         $this->write($packet, "SENDPACKET");
  88.     }
  89.  
  90.     public function CheckPacket($client, $packet) {
  91.         $this->write("Packet > " . $packet, "SERVER");
  92.         if (startsWith($packet, "<")) {
  93.             $this->write("Handling XML Packet", "SERVER");
  94.             $this->HandleXML($client, $packet);
  95.         } else {
  96.             $this->write("Handling % Packet", "SERVER");
  97.             $this->HandlePercentage($client, $packet);
  98.         }
  99.     }
  100.  
  101.     public function HandleXML($client, $xml) {
  102.         if (contains('policy', $xml)) {
  103.             $this->send($client, "<cross-domain-policy><allow-access-from domain='*' to-ports='5588'/></cross-domain-policy>");
  104.  
  105.         } else if (contains("verChk", $xml)) {
  106.             $this->send($client, "<msg t='sys'><body action='apiOK' r='0'></body></msg>");
  107.  
  108.         } else if (contains("login", $xml)){
  109.             $this->LoginParse($client, $xml);
  110.         }
  111.     }
  112.  
  113.     public function GetUoBranch() {
  114.         $Users = [];
  115.  
  116.         foreach($this->Room->UserList as $users) {              
  117.             $user = $this->GetClientData($users);
  118.  
  119.             array_push($Users, array(
  120.                 'strUsername' => $user->Username,
  121.                 "uoName" => $user->Username,
  122.                 'strFrame' => "Enter",
  123.                 'strPad' => "Spawn",
  124.                 'intMP' => 100,
  125.                 'intMPMax' => 100,
  126.                 'intHP' => 1500,
  127.                 'intHPMax' => 1500,
  128.                 'intLevel' => (int)$user->Level,
  129.                 'entID' => (int)$user->id,
  130.                 'afk' => false,
  131.                 'ty' => 0,
  132.                 'tx' => 0,
  133.                 'intState' => 1,
  134.                 'entType' => "p",
  135.                 'showHelm' => false,
  136.                 'showCloak' => false
  137.             ));
  138.            
  139.         }
  140.  
  141.         return $Users;
  142.     }
  143.  
  144.     public function SendRoomData($client, $name, $roomNum) {
  145.         $packet = json_decode('{"t":"xt","b":{"r":-1,"o":{"cmd":"moveToArea","areaName":"battleon-1","uoBranch":[{"strUsername":"toxic","uoName":"toxic","strFrame":"Enter","strPad":"Right2","intMP":200,"intMPMax":200,"intHP":596,"intHPMax":596,"intLevel":2,"entID":1,"afk":false,"ty":426,"tx":391,"intState":1,"entType":"p","showHelm":true,"showCloak":true}],"strMapFileName":"Battleon/town-NewBattleonTown-2May16.swf","intType":2,"monBranch":[],"sExtra":"","areaId":2,"strMapName":"battleon"}}}');
  146.  
  147.         $map = $this->Maps->get($name);
  148.  
  149.         $packet->b->o->areaName = $map['Name'] . '-' . $roomNum;
  150.         $packet->b->o->uoBranch = $this->GetUoBranch();
  151.         $packet->b->o->areaId = 2;
  152.         $packet->b->o->strMapFileName = $map['FileName'];
  153.         $packet->b->o->strMapName = $map['Name'];
  154.  
  155.         $this->send($client, stripslashes(json_encode($packet)));
  156.     }
  157.  
  158.     public function equipItem($client) {
  159.         $packet = null;
  160.         $user = $this->GetClientData($client);
  161.  
  162.         $useritems = $this->DB->query('SELECT * FROM users_items WHERE userid = ? AND equipped=1')->bind(1, $user->id);
  163.        
  164.         if($useritems->num_rows() > 0) {
  165.             $UItems = $useritems->resultset();
  166.  
  167.             foreach($UItems as $Item) {
  168.                 $packet = json_decode('{"t":"xt","b":{"r":-1,"o":{"uid":1,"ItemID":1,"strES":"Weapon","cmd":"equipItem","sFile":"items/swords/sword01.swf","sLink":"","sType":"Sword","sMeta":""}}}');
  169.  
  170.                 $items = $this->Items->get($Item->itemid);
  171.  
  172.                 $packet->b->o->uid = (int) $user->id;
  173.                 $packet->b->o->ItemID = (int) $items->id;
  174.                 $packet->b->o->strES = $Item->equipment;
  175.                 $packet->b->o->sFile = $items->File;
  176.                 $packet->b->o->sLink = $items->Link;
  177.                 $packet->b->o->sType = $items->Type;
  178.  
  179.                 $this->send($client, stripslashes(json_encode($packet)));
  180.             }
  181.         }
  182.        
  183.         $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"uid":'.$user->id.',"sStats":"Warriors favor Strength, Endurance, and Dexterity","iCP":568,"cmd":"updateClass","sDesc":"Warriors are quintessential melee fighters.  Simple, direct, and effective, they are masters of armed combat, and quite durable.","sClassCat":"M1","aMRM":["Warriors gain mana when they Strike an enemy in combat (more effective on crits) Are struck by an enemy in combat"],"sClassName":"Warrior"}}}');
  184.     }
  185.  
  186.     public function JoinOK($client) {
  187.         $pID = $this->GetPid($client);
  188.         $data = "<msg t='sys'><body action='joinOK' r='2'><pid id='1'/><vars /><uLs r='2'>";
  189.  
  190.         foreach($this->Room->UserList as $users) {
  191.             $user = $this->GetClientData($users);
  192.             $data .= "<u i='{$user->id}' m='0' s='0' p='1'><n><![CDATA[{$user->Username}]]></n><vars></vars></u>";
  193.         }
  194.  
  195.         $data .= "</uLs></body></msg>";
  196.  
  197.         $this->SendRoom(stripslashes($data));
  198.     }
  199.  
  200.     public function GetData_ID($id)
  201.     {
  202.         /*
  203.         if (!$this->ClientData->isEmpty()) {
  204.             $iterator = $this->ClientData->getIterator()->getIterator();
  205.             while ($iterator->valid()) {
  206.                 if ($this->ClientData->containsKey($iterator->key())) {
  207.                     if ($iterator->current()->id == $id) {
  208.                         return $iterator->current();
  209.                     }
  210.                 }
  211.                 $iterator->next();
  212.             }
  213.         }
  214.         return null;
  215.         */
  216.  
  217.         return $this->DB->query('SELECT * FROM users WHERE id = ?')->bind(1, $id)->single();
  218.     }
  219.  
  220.     public function RetriveUserInfo($id) {
  221.         $UserData = $this->GetData_ID($id);
  222.  
  223.         $this->write($id);
  224.         $userinfo = [];
  225.         $userinfo['uid'] = (int) $UserData->id;
  226.         $userinfo['data'] = [];
  227.         $userinfo['data']['intColorAccessory'] = (int)$UserData->ColorAccessory;
  228.         $userinfo['data']['iCP'] = 0;
  229.         $userinfo['data']['intLevel'] = (int) $UserData->Level;
  230.         $userinfo['data']['iBagSlots'] = (int) $UserData->BagSlots;
  231.         $userinfo['data']['iBoostRep'] = 0;
  232.         $userinfo['data']['intColorBase'] = (int) $UserData->ColorBase;
  233.         $userinfo['data']['iUpgDays'] = (int) $UserData->UpgradeDays;
  234.         $userinfo['data']['intDays'] = 0;
  235.         $userinfo['data']['sCountry'] = 'xx';
  236.         $userinfo['data']['iSTR'] = 0;
  237.         $userinfo['data']['strQuests2'] = '00000000000000000000000000000000000000000000000000000000000000000000000000000000A0000000000000000000';
  238.         $userinfo['data']['ip0'] = 0;
  239.         $userinfo['data']['iq0'] = 0;
  240.         $userinfo['data']['strQuests3'] = '00000000000000000000000000000000000000000000000000000000000000000000000000000000A0000000000000000000';
  241.         $userinfo['data']['iAge'] = (int) $UserData->Age;
  242.         $userinfo['data']['intExpToLevel'] = 400;
  243.         $userinfo['data']['iWIS'] = 0;
  244.         $userinfo['data']['ip2'] = 0;
  245.         $userinfo['data']['ip1'] = 0;
  246.         $userinfo['data']['intMP'] = 100;
  247.         $userinfo['data']['intGold'] = (int) $UserData->Gold;
  248.         $userinfo['data']['sHouseInfo'] = [];
  249.         $userinfo['data']['ip4'] = 0;
  250.         $userinfo['data']['id2'] = 0;
  251.         $userinfo['data']['iBankSlots'] = (int) $UserData->BankSlots;
  252.         $userinfo['data']['id1'] = 0;
  253.         $userinfo['data']['ip3'] = 0;
  254.         $userinfo['data']['id0'] = 0;
  255.         $userinfo['data']['ip6'] = 0;
  256.         $userinfo['data']['iHouseSlots'] = (int) $UserData->HouseSlots;
  257.         $userinfo['data']['ip5'] = 0;
  258.         $userinfo['data']['intColorSkin'] = (int) $UserData->ColorSkin;
  259.         $userinfo['data']['id3'] = 0;
  260.         $userinfo['data']['intMPMax'] = 200;
  261.         $userinfo['data']['intHPMax'] = 596;
  262.         $userinfo['data']['dUpgExp'] = '5/23/2011 9:02:33 PM';
  263.         $userinfo['data']['iBoostXP'] = 0;
  264.         $userinfo['data']['iUpg'] = 0;
  265.         $userinfo['data']['ip7'] = 0;
  266.         $userinfo['data']['ip8'] = 0;
  267.         $userinfo['data']['CharID'] = (int) $UserData->id;
  268.         $userinfo['data']['ip9'] = 0;
  269.         $userinfo['data']['strEmail'] = $UserData->Email;
  270.         $userinfo['data']['iINT'] = 0;
  271.         $userinfo['data']['intColorTrim'] = (int) $UserData->ColorTrim;
  272.         $userinfo['data']['lastArea'] = 'battleon-2';
  273.         $userinfo['data']['im0'] = 0;
  274.         $userinfo['data']['iFounder'] = 0;
  275.         $userinfo['data']['intDBExp'] = 102;
  276.         $userinfo['data']['intExp'] = 102;
  277.         $userinfo['data']['UserID'] = (int) $UserData->id;
  278.         $userinfo['data']['intHits'] = 1;
  279.         $userinfo['data']['ia1'] = 0;
  280.         $userinfo['data']['intHP'] = 596;
  281.         $userinfo['data']['dCreated'] = '5/23/2011 9:02:33 PM';
  282.         $userinfo['data']['strQuests'] = '00000000000000000000000000000000000000000000000000000000000000000000000000000000A0000000000000000000';
  283.         $userinfo['data']['iBoostG'] = 0;
  284.         $userinfo['data']['bitSuccess'] = 1;
  285.         $userinfo['data']['bPermaMute'] = false;
  286.         $userinfo['data']['intColorEye'] = (int) $UserData->ColorEye;
  287.         $userinfo['data']['strHairName'] = $UserData->HairName;
  288.         $userinfo['data']['iLCK'] = 0;
  289.         $userinfo['data']['iDailyAds'] = 0;
  290.         $userinfo['data']['iDBCP'] = 0;
  291.         $userinfo['data']['intDBGold'] = 955;
  292.         $userinfo['data']['iBoostCP'] = 0;
  293.         $userinfo['data']['intActivationFlag'] = 5;
  294.         $userinfo['data']['intAccessLevel'] = (int) $UserData->Access;
  295.         $userinfo['data']['strHairFilename'] = $UserData->HairFile;
  296.         $userinfo['data']['intColorHair'] = (int) $UserData->ColorHair;
  297.         $userinfo['data']['HairID'] = (int) $UserData->HairID;
  298.         $userinfo['data']['strGender'] = $UserData->Gender;
  299.         $userinfo['data']['strUsername'] = $UserData->Username;
  300.         $userinfo['data']['iDailyAdCap'] = 0;
  301.         $userinfo['data']['iDEX'] = 0;
  302.         $userinfo['data']['intCoins'] = 0;
  303.         $userinfo['data']['strMapName'] = 'battleon';
  304.         $userinfo['data']['iEND'] = 0;
  305.         $userinfo['data']['eqp'] = '';
  306.        
  307.         $useritems = $this->DB->query('SELECT * FROM users_items WHERE userid = ? AND equipped = 1 ORDER BY equipment DESC')->bind(1, $id)->resultset();
  308.  
  309.         foreach($useritems as $items) {
  310.             $item = $this->Items->get($items->itemid);
  311.             //{"Weapon":{"ItemID":1,"sFile":"items/swords/sword01.swf","sLink":""}
  312.             $itemEquip = $items->equipment;
  313.             $userinfo['data']['eqp'][$itemEquip] = [];
  314.             $userinfo['data']['eqp'][$itemEquip]['ItemID'] = (int) $item->id;
  315.             $userinfo['data']['eqp'][$itemEquip]['sFile'] = $item->File;
  316.             $userinfo['data']['eqp'][$itemEquip]['sLink'] = $item->Link;
  317.         }
  318.  
  319.         return $userinfo;
  320.     }
  321.  
  322.     public function testSendRoomData($client, $name, $id) {
  323.         $map = $this->Maps->get($name);
  324.  
  325.         $packet = [
  326.             't' => 'xt',
  327.             'b' => ['r' => -1,
  328.                     'o' => [
  329.                         'cmd' => 'moveToArea',
  330.                         'areaName' => $map->Name . '-' . $id,
  331.                         'uoBranch' => $this->GetUoBranch(),
  332.                         'strMapFileName' => $map->FileName,
  333.                         'intType' => 2,
  334.                         'monBranch' => [],
  335.                         'sExtra' => '',
  336.                         'areaId' => 2,
  337.                         'strMapName' => $map->Name
  338.                 ]
  339.             ]
  340.         ];
  341.  
  342.         $this->send($client, stripslashes(json_encode($packet)));
  343.         $this->send($client, "%xt%server%-1%You have joined {$map->Name}-{$id}!%");
  344.  
  345.     }
  346.  
  347.     public function RetrieveUserDatas($client, $perc) {
  348.         $a = [];
  349.  
  350.         $splitted = explode("%", $perc);
  351.  
  352.         for($i = 5; $i < count($splitted); $i++) {
  353.             $id = $splitted[$i];
  354.  
  355.             if($id != null && $id != 0) {
  356.                 array_push($a, $this->RetriveUserInfo($id));
  357.             }
  358.         }        
  359.  
  360.         $packet = [
  361.             't' => 'xt',
  362.             'b' => ['r' => -1,
  363.                     'o' => [
  364.                         'cmd' => 'initUserDatas',
  365.                         'a' => $a
  366.                 ]
  367.             ]
  368.         ];
  369.  
  370.         $this->send($client, stripslashes(json_encode($packet)));
  371.     }
  372.  
  373.     public function GetPid($client) {
  374.         for ($i=0; $i<$this->Room->UserList->size(); $i++) {
  375.             if ($this->Room->UserList->get($i) == $client) {
  376.                 return $i+2;
  377.             }
  378.         }
  379.         return -1;
  380.     }
  381.  
  382.     public function testJoinOK($client) {
  383.         $data = "";
  384.         $pid = $this->GetPid($client);
  385.  
  386.         $data .= "<msg t='sys'><body action='joinOK' r='2'><pid id='{$pid}'/><vars /><uLs r='2'>";
  387.  
  388.         foreach($this->Room->UserList as $users) {
  389.             $user = $this->GetClientData($users);
  390.             $test = $this->GetPid($users);
  391.  
  392.             $data .= "<u i='{$test}' m='0' s='0' p='{$test}'><n><![CDATA[{$user->Username}]]></n><vars></vars></u>";
  393.         }
  394.  
  395.         $data .= "</uLs></body></msg>";
  396.  
  397.         return $data;
  398.     }
  399.  
  400.     public function uER($client) {
  401.         $data = "";
  402.         $data .= "<msg t='sys'><body action='uER' r='2'>";
  403.  
  404.         foreach($this->Room->UserList as $users) {
  405.             $user = $this->GetClientData($users);
  406.             $test = $this->GetPid($users);
  407.             $data .= "<u i ='" . $user->id . "' m='0' s='0' p='" . $test . "'><n><![CDATA[" . $user->Username . "]]></n><vars></vars></u>";
  408.         }
  409.  
  410.         $data .= "</body></msg>";
  411.  
  412.         $this->SendRoom_Except($client, stripslashes($data));
  413.     }
  414.  
  415.     public function uotlsLoad($client) {
  416.                         // {"t":"xt","b":{"r":-1,"o":{"cmd":"uotls","o":{"strFrame":"Enter","intMP":100.0,"intLevel":1,"entID":2,"strPad":"Spawn","intMPMax":400.0,"intHP":400.0,"afk":false,"intHPMax":400.0,"ty":0,"tx":0,"intState":1,"entType":"p","showCloak":true,"showHelm":true,"strUsername":"twilly","uoName":"twilly"},"unm":"twilly"}}}
  417.         $packet = json_decode('{"t":"xt","b":{"r":-1,"o":{"cmd":"uotls","o":{"strFrame":"Enter","intMP":100.0,"intLevel":1,"entID":2,"strPad":"Spawn","intMPMax":400.0,"intHP":400.0,"afk":false,"intHPMax":400.0,"ty":0,"tx":0,"intState":1,"entType":"p","showCloak":true,"showHelm":true,"strUsername":"twilly","uoName":"twilly"},"unm":"twilly"}}}');
  418.  
  419.         $packet->b->o->strUsername = 'twilly';
  420.         $packet->b->o->unm = 'twilly';
  421.  
  422.  
  423.     }
  424.  
  425.     public function HandlePercentage($client, $perc) {
  426.         if(contains('firstJoin', $perc)) {
  427.             $this->Room->AddToRoom($client);
  428.  
  429.             $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"cmd":"cvu","o":{"PCstRatio":7.47,"PChpDelta":1640,"PChpBase1":360,"baseHit":0,"intSPtoDPS":10,"resistRating":17,"curveExponent":0.66,"baseCritValue":1.5,"PChpGoal100":4000,"intLevelCap":100,"baseMiss":0.1,"baseParry":0.03,"GstBase":12,"modRating":3,"baseResistValue":0.7,"baseBlockValue":0.7,"intHPperEND":5,"baseHaste":0,"baseBlock":0,"statsExponent":1,"PChpBase100":2000,"intAPtoDPS":10,"PCstBase":15,"baseCrit":0.05,"baseEventValue":0.05,"GstGoal":572,"PChpGoal1":400,"GstRatio":5.6,"intLevelMax":100,"bigNumberBase":8,"PCstGoal":762,"baseDodge":0.04,"PCDPSMod":0.85}}}}');
  430.  
  431.             $this->uER($client);
  432.  
  433.             $this->SendRoom_Except($client, '{"t":"xt","b":{"r":-1,"o":{"cmd":"uotls","o":{"strFrame":"Enter","intMP":100.0,"intLevel":1,"entID":2,"strPad":"Spawn","intMPMax":400.0,"intHP":400.0,"afk":false,"intHPMax":400.0,"ty":0,"tx":0,"intState":1,"entType":"p","showCloak":true,"showHelm":true,"strUsername":"twilly","uoName":"twilly"},"unm":"twilly"}}}');
  434.  
  435.             $this->JoinOK($client);
  436.  
  437.             $this->testSendRoomData($client, 'battleon', 1);
  438.         }
  439.  
  440.         if(contains('retrieveUserDatas', $perc)) {
  441.  
  442.             $this->RetrieveUserDatas($client, $perc);
  443.  
  444.         }
  445.  
  446.         if(contains('moveToCell', $perc)) {
  447.             $user = $this->GetClientData($client);
  448.             $this->SendRoom_Except($client, '%xt%uotls%-1%'.$user->Username.'%strPad:Spawn,tx:0,strFrame:"Enter",ty:0%');  
  449.            
  450.         }
  451.  
  452.         if(contains('retrieveInventory', $perc)) {
  453.             $user = $this->GetClientData($client);
  454.             $this->equipItem($client);
  455.            
  456.             $this->LoadInventory($client);
  457.            
  458.  
  459.             $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"tempSta":{"ba":{},"Weapon":{"STR":1,"INT":1,"DEX":1,"WIS":1,"END":1},"innate":{"STR":10,"INT":2,"DEX":8,"WIS":4,"LCK":2,"END":11},"ar":{"STR":1,"END":2},"he":{}},"cmd":"stu","sta":{"$tdo":0.061366354062338764,"$thi":0.009711979119244894,"_cmi":1,"$smb":0,"_tdo":0.04,"_cmo":1,"_sem":0.05,"$WIS":5,"$tha":0.014082369722905094,"_sp":0,"$tpa":0.03,"_cdi":1,"$cpo":1,"_chi":1,"$cpi":1,"_cdo":1,"_tbl":0,"_tpa":0.03,"_cho":1,"$LCK":2,"$shb":0,"$STR":12,"$sem":0.06942395823848979,"_ap":0,"_sbm":0.7,"$cmi":0.9854320313211327,"$cai":1,"$tbl":0,"_srm":0.7,"_cai":1,"$DEX":9,"_STR":10,"$ap":25,"$cao":1,"_DEX":8,"$sbm":0.6825184375853591,"$cmc":1,"$INT":3,"_cpi":1,"$chi":1,"$cho":1,"_INT":2,"_scm":1.5,"_cao":1,"_END":11,"_WIS":4,"_shb":0,"_tre":0.07,"$cdo":1,"$tcr":0.07525114571003673,"$END":14,"$cdi":1,"_cpo":1,"$scm":1.5485598955962245,"_tcr":0.05,"_tha":0,"_thi":0,"$srm":0.7,"$cmo":1,"$sp":6,"_LCK":2,"_cmc":1,"$tre":0.07,"_smb":0},"wDPS":18}}}');
  460.  
  461.  
  462.         }
  463.     }
  464.  
  465.  
  466.     public function LoadInventory($client) {
  467.         $packet = json_decode('{"t":"xt","b":{"r":-1,"o":{"bankCount":0,"cmd":"loadInventoryBig","items":[{"ItemID":1,"sDesc":"Sword","sName":"Default Sword","sFile":"items/swords/sword01.swf","sLink":"","sElmt":"Fire","iRng":100,"iDPS":100,"sES":"Weapon","sType":"Sword","iLvl":1,"sIcon":"iwsword","iRty":10,"iQSIndex":-1,"iQSValue":0,"iQty":1,"sReqQuests":"","iStk":1,"EnhLvl":1,"EnhID":1,"EnhDPS":0,"EnhRty":0,"EnhRng":0,"InvEnhPatternID":1,"EnhPatternID":1,"ProcID":-1,"bStaff":0,"bCoins":0,"bTemp":0,"bHouse":0,"bUpg":0,"iCost":0,"iHrs":-1,"sMeta":"","ClassId":-1,"bPTR":0,"bEquip":1},{"ItemID":2,"sDesc":"The heart of a warrior is filled with courage and strength. Your skills with weapons in close combat make you a powerful force on the battlefield.","sName":"Warrior","sFile":"NewWarriorB2.swf","sLink":"NewWarriorB2","sElmt":"Fire","iRng":100,"iDPS":100,"sES":"ar","sType":"Class","iLvl":1,"sIcon":"iiclass","iRty":10,"iQSIndex":-1,"iQSValue":0,"iQty":1,"sReqQuests":"","iStk":1,"EnhLvl":1,"EnhID":1,"EnhDPS":0,"EnhRty":0,"EnhRng":0,"InvEnhPatternID":1,"EnhPatternID":1,"ProcID":-1,"bStaff":0,"bCoins":0,"bTemp":0,"bHouse":0,"bUpg":0,"iCost":1000,"iHrs":-1,"sMeta":"33","ClassId":1,"bPTR":0,"bEquip":1}],"hitems":[]}}}');
  468.  
  469.         $user = $this->GetClientData($client);
  470.  
  471.         $packet->b->o->items = [];
  472.  
  473.         $query = $this->DB->query('SELECT * FROM users_items WHERE userid = ?')->bind(1, $user->id);
  474.  
  475.         $classID = 0;
  476.  
  477.         if($query->num_rows() > 0) {
  478.             $UserItems = $query->resultset();
  479.  
  480.             foreach($UserItems as $UserItem) {
  481.                 $item = $this->Items->get($UserItem->itemid);
  482.  
  483.                 if($item->ClassID > 0) {
  484.                     $classID = $item->ClassID;
  485.                 }
  486.  
  487.                 array_push($packet->b->o->items, [
  488.                     "ItemID" => (int) $item->id,
  489.                     "sDesc"  => $item->Desc,
  490.                     "sName"  => $item->Name,
  491.                     "sFile"  => $item->File,
  492.                     "sLink"  => $item->Link,
  493.                     "sElmt"  => $item->Elmt,
  494.                     "iRng"   => (int) $item->Rng,
  495.                     "iDPS"   => (int) $item->DPS,
  496.                     "sES"    => $item->ES,
  497.                     "sType"  => $item->Type,
  498.                     "iLvl"   => (int) $item->Lvl,
  499.                     "sIcon"  => $item->Icon,
  500.                     "iRty"   => (int) $item->Rty,
  501.                     "iQSIndex" => -1,
  502.                     "iQSValue" => 0,
  503.                     "sReqQuests" => "",
  504.                     "iStk"   => (int) $item->Stk,
  505.                     "EnhLvl" => 1,
  506.                     "EnhID"  => 1,
  507.                     "EnhDPS" => 0,
  508.                     "EnhRty" => 0,
  509.                     "EnhRng" => 0,
  510.                     "InvEnhPatternID" => 1,
  511.                     "EnhPatternID"    => 1,
  512.                     "ProcID" => -1,
  513.                     "bStaff" => $item->Staff,
  514.                     "bCoins" => $item->Coins,
  515.                     "bTemp"  => $item->Temp,
  516.                     "bHouse" => $item->House,
  517.                     "bUpg"   => $item->Upg,
  518.                     "iCost"  => $item->Cost,
  519.                     "iHrs"   => -1,
  520.                     "sMeta"  => "",
  521.                     "ClassId" => (int) $classID,
  522.                     "bPTR"   => 0,
  523.                     "bEquip" => $UserItem->equipped
  524.                 ]);
  525.             }
  526.  
  527.             $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"cmd":"clearAuras"}}}');
  528.             $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"cmd":"aura+p","auras":[],"tInf":"p:2"}}}');
  529.            
  530.             $this->write($classID);
  531.  
  532.             $skills = json_decode('{"t":"xt","b":{"r":-1,"o":{"cmd":"sAct","actions":{"passive":[{"id":71,"ref":"p1","icon":"isp2","nam":"Aggression","desc":"You deal 10% additional damage with physical attacks","range":null,"isOK":false,"fx":"m","tgt":"s","typ":"passive"},{"id":72,"ref":"p2","icon":"isp2","nam":"Resolute","desc":"Damage taken reduced by 10%","range":null,"isOK":false,"fx":"m","tgt":"s","typ":"passive"}],"active":[{"id":1,"icon":"iwd1","ref":"aa","mp":0,"nam":"Auto attack","anim":"Attack1,Attack2","desc":"A basic attack, taught to all adventurers.","range":301,"isOK":true,"fx":"m","damage":1,"auto":true,"tgt":"h","tgtMax":1,"typ":"aa","cd":2000,"dsrc":"AP2"},{"id":2,"icon":"ims2,iwaxe","ref":"a1","mp":20,"nam":"Decisive Strike","anim":"Attack3","desc":"A powerful strike, dealing 150% weapon damage.","range":301,"isOK":true,"fx":"m","damage":2,"auto":false,"tgt":"h","tgtMax":1,"typ":"p","cd":2000,"dsrc":"AP2"},{"id":3,"icon":"iss1","ref":"a2","mp":30,"nam":"Imbalancing Strike","anim":"Stab","desc":"A precise blow which stuns your opponent for 4 seconds.","range":301,"isOK":false,"fx":"m","damage":0,"auto":false,"tgt":"h","tgtMax":1,"typ":"p","cd":10000,"dsrc":"AP2"},{"id":4,"icon":"imd1,iwsword","ref":"a3","mp":20,"nam":"Prepared Strike","anim":"Point","desc":"Your next two auto attacks taken within 5 seconds will be powerful critical hits which cannot be avoided.","range":301,"isOK":false,"fx":"m","damage":0,"auto":false,"tgt":"s","tgtMax":1,"typ":"p","cd":15000},{"id":5,"icon":"iwshield","ref":"a4","mp":30,"nam":"On Guard","anim":"Attack4","desc":"Challenge your opponent, dealing 75% normal damage, and taking 50% damage from all sources for 10 seconds.","range":301,"isOK":false,"fx":"m","damage":0,"auto":false,"tgt":"h","tgtMax":1,"typ":"p","cd":30000,"dsrc":"AP2"},{"id":6,"icon":"icu1","ref":"i1","mp":0,"nam":"Potions","anim":"Cheer","desc":"Equip a potion or scroll from your inventory to use it here.","range":808,"isOK":true,"fx":"","damage":0,"auto":false,"tgt":"f","tgtMax":1,"typ":"i","cd":60000}]}}}}');        
  533.            
  534.             $skills->b->o->actions = [];
  535.             $skills->b->o->actions['passive'] = [];
  536.  
  537.             $classes = $this->DB->query('SELECT * FROM classes WHERE id = ?')->bind(1, $classID);
  538.  
  539.             if($classes->num_rows() > 0) {
  540.                 $class = $classes->single();
  541.                
  542.                 if(!empty($class->Passives)) {
  543.                     $PassiveIDs = explode(",", $class->Passives);
  544.  
  545.                     foreach($PassiveIDs as $PassiveID) {
  546.                         if($PassiveID != null && $PassiveID != 0) {
  547.                            $passive = $this->Passives->get($PassiveID);
  548.  
  549.                             array_push($skills->b->o->actions['passive'], [
  550.                                 'id' => $passive->auraid,
  551.                                 'ref' => $passive->Ref,
  552.                                 'icon' => $passive->Icon,
  553.                                 'nam'  => $passive->Name,
  554.                                 'range' => null,
  555.                                 'isOK'  => false,
  556.                                 'fx' => 'm',
  557.                                 'tgt' => 's',
  558.                                 'typ' => $passive->Type
  559.                             ]);
  560.  
  561.                         }
  562.                     }                                  
  563.                 }
  564.  
  565.                 $skills->b->o->actions['active'] = [];
  566.  
  567.                 if(!empty($class->Skills)) {
  568.                     $SkillIDs = explode(",", $class->Skills);
  569.  
  570.                     foreach($SkillIDs as $SkillID) {
  571.                         if($SkillID != null && $SkillID != 0) {
  572.                             $Skill = $this->Skills->get($SkillID);
  573.                            
  574.                             if (strpos($Skill->Extra, ",")) {
  575.                                 $ExtArray = explode(",", $Skill->Extra);
  576.                                 $Extra = array($ExtArray[0] => $ExtArray[1]);
  577.                             } else {
  578.                                 $Extra = (object)null;
  579.                             }
  580.  
  581.                             array_push($skills->b->o->actions['active'], [
  582.                                 'id' => (int)$Skill->id,
  583.                                 'nam' => $Skill->nam,
  584.                                 'icon' => $Skill->icon,
  585.                                 'desc' => $Skill->description,
  586.                                 'mp' => $Skill->mp,
  587.                                 'anim' => $Skill->anim,
  588.                                 'Ref' => $Skill->Ref,
  589.                                 'isOK' => (bool)$Skill->isOK,
  590.                                 'tgt' => $Skill->tgt,
  591.                                 'tgtMax' => (int)$Skill->tgtMax,
  592.                                 'typ' => $Skill->typ,
  593.                                 'range' => $Skill->rng,
  594.                                 'fx' => $Skill->fx,
  595.                                 'cd' => (int)$Skill->cd,
  596.                                 'Extra' => $Extra
  597.                             ]);
  598.  
  599.                         }
  600.                     }
  601.                 }
  602.             }
  603.  
  604.             $this->send($client, stripslashes(json_encode($skills)));          
  605.  
  606.             $this->send($client, '{"t":"xt","b":{"r":-1,"o":{"cmd":"enhp","o":{"1":{"iWIS":"16","sDesc":"none","ID":"1","iSTR":"16","iLCK":"0","sName":"Adventurer","iDEX":"16","iEND":"18","iINT":"16"}}}}}');            
  607.  
  608.  
  609.         }
  610.  
  611.         $this->send($client, stripslashes(json_encode($packet)));
  612.     }
  613.  
  614.  
  615.     public function SendRoom_Except($client, $packet) {
  616.         foreach ($this->Room->UserList as $user) {
  617.             if ($client != $user) {
  618.                 $this->send($user, $packet);
  619.             }
  620.         }
  621.     }
  622.  
  623.     public function SendRoom($packet) {
  624.         foreach ($this->Room->UserList as $user) {
  625.             $this->send($user, $packet);
  626.         }
  627.     }
  628.  
  629.     public function LoginParse($client, $xml) {
  630.         $XMLDom = new SimpleXMLElement($xml);
  631.         $unmArray = $XMLDom->xpath('/msg/body/login/nick');
  632.         $pwdArray = $XMLDom->xpath('/msg/body/login/pword');
  633.        
  634.         $username = explode("~",$unmArray[0])[1];
  635.         $password = $pwdArray[0];
  636.  
  637.         $this->write("Login attempt by: " . $username . ", " . $password, "XML");
  638.         $XMLDom = null;
  639.  
  640.         unset($unmArray);
  641.         unset($pwdArray);
  642.  
  643.         $query = $this->DB->query('SELECT * FROM users WHERE Username = ? AND Password = ?')->bind(1, $username)->bind(2, $password);
  644.  
  645.         if($query->num_rows() > 0) {
  646.             $UserData = $query->single();
  647.             $UserData->Username = strtolower($UserData->Username);
  648.             $Settings = $this->GetSettingsObject();
  649.  
  650.             $this->AddClientData($client, $UserData);
  651.  
  652.             $this->send($client, "%xt%server%-1%Accepting party invites.%");
  653.             $this->send($client, "%xt%server%-1%Accepting goto requests%");
  654.             $this->send($client, "%xt%server%-1%Accepting Friend requests.%");
  655.             $this->send($client, "%xt%server%-1%Accepting PMs.%");
  656.             $this->send($client, "%xt%server%-1%Ability ToolTips will always show on mouseover.%");
  657.             $this->send($client, "%xt%server%-1%Accepting duel invites.%");
  658.             $this->send($client, "%xt%server%-1%Accepting guild invites.%");
  659.             $this->send($client, "%xt%loginResponse%-1%true%{$UserData->id}%{$UserData->Username}%{$Settings->MOTD}%2016-07-18T01:01:05%sNews={$Settings->News},sMap={$Settings->Map},sBook={$Settings->Book},sFBC={$Settings->FBC},sAssets={$Settings->Assets},sWTSandbox={$Settings->WTSandbox},gMenu={$Settings->GameMenu},sVideo={$Settings->Video}%");
  660.            
  661.             unset($Settings);
  662.             unset($UserData);
  663.         }
  664.  
  665.         unset($query);
  666.  
  667.     }
  668. }
  669.  
  670.  
  671. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement