Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit (3600);
  4. include_once "rcon.php"; //путь до ркон скрипта
  5. class vk {
  6. private $token;
  7. public $ownerid;
  8. public $lastcurl;
  9.  
  10. public function __construct($token) {
  11. $this->token = $token;
  12. $this->users = array(250758046, 330677864); //айди людей вк, которые имеют доступ к консоли (через запятую)
  13. $this->ip = "91.214.70.46"; //айпи сервера
  14. $this->port = "19132"; //порт сервера
  15. $this->password = "пароль не покажу)"; //ркон пароль на сервере
  16. }
  17.  
  18. public function check($id) {
  19. $array = $this->users;
  20. return in_array($id, $array);
  21. }
  22.  
  23. public function get($chat) {
  24. var_dump($this->chat($chat, 1));
  25. $h = $this->chat($chat, 1);
  26. $msg = $h['response']['items'][0]['body'];
  27. $user = $h['response']['items'][0]['user_id'];
  28. var_dump($this->check($user));
  29. var_dump($user);
  30. $id = $h['response']['items'][0]['id'];
  31. if($this->check($user)) {
  32. var_dump($one = substr($msg, 0, 1));
  33. if($one == "/") {
  34. $cmd = substr($msg, 1);
  35. $sending = $this->sendCommand($cmd);
  36. if($sending) {
  37. $text = "Выбраны все сервера. Результат: $sending";
  38. } else {
  39. $text = "Выбраны все сервера. Сервер вернул пустой результат.";
  40. }
  41. $this->sendChatMessage($chat, $text);
  42. }
  43. }
  44. }
  45.  
  46.  
  47. public function sendCommand($cmd) {
  48. $password = $this->password;
  49. $ip = $this->ip;
  50. $port = $this->port;
  51. $r = new rcon($ip, $port, $password, 3);
  52. if($r->connect()) {
  53. return $r->send_command($cmd);
  54. }
  55. }
  56.  
  57. public function sendChatMessage($id, $message) {
  58. $this->go('messages.send', ['chat_id' => $id, 'message' => rawurlencode($message)]);
  59. $array = json_decode($this->lastcurl, true);
  60. if(isset($array["response"])) {
  61. return "Успешно выполнено.";
  62. } else {
  63. echo "[sendChatMessage] " .$array["error"]["error_msg"];
  64. }
  65. }
  66.  
  67. public function chat($id, $count = 20, $offset = 0) {
  68. $this->go('messages.getHistory', ['chat_id' => $id, 'count' => $count, 'offset' => $offset]);
  69. $array = json_decode($this->lastcurl, true);
  70. return $array;
  71. }
  72.  
  73. public function go($method, $par) { /* Данная функция выполняет методы API Вконтакте. */
  74. $params = '';
  75. foreach ($par as $key => $val) {
  76. $params .= $key.'='.$val.'&';
  77. }
  78.  
  79. $this->curl('http://api.vk.com/method/' .$method. '?' .$params. 'access_token=' .$this->token. '&v=5.50');
  80. }
  81.  
  82.  
  83. public function curl($args) { /* Данная функция выполняет curl запросы. Внимание! Требуется установленный php5-curl на веб.сервере! */
  84. $curl = curl_init($args);
  85. curl_setopt($curl, CURLOPT_URL, $args);
  86. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  87. curl_setopt($curl, CURLOPT_POST, true);
  88. curl_setopt($curl, CURLOPT_POSTFIELDS, "a=4&b=7");
  89. $data = @curl_exec($curl);
  90. @curl_close($curlObject);
  91. if ($data) {
  92. $this->lastcurl = $data;
  93. } else {
  94. $this->lastcurl = 'Курл не отвечает.';
  95. }
  96. }
  97. }
  98.  
  99. for($i = 0; $i < 40; $i++) { // оптимальная скорость
  100. $v = new vk('Токен не покажу))');
  101. $v->get(14); //айди конфы вк
  102. sleep(1.2); // оптимальная скорость
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement