Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- import socket
- import time
- import hashlib
- import sys
- import os
- import platform
- from copy import deepcopy
- try:
- import psyco
- psyco.full()
- print 'Psyco enabled.'
- except:
- print 'Psyco disabled.'
- '''
- class ConsoleColor:
- def __init__(self):
- self.platf = platform.system()
- if self.platf == 'Windows':
- import WConio
- else:
- from termcolor import colored
- def __call__(self, col, txt):
- if col == 'mod':
- if self.platf == 'Windows':
- WConio.textcolor(WConio.LIGHTMAGENTA)
- print txt
- WConio.textcolor(WConio.LIGHTGREY)
- else:
- colored(txt, 'yellow')
- if col == 'arb':
- if self.platf == 'Windows':
- WConio.textcolor(WConio.MAGENTA)
- print txt
- WConio.textcolor(WConio.LIGHTGREY)
- else:
- colored(txt, 'yellow')
- if col == 'green':
- if self.platf == 'Windows':
- WConio.textcolor(WConio.LIGHTGREEN)
- print txt
- WConio.textcolor(WConio.LIGHTGREY)
- else:
- colored(txt, 'green')
- if col == 'blue':
- if self.platf == 'Windows':
- WConio.textcolor(WConio.LIGHTBLUE)
- print txt
- WConio.textcolor(WConio.LIGHTGREY)
- else:
- colored(txt, 'blue')
- con_color = ConsoleColor()
- '''
- try:
- import WConio as con
- except:
- class NullCon:
- def textcolor(self, col):
- pass
- def __getattr__(self, v):
- return None
- con = NullCon()
- version = 151
- def bin_to_str(b):
- return ' '.join([hex(ord(c))[2:].rjust(2,'0') for c in b])
- import code
- def debugger(namespace):
- code.interact("<Bot debugging console>", local=namespace)
- class Server:
- EN1 = ('91.121.28.82', 443)
- EN2 = ('95.142.173.20', 44444)
- FR = ('91.121.116.13', 443)
- RU = ('91.121.85.153', 443)
- KR = ('91.121.157.83', 44444)
- BR = ('92.243.6.199', 44444)
- BR2 = ('173.246.100.255', 44444)
- BR3 = ('173.246.103.161', 44444)
- TR = ('92.243.10.245', 44444)
- CN = ('95.142.170.114', 443)
- class Packet:
- int_size = {1:'b', 2:'h', 4:'l'}
- def __init__(self, data=""):
- self.data = data
- self.protocol = 'new'
- def setProtocol(self, t):
- self.protocol = t
- def peek(self, b):
- return self.data[:b]
- def read(self, b):
- ret = self.data[:b]
- self.data = self.data[b:]
- return ret
- def readint(self, b):
- s = self.read(b)
- #return int(s.encode('hex'), 16)
- try:
- return struct.unpack('!'+self.int_size[b], s)[0]
- except:
- return 0
- def readstring(self):
- s_len = self.readint(2)
- return self.read(s_len)
- def write(self, s):
- self.data += s
- def writeint(self, i, size):
- size_c = self.int_size[size]
- self.data += struct.pack('!'+size_c, i)
- def writebyte(self, b):
- self.data += chr(b)
- def writestring(self, s):
- self.writeint(len(s), 2)
- self.write(s)
- def oldProtocolSplit(self):
- ret = self.data.split('\x01')
- ret = map(lambda s: s.replace('\x00',''), ret)
- return ret
- def size(self):
- return len(self.data)
- def __str__(self):
- if len(self.data) > 0: return bin_to_str(self.data)
- else: return 'Empty packet'
- 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):
- final = ""
- 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
- class Mouse:
- mice_ref = []
- def __init__(self, mousedata):
- data = mousedata.split('#')
- #print 'MouseData:',data
- self.name = "Unknown"
- self.code = "0"
- self.score = 0
- self.codeforum = "0"
- self.dead = False
- if len(data) == 9:
- self.name = data[0]
- self.code = data[1]
- self.score = int(data[3])
- self.codeforum = data[8]
- self.dead = data[2] == "1"
- self.x = 0
- self.y = 0
- self.speedx = 0
- self.speedy = 0
- self.jump = False
- self.left = False
- self.right = False
- self.lastdir = 0
- class MouseList:
- def __init__(self):
- self.mice = []
- def clear(self):
- self.mice = []
- def add(self, m):
- self.mice.append(m)
- def remove(self, m):
- self.mice.remove(m)
- def getCodes(self):
- return [m.code for m in self.mice]
- def findBy(self, lamb, con):
- f = filter(lamb, con)
- if len(f) > 0:
- return f[0]
- else: return None
- def findByCode(self, code):
- return self.findBy(lambda m: m.code == code, self.mice)
- def findByForumCode(self, fcode):
- return self.findBy(lambda m: m.forumcode == fcode, self.mice)
- def findByName(self, name):
- return self.findBy(lambda m: m.name == name, self.mice)
- class Magic:
- ARROW = 0
- SMALLBOX = 1
- LARGEBOX = 2
- SMALLBOARD = 3
- LARGEBOARD = 4
- BALL = 6
- TRAMPOLINE = 7
- ANVIL = 10
- CANNONDOWN = 18
- CANNONRIGHT = 19
- CANNONLEFT = 20
- SPIRIT = 24
- RUNE = 32
- class ForbiddenMagic:
- REDPOINT = 11
- REDLEFT = 12
- REDRIGHT = 13
- BLUEPOINT = 14
- BLUERIGHT = 15
- BLUELEFT = 16
- YELLOWPOINT = 22
- CANNONUP = 17
- BOMB = 23
- CHEESE = 25
- BLUEPORTAL = 26
- ORANGEPORTAL = 27
- BALLOON = 28
- REDBALLOON = 29
- GREENBALLOON = 30
- YELLOWBALLOON = 31
- SNOW = 34
- #HEAVYBALL = 5
- #SMALLROUGHPLANK = 8
- #LARGEROUGHPLANK = 9
- #STICKYBALL = 21
- class Bot:
- def __init__(self, roomname, username, password=""):
- self.sock = None
- self.GeneratePrefix = None
- self.r_data = ""
- self.packet_queue = []
- self.o_username = username
- self.username = username
- self.password = password
- self.roomname = roomname
- self.loginstate = "not ready"
- self.tzat_last = time.time()
- self.move_code = "0"
- self.mice = MouseList()
- self.disconnected = True
- self.shaman = False
- self.sync = False
- self.running = True
- self.stayalive = True
- self.casting = False
- self.object_count = 0
- self.map_number = 0
- self.dead = False
- self.last_packet = None
- def reset_data(self):
- self.disconnected = True
- self.sync = False
- self.casting = False
- self.r_data = ""
- self.packet_queue = []
- self.tzat_last = time.time()
- self.object_count = 0
- self.loginstate = "not ready"
- def TZAT(self):
- self.tzat_last = time.time()
- p = Packet("\x1A\x02111000")
- self.send(p)
- def send(self, packet, prefix=True):
- p_size = packet.size()+8
- if packet.protocol=='old': p_size += 4
- data = Packet()
- data.writeint(p_size, 4)
- pre = '\x00\x00\x00\x00' if not self.GeneratePrefix else self.GeneratePrefix()
- if prefix == False: pre = '\x00\x00\x00\x00'
- data.write(pre)
- if packet.protocol=='old':
- data.write('\x01\x01')
- data.writeint(packet.size(), 2)
- data.write(packet.data)
- #print 'Sending:',str(data)
- try:
- self.last_packet = deepcopy(data)
- self.sock.send(data.data)
- except:
- print 'Connection problem.'
- print 'crash packet',str(data)
- #os.system("pause")
- self.reset_data()
- def delay_packet(self, delay, packet, msg="", exe=""):
- self.packet_queue.append([time.time()+delay, packet, msg, exe])
- def sendVersion(self):
- packet = Packet()
- packet.writebyte(0x1C)
- packet.writebyte(0x01)
- packet.writeint(version, 2)
- self.send(packet, prefix=False)
- def login(self):
- passwordhash = hashlib.sha256(self.password).hexdigest()
- if self.password == "":
- passwordhash = ""
- print 'password:',self.password.encode('base64'),'passhash',passwordhash
- p = Packet()
- p.setProtocol('old')
- p.write('\x1A\x04\x01')
- p.write(self.o_username)
- p.write('\x01')
- p.write(passwordhash)
- p.write('\x01')
- p.write(self.roomname)
- self.send(p)
- self.loginstate = "logged in"
- if self.password == "":
- self.username = '*'+self.username
- def connect(self, server):
- self.reset_data()
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- self.sock.connect(server)
- except Exception as ex:
- print ex
- return False
- self.sendVersion()
- time.sleep(1)
- self.sock.setblocking(False)
- self.disconnected = False
- return True
- def parsePacket(self, packet):
- packet_type = packet.peek(2)
- # Mice in server & prefix gen data
- if packet_type == '\x1A\x1B':
- msg = packet.oldProtocolSplit()
- print 'Mice in server:',int(msg[1])
- self.GeneratePrefix = PrefixGen(packet.data)
- self.loginstate = "ready to login"
- # Name data
- if packet_type == '\x1A\x08':
- msg = packet.oldProtocolSplit()
- self.username = msg[1]
- self.event_login()
- # Ping
- if packet_type == '\x1A\x1A':
- #print ' * PING *'
- p = Packet()
- p.setProtocol('old')
- p.write('\x1A\x1A')
- self.delay_packet(11, p) #, ' * PONG *')
- # New Map
- if packet_type == '\x05\x05':
- self.dead = False
- msg = packet.oldProtocolSplit()
- self.map_number = int(msg[1])
- self.move_code = msg[3]
- self.object_count = 0
- if self.stayalive:
- keepalive = Packet("\x04\x0A")
- keepalive.setProtocol('old')
- self.send(keepalive)
- self.event_newmap()
- # New room
- if packet_type == '\x05\x15':
- msg = packet.oldProtocolSplit()
- self.roomname = msg[1]
- self.event_newroom(self.roomname)
- # Chat
- if packet_type == '\x06\x06':
- packet.read(2)
- number = packet.readint(4)
- who = packet.readstring()
- said = packet.readstring()
- self.event_chat(who, said)
- # Whisper
- if packet_type == '\x06\x07':
- #print 'WHISPER,',str(packet)
- packet.read(2)
- sent_by_me = not bool(packet.readint(1))
- #print 'sent_by_me',sent_by_me
- who = packet.readstring()
- try:
- whispered = packet.readstring()
- except:
- whispered = ""
- if not sent_by_me:
- self.event_whisper(who, whispered)
- # Mod message
- if packet_type == '\x06\x0A':
- packet.read(2)
- arb = not(packet.read(1)=='\x03')
- who = packet.readstring()
- said = packet.readstring()
- self.event_modmessage(who, said, arb=arb)
- #print 'Mod message ['+who+'] '+said
- # Server message
- if packet_type == '\x06\x14':
- msg = packet.oldProtocolSplit()
- self.event_servermessage(msg[1])
- if packet_type == '\x1A\x05':
- msg = packet.oldProtocolSplit()
- self.event_servermessage(msg[2])
- if packet_type == '\x1A\x06':
- msg = packet.oldProtocolSplit()
- self.event_servermessage(msg[2], arb=True)
- # Shaman info
- if packet_type == '\x08\x14':
- msg = packet.oldProtocolSplit()
- #print 'Shaman info',msg
- if len(msg) > 1:
- self.shaman = False
- sha_ids = msg[1:]
- for sha_id in sha_ids:
- tm = self.mice.findByCode(sha_id)
- if tm:
- #print "Shaman:",repr(tm.name)
- #print repr(tm.name),"vs.",repr(self.username)
- if tm.name == self.username:
- #print 'I am shaman'
- self.shaman = True
- self.event_shamaninfo(sha_ids)
- # Mice in room
- if packet_type == '\x08\x09':
- msg = packet.oldProtocolSplit()
- newlist = MouseList()
- for mouseinfo in msg[1:]:
- m_object = Mouse(mouseinfo)
- newlist.add(m_object)
- #old_codes = self.mice.getCodes()
- #for new_mouse in newlist.getCodes():
- # if not new_mouse in old_codes:
- # new_m = newlist.findByCode(new_mouse)
- #print 'New mouse',newlist.findByCode(new_mouse).name
- del self.mice
- self.mice = newlist
- # Mouse joined room
- if packet_type == '\x08\x08':
- msg = packet.oldProtocolSplit()
- print 'Mouse joined room ',msg
- m = Mouse(msg[1])
- self.mice.add(m)
- self.event_mousejoined(m.name)
- # Mouse left room
- if packet_type == '\x08\x07':
- msg = packet.oldProtocolSplit()
- print 'Mouse left room',msg
- tm = self.mice.findByCode(msg[2])
- if tm: self.mice.remove(tm)
- self.event_mouseleft(msg[2])
- # Join tribe request
- if packet_type == '\x10\x0E':
- msg = packet.oldProtocolSplit()
- self.event_jointribe(msg[2], msg[3])
- # Mouse movement
- if packet_type == '\x04\x04':
- packet.read(2)
- code = packet.read(4)
- data = packet.peek(13)
- goingright = packet.readint(1)
- goingleft = packet.readint(1)
- posx = packet.readint(2)
- posy = packet.readint(2)
- movx = packet.readint(2)
- movy = packet.readint(2)
- jump = bool(packet.readint(1))
- jumpimage = packet.readint(1)
- unk = packet.readint(1)
- mouse_code = packet.readint(4)
- tm = self.mice.findByCode(str(mouse_code))
- if tm:
- tm.right = goingright; tm.left = goingleft
- tm.x = posx; tm.y = posy
- tm.jump = jump
- tm.speedx = movx; tm.speedy = movy
- if tm.right: tm.lastdir = 1
- if tm.left: tm.lastdir = -1
- self.event_mousemove(mouse_code, data)
- # Got cheese
- if packet_type == '\x05\x13':
- msg = packet.oldProtocolSplit()
- self.event_gotcheese(msg[1])
- # Cheese to hole
- if packet_type == '\x08\x06':
- msg = packet.oldProtocolSplit()
- self.event_hole(msg[1])
- # Mouse died
- if packet_type == '\x08\x05':
- msg = packet.oldProtocolSplit()
- self.event_mousedied(msg[1])
- tm = self.mice.findByCode(msg[1])
- if tm: tm.dead = True
- # Mouse ballooned
- if packet_type == '\x08\x10':
- msg = packet.oldProtocolSplit()
- self.event_mouseballoon(msg[1])
- # 20 seconds remaining
- if packet_type == '\x06\x11':
- self.event_20seconds()
- # Ducking
- if packet_type == '\x04\x09':
- msg = packet.oldProtocolSplit()
- ducking = (len(msg) == 3)
- self.event_mouseduck(msg[1], ducking)
- # Emote
- if packet_type == '\x08\x16':
- msg = packet.oldProtocolSplit()
- #print 'emote packet',msg
- mouse_id = msg[1]
- emote = ['dance','laugh','cry','kiss'][int(msg[2])-1]
- self.event_emote(mouse_id, emote)
- # Sync status
- if packet_type == '\x08\x15':
- msg = packet.oldProtocolSplit()
- #print 'Sync status',msg
- self.event_syncstatus(msg[1])
- self.sync = False
- tm = self.mice.findByCode(msg[1])
- if tm and tm.name == self.username:
- self.sync = True
- # Tribe stuff
- if packet_type == '\x06\x08':
- packet.read(2)
- msg = packet.readstring()
- who = packet.readstring()
- self.event_tribechat(who, msg)
- def change_gravity(self, x_dir, y_dir, delay=0.0):
- p = Packet('\x05\x22\x01')
- p.write(str(x_dir)+'\x01')
- p.write(str(y_dir))
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def move_cheese(self, nx, ny, delay=0.0):
- p = Packet('\x05\x10\x01')
- p.write(str(int(nx))+'\x01')
- p.write(str(int(ny)))
- p.protocol = 'old'
- self.delay_packet(delay, p)
- def conjuration(self, x, y, delay=0.0):
- print 'Making conjuration at',(int(x),int(y))
- p = Packet('\x04\x0E\x01')
- p.write(str(int(x)))
- p.write(str(int(y)))
- p.setProtocol('old')
- self.delay_packet(delay, p)
- # [type, id, X, Y, speedX, speedY, rot, rotspeed, dur(?), sleep]
- def update_objects(self, obj_list, delay=0.0):
- p = Packet('\x04\x03')
- p.writeint(int(self.move_code), 4)
- for obj in obj_list:
- p.writeint(obj[0], 2)
- #p.writeint(obj[1], 2)
- p.writeint(obj[2], 2)
- p.writeint(obj[3], 2)
- p.writeint(obj[4], 2)
- p.writeint(obj[5], 2)
- p.writeint(obj[6], 2)
- p.writeint(obj[7], 2)
- p.writebyte(obj[8])
- p.writebyte(obj[9])
- print 'Sending',str(p)
- self.delay_packet(delay, p)
- def remove_object(self, code, delay=0.0):
- p = Packet('\x05\x18')
- p.writeint(code, 2)
- self.delay_packet(delay, p)
- def explosion(self, x, y, power=1, radius=1,unk=True, delay=0.0):
- p = Packet('\x05\x11\x01')
- p.write(str(int(x))+'\x01')
- p.write(str(int(y))+'\x01')
- p.write(str(power)+'\x01')
- p.write(str(radius)+'\x01')
- p.write(str(int(unk))+'\x01')
- p.write('1')
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def create_object(self, code, x, y, speedx=0, speedy=0, rot=0, normal=True, delay=0.0):
- #p = Packet('\x05\x15\x01')
- #p.write(str(code)+'\x01')
- #p.write(str(int(x))+'\x01')
- #p.write(str(int(y))+'\x01')
- #p.write(str(rot)+'\x01') # 1
- #p.write(str(speedx)+'\x01')
- #p.write(str(speedy)+'\x01')
- #p.write(str(int(normal))+'\x01') # 1
- #p.setProtocol('old')
- p = Packet('\x05\x14')
- p.writeint(code, 2)
- p.writeint(int(x), 2)
- p.writeint(int(y), 2)
- p.writeint(int(rot), 2)
- p.writeint(int(speedx), 1)
- p.writeint(int(speedy), 1)
- #p.write('\xFF\x00')
- p.writebyte(int(normal))
- self.delay_packet(delay, p)
- self.object_count += 1
- return self.object_count-1
- def magic_begin(self, code, x, y, delay=0.0, rot=1):
- p = Packet('\x05\x08\x01')
- p.write(str(code)+'\x01')
- p.write(str(x)+'\x01')
- p.write(str(y)+'\x01')
- p.write(str(int(rot)))
- p.setProtocol('old')
- if delay==0.0: self.send(p)
- else: self.delay_packet(delay, p, exe="self.casting = True")
- def magic_cast(self, code, x, y, delay=0.0, speedx=0, speedy=0, rot=0, normal=True):
- p = Packet('\x05\x14')
- p.writeint(code, 2)
- p.writeint(int(x), 2)
- p.writeint(int(y), 2)
- p.writeint(int(rot), 2)
- p.writebyte(int(speedx))
- p.writebyte(int(speedy))
- p.writebyte(int(normal))
- if delay==0.0: self.send(p)
- else: self.delay_packet(delay, p)
- def magic_stop(self, delay=0.0):
- p = Packet('\x05\x09')
- p.setProtocol('old')
- self.delay_packet(delay, p, exe="self.casting = False")
- def magic(self, code, x, y, delay=0.0, cast_time=1.0, speedx=0, speedy=0, rot=1, normal=True, attach=None):
- if self.casting: return
- if not self.shaman: return
- self.magic_begin(code,x,y, delay, rot)
- self.magic_cast(code,x,y,delay+cast_time, speedx, speedy, rot, normal)
- if attach:
- self.attach_balloon(attach, delay+cast_time+0.2)
- #else:
- # p = Packet('\x05\x07\x0111,0,0,0,0,-2,5.4,6.2,0')
- # p.setProtocol('old')
- # self.delay_packet(delay+cast_time+0.2, p)
- self.magic_stop(delay+cast_time+0.2)
- self.object_count += 1
- return self.object_count-1
- def create_anchor(self, anchor, obj=0, x=0, y=0, angle=0, x2=0, y2=0, delay=0.0):
- p = Packet('\x05\x07\x01')
- p.write(str(anchor)+',')
- p.write(str(obj)+',')
- p.write(str(x)+',')
- p.write(str(y)+',')
- p.write(str(angle)+',')
- p.write('-2,')
- p.write(str(x2)+',')
- p.write(str(y2)+',')
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def attach_balloon(self, mouse_code, delay=0.0):
- p = Packet('\x08\x10\x01')
- p.write(str(mouse_code))
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def command(self, txt, delay=0.0):
- p = Packet('\x06\x1A\x01')
- p.setProtocol('old')
- p.write(txt)
- self.delay_packet(delay, p)
- def modmessage(self, txt, delay=0.0):
- p = Packet('\x06\x0A\x00')
- p.writestring(txt)
- self.delay_packet(delay, p)
- def modchat(self, txt):
- p = Packet('\x06\x0A')
- p.write('\x03')
- p.writestring(txt)
- self.send(p)
- def arbchat(self, txt):
- p = Packet('\x06\x0A')
- p.write('\x02')
- p.writestring(txt)
- self.send(p)
- def chat(self, txt, delay=0.0):
- p = Packet('\x06\x06')
- p.writestring(txt)
- self.delay_packet(delay, p)
- def tribechat(self, txt, delay=0.0):
- p = Packet('\x06\x08')
- p.writestring(txt)
- self.delay_packet(delay, p)
- def whisper(self, who, txt):
- p = Packet('\x06\x07')
- p.writestring(who)
- p.writestring(txt)
- self.send(p)
- def duck(self, state, delay=0.0):
- if state == True: p = Packet('\x04\x09\x01\x31')
- else: p = Packet('\x04\x09\x01\x30')
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def get_cheese(self, delay=0.0):
- p = Packet('\x05\x13\x01'+str(self.move_code))
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def hole(self, delay=0.0):
- p = Packet('\x05\x12\x010\x01'+str(self.move_code))
- p.setProtocol('old')
- self.delay_packet(delay, p)
- def die(self, delay=0.0):
- self.dead = True
- p = Packet('\x04\x05')
- p.writeint(int(self.move_code), 4)
- self.delay_packet(delay, p)
- def change_room(self, new_room):
- self.command("room "+new_room)
- def event_20seconds(self):
- pass
- def event_mousemove(self, mouse_code, data):
- pass
- def event_mouseduck(self, mouse_code, state):
- pass
- def event_mousedied(self, mouse_code):
- pass
- def event_mousejoined(self, mouse_name):
- pass
- def event_mouseleft(self, mouse_name):
- pass
- def event_mouseballoon(self, mouse_code):
- pass
- def event_gotcheese(self, mouse_code):
- pass
- def event_hole(self, mouse_code):
- pass
- def event_emote(self, mouse_id, emote):
- pass
- def event_shamaninfo(self, sha_ids):
- pass
- def event_jointribe(self, who, tribename):
- pass
- def event_newmap(self):
- pass
- def event_chat(self, who, said):
- pass
- def event_tribechat(self, who, said):
- pass
- def event_whisper(self, who, whispered):
- pass
- def event_syncstatus(self, mouse_code):
- pass
- def event_modmessage(self, who, said, arb=False):
- pass
- def event_servermessage(self, msg, arb=False):
- pass
- def event_newroom(self, name):
- pass
- def event_login(self):
- pass
- def mainLoop(self):
- # Send delayed packets
- for packet_data in self.packet_queue:
- if time.time() >= packet_data[0]:
- self.send(packet_data[1])
- if packet_data[2] != "":
- print packet_data[2]
- if packet_data[3] != "":
- exec(packet_data[3])
- try:
- self.packet_queue.remove(packet_data)
- except: pass
- # TZAT packet
- if self.loginstate == "logged in" and time.time()-self.tzat_last >= 11.2:
- self.TZAT()
- # Receive data from the server
- data = ''
- try:
- data = self.sock.recv(2*1024)
- if data == '':
- print str(self.last_packet)
- print ' -- Connection problem --'
- self.reset_data()
- except socket.error:
- pass
- #if data == '':
- # return
- #print 'Got:',str(Packet(data))
- self.r_data += data
- # Parse data
- if self.r_data != "":
- try:
- packet_size = struct.unpack('!L', self.r_data[:4])[0]
- except:
- self.r_data = ""
- return
- #print 'Packet should be ',packet_size,', packet is ',len(self.r_data)
- if packet_size <= len(self.r_data):
- p_data = self.r_data[:packet_size]
- self.r_data = self.r_data[packet_size:]
- p = Packet(p_data)
- p.read(4)
- if p.peek(2) == '\x01\x01':
- p.read(4)
- p.setProtocol('old')
- if not (p.peek(2) in ['\x04\x03']):
- pass
- self.parsePacket(p)
- class Testbot(Bot):
- def __init__(self, *args, **kwargs):
- Bot.__init__(self, *args, **kwargs)
- self.lastcode = 0
- self.target = 'Maqqara'
- self.maprot = ['1','2','3','4','5']
- self.timer = time.time()
- def event_chat(self, who, said):
- print '['+who+'] '+said
- def event_newmap(self):
- print ' *** New map *** :',time.ctime()
- mp = self.maprot.pop(0)
- self.command('npp '+mp)
- self.maprot.append(mp)
- def event_syncstatus(self, mouse_code):
- tm = self.mice.findByCode(mouse_code)
- if tm:
- print 'Sync:',tm.name
- def event_whisper(self, who, w):
- if who == 'Maqqara':
- cmd = w.split(' ')
- if cmd[0] == 'die': self.die()
- if cmd[0] == 'shutdown':
- self.sock.close()
- self.running = False
- if cmd[0] == 'ms':
- self.modmessage(' '.join(cmd[1:]))
- if cmd[0] == 'm':
- self.modchat(' '.join(cmd[1:]))
- if cmd[0] == 'cmd':
- self.command(' '.join(cmd[1:]))
- def event_modmessage(self, who, msg, arb=False):
- if who != "":
- con.textcolor(con.LIGHTMAGENTA)
- if arb: con.textcolor(con.MAGENTA)
- arb_s = '' if not arb else '[A]'
- message = arb_s+'['+who+'] '+msg
- print message
- #if self.whisperchat and self.modfilter(message): self.whisper('Maqqara', message)
- con.textcolor(con.LIGHTGREY)
- def event_servermessage(self, msg, arb=False):
- con.textcolor(con.LIGHTGREEN)
- if arb: con.textcolor(con.GREEN)
- arb_s = '' if not arb else '[A]'
- message = arb_s+'[Server] '+msg
- print message
- #if self.whisperchat and self.modfilter(message): self.whisper('Maqqara', message)
- con.textcolor(con.LIGHTGREY)
- '''
- def event_mousemove(self, mouse_code, data):
- tm = self.mice.findByCode(str(mouse_code))
- if tm and tm.name == self.target:
- self.update_objects([[Magic.ANVIL, self.lastcode, tm.x, tm.y, tm.speedx, tm.speedy, 0, 0, False, False]])
- def event_mouseduck(self, mouse_code, ducking):
- tm = self.mice.findByCode(str(mouse_code))
- if tm and tm.name != self.username:
- if ducking and tm.name == self.target:
- print 'spawn',(tm.x,tm.y)
- #self.move_cheese(tm.x/3.3, tm.y/3.5)
- self.lastcode = self.create_object(Magic.ANVIL, tm.x/3.3, tm.y/3.5)
- #self.create_anchor(11, self.lastcode, x=0, y=0, x2=tm.x/100.3, y2=tm.y/100.5)
- #self.lastcode = self.create_object(Magic.ANVIL, tm.x/3.3, tm.y/3.5)
- #self.explosion(tm.x/3.3, tm.y/3.5, power=20, radius=120, delay=3.0)
- #self.remove_object(self.lastcode, delay=3.0)
- d = 0.0
- for mouse in self.mice.mice:
- print (mouse.x, mouse.y)
- if (mouse.x, mouse.y) != (0,0):
- self.magic_begin(Magic.SPIRIT, int(mouse.x/3.3), int(mouse.y/3.5), delay=d)
- self.magic_stop(delay=d)
- d += 0.1
- '''
- #def mainLoop(self):
- #if time.time()-self.timer > 2 and self.loginstate == "logged in":
- # for mouse in self.mice.mice:
- # self.magic_begin(Magic.SPIRIT, mouse.x/3.3, mouse.y/3.5)
- # self.magic_stop(delay=0.1)
- # Bot.mainLoop(self)
- if __name__ == '__main__':
- server = Server.EN2
- bot = Testbot("maq", "Idibot", "xxxxx")
- success = bot.connect(server)
- if not success:
- print 'Connecting to the server failed.'
- sys.exit(1)
- while True:
- bot.mainLoop()
- if bot.loginstate == "ready to login":
- print 'Logging in...'
- bot.login()
- if bot.disconnected:
- print 'Attempting to re-connect...'
- time.sleep(5)
- success = bot.connect(server)
- if not success:
- print 'Re-connecting failed.'
Add Comment
Please, Sign In to add comment