def remove(self): # 告诉各个客户端有玩家离线 ret = Protocol() ret.add_int32(2) ret.add_int32(self.get_conn().charId) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(ret.get_pck_has_head()) g_conn_pool.remove(self.get_conn())
def move_role(self): # 告诉各个客户端有玩家移动了 ret = Protocol() ret.add_str("playermove") ret.add_int32(self.get_conn().x) ret.add_int32(self.get_conn().y) ret.add_str(self.get_conn().name) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(ret.get_pck_has_head())
def other_role(self): # 告诉当前玩家,其他玩家的信息 for conn in g_conn_pool: if conn != self.get_conn(): ret = Protocol() ret.add_str("newplayer") ret.add_int32(conn.x) ret.add_int32(conn.y) ret.add_str(conn.name) self.request.sendall(ret.get_pck_has_head())
def new_role(self): # 告诉各个客户端有新玩家加入 ret = Protocol() ret.add_str("newplayer") ret.add_int32(self.get_conn().x) ret.add_int32(self.get_conn().y) ret.add_str(self.get_conn().name) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(ret.get_pck_has_head())
def send_role_move(): """ 发送角色的坐标给服务端 """ # 构建数据包 p = Protocol() p.add_str("move") p.add_int32(g_player.x) p.add_int32(g_player.y) data = p.get_pck_has_head() # 发送数据包 g_client.sendall(data)
def send_new_role(): """ 告诉服务端有新玩家加入 """ # 构建数据包 p = Protocol() p.add_str("newrole") p.add_int32(g_player.x) p.add_int32(g_player.y) p.add_str(g_player.name) data = p.get_pck_has_head() # 发送数据包 g_client.sendall(data)
def other_role(self): # 告诉当前玩家,其他玩家的信息 for conn in g_conn_pool: ret = Protocol() ret.add_str("newplayer") ret.add_int32(conn.x) ret.add_int32(conn.y) ret.add_str(conn.name) ret.add_str(conn.number) # 本人返回1,非本人返回0 if conn != self.get_conn(): ret.add_str('N') else: ret.add_str('Y') ret.add_str(conn.race) self.request.sendall(ret.get_pck_has_head())
def send_new_role(): """ 告诉服务端有新玩家加入 """ # 构建数据包 p = Protocol() # 请求名称,用来区分该请求执行的操作 p.add_str("newrole") # 传入角色的x坐标 p.add_int32(0) # 传入角色的y坐标 p.add_int32(1) # 传入角色的名字 p.add_str(deploy.g_player.name) data = p.get_pck_has_head() # 发送数据包 deploy.g_client.sendall(data)
def send_role_move(self): #发送角色的坐标给服务端 # 构建数据包 p = Protocol() p.add_int32(0) x = self.player.rect[0] y = self.player.rect[1] if x < 0: x = 0 if y <= 0: y = 0 p.add_int32(x) p.add_int32(y) data = p.get_pck_has_head() # 发送数据包 self.g_client.sendall(data)
def new_animation(self, trigger, charId): ani = Protocol() ani.add_int32(4) ani.add_int32(trigger) ani.add_int32(charId) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(ani.get_pck_has_head())
def new_mouse(self): p = Protocol() p.add_int32(3) p.add_int32(self.get_conn().mouseX) p.add_int32(self.get_conn().mouseY) p.add_int32(self.get_conn().charId) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(p.get_pck_has_head())
def move_role(self): # 告诉各个客户端有玩家移动了 ret = Protocol() ret.add_int32(0) ret.add_int32(self.get_conn().x) ret.add_int32(self.get_conn().y) ret.add_int32(self.get_conn().charId) for r in g_conn_pool: if r != self.get_conn(): r.conn.sendall(ret.get_pck_has_head())
def send_role_animation(self, trigger): #发送角色的动画状态给服务端 # 构建数据包 p = Protocol() p.add_int32(4) p.add_int32(trigger) p.add_int32(self.player.charId) data = p.get_pck_has_head() # 发送数据包 self.g_client.sendall(data)
def send_new_mouse(self): #发送角色的鼠标的位置 # 构建数据包 p = Protocol() p.add_int32(3) p.add_int32(self.player.mouseX) p.add_int32(self.player.mouseY) p.add_int32(self.player.charId) data = p.get_pck_has_head() # 发送数据包 self.g_client.sendall(data)
def send_new_role(self): #告诉服务端有新玩家加入 # 构建数据包 p = Protocol() p.add_int32(1) p.add_str(self.playerName) p.add_int32(self.player.rect[0]) p.add_int32(self.player.rect[1]) p.add_int32(self.player.charId) data = p.get_pck_has_head() # 发送数据包 self.g_client.sendall(data)