View difference between Paste ID: mFeYF1cf and h2jXGTEu
SHOW: | | - or go back to the newest paste.
1
from socket import *
2
import hashlib
3
import time
4
5
6
from threading import Thread
7
8
class PongThread(Thread):
9
    def __init__(self, sock):
10
        Thread.__init__(self)
11
        self.sock = sock
12
13
    def sendPong(self):
14
        self.sock.send(GeneratePrefix()+MsgType.PINGPONG+'\x00')
15
        print ' * PONG * '
16
17
    def run(self):
18
        time.sleep(11)
19
        self.sendPong()
20
21
22
version = "0.129\x00"
23
24
# username, password and the room that the bot will appear go here
25
username = 'Marvelousbot'
26
password = 'trolling123'
27
roomname = 'bottesting'
28
29
#1.5646.5646.463853.463853.
30
swf_thing = "http://www.transformice.com/Transformice.swf?d=1293972498110/[[DYNAMIC]]/31,5302,5302,464564,464564\x00".replace(',','\x01')
31
32
class MsgType:
33
    CHAT = '\x06\x06'
34
    WHISPER = '\x06\x1A'
35
    LOGIN = '\x1A\x04'
36
    GOT_CHEESE = '\x08\x06'
37
    MOUSE_DIED = '\x08\x05'
38
    PINGPONG = '\x1A\x1A'
39
40
class PrefixGen:
41
    def __init__(self, data):
42
        self.MDT = []
43
        self.data = data
44
        self.data = self.data.replace('\x00','')
45
        message = self.data.split('\x01')
46
        LCMDT = list(message[2])
47
        for c in map(int, LCMDT):
48
            if c == 0: self.MDT.append(chr(10))
49
            else: self.MDT.append(chr(c))
50
51
        self.CMDTEC = int(message[3])
52
53
    def __call__(self):
54
        loc_2 = map(int, list(str(self.CMDTEC%9000 + 1000)))
55
        final = ''.join([self.MDT[x] for x in loc_2])
56
        self.CMDTEC += 1
57
        return final
58
59
60
61
print 'Connecting to TFM server...'
62
sock = socket(AF_INET, SOCK_STREAM)
63
sock.connect(('94.23.251.168', 3724))
64
print 'Connected.'
65
66
print 'Sending version number...'
67
sock.send(version)
68
69
print 'Receiving base64 thing...'
70
71
while 1:
72
    data = sock.recv(2048)
73
    if '==' in data:
74
        break
75
76
77
print 'Sending swf thing...'
78
sock.send(swf_thing)
79
80
print 'Getting mice count and making prefix generator...'
81
data = sock.recv(1024)
82
GeneratePrefix = PrefixGen(data)
83
login_prefix = GeneratePrefix()
84
mice_count = data.split('\x01')[1]
85
print 'Mice in server:',mice_count
86
87
print 'Logging in...'
88
h = hashlib.sha256(password).hexdigest()
89
sock.send(login_prefix+MsgType.LOGIN+'\x01'+username+'\x01'+h+'\x01'+roomname+'\x00')
90
91
print 'Logged in.'
92
93
94
sock.setblocking(False)
95
96
last_time = time.time()
97
98
# List of mice in the room, will be filled when the server sends 08 09
99
mice = {}
100
101
102
while True:
103
    time.sleep(0.01)
104
    
105
    data = ""
106
    while True:
107
        try: data += sock.recv(2048)
108
        except: break
109
110
    if data == "": continue
111
112
    if time.time() - last_time > 5:
113
        # The dancing
114
        sock.send(GeneratePrefix()+'\x06\x1A\x01dance\x00')
115
        
116
        # Multi-line chat
117
        #sock.send(GeneratePrefix()+MsgType.CHAT+'\x01This\nshould\nbe\nseveral\nlines\nlong.\x00')
118
119
        last_time = time.time()
120
121
    # Parse the packets
122
    for m in data.split('\x00'):
123
124
        msg = m.split('\x01')
125
126
        if msg[0] == MsgType.CHAT:
127
            number = msg[1]
128
            who = msg[2]
129
            said = msg[3]
130
            if who != username:
131
                said = said[5:]
132
                print who,':',said
133
134
        if msg[0] == MsgType.GOT_CHEESE:
135
            print msg
136
            cname = mice[msg[1]]
137
            print 'CHEESE:',cname
138
    #       sock.send(GeneratePrefix()+MsgType.CHAT+'\x01'+cname+' got the cheese.\x00')
139
140
        if msg[0] == MsgType.MOUSE_DIED:
141
            print msg
142
            cname = mice[msg[1]]
143
    #       sock.send(GeneratePrefix()+MsgType.CHAT+'\x01'+cname+' died.\x00')
144
145
146
        # When the server sends a ping, the bot must send a pong after 11 seconds
147
        if msg[0] == MsgType.PINGPONG:
148
            p_thread = PongThread(sock)
149
            p_thread.start()
150
151
152
153
        # I haven't named these packets yet:
154
155
        # The 20 seconds remaining packet
156
        if msg[0] == '\x06\x11':
157
            print msg
158
    #       sock.send(GeneratePrefix()+MsgType.CHAT+'\x0120 seconds remaining.\x00')
159
160
        # New map
161
         #if msg[0] == '\x05\x05':
162
          #  print '--- new map ---'
163
           # if mice != {}:
164
            #    sock.send(GeneratePrefix()+MsgType.CHAT+'\x01New map started. '+(', '.join(mice.values()))+' are here.\x00')
165
166
       # Getting the list of mice in the room
167
        if msg[0] == '\x08\x09':
168
            for miceinfo in msg[1:]:
169
                mi = miceinfo.split('#')
170
                mice[mi[1]] = mi[0]
171
                print mice
172
173
        # Don't mind this
174
        #if msg[0] == '\x04\x03':
175
        #    movecode = '\x01'.join(msg)
176
177
178
       ## Whisper from a mouse
179
        #if msg[0] == '\x06\x07':
180
        #   whispered = msg[1]
181
        #  who = msg[2]
182
        # sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' whispered: '+whispered+'\x00')
183
184
       ## change map
185
        #if msg[0] == '\x06\x11':
186
        #
187
        #   
188
        #        sock.send(GeneratePrefix()+'\x06\x1A\x01np 12\x00')
189
190
191
        
192
#-------------------------------- BOT STARTS HERE -------------------------------#
193
194
        # music & map change /npp
195
        if msg[0] == '\x06\x07':
196
            whispered = msg[1]
197
            who = msg[2]
198
            part = whispered.split(' ')
199
            if part[0] == 'map':
200
                sock.send(GeneratePrefix()+'\x06\x1A\x01npp '+part[1]+'\x00')
201
                sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' asked for map '+part[1]+' to play.\nIt will be played next round.\x00')
202
            if part[0] == '123456789':
203
                sock.send(GeneratePrefix()+'\x06\x1A\x01musique '+part[1]+'\x00')
204
                sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' requested a song. \x00')
205
            if part[0] == 'info':
206
                sock.send(GeneratePrefix()+'\x06\x1A\x01c '+who+' \nHi, my name is Marvelousbot !\nHere is a list of valid commands:\n\n/c Marvelousbot map CODE\n\nIf you have any questions, ask Melyticat or Mariofanii (be nice to them!)\x00')