private static void StartConnect() { // reading the servers.ini for server configuration var ConfigFile = string.Format("{0}/{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data\\servers.ini"); // the config file's location. var Parser = new IniDocument(ConfigFile); Dictionary <string, Service> serviceList = new Dictionary <string, Service>(); foreach (DictionaryEntry de in Parser.Sections) { IniSection section = (IniSection)de.Value; Service s = new Service(); s.Name = de.Key.ToString(); s.IP = section.GetValue("ip"); s.Port = Convert.ToInt32(section.GetValue("port")); s.PasswordEncrypt = Convert.ToBoolean(section.GetValue("passwordencrypt")); serviceList.Add(de.Key.ToString(), s); } // if config.ini contains a valid server skip choosing a new one string service = Config.Server.Config.Instance.Name; if (string.IsNullOrEmpty(service) || !serviceList.ContainsKey(service)) { var selectedService = ConsoleHelper.GetConsoleMenu <Service>("Select your service", serviceList); _currentService = selectedService; Config.Server.Config.Instance.Name = selectedService.Name; Config.Server.Config.Instance.Save(); } else { _currentService = serviceList[service]; } // if config.ini contains a username skip asking for a new one string username = Config.Authentication.Config.Instance.Username; if (string.IsNullOrEmpty(username)) { username = ConsoleHelper.GetConsoleString("Please enter the username"); Config.Authentication.Config.Instance.Username = username; Config.Authentication.Config.Instance.Save(); } // if config.ini contains a password skip asking for a new one string password = Config.Authentication.Config.Instance.Password; if (string.IsNullOrEmpty(password)) { password = ConsoleHelper.GetConsoleString("Please enter the password"); Config.Authentication.Config.Instance.Password = password.Encrypt(PasswordEncryptionKey); Config.Authentication.Config.Instance.Save(); } else { // decrypting password password = password.Decrypt(PasswordEncryptionKey); } // creating login packet and enqueue so it will get sent once we are connected // might change this later to support password_encrypt from clientinfo.xml _packetQueue = new Queue <Net.Protocol.Methods.IMethodOut>(); _packetQueue.Enqueue(Net.Protocol.Methods.CA.Login.CreateBuilder() .SetVersion(20) .SetId(username.ToCharArray()) .SetPasswd(password.ToCharArray()) .SetClienttype(Static.ClientType.CLIENTTYPE_FRANCE) .Build()); // creating the buffer for the ragnarok packets _buffer = new Net.RoNetBuffer(); // start connection _connectThread = new Thread(Connect); _connectThread.Start(); }
private static void StartConnect() { // reading the servers.ini for server configuration var ConfigFile = string.Format("{0}/{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data\\servers.ini"); // the config file's location. var Parser = new IniDocument(ConfigFile); Dictionary<string, Service> serviceList = new Dictionary<string, Service>(); foreach (DictionaryEntry de in Parser.Sections) { IniSection section = (IniSection)de.Value; Service s = new Service(); s.Name = de.Key.ToString(); s.IP = section.GetValue("ip"); s.Port = Convert.ToInt32(section.GetValue("port")); s.PasswordEncrypt = Convert.ToBoolean(section.GetValue("passwordencrypt")); serviceList.Add(de.Key.ToString(), s); } // if config.ini contains a valid server skip choosing a new one string service = Config.Server.Config.Instance.Name; if (string.IsNullOrEmpty(service) || !serviceList.ContainsKey(service)) { var selectedService = ConsoleHelper.GetConsoleMenu<Service>("Select your service", serviceList); _currentService = selectedService; Config.Server.Config.Instance.Name = selectedService.Name; Config.Server.Config.Instance.Save(); } else { _currentService = serviceList[service]; } // if config.ini contains a username skip asking for a new one string username = Config.Authentication.Config.Instance.Username; if (string.IsNullOrEmpty(username)) { username = ConsoleHelper.GetConsoleString("Please enter the username"); Config.Authentication.Config.Instance.Username = username; Config.Authentication.Config.Instance.Save(); } // if config.ini contains a password skip asking for a new one string password = Config.Authentication.Config.Instance.Password; if (string.IsNullOrEmpty(password)) { password = ConsoleHelper.GetConsoleString("Please enter the password"); Config.Authentication.Config.Instance.Password = password.Encrypt(PasswordEncryptionKey); Config.Authentication.Config.Instance.Save(); } else { // decrypting password password = password.Decrypt(PasswordEncryptionKey); } // creating login packet and enqueue so it will get sent once we are connected // might change this later to support password_encrypt from clientinfo.xml _packetQueue = new Queue<Net.Protocol.Methods.IMethodOut>(); _packetQueue.Enqueue(Net.Protocol.Methods.CA.Login.CreateBuilder() .SetVersion(20) .SetId(username.ToCharArray()) .SetPasswd(password.ToCharArray()) .SetClienttype(Static.ClientType.CLIENTTYPE_FRANCE) .Build()); // creating the buffer for the ragnarok packets _buffer = new Net.RoNetBuffer(); // start connection _connectThread = new Thread(Connect); _connectThread.Start(); }