Skip to content

Commit 52e47c9

Browse files
committed
Client/Server: permitir criacao e entrada em gamelobby
Mudar o protocolo para informar o tipo de jogo Isso ainda ta errado: a mensagem action:lobby_game_created nao informa o mesmo que action:lobby_info na lista de jogos Agora eh possivel enviar chat no lobby principal e no lobby do jogo
1 parent 5d50864 commit 52e47c9

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

client/client_connection.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ def message_sender(self, msg):
118118
""" Oversees message sendings for important events """
119119

120120
if msg.__class__ == dict:
121-
if 'action' in msg and msg[u'action'] == 'lobby_create_game':
122-
#TODO do the same with 'lobby_join_game', but this requires
123-
#gametype info in self.rooms
121+
if msg[u'action'] in ('lobby_create_game', 'lobby_join_game'):
122+
if msg[u'action'] == 'lobby_create_game':
123+
gametype = msg[u'game_type']
124+
else:
125+
rooms = self.lh.rooms
126+
for r in rooms:
127+
if r['game_id'] == msg[u'room_id']:
128+
gametype = r['game_type']
129+
124130
self.gamehandler = games.GAMETYPE_TO_GAMEHANDLER[
125-
msg[u'game_type']
131+
gametype
126132
](msg_sender=self.message_sender, ui=self.ui)
127133

128134
self.write(self.message_handler.to_string(msg))

server/lobby.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def handle_create_game(self, session, message):
5050
logging.info("Session {0} is trying to create a game of type {1} and room name of {2}".format(session.username , message['game_type'], message['room_name']))
5151
game_lobby = self.game_builders[message['game_type']].build_lobby(main_lobby=self, room_owner=session, room_configuration= message, game_id=game_id)
5252

53-
self.games[game_id] = { 'game_name' : message['room_name'], 'game_lobby' : game_lobby }
53+
self.games[game_id] = { 'game_name' : message['room_name'], 'game_type': message['game_type'], 'game_lobby' : game_lobby }
5454

5555
logging.info("Created sucessfully")
5656

@@ -101,7 +101,11 @@ def handle_chat(self, session, message):
101101

102102
def get_rooms(self):
103103
logging.debug("Getting rooms")
104-
return [ { 'game_name' : self.games[room_id]['game_name'], 'game_id' : room_id } for room_id in self.games ]
104+
return [
105+
{ 'game_name' : self.games[room_id]['game_name'],
106+
'game_type' : self.games[room_id]['game_type'],
107+
'game_id' : room_id }
108+
for room_id in self.games ]
105109

106110
def get_users(self):
107111
logging.debug("Getting users")

0 commit comments

Comments
 (0)