1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
4 # This file is part of OpenAnno.
6 # OpenAnno is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
23 from game
.util
.color
import Color
24 from game
.network
import MPPlayer
, ClientConnection
, ServerConnection
25 from game
.packets
import *
28 # FIXME: update the values by using widget.capture, not by polling
30 class ServerLobby(object):
31 """Manages the data for the serverlobby
33 Data includes information about players, map, etc.
34 Infos about the player that plays on this machine
35 (local_player) are also stored here
39 def __init__(self
, gui
):
42 game
.main
.ext_scheduler
.add_new_object(self
._update
_gui
, self
, self
.guiUpdateInterval
, -1)
43 #game.main.fife.pump.append(self._update_gui)
46 game
.main
.ext_scheduler
.rem_all_classinst_calls(self
)
47 #game.main.fife.pump.remove(self._update_gui)
49 def _update_gui(self
):
50 """ Updates elements that are common for every lobby and
51 calls lobbyspecific update
55 o
= game
.main
.connection
.mpoptions
57 self
.gui
.distributeInitialData({
58 'playerlist' : o
['players'],
61 if len(o
['players']) > 0: # just display colors when playerlist is received
62 self
.gui
.distributeInitialData({
63 # display colors that are not taken by a player
64 'playercolors' : [ i
.name
for i
in Color
if i
not in [ j
.color
for j
in o
['players'] if j
.color
!= None ] ]
67 if not o
['bots'] is None:
68 self
.gui
.distributeData({'bots' : o
['bots']})
70 class MasterServerLobby(ServerLobby
):
71 """Serverlobby from the view of the game server
73 This class has the privileges to change important game settings
75 def __init__(self
,gui
):
76 super(MasterServerLobby
, self
).__init
__(gui
)
77 o
= game
.main
.connection
.mpoptions
78 o
['maps'] = game
.main
.getMaps(showOnlySaved
= False)
80 self
.gui
.distributeInitialData({
81 'server_slots' : range(2,9),
82 'maplist' : o
['maps'][1],
85 self
.gui
.distributeData({
86 'server_slots' : 2, # 2 means 4 slots
89 o
['players'].append(game
.main
.connection
.local_player
)
92 o
= game
.main
.connection
.mpoptions
93 o
['slots'] = self
.gui
.collectData('server_slots')+2
95 game
.main
.connection
.local_player
.name
= self
.gui
.collectData('playername')
96 game
.main
.connection
.local_player
.color
= Color
[self
.gui
.collectData('playercolor')+1]
97 o
['bots'] = self
.gui
.collectData('bots')
99 # sanity check for bot count
100 if o
['bots'] > (o
['slots'] - len(o
['players'])):
101 o
['bots'] = o
['slots'] - len(o
['players'])
103 o
['selected_map'] = self
.gui
.collectData('maplist')
105 self
.gui
.distributeInitialData({
106 'bots' : range(0, o
['slots'] - len(o
['players'])+1) # +1 cause to upper limit isn't included
108 self
.gui
.distributeData({
112 class ClientServerLobby(ServerLobby
):
113 """Serverlobby from the view of a client
115 def __init__(self
, gui
):
116 super(ClientServerLobby
, self
).__init
__(gui
)
118 def update_gui(self
):
119 o
= game
.main
.connection
.mpoptions
120 self
.gui
.distributeInitialData({
121 'bots' : [] if o
['bots'] is None else [o
['bots']],
122 'server_slots' : [] if o
['slots'] is None else [o
['slots']],
123 'maplist' : [] if len(o
['maps']) is 0 else o
['maps'][1]
126 self
.gui
.distributeData({
129 'maplist' : o
['selected_map']
132 newName
= self
.gui
.collectData('playername')
133 newColor
= Color
[self
.gui
.collectData('playercolor')+1]
135 if game
.main
.connection
.local_player
.name
!= newName
or \
136 game
.main
.connection
.local_player
.color
!= newColor
:
137 game
.main
.connection
.local_player
.name
= newName
138 game
.main
.connection
.local_player
.color
= newColor
139 game
.main
.connection
.sendToServer(LobbyPlayerModifiedPacket(None, None, game
.main
.connection
.local_player
))