public static void Command() { while (!Environment.HasShutdownStarted) { var input = ReadLine(); if (string.IsNullOrWhiteSpace(input)) continue; var split = input.Split(new[] { ' ' }, 2); var cmd = split[0].ToLower(); var cmdArgs = split.Length > 1 ? split[1].Split(' ') : null; using (var database = new DbUtils()) switch (cmd) { case "help": WriteLine("addaccount <username> <password>"); WriteLine("removeaccount <username>"); WriteLine("accountexists <username>"); WriteLine("ban <username>"); WriteLine("unban <username>"); WriteLine("printinfo <a for account, anything else for character> <username> [clipboard]"); WriteLine("deletecharacter <username>"); break; case "deletecharacter": if (cmdArgs?.Length >= 1) { var name = cmdArgs[0]; if (!database.CharacterExists(name)) { WriteLine("Character does not exist."); continue; } database.DeleteCharacter(database.GetCharacter(name)); WriteLine("Success!"); continue; } WriteLine("Invalid Arguments"); break; case "printinfo": if (cmdArgs?.Length >= 2) { var type = cmdArgs[0]; var username = cmdArgs[1]; if (type == "a" && !database.AccountExists(username)) { WriteLine("Account does not exist."); continue; } else if (type != "a" && !database.CharacterExists(username)) { WriteLine("Character does not exist!"); continue; } var account = JsonConvert.SerializeObject( (type == "a" ? (dynamic) database.GetAccount(username) : (dynamic) database.GetCharacter(username)), Formatting.Indented); WriteLine(account); if (cmdArgs.Length >= 3) Clipboard.SetText(account); continue; } WriteLine("Invalid Arguments!"); break; case "addaccount": if (cmdArgs != null && cmdArgs.Length >= 2) { var username = cmdArgs[0]; var password = cmdArgs[1]; database.CreateAccount(username, password); WriteLine("Success!"); continue; } WriteLine("Invalid Arguments."); break; case "ban": if (cmdArgs?.Length >= 1) { var username = cmdArgs[0]; if (!database.AccountExists(username)) { WriteLine("User does not exist."); continue; } var account = database.GetAccount(username); account.Banned = true; database.UpdateAccount(account); WriteLine("Success!"); continue; } WriteLine("Invalid Arguments."); break; case "unban": if (cmdArgs?.Length >= 1) { var username = cmdArgs[0]; if (!database.AccountExists(username)) { WriteLine("User does not exist."); continue; } var account = database.GetAccount(username); account.Banned = false; database.UpdateAccount(account); WriteLine("Success!"); continue; } WriteLine("Invalid Arguments."); break; case "removeaccount": if (cmdArgs?.Length >= 1) { var username = cmdArgs[0]; if (database.AccountExists(username)) { database.DeleteAccount(database.GetAccount(username)); WriteLine("Success!"); continue; } WriteLine("User does not exist."); continue; } WriteLine("Invalid Arguments."); break; case "accountexists": if (cmdArgs != null && cmdArgs.Length >= 1) { var username = cmdArgs[0]; WriteLine(database.AccountExists(username)); continue; } WriteLine("Invalid Arguments."); break; default: WriteLine("Unknown command."); break; } } }
public override void Handle(BinaryReader reader, LuClient client) { using (var database = new DbUtils()) { var loginRequest = new LoginRequest(reader); WriteLine($"{loginRequest.Username} sent authentication request."); byte valid = 0x01; if (!database.AccountExists(loginRequest.Username)) { valid = 0x06; } if (valid == 0x01) { var account = database.GetAccount(loginRequest.Username); var hash = SHA512.Create() .ComputeHash(Encoding.Unicode.GetBytes(loginRequest.Password).Concat(account.Salt).ToArray()); if (!account.Password.SequenceEqual(hash)) valid = 0x06; if (valid == 0x01 && account.Banned) valid = 0x02; } var message = "screwed up."; switch (valid) { case 0x01: message = "was successful."; break; case 0x06: message = "failed: invalid credentials."; break; case 0x02: message = "failed: banned."; break; default: WriteLine( "FATAL: Magically, the valid variable was not 0x01, 0x06, or 0x02! (How is that even possible..? I'm only checking because resharper is making me.)"); break; } WriteLine("User login " + message); if (valid == 0x01) { // TODO: Store user key } // Use C++ auth for now (I hope to eliminate this sometime) SendLoginResponse(client.Address, valid, RandomString(66), AuthServer.Server); // C# auth, not working atm /* using (var bitStream = new WBitStream()) { bitStream.WriteHeader(PacketEnums.RemoteConnection.Client, 0); bitStream.Write(valid); bitStream.WriteString("Talk_Like_A_Pirate", 33); for (var i = 0; i < 7; i++) { bitStream.WriteString("_", 0, 33); } // client version bitStream.Write((ushort)1); bitStream.Write((ushort)10); bitStream.Write((ushort)64); //bitStream.WriteWString(RandomString(32), false, true); // user key bitStream.WriteString(RandomString(66), 66, 66); bitStream.WriteString("localhost", 33); // redirect ip bitStream.WriteString("localhost", 33); // chat ip bitStream.Write((ushort)2006); // redirect port bitStream.Write((ushort)2003); // chat port bitStream.WriteString("localhost", 33); // another ip bitStream.WriteString("00000000-0000-0000-0000-000000000000", 37); // possible guid bitStream.Write((ushort)0); // zero short // localization bitStream.Write((byte)0x55); bitStream.Write((byte)0x53); bitStream.Write((byte)0x00); bitStream.Write((byte)0); // first login subscription bitStream.Write((byte)0); // subscribed bitStream.Write((ulong)0); // zero long bitStream.Write((ushort)0); // error message length bitStream.WriteString("T", 0, 1); // error message bitStream.Write((ushort)324); // extra data length CreateExtraPacketData(0, 0, 2803442767, bitStream); CreateExtraPacketData(7, 37381, 2803442767, bitStream); CreateExtraPacketData(8, 6, 2803442767, bitStream); CreateExtraPacketData(9, 0, 2803442767, bitStream); CreateExtraPacketData(10, 0, 2803442767, bitStream); CreateExtraPacketData(11, 1, 2803442767, bitStream); CreateExtraPacketData(14, 1, 2803442767, bitStream); CreateExtraPacketData(15, 0, 2803442767, bitStream); CreateExtraPacketData(17, 1, 2803442767, bitStream); CreateExtraPacketData(5, 0, 2803442767, bitStream); CreateExtraPacketData(6, 1, 2803442767, bitStream); CreateExtraPacketData(20, 1, 2803442767, bitStream); CreateExtraPacketData(19, 30854, 2803442767, bitStream); CreateExtraPacketData(21, 0, 2803442767, bitStream); CreateExtraPacketData(22, 0, 2803442767, bitStream); CreateExtraPacketData(23, 4114, 2803442767, bitStream); CreateExtraPacketData(27, 4114, 2803442767, bitStream); CreateExtraPacketData(28, 1, 2803442767, bitStream); CreateExtraPacketData(29, 0, 2803442767, bitStream); CreateExtraPacketData(30, 30854, 2803442767, bitStream); File.WriteAllBytes("Temp/loginresponse.bin", bitStream.GetBytes()); LuServer.CurrentServer.Send(bitStream, WPacketPriority.SystemPriority, WPacketReliability.ReliableOrdered, 0, client.Address, false); // Send the packet. } */ } }