brigas-team team mailing list archive
-
brigas-team team
-
Mailing list archive
-
Message #00086
[Branch ~brigas-team/brigas/trunk] Rev 7: Terminados os seguintes métodos:
------------------------------------------------------------
revno: 7
committer: Diogo Dutra <dda@optimus>
branch nick: trunk
timestamp: Thu 2009-06-04 19:44:22 -0300
message:
Terminados os seguintes métodos:
GetUUID
GetAvailableGames
GetAvailableRooms
CreateRoom
O método EnterRoom está com erros
modified:
game-server/bin/simple_control_point
game-server/src/game_server_impl.py
game-server/src/services/game_manager.py
game-server/src/services/xmls/game-manager-scpd.xml
=== modified file 'game-server/bin/simple_control_point'
--- game-server/bin/simple_control_point 2009-06-04 00:23:02 +0000
+++ game-server/bin/simple_control_point 2009-06-04 22:44:22 +0000
@@ -9,7 +9,9 @@
from brisa.upnp.control_point import ControlPoint
from brisa.core.threaded_call import run_async_function
+from brisa_game_server.services.game_manager import service_type
+game_manager = service_type
devices = []
@@ -92,12 +94,13 @@
elif input == 'uuid':
device = devices[0]
- k, service = device.services.items()[1]
- print service.GetUUID()
+ service = device.services[game_manager]
+ uuid = service.GetUUID()['UUID']
+ print uuid
elif input == 'games':
device = devices[0]
- k, service = device.services.items()[1]
+ service = device.services[game_manager]
print service.GetAvailableGames()
elif input == 'rooms':
@@ -108,12 +111,12 @@
elif input == 'createroom':
device = devices[0]
k, service = device.services.items()[1]
- print service.CreateRoom(Game='Truco')
+ print service.CreateRoom(Game='Truco', UUID=uuid)
elif input == 'enterroom':
device = devices[0]
k, service = device.services.items()[1]
- print service.EnterRoom(Game='Truco', RoomID=0, UUID=0)
+ print service.EnterRoom(Game='Truco', RoomID=0, UUID=uuid)
elif input == 'help':
print 'Commands available: list, exit, ' \
=== modified file 'game-server/src/game_server_impl.py'
--- game-server/src/game_server_impl.py 2009-06-04 00:23:02 +0000
+++ game-server/src/game_server_impl.py 2009-06-04 22:44:22 +0000
@@ -13,6 +13,11 @@
import brisa_game_server
from brisa_game_server.services import GameManager
+class Game(object):
+ def __init__(self, serv):
+ self.service = serv
+ self.rooms = {}
+
class GameServerDevice(object):
games_folder = brisa_game_server.__path__[0] + "/games"
@@ -21,7 +26,7 @@
def __init__(self, server_name, listen_url):
self._server_name = server_name
self._listen_url = listen_url
- self.games = {}
+ self._games = {}
self.device = None
def _create_device(self):
@@ -46,8 +51,9 @@
try:
module_path = "%s.%s" % (self.games_module_path, dir)
__import__(module_path)
- self.games[eval("%s.service.id" % module_path)] = []
- self.device.add_service(eval("%s.service" % module_path))
+ service = eval("%s.service" % module_path)
+ self._games[service.id] = Game(service)
+ self.device.add_service(service)
except Exception, e:
msg = 'Error while importing %s game. The module '\
'path used to load was: %s. Error: %s' % \
@@ -56,7 +62,7 @@
def _add_services(self):
self._add_games()
- self.device.add_service(GameManager(self))
+ self.device.add_service(GameManager(self._games))
def start(self):
self._create_device()
=== modified file 'game-server/src/services/game_manager.py'
--- game-server/src/services/game_manager.py 2009-06-04 00:23:02 +0000
+++ game-server/src/services/game_manager.py 2009-06-04 22:44:22 +0000
@@ -1,6 +1,7 @@
import os
+from uuid import uuid4
from brisa.upnp.device.service import Service
@@ -11,43 +12,69 @@
scpd_xml_path = os.path.join(xml_path, 'game-manager-scpd.xml')
class GameManager(Service):
- def __init__(self, device):
+ def __init__(self, games):
Service.__init__(self, service_name, service_type, '', scpd_xml_path)
- self._device = device
+ self._games = games
self._players = []
+ self._rooms_counter = 0
+
+ def _check_uuid(self, uuid):
+ if uuid in self._players:
+ for game in self._games.values():
+ for room in game.rooms.values():
+ if uuid in room:
+ return False
+ return True
+ else:
+ return False
def soap_GetUUID(self, *args, **kwargs):
- self._players.append(str(len(self._players)))
- return {'UUID' : (len(self._players) - 1)}
+ uuid = str(uuid4())
+ for i in range(len(self._players)):
+ if self._players[i] == uuid:
+ uuid = str(uuid4())
+ i -= 1
+ self._players.append(uuid)
+ return {'UUID' : uuid}
def soap_GetAvailableGames(self, *args, **kwargs):
- games = ':'.join(self._device.games.keys())
+ games = ':'.join(self._games.keys())
return {'Games' : games}
def soap_GetAvailableRooms(self, *args, **kwargs):
try:
- game = self._device.games[kwargs['Game']]
- rooms = ':'.join([str(len(room)) for room in game])
- return {'Rooms' : rooms}
+ game = self._games[kwargs['Game']]
+ roomsID = ':'.join([str(room) for room in game.rooms.keys()])
+ roomsLen = ':'.join([str(len(room_len)) for room_len in game.rooms.values()])
+ return {'RoomsID' : roomsID, 'RoomsLen' : roomsLen}
except:
- return {'Rooms' : 'ERROR: Game does not exist'}
+ return {'RoomsID' : '-1', 'RoomsLen' : '-1'}
def soap_CreateRoom(self, *args, **kwargs):
- try:
- game = self._device.games[kwargs['Game']]
- game.append([])
- return {'RoomID' : (len(game) - 1)}
- except:
- return {'RoomID' : -2}
+ uuid = kwargs['UUID']
+ if self._check_uuid(uuid):
+ try:
+ game = self._games[kwargs['Game']]
+ game.rooms[self._rooms_counter] = [uuid]
+ self._rooms_counter += 1
+ return {'RoomID' : (self._rooms_counter - 1)}
+ except:
+ return {'RoomID' : -2}
+ else:
+ return {'RoomID' : -3}
def soap_EnterRoom(self, *args, **kwargs):
try:
- game = self._device.games[kwargs['Game']]
+ game = self._games[kwargs['Game']]
rid = int(kwargs['RoomID'])
uuid = kwargs['UUID']
- if self._players.count(uuid):
+ if self._check_uuid(uuid):
try:
- game[rid].append(uuid)
+ if len(game.rooms[rid]) == 3:
+ full = True
+ game.rooms[rid].append(uuid)
+ if full:
+ games.rooms.pop(rid)
return {'Return' : 1}
except:
return {'Return' : 0}
=== modified file 'game-server/src/services/xmls/game-manager-scpd.xml'
--- game-server/src/services/xmls/game-manager-scpd.xml 2009-06-04 00:23:02 +0000
+++ game-server/src/services/xmls/game-manager-scpd.xml 2009-06-04 22:44:22 +0000
@@ -34,9 +34,14 @@
<relatedStateVariable>A_ARG_TYPE_Game</relatedStateVariable>
</argument>
<argument>
- <name>Rooms</name>
- <direction>out</direction>
- <relatedStateVariable>A_ARG_TYPE_Rooms</relatedStateVariable>
+ <name>RoomsID</name>
+ <direction>out</direction>
+ <relatedStateVariable>A_ARG_TYPE_RoomsID</relatedStateVariable>
+ </argument>
+ <argument>
+ <name>RoomsLen</name>
+ <direction>out</direction>
+ <relatedStateVariable>A_ARG_TYPE_RoomsLen</relatedStateVariable>
</argument>
</argumentList>
</action>
@@ -44,6 +49,11 @@
<name>CreateRoom</name>
<argumentList>
<argument>
+ <name>UUID</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_UUID</relatedStateVariable>
+ </argument>
+ <argument>
<name>Game</name>
<direction>in</direction>
<relatedStateVariable>A_ARG_TYPE_Game</relatedStateVariable>
@@ -95,7 +105,11 @@
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
- <name>A_ARG_TYPE_Rooms</name>
+ <name>A_ARG_TYPE_RoomsID</name>
+ <dataType>string</dataType>
+ </stateVariable>
+ <stateVariable sendEvents="no">
+ <name>A_ARG_TYPE_RoomsLen</name>
<dataType>string</dataType>
</stateVariable>
<stateVariable sendEvents="no">
--
lp:brigas
https://code.launchpad.net/~brigas-team/brigas/trunk
Your team Brisa Game Server Team is subscribed to branch lp:brigas.
To unsubscribe from this branch go to https://code.launchpad.net/~brigas-team/brigas/trunk/+edit-subscription.