Advertisement
Guest User

Untitled

a guest
May 13th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. namespace RCON;
  4.  
  5. final class Arcturus {
  6.  
  7.     private $_socket = null;
  8.  
  9.     public function __construct() {
  10.         $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  11.     }
  12.  
  13.     public function connect(string $host, int $port): bool {
  14.         if($this->_socket === null) {
  15.             return socket_connect($this->_socket, $host, $port);
  16.         }
  17.  
  18.         return true;
  19.     }
  20.  
  21.     public function close() {
  22.         socket_close($this->_socket);
  23.     }
  24.  
  25.     public function __destruct() {
  26.         $this->close();
  27.     }
  28.  
  29.     public function disconnectUser(int $userId): bool {
  30.         return $this->send('disconnect', [
  31.             'user_id' => $userId
  32.         ]);
  33.     }
  34.  
  35.     private function give(string $type, int $userId, int $amount): bool {
  36.         if(!in_array($type, ['credits', 'pixels', 'points'])) {
  37.             return false;
  38.         }
  39.  
  40.         $payload = [
  41.             'user_id' => $userId,
  42.             $type => $amount
  43.         ];
  44.  
  45.         if($type === 'points') {
  46.             $payload['type'] = 5;
  47.         }
  48.  
  49.         $this->send('give' . $type, $payload);
  50.     }
  51.  
  52.     public function giveBadge(int $userId, int $badgeName): bool {
  53.         return $this->send('givebadge', [
  54.             'user_id' => $userId,
  55.             'badge' => $badgeName,
  56.         ]);
  57.     }
  58.  
  59.     public function giveCredits(int $userId, int $amount): bool {
  60.         return $this->give('credits', $userId, $amount);
  61.     }
  62.  
  63.     public function givePixels(int $userId, int $amount): bool {
  64.         return $this->give('pixels', $userId, $amount);
  65.     }
  66.  
  67.     public function sendGift(int $userId, int $itemId, string $message = ''): bool {
  68.         return $this->send('sendgift', [
  69.             'user_id' => $userId,
  70.             'itemid' => $itemId,
  71.             'message' => $message,
  72.         ]);
  73.     }
  74.  
  75.     public function givePoints(int $userId, int $amount): bool {
  76.         return $this->give('points', $userId, $amount);
  77.     }
  78.  
  79.     public function sendHotelalert(string $message, string $url = ''): bool {
  80.         return $this->send('hotelalert', [
  81.             'message' => $message,
  82.             'url' => $url,
  83.         ]);
  84.     }
  85.  
  86.     private function send(string $key, array $data): bool {
  87.         return !!socket_write($this->_socket, json_encode([
  88.             'key' => $key,
  89.             'data' => $data
  90.         ]));
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement