def execute(self, sid, command, oid, *args): #@startTime = time.time() log.debug('execute', sid, oid, command, args) # check client id session = self.clientMngr.getSession(sid) if not session.cid: raise ige.SecurityException('No player object selected.') if not self.validateClient(session): raise ige.GameException('Wrong version of client.') # check game status (admin is allowed anytime) if self.status != Const.GS_RUNNING and session.cid != Const.OID_ADMIN: raise ige.ServerStatusException(self.status) # check existence of the commander if not self.db.has_key(session.cid): raise ige.GameException('This player does not exist. He/she could lose.') # update client's liveness session.touch() # find correct object type try: obj = self.db[oid] except KeyError: raise ige.NoSuchObjectException('Object %d does not exist.' % oid) cmdObj = getattr(self.cmdPool[obj.type], command) if not hasattr(cmdObj, 'public') or not cmdObj.public: raise ige.SecurityException('Access denied - method is not public.') # get acces level of the commander accLevel = Const.AL_NONE if obj.owner == session.cid: accLevel = Const.AL_OWNER if session.cid == Const.OID_ADMIN: accLevel = Const.AL_ADMIN #@log.debug('access rights', accLevel, cmdObj.accLevel) if cmdObj.accLevel > accLevel: raise ige.SecurityException('Access denied - low access level.') # create transaction (TODO - cache it!) tran = Transaction(self, session.cid, session) # invoke command on it result = cmdObj(*(tran, obj) + args) # commit transaction tran.commit() #@log.debug('result', result) # session messages #@log.debug('Messages:', session.messages.items()) messages = session.messages.items() session.messages.clear() #@log.debug("Execution time", time.time() - startTime) return result, messages
def execute(self, sid, command, oid, *args): #@startTime = time.time() log.debug('execute', sid, oid, command, args) # check client id session = self.clientMngr.getSession(sid) if not session.cid: # check if real id exists try: cid = self.db[OID_I_LOGIN2OID].get(session.login, None) except AttributeError: raise SecurityException('Not logged in.') log.debug('Adding cid to session', cid) if not cid: # no real id #@log.debug('Raising exception NoAccountException') raise NoAccountException('No game account exists.') session.cid = cid # validate client if not self.validateClient(session): raise GameException('Wrong version of client.') # notify object, that player has logged in player = self.db[cid] self.cmdPool[player.type].loggedIn(Transaction(self), player) # check game status (admin is allowed anytime) if self.status != GS_RUNNING and session.cid != OID_ADMIN: raise ServerStatusException(self.status) # check existence of the commander if not self.db.has_key(session.cid): raise GameException('This player does not exist. He/she could lose.') # update client's liveness session.touch() # find correct object type try: obj = self.db[oid] except KeyError: raise NoSuchObjectException('Object %d does not exist.' % oid) cmdObj = getattr(self.cmdPool[obj.type], command) # TODO check access level if not hasattr(cmdObj, 'public') or not cmdObj.public: raise SecurityException('Access denied - method is not public.') # get acces level of the commander accLevel = AL_NONE if obj.owner == session.cid: accLevel = AL_OWNER if session.cid == OID_ADMIN: accLevel = AL_ADMIN # TODO delete #tmpAL = self.getAccRights(obj, session.cid) #if tmpAL > accLevel: # accLevel = tmpAL #@log.debug('access rights', accLevel, cmdObj.accLevel) if cmdObj.accLevel > accLevel: raise SecurityException('Access denied - low access level.') # create transaction (TODO - cache it!) tran = Transaction(self, session.cid, session) # invoke command on it result = apply(cmdObj, (tran, obj) + args) # commit transaction tran.commit() #@log.debug('result', result) # session messages #@log.debug('Messages:', session.messages.items()) messages = session.messages.items() session.messages.clear() #@log.debug("Execution time", time.time() - startTime) return result, messages
def execute(self, sid, command, oid, *args): #@startTime = time.time() log.debug('execute', sid, oid, command, args) # check client id session = self.clientMngr.getSession(sid) if not session.cid: # check if real id exists try: cid = self.db[OID_I_LOGIN2OID].get(session.login, None) except AttributeError: raise SecurityException('Not logged in.') log.debug('Adding cid to session', cid) if not cid: # no real id #@log.debug('Raising exception NoAccountException') raise NoAccountException('No game account exists.') session.cid = cid # validate client if not self.validateClient(session): raise GameException('Wrong version of client.') # notify object, that player has logged in player = self.db[cid] self.cmdPool[player.type].loggedIn(Transaction(self), player) # check game status (admin is allowed anytime) if self.status != GS_RUNNING and session.cid != OID_ADMIN: raise ServerStatusException(self.status) # check existence of the commander if not self.db.has_key(session.cid): raise GameException( 'This player does not exist. He/she could lose.') # update client's liveness session.touch() # find correct object type try: obj = self.db[oid] except KeyError: raise NoSuchObjectException('Object %d does not exist.' % oid) cmdObj = getattr(self.cmdPool[obj.type], command) # TODO check access level if not hasattr(cmdObj, 'public') or not cmdObj.public: raise SecurityException('Access denied - method is not public.') # get acces level of the commander accLevel = AL_NONE if obj.owner == session.cid: accLevel = AL_OWNER if session.cid == OID_ADMIN: accLevel = AL_ADMIN # TODO delete #tmpAL = self.getAccRights(obj, session.cid) #if tmpAL > accLevel: # accLevel = tmpAL #@log.debug('access rights', accLevel, cmdObj.accLevel) if cmdObj.accLevel > accLevel: raise SecurityException('Access denied - low access level.') # create transaction (TODO - cache it!) tran = Transaction(self, session.cid, session) # invoke command on it result = apply(cmdObj, (tran, obj) + args) # commit transaction tran.commit() #@log.debug('result', result) # session messages #@log.debug('Messages:', session.messages.items()) messages = session.messages.items() session.messages.clear() #@log.debug("Execution time", time.time() - startTime) return result, messages