本文整理汇总了Python中server.Server.getClients方法的典型用法代码示例。如果您正苦于以下问题:Python Server.getClients方法的具体用法?Python Server.getClients怎么用?Python Server.getClients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.getClients方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServerInst
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import getClients [as 别名]
class ServerInst():
def __init__(self):
# Initialise Window
self.showbase=ShowBase()
# Disable Mouse Control for camera
self.showbase.disableMouse()
# Start our server up
self.server = Server(9099, compress=True)
self.db = DataBase()
self.users={} # We should send the clients from the lobby to here somehow? or just get it from somewhere...
for i in range(num_users):
new_user={}
new_user['name']='cake'
new_user['connection']='cake'
new_user['ready']=True
new_user['new_dest']=False
new_user['new_spell']=False
self.users[len(self.users)]=new_user
camera.setPos(0,0,45*num_users)
camera.lookAt(0,0,0)
taskMgr.doMethodLater(0.5, self.pregame_loop, 'Lobby Loop')
#taskMgr.doMethodLater(0.5, self.lobby_loop, 'Lobby Loop')
#if newGame == True:
# Lets make something that instances the gameServer class for everything game thats hosted?
#taskMgr.doMethodLater(0.5, self.login_loop, 'Login Loop') # Probly start the game then
# FROM HERE WILL GO TO GAME SERVER>>>
def pregame_loop(self,task):
"""# Guess all of this should move after the if.
#print "Pregame State"
if self.server.getClients():
self.game_time=0
self.tick=0
self.game=Game(len(self.users),game_tick,self.showbase)
temp=self.server.getData()
print temp
if temp!=[]:
for i in range(len(temp)):
valid_packet=False
package=temp[i]
if len(package)==2:
print "Received: "+str(package)+" "+str(package[1])
if len(package[0])==2:
print "Packet right size"
for u in range(len(self.users)):
self.users[u]['warlock']=self.game.warlock[u]
if self.users[u]['connection']==package[1]:
print "Packet from "+self.users[u]['name']
if package[0][0]=='ready':
print "So i got the ready and im in game state"
taskMgr.doMethodLater(0.5, self.game_loop, 'Game Loop')
return task.done
else:
print "well i didnt get shit"
return task.again
"""
# if in pregame state
temp=self.server.getData()
if temp!=[]:
for i in range(len(temp)):
valid_packet=False
package=temp[i]
if len(package)==2:
print "Received: " + str(package) +" "+ str(package[1].getAddress())
if len(package[0])==2:
# if username is sent, assign to client
if package[0][0]=='username':
user_found=False
valid_packet=True
for u in range(len(self.users)):
if self.users[u]['name']==package[0][1]:
print "User already exists"
user_found=True
data = {}
data[0] = "error"
data[1] = "User already exists"
self.server.sendData(data,package[1])
# send something back to the client saying to change username
if not user_found:
new_user={}
new_user['name']=package[0][1]
new_user['connection']=package[1]
new_user['ready']=False
new_user['new_dest']=False
new_user['new_spell']=False
self.users[len(self.users)]=new_user
data = {}
data[0] = "which"
data[1] = len(self.users)-1
self.server.sendData(data,package[1])
# else check to make sure connection has username
for u in range(len(self.users)):
if self.users[u]['connection']==package[1]:
#.........这里部分代码省略.........
示例2: ServerInst
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import getClients [as 别名]
#.........这里部分代码省略.........
elif package[0][0]=='ready':
print self.users[u]['name']+" is ready!"
self.users[u]['ready']=True
valid_packet=True
update_warlocks=True
# else if unready packet
elif package[0][0]=='unready':
print self.users[u]['name']+" is not ready!"
self.users[u]['ready']=False
valid_packet=True
update_warlocks=True
if update_warlocks:
data = {}
data[0]='warlocks'
data[1]=len(self.users)
self.server.broadcastData(data)
# break out of for loop
break
#else:
# print str(self.users[u]['connection'])+" "+str(package[1])
if not valid_packet:
data = {}
data[0] = "error"
data[1] = "Please Login"
self.server.sendData(data,package[1])
print "User not logged in"
else:
print "Data in packet wrong size"
else:
print "Packet wrong size"
# if all players are ready and there is X of them
game_ready=True
# if there is any clients connected
if not self.server.getClients():
game_ready=False
for u in range(len(self.users)):
if self.users[u]['ready']==False:
game_ready=False
if game_ready:
data = {}
data[0]='state'
data[1]='game'
self.server.broadcastData(data)
taskMgr.doMethodLater(0.5, self.pregame_loop, 'Pregame Loop')
return task.done
return task.again
def pregame_loop(self,task):
print "Pregame State"
self.game_time=0
self.tick=0
self.game=Game(len(self.users),game_tick,self.showbase)
for u in range(len(self.users)):
self.users[u]['warlock']=self.game.warlock[u]
taskMgr.doMethodLater(0.5, self.game_loop, 'Game Loop')
return task.done
#return task.again
def game_loop(self,task):
# if there is any clients connected
if self.server.getClients():
# process incoming packages
temp=self.server.getData()
if temp!=[]:
for i in range(len(temp)):
valid_packet=False