def login_thread(self, socket_obj, con_addr): socket_obj.settimeout(None) # 先出于等待登录状态 while True: cmd, vals = recv_cmd(socket_obj, decode=True) if cmd == 'Login': try: user_name = vals['Username'] password = vals['Password'] passed, login_info = self.check_login(user_name, password) except KeyError: logger.error('server.login', 'Login指令中缺少 username 和 password 项!') continue send_cmd(socket_obj, command='Login', LoginStateCode=1 if passed else 0, LoginMessage=login_info, ID=id) if passed: logger.info('server.login', 'sending gamer info...') self.add_gamer(socket_obj, con_addr, user_name) # todo: 修改为Gamer实现 self.sendGamerInfo() return # 玩家主动或者被动放弃登录 elif cmd == 'ExitLogin': return
def immediate_send_all_points(self): self.BufferLock.acquire(True) points = [] for x, y in self.PointBuffer: points.append((x, y)) # points[str(i)] = str(x_) + ' ' + str(y_) # send_cmd(self.Socket, 'PaintPoint', points=points) send_cmd(self.Socket, **make_paint_point_command(points)) self.PointBuffer.clear() self.BufferLock.release()
def send_cmd(self, command, **kwargs): send_cmd(self.Socket, command, **kwargs)
def send_all_cmd(self, command, **kwargs): for s_ in self.UsrSocket: send_cmd(s_, command, **kwargs)
def send_cmd(self, i, command, **kwargs): logger.debug('server.send_cmd', 'send cmd: {}, vals: {}'.format(command, kwargs)) send_cmd(self.UsrSocket[i], command, **kwargs)
def send_cmd(self, command, **kwargs): logger.debug('client.engine', 'send cmd: {}, {}'.format(command, kwargs)) send_cmd(self.Socket, command, **kwargs)