Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Shortcuts
- {
- private $steamUID;
- private $shortcut1;
- private $shortcut2;
- private $shortcut3;
- private $shortcut4;
- private $shortcut5;
- private $shortcut6;
- private $shortcut7;
- private $shortcut8;
- private $shortcut9;
- private $shortcut10;
- private $db;
- function __construct($steamUID)
- {
- $this->steamUID = $steamUID;
- $this->db = new PDO('mysql:host=127.0.0.1;dbname=dayz;charset=utf8', 'root', '');
- }
- function setShortcuts($shortcuts)
- {
- $this->shortcut1 = $shortcuts[0];
- $this->shortcut2 = $shortcuts[1];
- $this->shortcut3 = $shortcuts[2];
- $this->shortcut4 = $shortcuts[3];
- $this->shortcut5 = $shortcuts[4];
- $this->shortcut6 = $shortcuts[5];
- $this->shortcut7 = $shortcuts[6];
- $this->shortcut8 = $shortcuts[7];
- $this->shortcut9 = $shortcuts[8];
- $this->shortcut10 = $shortcuts[9];
- }
- function playerExists()
- {
- try
- {
- $stmt = $this->db->prepare("SELECT steamUID FROM shortcuts WHERE steamUID = ?");
- $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- $row_count = $stmt->rowCount();
- if($row_count > 0) { return true; }
- return false;
- }catch(Exception $ex)
- {
- }
- }
- function registerPlayer()
- {
- if($this->playerExists() == false)
- {
- try
- {
- $stmt = $this->db->prepare("INSERT INTO shortcuts(steamUID) VALUES(:steamUID)");
- $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- }catch(Exception $ex)
- {
- }
- }
- }
- function updateShortcuts()
- {
- if($this->playerExists() == false)
- {
- $this->registerPlayer();
- }
- if($this->playerExists() == true)
- {
- try
- {
- $stmt = $this->db->prepare("
- UPDATE shortcuts SET
- shortcut1 = :shortcut1,
- shortcut2 = :shortcut2,
- shortcut3 = :shortcut3,
- shortcut4 = :shortcut4,
- shortcut5 = :shortcut5,
- shortcut6 = :shortcut6,
- shortcut7 = :shortcut7,
- shortcut8 = :shortcut8,
- shortcut9 = :shortcut9,
- shortcut10 = :shortcut10
- WHERE steamUID = :steamUID");
- $stmt->bindValue(':shortcut1', $this->shortcut1);
- $stmt->bindValue(':shortcut2', $this->shortcut2);
- $stmt->bindValue(':shortcut3', $this->shortcut3);
- $stmt->bindValue(':shortcut4', $this->shortcut4);
- $stmt->bindValue(':shortcut5', $this->shortcut5);
- $stmt->bindValue(':shortcut6', $this->shortcut6);
- $stmt->bindValue(':shortcut7', $this->shortcut7);
- $stmt->bindValue(':shortcut8', $this->shortcut8);
- $stmt->bindValue(':shortcut9', $this->shortcut9);
- $stmt->bindValue(':shortcut10', $this->shortcut10);
- $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- }catch(Exception $ex)
- {
- }
- }
- }
- }
- DEFINE('SAVE_PATH', "C:\wamp\www\DayZServlet\saves\\");
- class Player
- {
- private $id;
- private $steamUID = '';
- private $json = '';
- private $model = '';
- private $pos = '';
- private $dir = '';
- private $up = '';
- private $alive;
- private $exposure = 0;
- private $modifiers = '';
- private $modstates = '';
- private $bloodType = '';
- private $blood;
- private $health;
- private $shock;
- private $energy;
- private $water;
- private $stomach;
- private $diet;
- private $bleedingSources;
- private $unconscious; //bool
- private $items;
- private $shortcuts;
- private $setting = '';
- private $db;
- function __construct()
- {
- $this->db = new PDO('mysql:host=127.0.0.1;dbname=dayz;charset=utf8', 'root', '');
- }
- public function getModStates(){
- return $this->modStates;
- }
- public function setModStates($modStates)
- {
- $this->modStates = $modStates;
- }
- public function getModifiers(){
- return $this->modifiers;
- }
- public function setModifiers($modifiers)
- {
- $this->modifiers = $modifiers;
- }
- public function getExposure(){
- return $this->exposure;
- }
- public function setExposure($exposure)
- {
- $this->exposure = $exposure;
- }
- public function getAlive(){
- return $this->alive;
- }
- public function setAlive($alive)
- {
- $this->alive = $alive;
- }
- public function getShortcuts(){
- return $this->shortcuts;
- }
- public function setShortcuts($shortcuts)
- {
- $this->shortcuts = new Shortcuts($this->steamUID);
- $this->shortcuts->setShortcuts($shortcuts);
- }
- public function getItems(){
- return $this->items;
- }
- public function setItems($items)
- {
- $this->items = $items;
- }
- public function getbloodType(){
- return $this->bloodType;
- }
- public function setbloodType($bloodType)
- {
- $this->bloodType = $bloodType;
- }
- public function getBlood(){
- return $this->blood;
- }
- public function setBlood($blood){
- $this->blood = $blood;
- }
- public function getHealth(){
- return $this->health;
- }
- public function setHealth($health){
- $this->health = $health;
- }
- public function getShock(){
- return $this->shock;
- }
- public function setShock($shock){
- $this->shock = $shock;
- }
- public function getEnergy(){
- return $this->energy;
- }
- public function setEnergy($energy){
- $this->energy = $energy;
- }
- public function getWater(){
- return $this->water;
- }
- public function setWater($water){
- $this->water = $water;
- }
- public function getStomach(){
- return $this->stomach;
- }
- public function setStomach($stomach){
- $this->stomach = $stomach;
- }
- public function getDiet(){
- return $this->diet;
- }
- public function setDiet($diet){
- $this->diet = $diet;
- }
- public function getBleedingSources(){
- return $this->bleedingSources;
- }
- public function setBleedingSources($bleedingSources){
- if($bleedingSources == null || $bleedingSources == '' || $bleedingSources == 'null')
- {
- $this->bleedingSources = '"[]"';
- }
- else
- {
- $this->bleedingSources = $bleedingSources;
- }
- }
- public function getUnconscious(){
- return $this->unconscious;
- }
- public function setUnconscious($unconscious){
- $this->unconscious = $unconscious;
- }
- function getSteamUID()
- {
- return $this->steamUID;
- }
- function setSteamUID($steamUID)
- {
- $this->steamUID = $steamUID;
- }
- function setPos($pos)
- {
- $this->pos = $pos[0] . ','.$pos[1].','.$pos[2];;
- }
- function setDir($dir)
- {
- $this->dir = $dir[0] . ','.$dir[1].','.$dir[2];;
- }
- function setUp($up)
- {
- $this->up = $up[0] . ','.$up[1].','.$up[2];;
- }
- function setModel($model)
- {
- $this->model = $model;
- }
- function setSetting($setting)
- {
- $this->setting = $setting;
- }
- function getJsonFile()
- {
- file_get_contents(SAVE_PATH.$this->steamUID.'.json');
- }
- function saveJsonFile($content)
- {
- if(empty($content))
- {
- file_put_contents(SAVE_PATH.$this->steamUID.'.json', "", LOCK_EX);
- }
- else
- {
- file_put_contents(SAVE_PATH.$this->steamUID.'.json', $content, LOCK_EX);
- }
- }
- function setFromJson($json)
- {
- $settings = json_decode($json);
- $this->setModel($settings->model);
- $this->setPos($settings->pos);
- $this->setDir($settings->dir);
- $this->setUp($settings->up);
- $this->setAlive($settings->alive);
- $this->setModifiers(json_encode($settings->state->vars->modifiers));
- $this->setModStates(json_encode($settings->state->vars->modstates));
- $this->setExposure($settings->state->vars->exposure);
- $this->setBloodType($settings->state->vars->bloodtype);
- $this->setBlood($settings->state->vars->blood);
- $this->setHealth($settings->state->vars->health);
- $this->setShock($settings->state->vars->shock);
- $this->setEnergy($settings->state->vars->energy);
- $this->setWater($settings->state->vars->water);
- $this->setStomach($settings->state->vars->stomach);
- $this->setDiet($settings->state->vars->diet);
- $this->setBleedingSources(json_encode($settings->state->vars->bleedingsources));
- $this->setUnconscious($settings->state->vars->unconscious);
- $this->setItems(json_encode($settings->items));
- $this->setShortcuts($settings->state->shortcuts);
- }
- function registerPlayer()
- {
- if($this->playerExists() == false)
- {
- try
- {
- $stmt = $this->db->prepare("INSERT INTO players(steamUID, firstPlayed) VALUES(:steamUID, NOW())");
- $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- }catch(Exception $ex)
- {
- }
- }
- }
- function playerExists()
- {
- try
- {
- $stmt = $this->db->prepare("SELECT steamUID FROM players WHERE steamUID = ?");
- $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- $row_count = $stmt->rowCount();
- if($row_count > 0) { return true; }
- return false;
- }catch(Exception $ex)
- {
- }
- }
- function updatePlayer()
- {
- if($this->playerExists() == true)
- {
- try
- {
- $stmt = $this->db->prepare("
- UPDATE players SET
- model = :model,
- pos = :pos,
- dir = :dir,
- up = :up,
- alive = :alive,
- modStates = :modStates,
- modifiers = :modifiers,
- exposure = :exposure,
- bloodType = :bloodType,
- blood = :blood,
- health = :health,
- shock = :shock,
- energy = :energy,
- water = :water,
- stomach = :stomach,
- diet = :diet,
- bleedingSources = :bleedingSources,
- unconscious = :unconscious,
- items =:items
- WHERE steamUID = :steamUID");
- $stmt->bindValue(':model', $this->model, PDO::PARAM_STR);
- $stmt->bindValue(':pos', $this->pos, PDO::PARAM_STR);
- $stmt->bindValue(':dir', $this->dir, PDO::PARAM_STR);
- $stmt->bindValue(':up', $this->up, PDO::PARAM_STR);
- $stmt->bindValue(':alive', $this->alive, PDO::PARAM_STR);
- $stmt->bindValue(':modStates', $this->modStates);
- $stmt->bindValue(':modifiers', $this->modifiers);
- $stmt->bindValue(':exposure', $this->exposure);
- $stmt->bindValue(':bloodType', $this->bloodType);
- $stmt->bindValue(':blood', $this->blood);
- $stmt->bindValue(':health', $this->health);
- $stmt->bindValue(':shock', $this->shock);
- $stmt->bindValue(':energy', $this->energy);
- $stmt->bindValue(':water', $this->water);
- $stmt->bindValue(':stomach', $this->stomach);
- $stmt->bindValue(':diet', $this->diet);
- $stmt->bindValue(':bleedingSources', $this->bleedingSources);
- $stmt->bindValue(':unconscious', $this->unconscious);
- $stmt->bindValue(':items', $this->items);
- $stmt->bindValue(':steamUID', $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- $this->shortcuts->updateShortcuts();
- }catch(Exception $ex)
- {
- }
- }
- }
- function getPlayer()
- {
- if($this->playerExists() == false)
- {
- $this->registerPlayer();
- }
- try
- {
- $stmt = $this->db->prepare("SELECT * FROM players WHERE steamUID = ?");
- $stmt->bindValue(1, $this->steamUID, PDO::PARAM_STR);
- $stmt->execute();
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
- }catch(Exception $ex)
- {
- }
- }
- function makeJson()
- {
- if($this->playerExists() == false)
- {
- $this->registerPlayer();
- }
- try
- {
- $stmt = $this->db->prepare("SELECT * FROM players WHERE steamUID = :steamUID");
- $stmt->bindValue(':steamUID', $this->steamUID);
- $stmt->execute();
- $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $stmt = $this->db->prepare("SELECT * FROM shortcuts WHERE steamUID = :steamUID");
- $stmt->bindValue(':steamUID', $this->steamUID);
- $stmt->execute();
- $possedeShortcuts = $stmt->rowCount();
- $stmt = $this->db->prepare("SELECT * FROM shortcuts WHERE steamUID = :steamUID");
- $stmt->bindValue(':steamUID', $this->steamUID);
- $stmt->execute();
- $rowsShortcuts = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $sets['model'] = $rows[0]['model'];
- $sets['alive'] = (int)$rows[0]['alive'];
- $positions = explode(',', $rows[0]['pos']);
- $sets['pos'][0] = (float)$positions[0];
- $sets['pos'][1] = (float)$positions[1];
- $sets['pos'][2] = (float)$positions[2];
- $dirs = explode(',', $rows[0]['dir']);
- $sets['dir'][0] = (float)$dirs[0];
- $sets['dir'][1] = (int)$dirs[1];
- $sets['dir'][2] = (float)$dirs[2];
- $ups = explode(',', $rows[0]['up']);
- $sets['up'][0] = (int)$ups[0];
- $sets['up'][1] = (int)$ups[1];
- $sets['up'][2] = (int)$ups[2];
- /* Items */
- $sets['items'] = json_decode($rows[0]['items']);
- /* States */
- $sets['state']['vars']['exposure'] = (int)$rows[0]['exposure'];
- $modifiers = $rows[0]['modifiers'];
- if($modifiers == '' || $modifiers == null)
- {
- $sets['state']['vars']['modifiers'] = array();
- }
- else
- {
- $sets['state']['vars']['modifiers'] = json_decode($rows[0]['modifiers']);
- }
- $modstates = $rows[0]['modStates'];
- if($modstates == '' || $modstates == ',,')
- {
- $sets['state']['vars']['modstates'] = array();
- }
- else
- {
- $sets['state']['vars']['modstates'] = json_decode($rows[0]['modStates']);
- }
- $sets['state']['vars']['bloodtype'] = $rows[0]['bloodType'];
- $sets['state']['vars']['blood'] = (int)$rows[0]['blood'];
- $sets['state']['vars']['health'] = (int)$rows[0]['health'];
- $sets['state']['vars']['shock'] = (float)$rows[0]['shock'];
- $sets['state']['vars']['energy'] = (float)$rows[0]['energy'];
- $sets['state']['vars']['water'] = (float)$rows[0]['water'];
- $sets['state']['vars']['stomach'] = (int)$rows[0]['stomach'];
- $sets['state']['vars']['diet'] = (float)$rows[0]['diet'];
- if($rows[0]['bleedingSources'] == '')
- {
- $sets['state']['vars']['bleedingsources'] = array();
- }
- else
- {
- $sets['state']['vars']['bleedingsources'] = json_decode($rows[0]['bleedingSources']);
- }
- $sets['state']['vars']['unconscious'] = (bool)$rows[0]['unconscious'];
- /* Shortcuts */
- if($possedeShortcuts > 0)
- {
- $sets['state']['shortcuts'] = array( $rowsShortcuts[0]['shortcut1'],
- $rowsShortcuts[0]['shortcut2'],
- $rowsShortcuts[0]['shortcut3'],
- $rowsShortcuts[0]['shortcut4'],
- $rowsShortcuts[0]['shortcut5'],
- $rowsShortcuts[0]['shortcut6'],
- $rowsShortcuts[0]['shortcut7'],
- $rowsShortcuts[0]['shortcut8'],
- $rowsShortcuts[0]['shortcut9'],
- $rowsShortcuts[0]['shortcut10'] );
- }
- else
- {
- $sets['state']['shortcuts'] = array( '',
- '',
- '',
- '',
- '',
- '',
- '',
- '','',
- '' );
- }
- return json_encode($sets);
- }catch(Exception $ex)
- {
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement