Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.87 KB | None | 0 0
  1. <?PHP
  2.  
  3. /*-------USTAWIENIA------*/
  4. $ts3_ip = 'localhost';
  5. $ts3_user = 'serveradmin';
  6. $ts3_pass = 'fZjJWY8P';
  7. $ts3_port = 9987;
  8. $ts3_queryport = 10011;
  9. $przeniesna = 3;
  10. $przeniesz = 2;
  11. $channellpass = NULL;
  12. $msg = "test";
  13. $name = "BOT";
  14. $sek = 1;
  15. /*----------------------*/
  16.  
  17. class klasa {
  18. private $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '');
  19. function clientList($params = null) {if(!$this->runtime['selected']) { return $this->checkSelected();}if(!empty($params)) { $params = ' '.$params; }return $this->getData('multi', 'clientlist'.$params);}
  20. function clientMove($clid, $cid, $cpw = null){if(!$this->runtime['selected']) { return $this->checkSelected();}return $this->getData('boolean', 'clientmove clid='.$clid.' cid='.$cid.(!empty($cpw) ? ' cpw='.$this->escapeText($cpw) : ''));}
  21. function login($username, $password){return $this->getData('boolean', 'login '.$this->escapeText($username).' '.$this->escapeText($password));}
  22. function selectServer($value, $type = 'port', $virtual = false){if(in_array($type, array('port', 'serverId'))){if($type == 'port'){if($virtual){$virtual = ' -virtual'; }else{ $virtual = ''; } $res = $this->getData('boolean', 'use port='.$value.$virtual); if($res['success']) { $this->runtime['selected'] = true; } return $res;}else{if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; }$res = $this->getData('boolean', 'use sid='.$value.$virtual); if($res['success']) {$this->runtime['selected'] = true;}return $res;}}else{$this->addDebugLog('wrong value type'); return $this->generateOutput(false, array('Error: wrong value type'), false);}}
  23. function sendMessage($mode, $target, $msg) {if(!$this->runtime['selected']) { return $this->checkSelected(); } return $this->getData('boolean', 'sendtextmessage targetmode='.$mode.' target='.$target.' msg='.$this->escapeText($msg));}
  24. function serverIdGetByPort($port) {return $this->getData('array', 'serveridgetbyport virtualserver_port='.$port);}
  25. function setName($newName) {return $this->getData('boolean', 'clientupdate client_nickname='.$this->escapeText($newName));}
  26. function __construct($host, $queryport, $timeout = 2) {if($queryport >= 1 and $queryport <= 65536){if($timeout >= 1) {$this->runtime['host'] = $host; $this->runtime['queryport'] = $queryport;$this->runtime['timeout'] = $timeout;}else{$this->addDebugLog('invalid timeout value');}}else{$this->addDebugLog('invalid queryport');}}
  27. function __destruct() {$this->quit();}
  28. function __call($name, $args) { $this->addDebugLog('Method '.$name.' doesn\'t exist', $name, 0); return $this->generateOutput(false, array('Method '.$name.' doesn\'t exist'), false);} private function isConnected() {if(empty($this->runtime['socket'])){return false;}else{return true;}} private function generateOutput($success, $errors, $data) {return array('success' => $success, 'errors' => $errors, 'data' => $data);} private function unEscapeText($text) { $escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/"); $unEscapedChars = array('', '', '', '', '', ' ', '|', '/'); $text = str_replace($escapedChars, $unEscapedChars, $text); return $text;} private function escapeText($text) { $text = str_replace("\t", '\t', $text); $text = str_replace("\v", '\v', $text); $text = str_replace("\r", '\r', $text); $text = str_replace("\n", '\n', $text); $text = str_replace("\f", '\f', $text); $text = str_replace(' ', '\s', $text); $text = str_replace('|', '\p', $text); $text = str_replace('/', '\/', $text); return $text;}private function splitBanIds($text) {$data = array(); $text = str_replace(array("\n", "\r"), '', $text); $ids = explode("banid=", $text); unset($ids[0]); return $ids;}
  29. function connect() {if($this->isConnected()) {$this->addDebugLog('Error: you are already connected!'); return $this->generateOutput(false, array('Error: the script is already connected!'), false);} $socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']); if(!$socket) {$this->addDebugLog('Error: connection failed!');return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);}else{if(strpos(fgets($socket), 'TS3') !== false) {$tmpVar = fgets($socket);$this->runtime['socket'] = $socket;return $this->generateOutput(true, array(), true);}else{$this->addDebugLog('host isn\'t a ts3 instance!');return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);}}}private function executeCommand($command, $tracert) {if(!$this->isConnected()) {$this->addDebugLog('script isn\'t connected to server', $tracert[1]['function'], $tracert[0]['line']); return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);}$data = ''; $splittedCommand = str_split($command, 1024); $splittedCommand[(count($splittedCommand) - 1)] .= "\n";foreach($splittedCommand as $commandPart) {fputs($this->runtime['socket'], $commandPart);} do {$data .= fgets($this->runtime['socket'], 4096);if(strpos($data, 'error id=3329 msg=connection') !== false) {$this->runtime['socket'] = '';$this->addDebugLog('You got banned from server. Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
  30. return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);}} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);if(strpos($data, 'error id=0 msg=ok') === false) {$splittedResponse = explode('error id=', $data);$chooseEnd = count($splittedResponse) - 1;$cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);$this->addDebugLog('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1]), $tracert[1]['function'], $tracert[0]['line']);return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);}else{return $this->generateOutput(true, array(), $data);}}private function getData($mode, $command) {$validModes = array('boolean', 'array', 'multi', 'plain');if(!in_array($mode, $validModes)) {$this->addDebugLog($mode.' is an invalid mode');return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);}if(empty($command)) {$this->addDebugLog('you have to enter a command');return $this->generateOutput(false, array('Error: you have to enter a command'), false);}$fetchData = $this->executeCommand($command, debug_backtrace());$fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);if($fetchData['success']) {if($mode == 'boolean') {return $this->generateOutput(true, array(), true);}if($mode == 'array') {if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array());}$datasets = explode(' ', $fetchData['data']);$output = array();foreach($datasets as $dataset) {$dataset = explode('=', $dataset);if(count($dataset) > 2) {for($i = 2; $i < count($dataset); $i++){$dataset[1] .= '='.$dataset[$i];}$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);}else{if(count($dataset) == 1) {$output[$this->unEscapeText($dataset[0])] = '';}else{$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);}}}return $this->generateOutput(true, array(), $output);}if($mode == 'multi') {if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); } $datasets = explode('|', $fetchData['data']); $output = array(); foreach($datasets as $datablock) {$datablock = explode(' ', $datablock); $tmpArray = array(); foreach($datablock as $dataset){$dataset = explode('=', $dataset); if(count($dataset) > 2) {for($i = 2; $i < count($dataset); $i++){$dataset[1] .= '='.$dataset[$i];}$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);}else{if(count($dataset) == 1) {$tmpArray[$this->unEscapeText($dataset[0])] = '';}else{$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);}}}$output[] = $tmpArray;} return $this->generateOutput(true, array(), $output);} if($mode == 'plain'){return $fetchData;}}else{return $this->generateOutput(false, $fetchData['errors'], false);}} public function getDebugLog() {return $this->runtime['debug'];}private function addDebugLog($text, $methodName = '', $line = '') {if(empty($methodName) and empty($line)){$backtrace = debug_backtrace();$methodName = $backtrace[1]['function'];$line = $backtrace[0]['line'];}$this->runtime['debug'][] = 'Error in '.$methodName.'() on line '.$line.': '.$text;}}$tsAdmin = new klasa($ts3_ip, $ts3_queryport); if($tsAdmin->getElement('success', $tsAdmin->connect())){$tsAdmin->login($ts3_user, $ts3_pass); $tsAdmin->selectServer($ts3_port); $tsAdmin->setName($name); while(1){sleep($sek);$clients = $tsAdmin->clientList(); foreach($clients['data'] as $client){if ($client['cid'] == $przeniesz){$clid = $client['clid'];$tsAdmin->clientMove($clid, $przeniesna, $channellpass);$tsAdmin->sendMessage(1, $clid, $msg);}}}}else echo 'Connection could not be established.';
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement