class ServerController(): """Controller class for the RTS server.""" def __init__(self): self.ip = str(ServerTools.get_local_ip()) Popen(["python", "rtsserver.py"]) try: self.connect_server() except: ServerTools.erbox("Erreur de connexion", "Le serveur n'a pas pu être rejoint.\n" + "Le gestionnaire de serveur va maintenant fermer.") else: self.gui = ServerView(self.server, ns) self.gui_update() self.gui.mainloop() def gui_update(self): self.gui.new_messages() self.gui.new_user() self.gui.after(50, self.gui_update) def connect_server(self): """Attempts to open a new server connection.""" uri = "PYRO:uri@" + self.ip + ":48280" self.server = Pyro4.Proxy(uri)
class Server(): """Dedicated server instance for **RTSTITLE**.""" def __init__(self): self.game_data = GameData() self.view = ServerView(self.game_data) self.server_ui_loop() self.view.mainloop() def server_ui_loop(self): self.view.new_messages() self.view.after(40, self.server_ui_loop) def create_server(self): """Creates a new server instance.""" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 0)) local_ip_address = s.getsockname()[0] self.deamon = Pyro4.Daemon(host=local_ip_address, port=47098) uri = self.deamon.register(self, "uri") self.deamon.requestLoop() def chat_message(self, name, message): self.game_data.append(str(name) + ": " + str(message)) def event_loop(self): pass def register(self, name): return self.game_data.register(name) def game_packets(self, name): return self.game_data.game_packets(name) def receive_info(self, actions): return self.game_data.receive_info(actions) def client_quit(self, name): pass