@@ -5,9 +5,55 @@ class MockSocket(object):
5
5
b'SAMP3\xfe \x82 \x0e a\x1e d' : b"\x0c \x00 \x00 \x0b pedr$$Nn157_G\x00 \x00 \xfc \x00 \x00 \x00 \x01 \x04 SuBa\x9c \x03 \x00 \x00 8\x00 \x00 \x00 \x02 \t ChocolateW\x1e \x00 \x00 \x18 \x00 \x00 \x00 \x03 \x0c biieL$iNn157YG\x00 \x00 \xe4 \x00 \x00 \x00 \x04 \x0b Martin80nik\xd0 '\x00 \x00 H\x00 \x00 \x00 \x05 \x0c NadoVGs(AFK)*\x14 \x00 \x00 \xd4 \x00 \x00 \x00 \x08 \x04 Ottof\x00 \x00 \x00 j\x00 \x00 \x00 \t \x0b Kristo_Rand\x01 \x00 \x00 \x00 P\x00 \x00 \x00 \n \x07 abeceda\x02 \x00 \x00 \x00 :\x00 \x00 \x00 \x0b \x08 katerina\x00 \x00 \x00 \x00 F\x00 \x00 \x00 \x0c \x11 Jonas_Nicholls_II5l\x00 \x00 B\x00 \x00 \x00 \x0e \n Murs_Beten\x81 \x02 \x00 \x00 7\x00 \x00 \x00 " ,
6
6
b'SAMP3\xfe \x82 \x0e a\x1e i' : b'\x00 \x0c \x00 d\x00 \x0f \x00 \x00 \x00 Convoy Trucking\x15 \x00 \x00 \x00 Convoy Trucking 3.4.4\x07 \x00 \x00 \x00 English' ,
7
7
b'SAMP3\xfe \x82 \x0e a\x1e r' : b'\x06 \x00 \x07 lagcomp\x02 On\x07 mapname\x0b San Andreas\x07 version\x08 0.3.7-R2\x07 weather\x02 10\x06 weburl\x16 www.convoytrucking.net\t worldtime\x05 18:00' ,
8
+ # RCON
8
9
b'SAMP3\xfe \x82 \x0e a\x1e x\x0f \x00 invalidpassword\x07 \x00 players' : b'\x16 \x00 Invalid RCON password.' ,
10
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x0f \x00 invalidpassword\x07 \x00 players' : [b'\x16 \x00 Invalid RCON password.' , None ],
11
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x05 \x00 ban 0' : [b')\x00 mick88 <#0 - 172.19.0.1> has been banned.' , b'*\x00 Logged time spent online for mick88: 0 min' , b'\x1f \x00 mick88 left the server (Kicked)' , b'\x16 \x00 wanted level set to 0' , b"'\x00 [part] mick88 has left the server (0:2)" , None ],
12
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x07 \x00 ban 999' : [None ],
13
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x11 \x00 banip 192.168.1.1' : [
14
+ b'\x1f \x00 IP 192.168.1.1 has been banned.' , None ],
15
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x11 \x00 changemode convoy' : [None ],
16
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x12 \x00 changemode invalid' : [None ],
17
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x07 \x00 cmdlist' : [b'\x11 \x00 Console Commands:' , b'\x06 \x00 echo' , b'\x06 \x00 exec' , b'\t \x00 cmdlist' , b'\t \x00 varlist' , b'\x06 \x00 exit' , b'\x06 \x00 kick' , b'\x05 \x00 ban' , b'\x05 \x00 gmx' , b'\x0c \x00 changemode' , b'\x05 \x00 say' , b'\x0c \x00 reloadbans' , b'\x0b \x00 reloadlog' , b'\t \x00 players' , b'\x07 \x00 banip' , b'\t \x00 unbanip' , b'\t \x00 gravity' , b'\t \x00 weather' , b'\x08 \x00 loadfs' , b'\n \x00 unloadfs' , b'\n \x00 reloadfs' , b'\x00 \x00 ' ],
18
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\n \x00 echo Hello' : [b'\x05 \x00 Hello' , None ],
19
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x0b \x00 exec server' : [b'\x1e \x00 bind = "" (string, read-only)' , b'\x17 \x00 password = "" (string)' , b'!\x00 maxplayers = 10 (int, read-only)' , b'\x1d \x00 port = 7777 (int, read-only)' , b'6\x00 filterscripts = "WeatherStreamer" (string, read-only)' , b'+\x00 plugins = "CVector.so" (string, read-only)' , b'"\x00 onfoot_rate = 40 (int, read-only)' , b'!\x00 incar_rate = 40 (int, read-only)' , b'"\x00 weapon_rate = 40 (int, read-only)' , b'7\x00 logtimeformat = "[%d %b %H:%M:%S]" (string, read-only)' , None ],
20
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x0c \x00 exec invalid' : [b'"\x00 Unable to exec file \' invalid.cfg\' .' , None ],
21
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\t \x00 ackslimit' : [b'\x17 \x00 ackslimit = 3000 (int)' , None ],
22
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x0c \x00 gamemodetext' : [b'.\x00 gamemodetext = "Convoy Trucking DEV" (string)' , None ],
23
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x08 \x00 hostname' : [b'&\x00 hostname = "Convoy Trucking" (string)' , None ],
24
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x08 \x00 language' : [b'\x1e \x00 language = "English" (string)' , None ],
25
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x07 \x00 mapname' : [b'!\x00 mapname = "San Andreas" (string)' , None ],
26
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x10 \x00 messageholelimit' : [b'\x1e \x00 messageholelimit = 3000 (int)' , None ],
27
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\r \x00 messageslimit' : [b'\x1a \x00 messageslimit = 500 (int)' , None ],
28
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x08 \x00 password' : [b'\x17 \x00 password = "" (string)' , None ],
29
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\r \x00 playertimeout' : [b'\x1c \x00 playertimeout = 10000 (int)' ,
30
+ None ],
31
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\r \x00 rcon_password' : [
32
+ b'$\x00 rcon_password = "password" (string)' , None ],
33
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x06 \x00 weburl' : [b'#\x00 weburl = "localhost:8000" (string)' ,
34
+ None ],
35
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x03 \x00 gmx' : [None ],
36
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\r \x00 gravity 0.008' : [None ],
37
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x06 \x00 kick 0' : [b')\x00 mick88 <#0 - 172.19.0.1> has been kicked.' , b'*\x00 Logged time spent online for mick88: 0 min' , b'\x1f \x00 mick88 left the server (Kicked)' , b'\x16 \x00 wanted level set to 0' , b"'\x00 [part] mick88 has left the server (0:2)" , None ],
38
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x08 \x00 kick 999' : [None ],
39
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x16 \x00 loadfs WeatherStreamer' : [b",\x00 Filterscript 'WeatherStreamer.amx' loaded." , None ],
40
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x0e \x00 loadfs invalid' : [b")\x00 Filterscript 'invalid.amx' load failed." , None ],
41
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x07 \x00 players' : [b'\x0f \x00 ID\t Name\t Ping\t IP' , b'\x16 \x00 0\t mick88\t 15\t 172.19.0.1' , None ],
42
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\n \x00 reloadbans' : [None , None ],
43
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x18 \x00 reloadfs WeatherStreamer' : [b".\x00 Filterscript 'WeatherStreamer.amx' unloaded." , b",\x00 Filterscript 'WeatherStreamer.amx' loaded." , None ],
44
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\t \x00 say Hello' : [None ],
45
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\r \x00 password pass' : [b'"\x00 Setting server password to: "pass"' , None ],
46
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x15 \x00 rcon_password newpass' : [None ],
47
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x19 \x00 weburl convoytrucking.net' : [None ],
48
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x13 \x00 unbanip 192.168.1.1' : [None ],
49
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x18 \x00 unloadfs WeatherStreamer' : [
50
+ b".\x00 Filterscript 'WeatherStreamer.amx' unloaded." , None ],
51
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\t \x00 weather 1' : [None ],
52
+ b'SAMP\x7f \x00 \x00 \x01 a\x1e x\x08 \x00 password\x07 \x00 varlist' : [b'\x12 \x00 Console Variables:' , b'\x19 \x00 ackslimit\t = 3000 (int)' , b'\x16 \x00 announce\t = 0 (bool)' , b'"\x00 bind\t \t = "" (string) (read-only)' , b'\x18 \x00 chatlogging\t = 1 (int)' , b'\x18 \x00 conncookies\t = 1 (int)' , b'\x1e \x00 connseedtime\t = 300000 (int)' , b'\x1a \x00 cookielogging\t = 0 (int)' , b'\x1b \x00 db_log_queries\t = 0 (int)' , b'\x17 \x00 db_logging\t = 0 (int)' , b'9\x00 filterscripts\t = "WeatherStreamer" (string) (read-only)' , b' \x00 gamemode0\t = "convoy" (string)' , b'\x1a \x00 gamemode1\t = "" (string)' , b'\x1b \x00 gamemode10\t = "" (string)' , b'\x1b \x00 gamemode11\t = "" (string)' , b'\x1b \x00 gamemode12\t = "" (string)' , b'\x1b \x00 gamemode13\t = "" (string)' , b'\x1b \x00 gamemode14\t = "" (string)' , b'\x1b \x00 gamemode15\t = "" (string)' , b'\x1a \x00 gamemode2\t = "" (string)' , b'\x1a \x00 gamemode3\t = "" (string)' , b'\x1a \x00 gamemode4\t = "" (string)' , b'\x1a \x00 gamemode5\t = "" (string)' , b'\x1a \x00 gamemode6\t = "" (string)' , b'\x1a \x00 gamemode7\t = "" (string)' , b'\x1a \x00 gamemode8\t = "" (string)' , b'\x1a \x00 gamemode9\t = "" (string)' , b'0\x00 gamemodetext\t = "Convoy Trucking DEV" (string)' , b'\x1d \x00 gravity\t = "0.008" (string)' , b'(\x00 hostname\t = "Convoy Trucking" (string)' , b'$\x00 incar_rate\t = 40 (int) (read-only)' , b'-\x00 lagcomp\t = "On" (string) (read-only) (rule)' , b'$\x00 lagcompmode\t = 1 (int) (read-only)' , b' \x00 language\t = "English" (string)' , b'\x15 \x00 lanmode\t = 0 (bool)' , b'\x18 \x00 logqueries\t = 0 (bool)' , b':\x00 logtimeformat\t = "[%d %b %H:%M:%S]" (string) (read-only)' , b'*\x00 mapname\t = "San Andreas" (string) (rule)' , b'\x13 \x00 maxnpc\t = 0 (int)' , b'$\x00 maxplayers\t = 10 (int) (read-only)' , b' \x00 messageholelimit\t = 3000 (int)' , b'\x1c \x00 messageslimit\t = 500 (int)' , b'\x1e \x00 minconnectiontime\t = 0 (int)' , b'\x14 \x00 myriad\t = 0 (bool)' , b'#\x00 nosign\t = "" (string) (read-only)' , b'%\x00 onfoot_rate\t = 40 (int) (read-only)' , b'\x14 \x00 output\t = 0 (bool)' , b'\x19 \x00 password\t = "" (string)' , b'\x1e \x00 playertimeout\t = 10000 (int)' , b'.\x00 plugins\t = "CVector.so" (string) (read-only)' , b'!\x00 port\t \t = 7777 (int) (read-only)' , b'\x14 \x00 query\t \t = 1 (bool)' , b'\x13 \x00 rcon\t \t = 1 (bool)' , b'&\x00 rcon_password\t = "password" (string)' , b'\x13 \x00 sleep\t \t = 5 (int)' , b"'\x00 stream_distance\t = 300.000000 (float)" , b'\x1b \x00 stream_rate\t = 1000 (int)' , b'\x17 \x00 timestamp\t = 1 (bool)' , b'3\x00 version\t = "0.3.7-R2" (string) (read-only) (rule)' , b'%\x00 weapon_rate\t = 40 (int) (read-only)' , b'!\x00 weather\t = "10" (string) (rule)' , b',\x00 weburl\t = "localhost:8000" (string) (rule)' , b'&\x00 worldtime\t = "12:00" (string) (rule)' , b'\x00 \x00 ' ],
9
53
}
10
54
response_prefix = b'SAMP3\xfe \x82 \x0e a\x1e x'
55
+ # Keeps position of next response if response is in a list
56
+ counter = 0
11
57
12
58
def __init__ (self , * args , ** kwargs ):
13
59
self .connected = True
@@ -17,19 +63,26 @@ def settimeout(self, value):
17
63
18
64
def close (self ):
19
65
self .connected = False
66
+ self .request = False
20
67
21
68
def sendto (self , data , * args , ** kwargs ):
22
69
assert self .connected
23
70
self .request = data
71
+ self .counter = 0
24
72
25
73
def recv (self , bufsize ):
26
74
assert self .connected
27
75
try :
76
+ response = self .response_prefix
28
77
if self .request :
29
- return self .response_prefix + self .responses [self .request ]
30
- else :
31
- return self .response_prefix
78
+ value = self .responses [self .request ]
79
+ if isinstance (value , list ):
80
+ try :
81
+ value = value [self .counter ] or b''
82
+ self .counter += 1
83
+ except IndexError :
84
+ value = b''
85
+ response += value
86
+ return response
32
87
except KeyError :
33
88
raise ConnectionError (10054 , 'Connection error' )
34
- finally :
35
- self .request = None
0 commit comments