Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace RCON;
- final class Arcturus {
- private $_socket = null;
- public function __construct() {
- $this->_socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- }
- public function connect(string $host, int $port): bool {
- if($this->_socket === null) {
- return socket_connect($this->_socket, $host, $port);
- }
- return true;
- }
- public function close() {
- socket_close($this->_socket);
- }
- public function __destruct() {
- $this->close();
- }
- public function disconnectUser(int $userId): bool {
- return $this->send('disconnect', [
- 'user_id' => $userId
- ]);
- }
- private function give(string $type, int $userId, int $amount): bool {
- if(!in_array($type, ['credits', 'pixels', 'points'])) {
- return false;
- }
- $payload = [
- 'user_id' => $userId,
- $type => $amount
- ];
- if($type === 'points') {
- $payload['type'] = 5;
- }
- $this->send('give' . $type, $payload);
- }
- public function giveBadge(int $userId, int $badgeName): bool {
- return $this->send('givebadge', [
- 'user_id' => $userId,
- 'badge' => $badgeName,
- ]);
- }
- public function giveCredits(int $userId, int $amount): bool {
- return $this->give('credits', $userId, $amount);
- }
- public function givePixels(int $userId, int $amount): bool {
- return $this->give('pixels', $userId, $amount);
- }
- public function sendGift(int $userId, int $itemId, string $message = ''): bool {
- return $this->send('sendgift', [
- 'user_id' => $userId,
- 'itemid' => $itemId,
- 'message' => $message,
- ]);
- }
- public function givePoints(int $userId, int $amount): bool {
- return $this->give('points', $userId, $amount);
- }
- public function sendHotelalert(string $message, string $url = ''): bool {
- return $this->send('hotelalert', [
- 'message' => $message,
- 'url' => $url,
- ]);
- }
- private function send(string $key, array $data): bool {
- return !!socket_write($this->_socket, json_encode([
- 'key' => $key,
- 'data' => $data
- ]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement