Esempio n. 1
0
 def getItemLength(self, key):
     key = self.keyMethod(key)
     self.cursor.execute("select * from data where oid = ?", (key,))
     row = self.cursor.fetchone()
     if row is None:
         raise ige.NoSuchObjectException(key)
     return len(str(row[1]))
Esempio n. 2
0
 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
Esempio n. 3
0
	def __getitem__(self, key):
		self.statCount += 1
		if key in self.cache:
			self.statHit += 1
			self.moveExistingCacheItem(key)
			return self.cache[key]
		self.statMiss += 1
		idx = self.view.find(oid = key)
		if idx == -1:
			raise ige.NoSuchObjectException(key)
		item = pickle.loads(self.view[idx].data)
		self.addNewCacheItem(key)
		self.cache[key] = item
		#TODOitem.setModified(0)
		return item
	def __getitem__(self, key):
		key = str(key)
		self.statCount += 1
		if key in self.cache:
			self.statHit += 1
			self.moveExistingCacheItem(key)
			return self.cache[key]
		self.statMiss += 1
		try:
			item = pickle.loads(self.db.get(key, txn = self.txn))
		except db.DBNotFoundError:
			raise ige.NoSuchObjectException(key)
		self.addNewCacheItem(key)
		self.cache[key] = item
		#TODOitem.setModified(0)
		return item
Esempio n. 5
0
 def __getitem__(self, key):
     key = self.keyMethod(key)
     self.statCount += 1
     if key in self.cache:
         self.statHit += 1
         self._moveExistingCacheItem(key)
         return self.cache[key]
     self.statMiss += 1
     self.cursor.execute("select * from data where oid = ?", (key,))
     row = self.cursor.fetchone()
     if row is None:
         raise ige.NoSuchObjectException(key)
     item = pickle.loads(row[1])
     self._addNewCacheItem(key)
     self.cache[key] = item
     #TODOitem.setModified(0)
     return item