当前位置: 首页>>代码示例>>Python>>正文


Python Packet.add_player方法代码示例

本文整理汇总了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)
开发者ID:oncer,项目名称:netproto,代码行数:30,代码来源:np_server.py

示例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)
开发者ID:oncer,项目名称:netproto,代码行数:8,代码来源:np_server.py


注:本文中的packet.Packet.add_player方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。