-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBot.py
226 lines (190 loc) · 5.87 KB
/
Bot.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python
import threading, sys, time, os, hashlib, base64
sys.dont_write_bytecode = True
import ByteStream, Connection, Settings, Keys, Token
class Bot:
def __init__(bot):
bot.running = True
bot.fingerprint = 0
bot.id = 0
bot.room = ""
bot.runtime = time.time()
bot.room_list = {}
bot.main_conn = Connection.new("Main")
bot.bulle_conn = Connection.new("Bulle")
def handle_packet(bot, conn, b):
if b.length() < 2: return 0
ccc = b.read_u16()
if ccc == Token.SWITCH_BULLE:
bot.id = b.read_u32()
host = b.read_str()
bot.bulle_conn.open_sock(host, 5555)
b = ByteStream.new()
b.write_u16(Token.SWITCH_BULLE)
b.write_u32(bot.id)
bot.bulle_conn.send(b)
if ccc == Token.HANDSHAKE_OK:
players_online = b.read_u32()
conn.fingerprint = b.read_byte()
community = b.read_str()
country = b.read_str()
login_xor = b.read_u32()
print("Connected %s.%s :: %i online players" %
(country, community, players_online))
threading.Timer(10, bot.heartbeat_task).start()
b = ByteStream.new()
b.write_u16(Token.SET_COMMUNITY)
b.write_byte(Settings.COMMUNITY); b.write_byte(0)
bot.main_conn.send(b)
b = ByteStream.new()
b.write_u16(Token.OS_INFO)
b.write_str("en")
b.write_str("Linux")
b.write_str("LNX 29,0,0,140")
b.write_byte(0);
bot.main_conn.send(b)
b = ByteStream.new()
b.write_u16(Token.LOGIN)
b.write_str(Settings.USERNAME.lower().capitalize())
b.write_str(base64.b64encode(hashlib.sha256(hashlib.sha256(Settings.PASSWORD).hexdigest() + 'f71aa6de8f1776a8039d32b8a156b2a93edd439dc5ddce56d3b7a4054a0d08b0'.decode('hex')).digest()))
b.write_str(Settings.FLASH_URL)
b.write_str(Settings.ROOM_NAME)
b.write_u32(Keys.LOGIN_KEY ^ login_xor)
b.block_cipher()
b.write_byte(0)
bot.main_conn.send(b)
if ccc == Token.SET_KEY_OFFSET:
conn.fingerprint = b.read_byte()
if ccc == Token.ROOM_JOIN:
b.read_byte()
bot.room = b.read_str()
print("Joined room : %s" % bot.room)
threading.Thread(target = bot.terminal).start()
if ccc == Token.PLAYER_CHAT:
player_id, username, language, message = b.read_u32(), b.read_str(), b.read_byte(), b.read_str()
if ccc == Token.LOGIN_OK:
forum_id, username = b.read_u32(), b.read_str()
print("Connected with name : %s" % username)
bot.update_room_list()
if ccc == Token.NEW_MAP:
pass
if ccc == Token.CP_PROTOCOL:
cp_ccc = b.read_u16()
if cp_ccc == Token.CP_CCC_CONNECT:
print("Connected to community platform.")
if ccc == Token.PLAYER_POSITION:
pass
if ccc == Token.GAME_MODE_LIST:
length = b.read_byte()
mode_list = []
for c in range(length):
mode_list.append(b.read_byte())
current_mode = b.read_byte()
b.read_byte()
community_id = b.read_byte()
mode_name = b.read_str()
players = b.read_str()
command = b.read_str()
args = b.read_str()
rooms = []
while b.avalible():
room_type = b.read_byte()
room_community = b.read_byte()
room_name = b.read_str()
room_players = b.read_u16()
b.read_u16()
rooms.append(room_name)
bot.room_list[mode_name] = rooms
def heartbeat_task(bot):
b = ByteStream.new()
b.write_u16(Token.HEARTBEAT)
bot.main_conn.send(b)
bot.bulle_conn.send(b)
if bot.running:
threading.Timer(10, bot.heartbeat_task).start()
def update_room_list(bot):
mod_list = [1, 3, 8, 9, 11, 2, 10, 16]
for mod in mod_list:
bot.game_mode(mod)
threading.Timer(3, bot.update_room_list).start()
def change_room(bot, room_name):
b = ByteStream.new()
b.write_u16(Token.ROOM_JOIN_REQUEST)
b.write_byte(0xff)
b.write_str(room_name)
b.write_byte(0)
bot.main_conn.send(b)
def send_chat(bot, message, conn):
b = ByteStream.new()
b.write_u16(Token.PLAYER_CHAT)
b.write_str(message)
b.xor_cipher(conn.fingerprint)
conn.send(b)
def game_mode(bot, mode):
b = ByteStream.new()
b.write_u16(Token.GAME_MODE_LIST)
b.write_byte(mode)
bot.main_conn.send(b)
def handshake(bot):
b = ByteStream.new()
b.write_u16(Token.HANDSHAKE)
b.write_u16(Keys.HANDSHAKE_NUMBER)
b.write_str(Keys.HANDSHAKE_STRING)
b.write_str("Desktop")
b.write_str("-")
b.write_u32(0x00001FBD)
b.write_str("")
b.write_str("86bd7a7ce36bec7aad43d51cb47e30594716d972320ef4322b7d88a85904f0ed")
b.write_str("A=t&SA=t&SV=t&EV=t&MP3=t&AE=t&VE=t&ACC=t&PR=t&SP=f&SB=f&DEB=f&V=LNX 29,0,0,140&M=Adobe Linux&R=1920x1080&COL=color&AR=1.0&OS=Linux&ARCH=x86&L=en&IME=t&PR32=t&PR64=t&LS=en-US&PT=Desktop&AVD=f&LFD=f&WD=f&TLS=t&ML=5.1&DP=72")
b.write_u32(0)
b.write_u32(0x00006257)
b.write_str("")
bot.main_conn.send(b)
def check_conn(bot, conn):
if conn.socket == None:
return 0
ret = conn.socket.recv(1)
if len(ret) > 0:
int_t = ord(ret)
length = 0
if int_t == 1:
length = ord(conn.socket.recv(1))
elif int_t == 2:
length = (ord(conn.socket.recv(1)) << 8) | ord(conn.socket.recv(1))
else:
length = 0
pack = conn.socket.recv(length)
bot.handle_packet(conn, ByteStream.new(pack))
def terminal(bot):
while 1:
command = raw_input('')
if command == 'exit':
if bot.bulle_conn.socket != None:
bot.bulle_conn.socket.close()
bot.main_conn.socket.close()
os._exit(1)
if command.startswith('room '):
room_name = ' '.join(command.split()[1:])
bot.change_room(room_name)
if command.startswith('msg '):
message = ' '.join(command.split()[1:])
bot.send_chat(message, bot.bulle_conn)
def bulle(bot):
while bot.running:
if bot.bulle_conn.socket != None:
bot.check_conn(bot.bulle_conn)
def start(bot):
bot.main_conn.open_sock(Settings.HOST, Settings.PORT)
bot.handshake()
threading.Thread(target = bot.bulle).start()
while bot.running:
if bot.main_conn.socket != None:
bot.check_conn(bot.main_conn)
main = Bot()
try:
main.start()
except KeyboardInterrupt:
if main.bulle_conn.socket != None:
main.bulle_conn.socket.close()
main.main_conn.socket.close()
os._exit(1)