Пример #1
0
 def HandleMsg(cls, **kwargs):
     room = cls.FindRoom(kwargs['roomID'])
     player = PlayerPool.Get(kwargs['selfID'])
     if kwargs['inner_msg_type'] == 0x3003: # Move
         player.game_status.Move(kwargs['new_x'], kwargs['new_y'], kwargs['new_z'])
         room.BroadcastRoom("PlayerMove", kwargs)
     elif kwargs['inner_msg_type'] == 0x3004: # Shoot
         player.game_status.Shoot(kwargs['bullets'])
         resp = kwargs.copy()
         resp['bullets'] = player.game_status.gun_bullet
         player.Send("PlayerShoot", resp)
         if kwargs['playerID'] > 0:
             hurtPlayer = PlayerPool.Get(kwargs['playerID'])
             if hurtPlayer.game_status.health == 0: return
             hurtPlayer.game_status.Demage(kwargs['hurt'])
             hurtPlayer.Send("PlayerHurt",{
                 'msg_type': kwargs['msg_type'],
                 'frameID': kwargs['frameID'],
                 'selfID': hurtPlayer.user_id,
                 'roomID': kwargs['roomID'],
                 'inner_msg_len': 8,
                 'inner_msg_type': 0x3005,
                 'hp': hurtPlayer.game_status.health
             })
             if hurtPlayer.game_status.health == 0:
                 player.game_status.score += 1
                 room.BroadcastRoom("PlayerScore",{
                     'msg_type': kwargs['msg_type'],
                     'frameID': kwargs['frameID'],
                     'selfID': 0,
                     'roomID': kwargs['roomID'],
                     'inner_msg_len': 4*6 + len(player.name) + len(hurtPlayer.name),
                     'inner_msg_type': 0x3006,
                     'score': player.game_status.score,
                     'killer': player.user_id,
                     'dead': hurtPlayer.user_id,
                     'killer_len': len(player.name),
                     'dead_len': len(hurtPlayer.name),
                     'killer_name': player.name,
                     'dead_name': hurtPlayer.name
                 })
     elif kwargs['inner_msg_type'] == 0x3007: # Reload
         player = PlayerPool.Get(kwargs['selfID'])
         player.game_status.Reload()
         player.Send("PlayerReload", {
             'msg_type': kwargs['msg_type'],
             'frameID': kwargs['frameID'],
             'selfID': kwargs['selfID'],
             'roomID': kwargs['roomID'],
             'inner_msg_len': 12,
             'inner_msg_type': 0x3007,
             'gun': player.game_status.gun_bullet,
             'bag': player.game_status.bag_bullet
         })
     elif kwargs['inner_msg_type'] == 0x3008: # Jump
         room = cls.FindRoom(kwargs['roomID'])
         room.BroadcastRoom("PlayerJump", kwargs)
Пример #2
0
 def handle(cls, msg, broker):
     (func, resp_type) = cls.router[msg.__class__.__name__]
     resp_dict = func(**msg.data)
     if resp_type == '': return None
     elif resp_type == 'Login' and resp_dict['resp_code'] > 0:
         player = PlayerPool.Get(resp_dict['resp_code'])
         if player:
             player.Renew(broker)
         else:
             PlayerPool.NewPlayer(resp_dict['resp_code'], broker,
                                  msg.data['name'])
     return Message.response(resp_type, resp_dict)
Пример #3
0
 def JoinRoom(cls, user_id, room_id):
     player = PlayerPool.Get(user_id)
     room = cls.FindRoom(room_id)
     if not room:
         return {'resp_type': 0x5004, 'room_id': -1, 'max_num': 0}
     room_id = room.JoinRoom(player)
     return {'resp_type': 0x5004, 'room_id': room_id, 'max_num': room.max_num}
Пример #4
0
 def login(cls, name, pwd, **kwargs):
     user = fetch_user_by_name(name)
     if not user:
         return {'resp_type': 0x5001, 'resp_code': -2}
     user = dict(zip(['id', 'name', 'password'], user))
     if user['password'] != pwd:
         return {'resp_type': 0x5001, 'resp_code': -1}
     player = PlayerPool.Get(user['id'])
     if not player:
         return {'resp_type': 0x5001, 'resp_code': user['id']}
     if player.broker.active:
         return {'resp_type': 0x5001, 'resp_code': -3}
     gameStatus = player.game_status
     if gameStatus.gaming == False:
         return {'resp_type': 0x5001, 'resp_code': user['id']}
     ret = {
         'resp_type': 0x5005,
         'resp_code': user['id'],
         'room_id': player.room.room_id,
         'pos_x': gameStatus.position[0],
         'pos_y': gameStatus.position[1],
         'pos_z': gameStatus.position[2],
         'hp': gameStatus.health,
         'gun': gameStatus.gun_bullet,
         'bag': gameStatus.bag_bullet,
         'score': gameStatus.score
     }
     player.Reconnect(ret)
     return {'resp_type': 0x5001, 'resp_code': user['id']}
Пример #5
0
 def CreateRoom(cls, user_id, max_num):
     player = PlayerPool.Get(user_id)
     with threading.Lock():
         room_id = 1000 + len(cls.rooms)
         room = Room(room_id, player, max_num)
         cls.rooms[room_id] = room
         player.room = room
     return {'resp_type': 0x5003, 'room_id': room_id, 'max_num': room.max_num}
Пример #6
0
 def ExitRoom(cls, user_id, room_id):
     player = PlayerPool.Get(user_id)
     room = cls.FindRoom(room_id)
     room.LeaveRoom(player)
Пример #7
0
 def check_online(cls, user_id):
     player = PlayerPool.Get(user_id)
     if player and player.broker.active:
         return True
     return False