# self.buffer=="" else: self.parseData(self.buffer) self.buffer = "" def startRestart(self, time): self.timer1 = threading.Timer(1, self.restartMin2) self.timer1.start() #self.sendServerMessage("Server is restarting in 5...") def restartMin2(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reiniciar em 2 minutos") self.timer1 = threading.Timer(60, self.restartMin1) self.timer1.start() def restartMin1(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reiniciar em 1 minuto") self.timer1 = threading.Timer(30, self.restartMin30) self.timer1.start() def restartMin30(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reiniciar em 30 segundos") self.timer1 = threading.Timer(15, self.restartMin15) self.timer1.start() def restartMin15(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 15 segundos") self.timer1 = threading.Timer(5, self.restart10) self.timer1.start() def restart10(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reiniciar em 10 segundos") self.timer1 = threading.Timer(1, self.restart9) self.timer1.start() def restart9(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em in 9 segundos") self.timer1 = threading.Timer(1, self.restart8) self.timer1.start() def restart8(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 8 segundos") self.timer1 = threading.Timer(1, self.restart7) self.timer1.start() def restart7(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 7 segundos") self.timer1 = threading.Timer(1, self.restart6) self.timer1.start() def restart6(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 6 segundos") self.timer1 = threading.Timer(1, self.restart5) self.timer1.start() def restart5(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 5 segundos") self.timer1 = threading.Timer(1, self.restart4) self.timer1.start() def restart4(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 4 segundos") self.timer1 = threading.Timer(1, self.restart3) self.timer1.start() def restart3(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 3 segundos") self.timer1 = threading.Timer(1, self.restart2) self.timer1.start() def restart2(self): try: self.timer1.cancel() except: pass self.sendRestartMessage("O servidor ira reinicar em 2 segundos") for room in self.server.rooms.itervalues(): for player in room.clients.itervalues(): try:room.updatesqlserver() except: pass self.server.disconnectPlayer(player) def rested(self, time): self.restartTimer(time) def parseData(self, data): MDT_stuff = data[:4] data = data[4:] #print data values = data.split("\x01") #print repr(MDT_stuff), values #logging.warning("DATA: %s" % data) #logging.warning("DATAD: %s" % repr(MDT_stuff)) #logging.warning("DATAV: %s" % values) eventTokens = values.pop(0) eventToken1, eventToken2 = eventTokens if eventToken1 == "\x1A": if eventToken2 == "\x02": #awake timer unknownTime, = values unknownTime = int(unknownTime) elif eventToken2 == "\x03": #create account username, passwordHash = values username = username.replace("<","") if self.server.checkExistingUsers(username): self.sendData("\x1A" + "\x03", ) #Nickname Already Taken message else: passwordHash=hashlib.sha512(passwordHash).hexdigest() self.server.createAccount(username, passwordHash) self.login(username, passwordHash, "1") elif eventToken2 == "\x0E": #Sent Change Password if self.privilegeLevel!=0: utfLength=struct.unpack('!h', data[:2])[0] PassHash=data[2:utfLength+2] data=data[utfLength+2:] utfLength=struct.unpack('!h', data[:2])[0] ForumPassHash=data[2:utfLength+2] data=data[utfLength+2:] utfLength=struct.unpack('!h', data[:2])[0] ForumSalt=data[2:utfLength+2] if self.ValidatedPassChange: self.ValidatedPassChange=False passwordHash=hashlib.sha512(PassHash).hexdigest() dbcur.execute('UPDATE users SET password = ? WHERE name = ?', [passwordHash, self.username]) elif eventToken2 == "\x04": #login username, passwordHash, startRoom = values if passwordHash != "": passwordHash=hashlib.sha512(passwordHash).hexdigest() username = username.replace("<","") self.login(username, passwordHash, startRoom) else: logging.warning("Unimplemented %r" % eventTokens) #raise NotImplementedError, eventTokens elif eventToken1 == "\x04": if eventToken2 == "\x03": #print 'values: '+str(values) #world physics update #CodePartieEnCours = values.pop(0) #for objectData in values: # if objectData == 'x': # continue # objectType, x, y, dx, dy, rotation, angularVelocity, isSolid, valuea = objectData.split(',') if self.isSyncroniser: self.room.sendAllOthersAndSelf(self, eventTokens, values) #self.room.stateRecorder.setPhyscisState(eventTokens, values) elif eventToken2 == "\x04": #position update #isMovingRight, isMovingLeft, x, y, dx, dy, isJumping, jumpAnimation = values #self.room.sendAllOthers(self, eventTokens, values + [self.playerCode]) self.room.sendAll(eventTokens, values + [self.playerCode]) elif eventToken2 == "\x05": #player went out of bounds self.isDead = True #score #self.score = self.score-1 #if self.score < 0: # self.score = 0 #end self.score -=