Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.88 KB | None | 0 0
  1. <?php
  2. class Shortcuts
  3. {
  4. private $steamUID;
  5. private $shortcut1;
  6. private $shortcut2;
  7. private $shortcut3;
  8. private $shortcut4;
  9. private $shortcut5;
  10. private $shortcut6;
  11. private $shortcut7;
  12. private $shortcut8;
  13. private $shortcut9;
  14. private $shortcut10;
  15. private $db;
  16.  
  17. function __construct($steamUID)
  18. {
  19. $this->steamUID = $steamUID;
  20. $this->db = new PDO('mysql:host=127.0.0.1;dbname=dayz;charset=utf8', 'root', '');
  21. }
  22.  
  23. function setShortcuts($shortcuts)
  24. {
  25. $this->shortcut1 = $shortcuts[0];
  26. $this->shortcut2 = $shortcuts[1];
  27. $this->shortcut3 = $shortcuts[2];
  28. $this->shortcut4 = $shortcuts[3];
  29. $this->shortcut5 = $shortcuts[4];
  30. $this->shortcut6 = $shortcuts[5];
  31. $this->shortcut7 = $shortcuts[6];
  32. $this->shortcut8 = $shortcuts[7];
  33. $this->shortcut9 = $shortcuts[8];
  34. $this->shortcut10 = $shortcuts[9];
  35. }
  36.  
  37. function playerExists()
  38. {
  39. try
  40. {
  41.  
  42. $stmt = $this->db->prepare("SELECT steamUID FROM shortcuts WHERE steamUID = ?");
  43. $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
  44. $stmt->execute();
  45. $row_count = $stmt->rowCount();
  46. if($row_count > 0) { return true; }
  47. return false;
  48. }catch(Exception $ex)
  49. {
  50.  
  51. }
  52. }
  53.  
  54. function registerPlayer()
  55. {
  56. if($this->playerExists() == false)
  57. {
  58. try
  59. {
  60. $stmt = $this->db->prepare("INSERT INTO shortcuts(steamUID) VALUES(:steamUID)");
  61. $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
  62. $stmt->execute();
  63. }catch(Exception $ex)
  64. {
  65.  
  66. }
  67. }
  68. }
  69.  
  70. function updateShortcuts()
  71. {
  72. if($this->playerExists() == false)
  73. {
  74. $this->registerPlayer();
  75. }
  76. if($this->playerExists() == true)
  77. {
  78. try
  79. {
  80.  
  81. $stmt = $this->db->prepare("
  82. UPDATE shortcuts SET
  83. shortcut1 = :shortcut1,
  84. shortcut2 = :shortcut2,
  85. shortcut3 = :shortcut3,
  86. shortcut4 = :shortcut4,
  87. shortcut5 = :shortcut5,
  88. shortcut6 = :shortcut6,
  89. shortcut7 = :shortcut7,
  90. shortcut8 = :shortcut8,
  91. shortcut9 = :shortcut9,
  92. shortcut10 = :shortcut10
  93. WHERE steamUID = :steamUID");
  94. $stmt->bindValue(':shortcut1', $this->shortcut1);
  95. $stmt->bindValue(':shortcut2', $this->shortcut2);
  96. $stmt->bindValue(':shortcut3', $this->shortcut3);
  97. $stmt->bindValue(':shortcut4', $this->shortcut4);
  98. $stmt->bindValue(':shortcut5', $this->shortcut5);
  99. $stmt->bindValue(':shortcut6', $this->shortcut6);
  100. $stmt->bindValue(':shortcut7', $this->shortcut7);
  101. $stmt->bindValue(':shortcut8', $this->shortcut8);
  102. $stmt->bindValue(':shortcut9', $this->shortcut9);
  103. $stmt->bindValue(':shortcut10', $this->shortcut10);
  104. $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
  105. $stmt->execute();
  106. }catch(Exception $ex)
  107. {
  108.  
  109. }
  110. }
  111. }
  112. }
  113.  
  114. DEFINE('SAVE_PATH', "C:\wamp\www\DayZServlet\saves\\");
  115.  
  116. class Player
  117. {
  118. private $id;
  119. private $steamUID = '';
  120. private $json = '';
  121. private $model = '';
  122. private $pos = '';
  123. private $dir = '';
  124. private $up = '';
  125. private $alive;
  126.  
  127. private $exposure = 0;
  128. private $modifiers = '';
  129. private $modstates = '';
  130. private $bloodType = '';
  131. private $blood;
  132. private $health;
  133. private $shock;
  134. private $energy;
  135. private $water;
  136. private $stomach;
  137. private $diet;
  138. private $bleedingSources;
  139. private $unconscious; //bool
  140.  
  141. private $items;
  142. private $shortcuts;
  143.  
  144. private $setting = '';
  145. private $db;
  146.  
  147. function __construct()
  148. {
  149. $this->db = new PDO('mysql:host=127.0.0.1;dbname=dayz;charset=utf8', 'root', '');
  150. }
  151.  
  152. public function getModStates(){
  153. return $this->modStates;
  154. }
  155.  
  156. public function setModStates($modStates)
  157. {
  158. $this->modStates = $modStates;
  159. }
  160.  
  161. public function getModifiers(){
  162. return $this->modifiers;
  163. }
  164.  
  165. public function setModifiers($modifiers)
  166. {
  167. $this->modifiers = $modifiers;
  168. }
  169.  
  170. public function getExposure(){
  171. return $this->exposure;
  172. }
  173.  
  174. public function setExposure($exposure)
  175. {
  176. $this->exposure = $exposure;
  177. }
  178.  
  179. public function getAlive(){
  180. return $this->alive;
  181. }
  182.  
  183. public function setAlive($alive)
  184. {
  185. $this->alive = $alive;
  186. }
  187.  
  188. public function getShortcuts(){
  189. return $this->shortcuts;
  190. }
  191.  
  192. public function setShortcuts($shortcuts)
  193. {
  194. $this->shortcuts = new Shortcuts($this->steamUID);
  195. $this->shortcuts->setShortcuts($shortcuts);
  196. }
  197.  
  198.  
  199. public function getItems(){
  200. return $this->items;
  201. }
  202.  
  203. public function setItems($items)
  204. {
  205. $this->items = $items;
  206. }
  207.  
  208. public function getbloodType(){
  209. return $this->bloodType;
  210. }
  211.  
  212. public function setbloodType($bloodType)
  213. {
  214. $this->bloodType = $bloodType;
  215. }
  216.  
  217. public function getBlood(){
  218. return $this->blood;
  219. }
  220.  
  221. public function setBlood($blood){
  222. $this->blood = $blood;
  223. }
  224.  
  225. public function getHealth(){
  226. return $this->health;
  227. }
  228.  
  229. public function setHealth($health){
  230. $this->health = $health;
  231. }
  232.  
  233. public function getShock(){
  234. return $this->shock;
  235. }
  236.  
  237. public function setShock($shock){
  238. $this->shock = $shock;
  239. }
  240.  
  241. public function getEnergy(){
  242. return $this->energy;
  243. }
  244.  
  245. public function setEnergy($energy){
  246. $this->energy = $energy;
  247. }
  248.  
  249. public function getWater(){
  250. return $this->water;
  251. }
  252.  
  253. public function setWater($water){
  254. $this->water = $water;
  255. }
  256.  
  257. public function getStomach(){
  258. return $this->stomach;
  259. }
  260.  
  261. public function setStomach($stomach){
  262. $this->stomach = $stomach;
  263. }
  264.  
  265. public function getDiet(){
  266. return $this->diet;
  267. }
  268.  
  269. public function setDiet($diet){
  270. $this->diet = $diet;
  271. }
  272.  
  273. public function getBleedingSources(){
  274. return $this->bleedingSources;
  275. }
  276.  
  277. public function setBleedingSources($bleedingSources){
  278. if($bleedingSources == null || $bleedingSources == '' || $bleedingSources == 'null')
  279. {
  280. $this->bleedingSources = '"[]"';
  281. }
  282. else
  283. {
  284. $this->bleedingSources = $bleedingSources;
  285. }
  286. }
  287.  
  288. public function getUnconscious(){
  289. return $this->unconscious;
  290. }
  291.  
  292. public function setUnconscious($unconscious){
  293. $this->unconscious = $unconscious;
  294. }
  295.  
  296. function getSteamUID()
  297. {
  298. return $this->steamUID;
  299. }
  300.  
  301. function setSteamUID($steamUID)
  302. {
  303. $this->steamUID = $steamUID;
  304. }
  305.  
  306. function setPos($pos)
  307. {
  308. $this->pos = $pos[0] . ','.$pos[1].','.$pos[2];;
  309. }
  310. function setDir($dir)
  311. {
  312. $this->dir = $dir[0] . ','.$dir[1].','.$dir[2];;
  313. }
  314. function setUp($up)
  315. {
  316. $this->up = $up[0] . ','.$up[1].','.$up[2];;
  317. }
  318.  
  319. function setModel($model)
  320. {
  321. $this->model = $model;
  322. }
  323.  
  324. function setSetting($setting)
  325. {
  326. $this->setting = $setting;
  327. }
  328.  
  329. function getJsonFile()
  330. {
  331. file_get_contents(SAVE_PATH.$this->steamUID.'.json');
  332. }
  333.  
  334. function saveJsonFile($content)
  335. {
  336. if(empty($content))
  337. {
  338. file_put_contents(SAVE_PATH.$this->steamUID.'.json', "", LOCK_EX);
  339. }
  340. else
  341. {
  342. file_put_contents(SAVE_PATH.$this->steamUID.'.json', $content, LOCK_EX);
  343. }
  344. }
  345.  
  346. function setFromJson($json)
  347. {
  348. $settings = json_decode($json);
  349. $this->setModel($settings->model);
  350. $this->setPos($settings->pos);
  351. $this->setDir($settings->dir);
  352. $this->setUp($settings->up);
  353. $this->setAlive($settings->alive);
  354. $this->setModifiers(json_encode($settings->state->vars->modifiers));
  355. $this->setModStates(json_encode($settings->state->vars->modstates));
  356. $this->setExposure($settings->state->vars->exposure);
  357. $this->setBloodType($settings->state->vars->bloodtype);
  358. $this->setBlood($settings->state->vars->blood);
  359. $this->setHealth($settings->state->vars->health);
  360. $this->setShock($settings->state->vars->shock);
  361. $this->setEnergy($settings->state->vars->energy);
  362. $this->setWater($settings->state->vars->water);
  363. $this->setStomach($settings->state->vars->stomach);
  364. $this->setDiet($settings->state->vars->diet);
  365. $this->setBleedingSources(json_encode($settings->state->vars->bleedingsources));
  366. $this->setUnconscious($settings->state->vars->unconscious);
  367. $this->setItems(json_encode($settings->items));
  368. $this->setShortcuts($settings->state->shortcuts);
  369. }
  370.  
  371. function registerPlayer()
  372. {
  373. if($this->playerExists() == false)
  374. {
  375. try
  376. {
  377.  
  378. $stmt = $this->db->prepare("INSERT INTO players(steamUID, firstPlayed) VALUES(:steamUID, NOW())");
  379. $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
  380. $stmt->execute();
  381. }catch(Exception $ex)
  382. {
  383.  
  384. }
  385. }
  386. }
  387.  
  388. function playerExists()
  389. {
  390. try
  391. {
  392.  
  393. $stmt = $this->db->prepare("SELECT steamUID FROM players WHERE steamUID = ?");
  394. $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
  395. $stmt->execute();
  396. $row_count = $stmt->rowCount();
  397. if($row_count > 0) { return true; }
  398. return false;
  399. }catch(Exception $ex)
  400. {
  401.  
  402. }
  403. }
  404.  
  405. function updatePlayer()
  406. {
  407. if($this->playerExists() == true)
  408. {
  409. try
  410. {
  411.  
  412. $stmt = $this->db->prepare("
  413. UPDATE players SET
  414. model = :model,
  415. pos = :pos,
  416. dir = :dir,
  417. up = :up,
  418. alive = :alive,
  419. modStates = :modStates,
  420. modifiers = :modifiers,
  421. exposure = :exposure,
  422. bloodType = :bloodType,
  423. blood = :blood,
  424. health = :health,
  425. shock = :shock,
  426. energy = :energy,
  427. water = :water,
  428. stomach = :stomach,
  429. diet = :diet,
  430. bleedingSources = :bleedingSources,
  431. unconscious = :unconscious,
  432. items =:items
  433. WHERE steamUID = :steamUID");
  434. $stmt->bindValue(':model', $this->model, PDO::PARAM_STR);
  435. $stmt->bindValue(':pos', $this->pos, PDO::PARAM_STR);
  436. $stmt->bindValue(':dir', $this->dir, PDO::PARAM_STR);
  437. $stmt->bindValue(':up', $this->up, PDO::PARAM_STR);
  438. $stmt->bindValue(':alive', $this->alive, PDO::PARAM_STR);
  439. $stmt->bindValue(':modStates', $this->modStates);
  440. $stmt->bindValue(':modifiers', $this->modifiers);
  441. $stmt->bindValue(':exposure', $this->exposure);
  442. $stmt->bindValue(':bloodType', $this->bloodType);
  443. $stmt->bindValue(':blood', $this->blood);
  444. $stmt->bindValue(':health', $this->health);
  445. $stmt->bindValue(':shock', $this->shock);
  446. $stmt->bindValue(':energy', $this->energy);
  447. $stmt->bindValue(':water', $this->water);
  448. $stmt->bindValue(':stomach', $this->stomach);
  449. $stmt->bindValue(':diet', $this->diet);
  450. $stmt->bindValue(':bleedingSources', $this->bleedingSources);
  451. $stmt->bindValue(':unconscious', $this->unconscious);
  452. $stmt->bindValue(':items', $this->items);
  453. $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
  454. $stmt->execute();
  455.  
  456. $this->shortcuts->updateShortcuts();
  457. }catch(Exception $ex)
  458. {
  459.  
  460. }
  461. }
  462. }
  463.  
  464. function getPlayer()
  465. {
  466. if($this->playerExists() == false)
  467. {
  468. $this->registerPlayer();
  469. }
  470.  
  471. try
  472. {
  473.  
  474. $stmt = $this->db->prepare("SELECT * FROM players WHERE steamUID = ?");
  475. $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
  476. $stmt->execute();
  477. $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  478. }catch(Exception $ex)
  479. {
  480.  
  481. }
  482. }
  483.  
  484. function makeJson()
  485. {
  486. if($this->playerExists() == false)
  487. {
  488. $this->registerPlayer();
  489. }
  490.  
  491. try
  492. {
  493.  
  494. $stmt = $this->db->prepare("SELECT * FROM players WHERE steamUID = :steamUID");
  495. $stmt->bindValue(':steamUID', $this->steamUID);
  496. $stmt->execute();
  497. $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
  498.  
  499. $stmt = $this->db->prepare("SELECT * FROM shortcuts WHERE steamUID = :steamUID");
  500. $stmt->bindValue(':steamUID', $this->steamUID);
  501. $stmt->execute();
  502. $possedeShortcuts = $stmt->rowCount();
  503.  
  504. $stmt = $this->db->prepare("SELECT * FROM shortcuts WHERE steamUID = :steamUID");
  505. $stmt->bindValue(':steamUID', $this->steamUID);
  506. $stmt->execute();
  507. $rowsShortcuts = $stmt->fetchAll(PDO::FETCH_ASSOC);
  508.  
  509. $sets['model'] = $rows[0]['model'];
  510. $sets['alive'] = (int)$rows[0]['alive'];
  511.  
  512. $positions = explode(',', $rows[0]['pos']);
  513. $sets['pos'][0] = (float)$positions[0];
  514. $sets['pos'][1] = (float)$positions[1];
  515. $sets['pos'][2] = (float)$positions[2];
  516.  
  517. $dirs = explode(',', $rows[0]['dir']);
  518. $sets['dir'][0] = (float)$dirs[0];
  519. $sets['dir'][1] = (int)$dirs[1];
  520. $sets['dir'][2] = (float)$dirs[2];
  521.  
  522. $ups = explode(',', $rows[0]['up']);
  523. $sets['up'][0] = (int)$ups[0];
  524. $sets['up'][1] = (int)$ups[1];
  525. $sets['up'][2] = (int)$ups[2];
  526.  
  527. /* Items */
  528. $sets['items'] = json_decode($rows[0]['items']);
  529.  
  530. /* States */
  531. $sets['state']['vars']['exposure'] = (int)$rows[0]['exposure'];
  532.  
  533. $modifiers = $rows[0]['modifiers'];
  534.  
  535. if($modifiers == '' || $modifiers == null)
  536. {
  537. $sets['state']['vars']['modifiers'] = array();
  538. }
  539. else
  540. {
  541. $sets['state']['vars']['modifiers'] = json_decode($rows[0]['modifiers']);
  542. }
  543.  
  544.  
  545. $modstates = $rows[0]['modStates'];
  546. if($modstates == '' || $modstates == ',,')
  547. {
  548. $sets['state']['vars']['modstates'] = array();
  549. }
  550. else
  551. {
  552. $sets['state']['vars']['modstates'] = json_decode($rows[0]['modStates']);
  553. }
  554.  
  555.  
  556. $sets['state']['vars']['bloodtype'] = $rows[0]['bloodType'];
  557. $sets['state']['vars']['blood'] = (int)$rows[0]['blood'];
  558. $sets['state']['vars']['health'] = (int)$rows[0]['health'];
  559. $sets['state']['vars']['shock'] = (float)$rows[0]['shock'];
  560. $sets['state']['vars']['energy'] = (float)$rows[0]['energy'];
  561. $sets['state']['vars']['water'] = (float)$rows[0]['water'];
  562. $sets['state']['vars']['stomach'] = (int)$rows[0]['stomach'];
  563. $sets['state']['vars']['diet'] = (float)$rows[0]['diet'];
  564. if($rows[0]['bleedingSources'] == '')
  565. {
  566. $sets['state']['vars']['bleedingsources'] = array();
  567. }
  568. else
  569. {
  570. $sets['state']['vars']['bleedingsources'] = json_decode($rows[0]['bleedingSources']);
  571. }
  572. $sets['state']['vars']['unconscious'] = (bool)$rows[0]['unconscious'];
  573.  
  574. /* Shortcuts */
  575. if($possedeShortcuts > 0)
  576. {
  577. $sets['state']['shortcuts'] = array( $rowsShortcuts[0]['shortcut1'],
  578. $rowsShortcuts[0]['shortcut2'],
  579. $rowsShortcuts[0]['shortcut3'],
  580. $rowsShortcuts[0]['shortcut4'],
  581. $rowsShortcuts[0]['shortcut5'],
  582. $rowsShortcuts[0]['shortcut6'],
  583. $rowsShortcuts[0]['shortcut7'],
  584. $rowsShortcuts[0]['shortcut8'],
  585. $rowsShortcuts[0]['shortcut9'],
  586. $rowsShortcuts[0]['shortcut10'] );
  587. }
  588. else
  589. {
  590. $sets['state']['shortcuts'] = array( '',
  591. '',
  592. '',
  593. '',
  594. '',
  595. '',
  596. '',
  597. '','',
  598. '' );
  599. }
  600. return json_encode($sets);
  601.  
  602. }catch(Exception $ex)
  603. {
  604.  
  605. }
  606. }
  607.  
  608. }
  609. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement