-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRcon.php
More file actions
101 lines (101 loc) · 3.64 KB
/
Copy pathRcon.php
File metadata and controls
101 lines (101 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
class Rcon{
private $ip;
private $port;
private $password;
public function __construct($i, $p, $pass = null){
$this->ip = $i;
$this->port = $p;
$this->password = $pass;
}
public function openSocket(){
$tcpsocket = stream_socket_client("tcp://$this->ip:$this->port", $errno, $errorMessage, 3);
if ($tcpsocket === false) return null;
else return $tcpsocket;
}
public function send($tcpsocket, $command){
if(!$tcpsocket) return "Error";
fwrite($tcpsocket, $command);
$response = fread($tcpsocket, 3001);
fclose($tcpsocket);
return $response;
}
private function sendExcecuteCommand($UserID, $commandStr) {
$tcpsocket = $this->openSocket();
$payload = array(
"key" => "executecommand",
"data" => array(
"user_id" => (string)$UserID,
"command" => $commandStr
)
);
$jsonPayload = json_encode($payload);
if($this->send($tcpsocket, $jsonPayload) == "Error") return false;
else return true;
}
public function sendAlert($UserID, $message){
$tcpsocket = $this->openSocket();
$payload = array(
"key" => "alertuser",
"data" => array(
"user_id" => (string)$UserID,
"message" => $message
)
);
if($this->send($tcpsocket, json_encode($payload)) == "Error") return false;
else return true;
}
public function talkUser($UserID, $chattype, $message){
$tcpsocket = $this->openSocket();
$payload = array(
"key" => "talkuser",
"data" => array(
"user_id" => (string)$UserID,
"bubble" => "-1",
"type" => $chattype,
"message" => $message
)
);
if($this->send($tcpsocket, json_encode($payload)) == "Error") return false;
else return true;
}
public function newexecutecommand($UserID, $command){
return $this->sendExcecuteCommand($UserID, $command);
}
public function executecommand($UserID){
return $this->sendExcecuteCommand($UserID, ":about");
}
public function seticoncommand($UserID, $iconID){
if ($iconID !== "none" && !is_numeric($iconID)) return false;
if ($iconID !== "none") $iconID = (int)$iconID;
return $this->sendExcecuteCommand($UserID, ":seticon " . $iconID);
}
public function setmodifiercommand($UserID, $modifierID){
if ($modifierID !== "none" && !is_numeric($modifierID)) return false;
if ($modifierID !== "none") $modifierID = (int)$modifierID;
return $this->sendExcecuteCommand($UserID, ":setmodifier " . $modifierID);
}
public function setcolorscommand($UserID, $color){
if (!preg_match('/^[a-zA-Z]{1,20}$/', $color)) return false;
return $this->sendExcecuteCommand($UserID, ":setcolor " . $color);
}
public function setbordercolorscommand($UserID, $bordercolor){
if (!preg_match('/^[a-zA-Z]{1,20}$/', $bordercolor)) return false;
return $this->sendExcecuteCommand($UserID, ":setborder " . $bordercolor);
}
public function reloadRoom($username) {
$tcpsocket = $this->openSocket();
$payload = array(
"key" => "reloadroom",
"data" => array(
"username" => $username
)
);
if($this->send($tcpsocket, json_encode($payload)) == "Error") return false;
else return true;
}
public function oldexecutecommand($UserID) {
return $this->executecommand($UserID);
}
}
?>