#!/usr/bin/python2.6 import playerio import time class EverybodyEditsBot(object): def run(self): print "Connecting..." for attempt in range(1, 6): print "Attempt " + str(attempt) try: playerio.connect("everybody-edits-su9rn58o40itdbnw69plyw", "public", "whatever", "", self.connected) break except Exception, e: raise print "Errored: " + str(e) time.sleep(5) def connected(self, client): self.client = client self.client.trace = True print "Listing rooms..." self.client.multiplayer.list_rooms("FlixelWalker", {}, 0, 0, self.list_rooms) print "Joining room..." self.client.multiplayer.create_join_room("1x0", "FlixelWalker", True, {}, {}, self.joined) def list_rooms(self, rooms): print "Rooms (%s):" % len(rooms) for r in rooms: print r def joined(self, connection): print "Joined room!" self.connection = connection self.connection.add_message_handler("init", self.inited) #self.connection.add_message_handler("update", self.updated) self.connection.send("init") try: time.sleep(60) finally: print "keyboard exit" connection.disconnect() import sys sys.exit(0) def inited(self, msg): pass #self.blit("coolface.png") #for x in range(10, 250): # for y in range(10, 20): # self.change(x, y, 0) def change(self, x, y, type): if x >= 0 and x < 200 and y >= 0 and y < 200: self.connection.send("change", x, y, type) def updated(self, msg): t = time.time() if int(t) % 10 == 0: px = int(msg[1] / 16) py = int(msg[2] / 16) print repr((px, py)) for t in range(0, 5): self.change(px - 2 + t, py - 2, 5) self.change(px - 2 + t, py + 2, 5) self.change(px - 2, py - 2 + t, 5) self.change(px + 2, py - 2 + t, 5) def blit(self, image): from PIL import Image palim = Image.open("blitwalker-colors.png") palim.mode = "RGB" pal = list(palim.getdata()) im = Image.open(image) x = 0 y = 0 for p in im.getdata(): if len(p) != 4 or p[3] != 0: best = 0 index = 0 bdist = 65535 for color in pal: dist = abs(color[0] - p[0]) + abs(color[1] - p[1]) + abs(color[2] - p[2]) if dist < bdist: best = index bdist = dist index += 1 if best == 0: type = 0 else: type = best + 4 print type self.change(x + 20, y + 20, type) x += 1 if x >= im.size[0]: x = 0 y += 1 time.sleep(0.1) EverybodyEditsBot().run()