summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-06-08 04:49:37 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-06-08 04:59:14 +0100
commitabd360d9fd6dc1a77cd38c213bc9532d85973ca0 (patch)
treee873599c621e31829fd942982dfda2780258a9a7
parent9d7f0754ff9db1645635647f4acd63aa38c173c5 (diff)
the server now handles the language properly
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--CAO_Cards.py4
-rw-r--r--CAO_Client.py10
-rw-r--r--CAO_GameManager.py28
-rwxr-xr-xserver.py3
4 files changed, 34 insertions, 11 deletions
diff --git a/CAO_Cards.py b/CAO_Cards.py
index 537abe7..1feecef 100644
--- a/CAO_Cards.py
+++ b/CAO_Cards.py
@@ -1,12 +1,12 @@
class CAO_Cards():
@staticmethod
- def get_white_cards(lang='en'):
+ def get_white_cards(lang):
''' Read the file containing the white cards and return a list of cards '''
with open('lang/' + lang + '/cards/white') as fd:
return [line.strip() for line in fd]
@staticmethod
- def get_black_cards(lang='en'):
+ def get_black_cards(lang):
''' Read the file containing the black cards and return a list of cards '''
with open('lang/' + lang + '/cards/black') as fd:
diff --git a/CAO_Client.py b/CAO_Client.py
index bdcc000..c3554ac 100644
--- a/CAO_Client.py
+++ b/CAO_Client.py
@@ -10,13 +10,19 @@ class CAO_Client():
self.socket = socket
self.player = None
- def join_game(self, game_name):
+ def join_game(self, game_name, lang):
if self.game is not None:
return cao_error('You are already in a game')
- game = self.game_manager.join_game(game_name)
+ if lang is None:
+ lang = 'en'
+
+ game = self.game_manager.join_game(game_name, lang)
# XXX self.game will be assigned by game.try_join()
+ if game is None:
+ return cao_error('Invalid language')
+
return game.try_join(self)
def set_game(self, game):
diff --git a/CAO_GameManager.py b/CAO_GameManager.py
index a3a12e5..8c01547 100644
--- a/CAO_GameManager.py
+++ b/CAO_GameManager.py
@@ -1,18 +1,34 @@
from CAO_Game import CAO_Game
from CAO_Cards import CAO_Cards
+import os
+
class CAO_GameManager():
def __init__(self):
- self.games = {}
+ self.langs = {}
+
+ for filename in next(os.walk('lang'))[1]:
+ self.langs[filename] = {}
+
+ for lang in self.langs:
+ self.langs[lang]['black_cards'] = CAO_Cards.get_black_cards(lang)
+ self.langs[lang]['white_cards'] = CAO_Cards.get_white_cards(lang)
- self.black_cards = CAO_Cards.get_black_cards()
- self.white_cards = CAO_Cards.get_white_cards()
+ self.langs[lang]['games'] = {}
- def join_game(self, game_name):
- game = self.games.get(game_name)
+ def join_game(self, game_name, lang):
+ if self.langs.get(lang) is None:
+ return None
+
+ games = self.langs[lang]['games']
+ black_cards = self.langs[lang]['black_cards']
+ white_cards = self.langs[lang]['white_cards']
+
+ game = games.get(game_name)
if game is None:
print('Starting new game')
- game = self.games[game_name] = CAO_Game(self.white_cards, self.black_cards)
+
+ game = games[game_name] = CAO_Game(white_cards, black_cards)
return game
diff --git a/server.py b/server.py
index 80cc153..7391e8e 100755
--- a/server.py
+++ b/server.py
@@ -28,7 +28,8 @@ def message_received_handler(client, server, message):
except KeyError:
res = cao_error('field `game_name\' is required')
else:
- res = client['cao_client'].join_game(game_name)
+ lang = json_msg.get('lang')
+ res = client['cao_client'].join_game(game_name, lang)
elif op == 'view_player_cards':
res = client['cao_client'].view_player_cards()
elif op == 'view_black_card':