?? simuser.py
字號:
# $Id: simuser.py,v 1.6 2002/02/04 15:50:34 marijn Exp $# An air traffic simulation game.# Copyright (C) 2000,1,2 Marijn Vriens <marijn@sanity.dhs.org>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAimport randomimport timeimport UserDictclass SimUsers(UserDict.UserDict): _idmax = pow(2, 30) def __init__(self): UserDict.UserDict.__init__(self) self._userNicks = {} def createUser(self, nick): if self._userNicks.has_key(nick): raise "NickTaken" value = SimUserInfo(self._genId()) value.nick(nick) self.data[value.id()] = value self._userNicks[nick] = value.id() return value.id() def removeUser(self, id): del self.data[id] def getUpdateTimeOfSlowestUser(self): t = time.time() for d in self.data.values(): if d.getTimeOfLastUpdate() < t: t = d.getTimeOfLastUpdate() return t def _genId(self): k = random.randint(0, self._idmax) while(self.data.has_key(k)): k = random.randint(0, self._idmax) return k def __setitem__(self): raise "METHOD_NOT_SUPPORTED"# This class keeps track of user data.class SimUserInfo: def __init__(self, id): self._id = id self._timeUpdated = time.time() self._nick = '' self.objs = {} # objs this client is subscribed to. def id(self, id=None): if(id == None): return self._id else: self._id = id def nick(self, nick=None): if(nick == None): return self._nick else: self._nick = nick def subscribeToEntity(self, obj): self.objs[obj.id] = obj def unsubscribeFromEntity(self, id): del self.objs[id] def markAsUpdated(self): self._timeUpdated = time.time() def getTimeOfLastUpdate(self): return self._timeUpdated def genIdlPlaneUpdateList(self): r = [] for i in self.objs.values(): r.append(i.genIdlFull()) #print "SimUserInfo::genIdlPlaneUpdateList: %s" % repr(r) return r def checkAuthority(self, objId): if(self.objs.has_key(objId)): return 1 else: return 0 # $Log: simuser.py,v $# Revision 1.6 2002/02/04 15:50:34 marijn# Added order receiving methods## Revision 1.5 2002/02/01 15:07:36 marijn# updated copyright information## Revision 1.4 2002/01/13 16:05:56 marijn# All updates now go via getUpdate(). Split genIdl into Full and Reduced## Revision 1.3 2002/01/12 23:53:22 marijn# Refactored simuser## Revision 1.2 2001/12/25 02:00:08 marijn# various fixes and updates.## Revision 1.1 2001/11/27 20:59:06 marijn# sending of simple sim objcts#
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -