/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="loginKey"> /// </param> /// <returns> /// </returns> public bool IsLoginCorrect(Client client, string loginKey) { var le = new LoginEncryption(); this.lp.GetLoginPassword(client.AccountName); return le.IsValidLogin(loginKey, client.ServerSalt, client.AccountName, this.lp.PasswdL); }
/// <summary> /// </summary> /// <param name="client"> /// </param> /// <param name="characterId"> /// </param> /// <returns> /// </returns> public bool IsCharacterOnAccount(Client client, int characterId) { var le = new LoginEncryption(); return le.IsCharacterOnAccount(client.AccountName, (UInt32)characterId); }
private static void Main(string[] args) { #region Console Texts... Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion + " " + AssemblyInfoclass.Trademark; ConsoleText ct = new ConsoleText(); ct.TextRead("main.txt"); Console.WriteLine("Loading " + AssemblyInfoclass.Title + "..."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[OK]"); Console.ResetColor(); #endregion //Sying helped figure all this code out, about 5 yearts ago! :P bool processedargs = false; loginLoginServer = new LoginServer(); loginLoginServer.EnableTCP = true; loginLoginServer.EnableUDP = false; try { loginLoginServer.TcpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP); } catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; } loginLoginServer.TcpPort = Convert.ToInt32(Config.Instance.CurrentConfig.LoginPort); #region NLog LoggingConfiguration config = new LoggingConfiguration(); ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget(); consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; FileTarget fileTarget = new FileTarget(); config.AddTarget("file", fileTarget); fileTarget.FileName = "${basedir}/LoginEngineLog.txt"; fileTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}"; LoggingRule rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget); config.LoggingRules.Add(rule1); LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget); config.LoggingRules.Add(rule2); LogManager.Configuration = config; #endregion #region NBug SettingsOverride.LoadCustomSettings("NBug.LoginEngine.Config"); NBug.Settings.WriteLogToDisk = true; AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException; TaskScheduler.UnobservedTaskException += Handler.UnobservedTaskException; //TODO: ADD More Handlers. #endregion loginLoginServer.MaximumPendingConnections = 100; #region Console Commands //Andyzweb: Added checks for start and stop //also added a running command to return status of the server //and added Console.Write("\nServer Command >>"); to login server string consoleCommand; ct.TextRead("login_consolecommands.txt"); while (true) { if (!processedargs) { if (args.Length == 1) { if (args[0].ToLower() == "/autostart") { ct.TextRead("autostart.txt"); ThreadMgr.Start(); loginLoginServer.Start(); } } processedargs = true; } Console.Write("\nServer Command >>"); consoleCommand = Console.ReadLine(); string temp = ""; while (temp != consoleCommand) { temp = consoleCommand; consoleCommand = consoleCommand.Replace(" ", " "); } consoleCommand = consoleCommand.Trim(); switch (consoleCommand.ToLower()) { case "start": if (loginLoginServer.Running) { Console.ForegroundColor = ConsoleColor.Red; ct.TextRead("loginisrunning.txt"); Console.ResetColor(); break; } ThreadMgr.Start(); loginLoginServer.Start(); break; case "stop": if (!loginLoginServer.Running) { Console.ForegroundColor = ConsoleColor.Red; ct.TextRead("loginisnotrunning.txt"); Console.ResetColor(); break; } ThreadMgr.Stop(); loginLoginServer.Stop(); break; case "exit": Process.GetCurrentProcess().Kill(); break; case "running": if (loginLoginServer.Running) { //Console.WriteLine("Login Server is running"); ct.TextRead("loginisrunning.txt"); break; } //Console.WriteLine("Login Server not running"); ct.TextRead("loginisnotrunning.txt"); break; #region Help Commands.... case "help": ct.TextRead("logincmdhelp.txt"); break; case "help start": ct.TextRead("helpstart.txt"); break; case "help exit": ct.TextRead("helpstop.txt"); break; case "help running": ct.TextRead("loginhelpcmdrunning.txt"); break; case "help Adduser": ct.TextRead("logincmdadduserhelp.txt"); break; case "help setpass": ct.TextRead("logincmdhelpsetpass.txt"); break; #endregion default: #region Adduser //This section handles the command for adding a user to the database if (consoleCommand.ToLower().StartsWith("adduser")) { string[] parts = consoleCommand.Split(' '); if (parts.Length < 9) { Console.WriteLine( "Invalid command syntax.\nPlease use:\nAdduser <username> <password> <number of characters> <expansion> <gm level> <email> <FirstName> <LastName>"); break; } string username = parts[1]; string password = parts[2]; int numChars = 0; try { numChars = int.Parse(parts[3]); } catch { Console.WriteLine("Error: <number of characters> must be a number (duh!)"); break; } int expansions = 0; try { expansions = int.Parse(parts[4]); } catch { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); break; } if (expansions < 0 || expansions > 2047) { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); break; } int gm = 0; try { gm = int.Parse(parts[5]); } catch { Console.WriteLine("Error: <GM Level> must be number (duh!)"); break; } string email = parts[6]; if (email == null) { email = String.Empty; } if (!TestEmailRegex(email)) { Console.WriteLine("Error: <Email> You must supply an email address for this account"); break; } string firstname = parts[7]; try { if (firstname == null) { throw new ArgumentNullException(); } } catch { Console.WriteLine("Error: <FirstName> You must supply a first name for this accout"); break; } string lastname = parts[8]; try { if (lastname == null) { throw new ArgumentNullException(); } } catch { Console.WriteLine("Error: <LastName> You must supply a last name for this account"); break; } const string FormatString = "INSERT INTO `login` (`CreationDate`, `Flags`,`AccountFlags`,`Username`,`Password`,`Allowed_Characters`,`Expansions`, `GM`, `Email`, `FirstName`, `LastName`) VALUES " + "(NOW(), '0', '0', '{0}', '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}');"; LoginEncryption le = new LoginEncryption(); string hashedPassword = le.GeneratePasswordHash(password); string sql = String.Format( FormatString, username, hashedPassword, numChars, expansions, gm, email, firstname, lastname); SqlWrapper sqlWrapper = new SqlWrapper(); try { sqlWrapper.SqlInsert(sql); } catch (MySqlException ex) { switch (ex.Number) { case 1062: //duplicate entry for key Console.WriteLine("A user account with this username already exists."); break; default: Console.WriteLine( "An error occured while trying to add a new user account:\n{0}", ex.Message); break; } break; } Console.WriteLine("User added successfully."); break; } #endregion #region Hashpass //This function just hashes the string you enter using the loginencryption method if (consoleCommand.ToLower().StartsWith("hash")) { string Syntax = "The Syntax for this command is \"hash <String to hash>\" alphanumeric no spaces"; string[] parts = consoleCommand.Split(' '); if (parts.Length != 2) { Console.WriteLine(Syntax); break; } string pass = parts[1]; LoginEncryption le = new LoginEncryption(); string hashed = le.GeneratePasswordHash(pass); Console.WriteLine(hashed); break; } #endregion #region setpass //sets the password for the given username //Added by Andyzweb //Still TODO add exception and error handling if (consoleCommand.ToLower().StartsWith("setpass")) { string Syntax = "The syntax for this command is \"setpass <account username> <newpass>\" where newpass is alpha numeric no spaces"; string[] parts = consoleCommand.Split(' '); if (parts.Length != 3) { Console.WriteLine(Syntax); break; } string username = parts[1]; string newpass = parts[2]; LoginEncryption le = new LoginEncryption(); string hashed = le.GeneratePasswordHash(newpass); string formatString; formatString = "UPDATE `login` SET Password = '******' WHERE login.Username = '******'"; string sql = String.Format(formatString, hashed, username); SqlWrapper updt = new SqlWrapper(); try { updt.SqlUpdate(sql); } //yeah this part here, some kind of exception handling for mysql errors catch { } } #endregion ct.TextRead("login_consolecmdsdefault.txt"); break; } } #endregion }
/// <summary> /// The read. /// </summary> /// <param name="client"> /// </param> /// <param name="packet"> /// </param> public static void Read(Client client, ref byte[] packet) { MemoryStream m_stream = new MemoryStream(packet); BinaryReader m_reader = new BinaryReader(m_stream); // now we should do password check and then send OK or Error // sending OK now m_stream.Position = 12; short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength)); short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16()); string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength)); uint characterId = BitConverter.ToUInt32(new[] { packet[11], packet[10], packet[9], packet[8] }, 0); LoginEncryption loginEncryption = new LoginEncryption(); if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName) && loginEncryption.IsCharacterOnAccount(userName, characterId)) { byte[] loginok = LoginOk.Create(); client.Send(loginok); } else { byte[] loginerr = LoginError.Create(); client.Send(loginerr); client.Server.DisconnectClient(client); byte[] invalid = BitConverter.GetBytes(characterId); ZoneCom.Client.SendMessage(99, invalid); return; } // server welcome message string motd = ConfigReadWrite.Instance.CurrentConfig.Motd; // save characters ID in client - note, this is usually 0 if it is a chat client connecting client.Character = new Character(characterId, client); // add client to connected clients list if (!client.Server.ConnectedClients.ContainsKey(client.Character.characterId)) { client.Server.ConnectedClients.Add(client.Character.characterId, client); } // add yourself to that list client.KnownClients.Add(client.Character.characterId); // and give client its own name lookup byte[] pname = PlayerName.New(client, client.Character.characterId); client.Send(pname); // send server welcome message to client byte[] anonv = MsgAnonymousVicinity.Create( string.Empty, string.Format(motd, AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion), string.Empty); client.Send(anonv); // tell client to join channel "Global" // hardcoded right now foreach (ChannelsEntry channel in ChatChannels.ChannelNames) { byte[] chanGlobal = ChannelJoin.Create( channel.Id, channel.Name, channel.ChannelMode, new byte[] { 0x00, 0x00 }); client.Send(chanGlobal); } // First Attempt at Guild Channel.... // This code is completly untested however if it works // we will have to add some what for you to join GuildChat on creation of guild // and when you join a guild... this just connects you to it if you already exist in a guild // at character login.. enjoy hope it works.. I cant seem to test it my computer wont let me install the sql tables atm.. if (client.Character.orgId == 0) { } else { ulong channelBuffer = (ulong)ChannelType.Organization << 32; channelBuffer |= (uint)client.Character.orgId; byte[] guildChannel = ChannelJoin.Create(channelBuffer, client.Character.orgName, 0x8044, new byte[] { 0x00, 0x00 }); client.Send(guildChannel); } // Do Not Delete this just yet! // byte[] chn_global = new Packets.ChannelJoin().Create // ( // new byte[] { 0x04, 0x00, 0x00, 0x23, 0x28 }, // "Global", // 0x8044, // new byte[] { 0x00, 0x00 } // ); // client.Send(chn_global); }
/// <summary> /// </summary> /// <param name="args"> /// </param> /// <exception cref="ArgumentNullException"> /// </exception> private static void Main(string[] args) { LogUtil.SetupConsoleLogging(LogLevel.Debug); LogUtil.SetupFileLogging("${basedir}/LoginEngineLog.txt", LogLevel.Trace); SettingsOverride.LoadCustomSettings("NBug.LoginEngine.Config"); Settings.WriteLogToDisk = true; AppDomain.CurrentDomain.UnhandledException += Handler.UnhandledException; TaskScheduler.UnobservedTaskException += Handler.UnobservedTaskException; Console.Title = "CellAO " + AssemblyInfoclass.Title + " Console. Version: " + AssemblyInfoclass.Description + " " + AssemblyInfoclass.AssemblyVersion + " " + AssemblyInfoclass.Trademark; var ct = new ConsoleText(); ct.TextRead("main.txt"); Console.Write("Loading "); Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write(AssemblyInfoclass.Title + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(AssemblyInfoclass.Description); Console.ResetColor(); Console.WriteLine("..."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[OK]"); Console.ResetColor(); // Sying helped figure all this code out, about 5 yearts ago! :P bool processedargs = false; loginServer = Container.GetInstance<LoginServer>(); bool TCPEnable = true; bool UDPEnable = false; int Port = Convert.ToInt32(Config.Instance.CurrentConfig.LoginPort); try { if (Config.Instance.CurrentConfig.ListenIP == "0.0.0.0") { loginServer.TcpEndPoint = new IPEndPoint(IPAddress.Any, Port); } else { loginServer.TcpIP = IPAddress.Parse(Config.Instance.CurrentConfig.ListenIP); } } catch { ct.TextRead("ip_config_parse_error.txt"); Console.ReadKey(); return; } // TODO: ADD More Handlers. loginServer.MaximumPendingConnections = 100; #region Console Commands // Andyzweb: Added checks for start and stop // also added a running command to return status of the server // and added Console.Write("\nServer Command >>"); to login server string consoleCommand; ct.TextRead("login_consolecommands.txt"); while (true) { if (!processedargs) { if (args.Length == 1) { if (args[0].ToLower() == "/autostart") { ct.TextRead("autostart.txt"); loginServer.Start(TCPEnable, UDPEnable); } } processedargs = true; } Console.Write("\nServer Command >>"); consoleCommand = Console.ReadLine(); string temp = string.Empty; while (temp != consoleCommand) { temp = consoleCommand; consoleCommand = consoleCommand.Replace(" ", " "); } consoleCommand = consoleCommand.Trim(); switch (consoleCommand.ToLower()) { case "start": if (loginServer.IsRunning) { Console.ForegroundColor = ConsoleColor.Red; ct.TextRead("loginisrunning.txt"); Console.ResetColor(); break; } loginServer.Start(TCPEnable, UDPEnable); break; case "stop": if (!loginServer.IsRunning) { Console.ForegroundColor = ConsoleColor.Red; ct.TextRead("loginisnotrunning.txt"); Console.ResetColor(); break; } loginServer.Stop(); break; case "exit": Process.GetCurrentProcess().Kill(); break; case "running": if (loginServer.IsRunning) { // Console.WriteLine("Login Server is running"); ct.TextRead("loginisrunning.txt"); break; } // Console.WriteLine("Login Server not running"); ct.TextRead("loginisnotrunning.txt"); break; #region Help Commands.... case "help": ct.TextRead("logincmdhelp.txt"); break; case "help start": ct.TextRead("helpstart.txt"); break; case "help exit": ct.TextRead("helpstop.txt"); break; case "help running": ct.TextRead("loginhelpcmdrunning.txt"); break; case "help Adduser": ct.TextRead("logincmdadduserhelp.txt"); break; case "help setpass": ct.TextRead("logincmdhelpsetpass.txt"); break; #endregion default: #region Adduser // This section handles the command for adding a user to the database if (consoleCommand.ToLower().StartsWith("adduser")) { string[] parts = consoleCommand.Split(' '); if (parts.Length < 9) { Console.WriteLine( "Invalid command syntax.\nPlease use:\nAdduser <username> <password> <number of characters> <expansion> <gm level> <email> <FirstName> <LastName>"); break; } string username = parts[1]; string password = parts[2]; int numChars = 0; try { numChars = int.Parse(parts[3]); } catch { Console.WriteLine("Error: <number of characters> must be a number (duh!)"); break; } int expansions = 0; try { expansions = int.Parse(parts[4]); } catch { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); break; } if (expansions < 0 || expansions > 2047) { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); break; } int gm = 0; try { gm = int.Parse(parts[5]); } catch { Console.WriteLine("Error: <GM Level> must be number (duh!)"); break; } string email = parts[6]; if (email == null) { email = string.Empty; } if (!TestEmailRegex(email)) { Console.WriteLine("Error: <Email> You must supply an email address for this account"); break; } string firstname = parts[7]; try { if (firstname == null) { throw new ArgumentNullException(); } } catch { Console.WriteLine("Error: <FirstName> You must supply a first name for this accout"); break; } string lastname = parts[8]; try { if (lastname == null) { throw new ArgumentNullException(); } } catch { Console.WriteLine("Error: <LastName> You must supply a last name for this account"); break; } DBLoginData login = new DBLoginData { Username=username, AccountFlags = 0, Allowed_Characters = numChars, CreationDate = DateTime.Now, Email = email, Expansions = expansions, FirstName = firstname, LastName = lastname, GM = gm, Flags = 0, Password = new LoginEncryption().GeneratePasswordHash(password) }; try { LoginDataDao.WriteLoginData(login); } catch (Exception ex) { Console.WriteLine( "An error occured while trying to add a new user account:\n{0}", ex.Message); break; } Console.WriteLine("User added successfully."); break; } #endregion #region Hashpass // This function just hashes the string you enter using the loginencryption method if (consoleCommand.ToLower().StartsWith("hash")) { string Syntax = "The Syntax for this command is \"hash <String to hash>\" alphanumeric no spaces"; string[] parts = consoleCommand.Split(' '); if (parts.Length != 2) { Console.WriteLine(Syntax); break; } string pass = parts[1]; var le = new LoginEncryption(); string hashed = le.GeneratePasswordHash(pass); Console.WriteLine(hashed); break; } #endregion #region setpass // sets the password for the given username // Added by Andyzweb // Still TODO add exception and error handling if (consoleCommand.ToLower().StartsWith("setpass")) { string Syntax = "The syntax for this command is \"setpass <account username> <newpass>\" where newpass is alpha numeric no spaces"; string[] parts = consoleCommand.Split(' '); if (parts.Length != 3) { Console.WriteLine(Syntax); break; } string username = parts[1]; string newpass = parts[2]; var le = new LoginEncryption(); string hashed = le.GeneratePasswordHash(newpass); try { LoginDataDao.WriteNewPassword( new DBLoginData { Username = username, Password = hashed }); } // yeah this part here, some kind of exception handling for mysql errors catch (Exception ex) { Console.WriteLine("Could not set new Password\r\n"+ex.Message); LogUtil.ErrorException(ex); } } #endregion ct.TextRead("login_consolecmdsdefault.txt"); break; } } #endregion }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="characterId"></param> /// <returns></returns> public bool IsCharacterOnAccount(Client client, int characterId) { LoginEncryption le = new LoginEncryption(); return le.IsCharacterOnAccount(client.accountName, characterId); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="LoginKey"></param> /// <returns></returns> public bool IsLoginCorrect(Client client, string LoginKey) { LoginEncryption le = new LoginEncryption(); lp.GetLoginPassword(client.accountName); return le.IsValidLogin(LoginKey, client.serverSalt, client.accountName, lp.PasswdL); }