本文整理汇总了Python中packet.Packet.add_player方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.add_player方法的具体用法?Python Packet.add_player怎么用?Python Packet.add_player使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packet.Packet
的用法示例。
在下文中一共展示了Packet.add_player方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import add_player [as 别名]
def run(self):
while True:
data, addr = self.server.recv()
pkg = Packet.unpack(data)
# print "got packet: %s, %s, %s" % (pkg.tick, pkg.players, pkg.input)
with self.lock:
net_tick = self.parent.net_tick
if addr not in self.clients:
if pkg.tick == 0 and len(pkg.players) == 0 and len(pkg.input) == 0:
self.clients[addr] = Client(addr, self.next_id, Player(50 + self.next_id * 30, 50))
self.next_id += 1
pkg_response = Packet(net_tick)
pkg_response.add_player(self.clients[addr].id, self.clients[addr].player)
self.server.send(pkg_response, addr)
print "authenticating new client: %s -> %s" % (addr, self.clients[addr].id)
else:
print "invalid authentication attempt: %s, %s, %s" % (pkg.tick, pkg.players, pkg.input)
else:
client = self.clients[addr]
client.ack()
if pkg.tick >= net_tick:
if len(pkg.input) > 0:
client.events[pkg.tick] = pkg.input
# if net_tick not in self.pkg_queue:
# self.pkg_queue[net_tick] = []
# self.pkg_queue[net_tick].insert(0, pkg)
else:
print "discard packet (too old: %d < %d)" % (pkg.tick, net_tick)
示例2: send_new_state
# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import add_player [as 别名]
def send_new_state(self):
pkg_state = Packet(self.net_tick)
for client in self.clients.values(): # construct current state from client data
pkg_state.add_player(client.id, client.player)
for addr in self.clients.keys(): # broadcast current state to all connected clients
self.server.send(pkg_state, addr)