2 # -*- coding: utf-8 -*-
4 GalTacK Proxy - No need to leave a game when restarting the client.
6 # Copyright (C) 2007 Michael Carter
7 # Copyright (C) 2007 Felix Rabe <public@felixrabe.textdriven.com>
9 # Permission is hereby granted, free of charge, to any person obtaining a
10 # copy of this software and associated documentation files (the
11 # "Software"), to deal in the Software without restriction, including
12 # without limitation the rights to use, copy, modify, merge, publish,
13 # distribute, sublicense, and/or sell copies of the Software, and to permit
14 # persons to whom the Software is furnished to do so, subject to the
15 # following conditions:
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
25 # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
26 # THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # Recommended line length or text width: 75 characters.
30 from galtack_client
import *
33 class GaltackProxyClient( # to the server
34 galtack
.net
.GaltackClientRecvCmdLoggerMixin
,
35 galtack
.net
.GaltackClientSendCmdLoggerMixin
,
36 galtack
.net
.GaltackClientUniverseTrackerMixin
,
37 galtack
.net
.GaltackClientHousekeeperMixin
,
38 galtack
.net
.GaltackClientBase
,
42 class GaltackServerHousekeeperMixin(
43 galtack
.net
.GaltackClientAckExpectingMixin
,
44 galtack
.net
.GaltackClientPingSenderMixin
,
45 galtack
.net
.GaltackClientAckSenderMixin
,
46 galtack
.net
.GaltackClientSendCmdBaseMixin
,
49 GaltackServer that interacts properly with a Galcon server.
51 It takes the responsibility for setting up and shutting down the
54 It (implicitly) defines an imaginary server-side command name
55 "[CLOSE]-[ACK]" to which callbacks with the following signature may be
57 def callback() # *no* argument
58 It gets called whenever a logout could be completed successfully.
60 Alternatively, you may connect to the deferred returned by logout(),
61 which receives None as an argument.
64 class LogoutAborted(Exception): pass
66 def __init__(self
, *a
, **kw
):
67 super(GaltackServerHousekeeperMixin
, self
).__init
__(*a
, **kw
)
68 self
.register_command_callback("version", self
.__cmd
_version
)
69 self
.register_command_callback("logout", self
.__cmd
_logout
)
70 self
.__logout
_deferred
= None
72 def startProtocol(self
):
75 def __cmd_version(self
, command
):
76 self
.send_commands((1, "version", command
[3]))
78 def __cmd_logout(self
, command
):
79 self
.send_commands((1, "[CLOSE]", command
[3]))
83 class GaltackProxyServer( # to the client
84 GaltackServerHousekeeperMixin
,
88 class GaltackProxyWindow(WindowF12RawConsoleMixin
):
90 GalTacK Proxy control.
93 def __init__(self
, *a
, **kw
):
94 super(GaltackProxyWindow
, self
).__init
__()
95 self
.set_title("GalTacK Proxy")
97 (outer
, inner
) = gnome_hig(self
)
98 table
= gnome_hig(inner(Table(), False, False))
103 table
.attach_cell(LeftLabel("Listening Port:"), **xo
)
104 self
.__port
_entry
= table
.attach_cell(Entry())
107 self
.__listen
_button
= table
.attach_row(Button("Listen"))
108 self
.__listen
_button
.connect("clicked", self
.__cb
_listen
_clicked
)
111 self
.galtack_client
= C(self
.__options
,
112 self
.__user
_info
, self
.__server
_info
)
114 def __cb_listen_clicked(self
, button
):
118 class GaltackServerListWindow(GaltackServerListWindow
):
120 Window displaying the list of Galcon servers.
123 def __init__(self
, *a
, **kw
):
124 super(GaltackServerListWindow
, self
).__init
__(*a
, **kw
)
125 self
.set_title("Galcon Server List - GalTacK Proxy")
127 def join_with_server_info(self
, server_info
):
128 chat_window
= GaltackProxyWindow(self
.__options
,
129 self
.__user
_info
, server_info
)
130 gobject
.idle_add(self
.hide
)
133 class GaltackLoginWindow(GaltackLoginWindow
):
135 NEXT_CLASS
= GaltackServerListWindow
137 def __init__(self
, *a
, **kw
):
138 super(GaltackLoginWindow
, self
).__init
__(*a
, **kw
)
139 self
.set_title("GalTacK Proxy Login")
143 option_parser
= optparse
.OptionParser(prog
= "GalTacK Proxy",
144 version
= "%%prog %s" %
146 option_parser
= GaltackLoginWindow
._modify
_option
_parser
(option_parser
)
147 option_parser
= GaltackClient
._modify
_option
_parser
(option_parser
)
148 options
, arguments
= option_parser
.parse_args(argv
[1:])
149 GaltackLoginWindow
._instance
= GaltackLoginWindow(options
)
153 if __name__
== "__main__":
155 sys
.exit(main(sys
.argv
))