def cmd_connect(self, arg): global CURRENT_PROTOCOL_VERSION np = arg.split(',') if len(np) != 3: print("mal-formatted connect command from " + self.addr + ": " + arg) return self.name = encoding.safefilename(encoding.dequote(np[0])) pw = encoding.dequote(np[1]) proto = int(np[2]) if (proto != CURRENT_PROTOCOL_VERSION): print("bad version in connect from " + self.addr + ": " + np[2]) return ok = 0 try: file = None try: file = open("user/" + self.name, "rb") except: pass if not file: # look for a back-up file, if we died while trying a rename() operation file = open("user/" + self.name + ".tmp", "rb") self.userdata = pickle.load(file) file.close() ok = (self.userdata["password"] == pw) except Exception, x: print("User file open exception " + str(x) + " on file " + self.name);
def unpack(self, rep): q = rep.split(',', 4) if (len(q) < 4): raise BadDataFormat() self.type = encoding.dequote(q[0]) self.pos = (float(encoding.dequote(q[1])), float(encoding.dequote(q[2])), float(encoding.dequote(q[3]))) if (len(q) > 4): return q[4] return ""
def cmd_move(self, sub): q = sub.split(",") if len(q) < 3: print("short move command from " + self.name) return self.desiredpos = (float(encoding.dequote(q[0])), \ float(encoding.dequote(q[1])), float(encoding.dequote(q[2]))) self.notifylisteners("mov " + str(self.id) + "," + \ ",".join(map(str, self.desiredpos)) + "\n")
def unpack(self, rep): rep = world.Entity.unpack(self, rep) q = rep.split(",", 4) if len(q) < 4: print("Player rep: " + rep) raise world.BadDataFormat() self.name = encoding.dequote(q[0]) self.desiredpos = (float(encoding.dequote(q[1])), \ float(encoding.dequote(q[2])), float(encoding.dequote(q[3]))) if (len(q) > 4): return q[4] return ""