def OnRegister(self, event): if (self.text_connect_nameData.GetValue() == "" or self.text_connect_passwordData.GetValue() == ""): misc.CreateMessageBox(self, misc.MSGBOX_EMPTYPASSWORDFIELDS) username = self.text_connect_nameData.GetValue().split(" ") if len(username) > 1: misc.CreateMessageBox(self, MSGBOX_ERROR, "Usernames cannot contain spaces.") return False password = self.text_connect_passwordData.GetValue().split(" ") if len(password) > 1: misc.CreateMessageBox(self, MSGBOX_ERROR, "Passwords cannot contain spaces.") return False else: self.GetParent().connectToServer( True, self.text_connect_nameData.GetValue(), self.text_connect_passwordData.GetValue()) self.Close()
def joinBattle(self, index): battle = self.battleList[index] if battle == None: misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR, str(index)) if battle.passworded == True: #ask for the password using a dialog getpass = wx.TextEntryDialog(self.parent_window, "Password needed to join \"" + battle.name + "\":", "Enter password", "", wx.OK|wx.CANCEL) choice = getpass.ShowModal() if choice == wx.ID_OK: if getpass.GetValue() != "": password = getpass.GetValue() #config.Write("/Player/Name", self.client_username) getpass.Close(True) else: misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR, "Password entered is invalid.") getpass.Close(True) return None else: getpass.Close(True) return False self.parent_window.client.send("JOINBATTLE " + str(battle.server_id) + " " + password) else: self.parent_window.client.send("JOINBATTLE " + str(battle.server_id)) return True
def OnJoinClick(self, event): channel = self.text_channel_channel.GetValue() if channel != "": self.GetParent().client.send("JOIN", channel) self.Close(True) else: misc.CreateMessageBox(self, MSGBOX_EMPTYFIELDS)
def OnLogin(self, event): if (self.text_connect_nameData.GetValue() == "" or self.text_connect_passwordData.GetValue() == ""): misc.CreateMessageBox(self, MSGBOX_EMPTYPASSWORDFIELDS) elif self.text_connect_passwordData.GetValue() == "************": self.GetParent().connectToServer( False, self.text_connect_nameData.GetValue()) self.Close() else: self.GetParent().connectToServer( False, self.text_connect_nameData.GetValue(), self.text_connect_passwordData.GetValue()) self.Close()
def joinBattle(self, index): battle = self.battleList[index] #make sure we are in the right directory! ======= config = wx.Config().Get() cwd = os.getcwd() if os.path.exists(config.Read("/Spring/DataDirectory")): map_path = os.path.join(config.Read("/Spring/DataDirectory"), 'maps/') # HACK need to fix this os.chdir(config.Read("/Spring/DataDirectory")) #================================================ if battle == None: misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR, str(index)) password = "" mod_passed = False map_passed = False #Check for password if battle.passworded == True: #ask for the password using a dialog getpass = wx.TextEntryDialog( self.parent_window, "Password needed to join \"" + battle.name + "\":", "Enter password", "", wx.OK | wx.CANCEL) choice = getpass.ShowModal() if choice == wx.ID_OK: if getpass.GetValue() != "": password = getpass.GetValue() #config.Write("/Player/Name", self.client_username) getpass.Close(True) else: misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR, "Password entered is invalid.") getpass.Close(True) return None else: getpass.Close(True) return False #Check for mod availability mod = str(battle.modName) unitsync.Init(False, 0) unitsync.InitArchiveScanner() count = unitsync.GetPrimaryModCount() modList = [] fileList = [] selection = False for i in range(0, count): modname = unitsync.GetPrimaryModName(i) if modname == mod: mod_passed = True if mod_passed == False: misc.CreateMessageBox( self.parent_window, MSGBOX_ERROR, "You do not have the correct mod to join this battle.\nMod \'" + mod + "\' not found.") unitsync.UnInit() os.chdir(cwd) return False #Check for map availability map = str(battle.mapName) count = unitsync.GetMapCount() mapList = [] for i in range(0, count): mapname = unitsync.GetMapName(i) if mapname == map: map_passed = True if map_passed == False: misc.CreateMessageBox( self.parent_window, MSGBOX_ERROR, "You do not have the correct map to join this battle.\nMap \'" + mod + "\' not found.") unitsync.UnInit() os.chdir(cwd) return False #uninit unitsync and change to the old cwd unitsync.UnInit() os.chdir(cwd) if password != "": self.parent_window.client.send("JOINBATTLE " + str(battle.server_id) + " " + password) else: self.parent_window.client.send("JOINBATTLE " + str(battle.server_id)) return True
def __init__(self, parent, username="", password=""): # Initialize variables config = wx.Config().Get() self.server_address = str(config.Read("/Global/SpringServer")) self.server_port = config.ReadInt("/Global/SpringServerPort") self.client_messageQueue = Queue.Queue() self.client_sendQueue = Queue.Queue() self.client_pingTimer = pingTimer() self.client_pingTimer.UpdateClient(self) self.client_recvTimer = recvTimer() self.client_recvTimer.UpdateClient(self) self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.parent_window = parent self.client_localIP = "*" #Get the correct username from the right place if not config.Read("/Player/Name") == "" and username == "": self.client_username = config.Read("/Player/Name") elif not username == "": self.client_username = username.rstrip("\n") else: #Cant find the username anywhere, Finally just ask for it using a dialog getuser = wx.TextEntryDialog( parent, "Enter your username to connect to " + self.server_address + ":", "Enter username", "", wx.OK | wx.CANCEL) choice = getuser.ShowModal() if choice == wx.ID_OK: if getuser.GetValue() != "": self.client_username = getuser.GetValue().rstrip("\n") #config.Write("/Player/Name", self.client_username) getuser.Close(True) else: misc.CreateMessageBox( parent, MSGBOX_ERROR, "Username entered is invalid.\nYou will be unable to join the server without a username." ) getuser.Close(True) return None else: getuser.Close(True) return None #Get the correct password from the right place u = md5.new(password).digest() encoded_pass = base64.encodestring(u) if password != "": self.client_password = encoded_pass.rstrip("\n") elif config.ReadBool("/Player/RememberPass") == True and config.Read( "/Player/Password") != "": self.client_password = config.Read("/Player/Password") else: #Cant find the password anywhere, Finally just ask for it using a dialog getpass = wx.TextEntryDialog( parent, "Enter your password to connect to " + self.server_address + "\nwith username '" + self.client_username + "':", "Enter password", "", wx.OK | wx.CANCEL | wx.TE_PASSWORD) choice = getpass.ShowModal() if choice == wx.ID_OK: if not getpass.GetValue() == "": u = md5.new(getpass.GetValue()).digest() encoded_dialog_pass = base64.encodestring(u) self.client_password = encoded_dialog_pass.rstrip("\n") getpass.Close(True) else: misc.CreateMessageBox( parent, MSGBOX_ERROR, "Password entered is invalid.\nYou will be unable to join the server without a valid password." ) getpass.Close(True) return None else: getpass.Close(True) return None
def output(self, msg, priority, target=0): config = wx.Config().Get() if target == 0: chat_area = self.parent_window.tabManager.GetCurrentChatArea() elif target == -1: chat_area = self.parent_window.battleroom.text_battleroom_players_chatarea else: chat_area = self.parent_window.tabManager.GetCurrentChatArea( target) if chat_area == None: return False if priority == DEBUG_ERROR: chat_area.SetDefaultStyle(wx.TextAttr(self.color_error_text)) elif priority == ERROR_MSG: chat_area.SetDefaultStyle(wx.TextAttr(self.color_error_text)) elif priority == DEBUG_MESSAGE: chat_area.SetDefaultStyle(wx.TextAttr(self.color_debug_text)) elif priority == SERVER_HIGH: chat_area.SetDefaultStyle(wx.TextAttr(self.color_server_text)) elif priority == SERVER_OTHER: chat_area.SetDefaultStyle(wx.TextAttr(self.color_server_text)) elif priority == CHANNEL_MSG: chat_area.SetDefaultStyle(wx.TextAttr(self.color_channel_text)) elif priority == USER_MSG: chat_area.SetDefaultStyle(wx.TextAttr(self.color_user_text)) elif priority == PRIVATE_MSG: chat_area.SetDefaultStyle(wx.TextAttr(self.color_private_text)) elif priority == OTHER_MSG: chat_area.SetDefaultStyle(wx.TextAttr(self.color_channel_text)) if msg.find("^") != -1: msg_parsed = msg.split("^") increment = 1 if msg_parsed[0] != "": if priority == DEBUG_ERROR: chat_area.AppendText(msg_parsed[0]) print(msg) elif priority == ERROR_MSG: chat_area.AppendText(msg_parsed[0]) elif priority == DEBUG_MESSAGE: if config.ReadBool("/Global/ShowDebug") == True: chat_area.AppendText(msg_parsed[0]) print(msg) else: print(msg) elif priority == SERVER_HIGH: chat_area.AppendText(msg_parsed[0]) print(msg) elif priority == SERVER_OTHER: chat_area.AppendText(msg_parsed[0]) elif priority == SERVER_USELESS: if config.ReadBool("/Global/ShowDebug") == True: print(msg) return True elif priority == DEBUG_USELESS: if config.ReadBool("/Global/ShowDebug") == True: print(msg) return True elif priority == CHANNEL_MSG: chat_area.AppendText(msg_parsed[0]) elif priority == USER_MSG: chat_area.AppendText(msg_parsed[0]) elif priority == PRIVATE_MSG: chat_area.AppendText(msg_parsed[0]) elif priority == OTHER_MSG: chat_area.AppendText(msg_parsed[0]) while len(msg_parsed) > increment: tmp_str = msg_parsed[increment] noColor = False if tmp_str != "": if tmp_str[0] == str(COLOR_MACRO_CHANNEL): chat_area.SetDefaultStyle( wx.TextAttr(self.color_channel_text)) elif tmp_str[0] == str(COLOR_MACRO_USER): chat_area.SetDefaultStyle( wx.TextAttr(self.color_user_text)) elif tmp_str[0] == str(COLOR_MACRO_PRIVATE): chat_area.SetDefaultStyle( wx.TextAttr(self.color_private_text)) elif tmp_str[0] == str(COLOR_MACRO_SERVER): chat_area.SetDefaultStyle( wx.TextAttr(self.color_server_text)) elif tmp_str[0] == str(COLOR_MACRO_ERROR): chat_area.SetDefaultStyle( wx.TextAttr(self.color_error_text)) elif tmp_str[0] == str(COLOR_MACRO_DEBUG): chat_area.SetDefaultStyle( wx.TextAttr(self.color_debug_text)) elif tmp_str[0] == str(COLOR_MACRO_RED): chat_area.SetDefaultStyle( wx.TextAttr(self.color_red_text)) elif tmp_str[0] == str(COLOR_MACRO_ORANGE): chat_area.SetDefaultStyle( wx.TextAttr(self.color_orange_text)) elif tmp_str[0] == str(COLOR_MACRO_BLUE): chat_area.SetDefaultStyle( wx.TextAttr(self.color_blue_text)) elif tmp_str[0] == str(COLOR_MACRO_GREEN): chat_area.SetDefaultStyle( wx.TextAttr(self.color_green_text)) else: tmp_str = "^" + tmp_str noColor = True if len(msg_parsed) == increment + 1: if noColor == False: chat_area.AppendText(tmp_str[1:] + "\n") else: chat_area.AppendText(tmp_str + "\n") else: if noColor == False: chat_area.AppendText(tmp_str[1:]) else: chat_area.AppendText(tmp_str) else: tmp_str = "^" + tmp_str noColor = True if len(msg_parsed) == increment + 1: chat_area.AppendText(tmp_str + "\n") else: chat_area.AppendText(tmp_str) increment += 1 else: if priority == DEBUG_CRITICAL: misc.CreateMessageBox(self.parent_window, MSGBOX_CRITICAL_ERROR, str(msg)) print(msg) elif priority == DEBUG_ERROR: chat_area.AppendText(msg + "\n") print(msg) elif priority == ERROR_MSG: chat_area.AppendText(msg + "\n") elif priority == DEBUG_MESSAGE: if config.ReadBool("/Global/ShowDebug") == True: chat_area.AppendText(msg + "\n") print(msg) else: print(msg) elif priority == DEBUG_USELESS: if config.ReadBool("/Global/ShowDebug") == True: print(msg) elif priority == SERVER_HIGH: chat_area.AppendText(msg + "\n") print(msg) elif priority == SERVER_LOW: print(msg) elif priority == SERVER_OTHER: chat_area.AppendText(msg + "\n") elif priority == SERVER_USELESS: if config.ReadBool("/Global/ShowDebug") == True: print(msg) elif priority == CHANNEL_MSG: chat_area.AppendText(msg + "\n") elif priority == USER_MSG: chat_area.AppendText(msg + "\n") elif priority == PRIVATE_MSG: chat_area.AppendText(msg + "\n") elif priority == OTHER_MSG: chat_area.AppendText(msg + "\n")