Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import *
- import hashlib
- import time
- from threading import Thread
- class PongThread(Thread):
- def __init__(self, sock):
- Thread.__init__(self)
- self.sock = sock
- def sendPong(self):
- self.sock.send(GeneratePrefix()+MsgType.PINGPONG+'\x00')
- print ' * PONG * '
- def run(self):
- time.sleep(11)
- self.sendPong()
- version = "0.129\x00"
- # username, password and the room that the bot will appear go here
- username = 'Marvelousbot'
- password = 'trolling123'
- roomname = 'bottesting'
- #1.5646.5646.463853.463853.
- swf_thing = "http://www.transformice.com/Transformice.swf?d=1293972498110/[[DYNAMIC]]/31,5302,5302,464564,464564\x00".replace(',','\x01')
- class MsgType:
- CHAT = '\x06\x06'
- WHISPER = '\x06\x1A'
- LOGIN = '\x1A\x04'
- GOT_CHEESE = '\x08\x06'
- MOUSE_DIED = '\x08\x05'
- PINGPONG = '\x1A\x1A'
- class PrefixGen:
- def __init__(self, data):
- self.MDT = []
- self.data = data
- self.data = self.data.replace('\x00','')
- message = self.data.split('\x01')
- LCMDT = list(message[2])
- for c in map(int, LCMDT):
- if c == 0: self.MDT.append(chr(10))
- else: self.MDT.append(chr(c))
- self.CMDTEC = int(message[3])
- def __call__(self):
- loc_2 = map(int, list(str(self.CMDTEC%9000 + 1000)))
- final = ''.join([self.MDT[x] for x in loc_2])
- self.CMDTEC += 1
- return final
- print 'Connecting to TFM server...'
- sock = socket(AF_INET, SOCK_STREAM)
- sock.connect(('94.23.251.168', 3724))
- print 'Connected.'
- print 'Sending version number...'
- sock.send(version)
- print 'Receiving base64 thing...'
- while 1:
- data = sock.recv(2048)
- if '==' in data:
- break
- print 'Sending swf thing...'
- sock.send(swf_thing)
- print 'Getting mice count and making prefix generator...'
- data = sock.recv(1024)
- GeneratePrefix = PrefixGen(data)
- login_prefix = GeneratePrefix()
- mice_count = data.split('\x01')[1]
- print 'Mice in server:',mice_count
- print 'Logging in...'
- h = hashlib.sha256(password).hexdigest()
- sock.send(login_prefix+MsgType.LOGIN+'\x01'+username+'\x01'+h+'\x01'+roomname+'\x00')
- print 'Logged in.'
- sock.setblocking(False)
- last_time = time.time()
- # List of mice in the room, will be filled when the server sends 08 09
- mice = {}
- while True:
- time.sleep(0.01)
- data = ""
- while True:
- try: data += sock.recv(2048)
- except: break
- if data == "": continue
- if time.time() - last_time > 5:
- # The dancing
- sock.send(GeneratePrefix()+'\x06\x1A\x01dance\x00')
- # Multi-line chat
- #sock.send(GeneratePrefix()+MsgType.CHAT+'\x01This\nshould\nbe\nseveral\nlines\nlong.\x00')
- last_time = time.time()
- # Parse the packets
- for m in data.split('\x00'):
- msg = m.split('\x01')
- if msg[0] == MsgType.CHAT:
- number = msg[1]
- who = msg[2]
- said = msg[3]
- if who != username:
- said = said[5:]
- print who,':',said
- if msg[0] == MsgType.GOT_CHEESE:
- print msg
- cname = mice[msg[1]]
- print 'CHEESE:',cname
- # sock.send(GeneratePrefix()+MsgType.CHAT+'\x01'+cname+' got the cheese.\x00')
- if msg[0] == MsgType.MOUSE_DIED:
- print msg
- cname = mice[msg[1]]
- # sock.send(GeneratePrefix()+MsgType.CHAT+'\x01'+cname+' died.\x00')
- # When the server sends a ping, the bot must send a pong after 11 seconds
- if msg[0] == MsgType.PINGPONG:
- p_thread = PongThread(sock)
- p_thread.start()
- # I haven't named these packets yet:
- # The 20 seconds remaining packet
- if msg[0] == '\x06\x11':
- print msg
- # sock.send(GeneratePrefix()+MsgType.CHAT+'\x0120 seconds remaining.\x00')
- # New map
- #if msg[0] == '\x05\x05':
- # print '--- new map ---'
- # if mice != {}:
- # sock.send(GeneratePrefix()+MsgType.CHAT+'\x01New map started. '+(', '.join(mice.values()))+' are here.\x00')
- # Getting the list of mice in the room
- if msg[0] == '\x08\x09':
- for miceinfo in msg[1:]:
- mi = miceinfo.split('#')
- mice[mi[1]] = mi[0]
- print mice
- # Don't mind this
- #if msg[0] == '\x04\x03':
- # movecode = '\x01'.join(msg)
- ## Whisper from a mouse
- #if msg[0] == '\x06\x07':
- # whispered = msg[1]
- # who = msg[2]
- # sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' whispered: '+whispered+'\x00')
- ## change map
- #if msg[0] == '\x06\x11':
- #
- #
- # sock.send(GeneratePrefix()+'\x06\x1A\x01np 12\x00')
- #-------------------------------- BOT STARTS HERE -------------------------------#
- # music & map change /npp
- if msg[0] == '\x06\x07':
- whispered = msg[1]
- who = msg[2]
- part = whispered.split(' ')
- if part[0] == 'map':
- sock.send(GeneratePrefix()+'\x06\x1A\x01npp '+part[1]+'\x00')
- sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' asked for map '+part[1]+' to play.\nIt will be played next round.\x00')
- if part[0] == '123456789':
- sock.send(GeneratePrefix()+'\x06\x1A\x01musique '+part[1]+'\x00')
- sock.send(GeneratePrefix()+'\x06\x1A\x01ms '+who+' requested a song. \x00')
- if part[0] == 'info':
- 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')
Add Comment
Please, Sign In to add comment