/// <summary> /// User clicked button to log in. /// </summary> private void BtnLogin_Click(object sender, EventArgs e) { LoginArgsContainer Args = new LoginArgsContainer(); if (TxtPassword.Text != "" && TxtUsername.Text != "") { NetworkFacade.Client = new NetworkClient(GlobalSettings.Default.LoginServerIP, 2106, GonzoNet.Encryption.EncryptionMode.AESCrypto); NetworkFacade.Client.OnConnected += new OnConnectedDelegate(NetworkController.Client_OnConnected); Args.Username = TxtUsername.Text.ToUpper(); Args.Password = TxtPassword.Text.ToUpper(); SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length); byte[] HashBuf = Hash.ComputePasswordHash(Args.Username.ToUpper(), Args.Password.ToUpper()); Args.Enc = new AESEncryptor(Convert.ToBase64String(HashBuf)); Args.Client = NetworkFacade.Client; PlayerAccount.Username = TxtUsername.Text; LblStatus.Invoke(new MethodInvoker(delegate{ LblStatus.Visible = true; })); LblStatus.Invoke(new MethodInvoker(delegate { LblStatus.Text = "Connecting..."; })); NetworkController.OnReceivedCharacters += new OnReceivedCharactersDelegate(NetworkController_OnReceivedCharacters); NetworkFacade.Client.Connect(Args); } else MessageBox.Show("Please enter a username and password!"); }
public static void SendLoginRequest(LoginArgsContainer Args) { //Variable length... PacketStream Packet = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0); Packet.WriteByte(0x00); SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length); MemoryStream MemStream = new MemoryStream(); DecryptionArgsContainer DecryptionArgs = Args.Enc.GetDecryptionArgsContainer(); byte[] EncKey = DecryptionArgs.ARC4DecryptArgs.EncryptionKey; MemStream.WriteByte((byte)Args.Username.Length); MemStream.Write(Encoding.ASCII.GetBytes(Args.Username), 0, Encoding.ASCII.GetBytes(Args.Username).Length); byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password); PlayerAccount.Hash = HashBuf; MemStream.WriteByte((byte)HashBuf.Length); MemStream.Write(HashBuf, 0, HashBuf.Length); MemStream.WriteByte((byte)EncKey.Length); MemStream.Write(EncKey, 0, EncKey.Length); Packet.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + MemStream.ToArray().Length + 4)); Packet.WriteBytes(MemStream.ToArray()); string[] Version = GlobalSettings.Default.ClientVersion.Split('.'); Packet.WriteByte((byte)int.Parse(Version[0])); //Version 1 Packet.WriteByte((byte)int.Parse(Version[1])); //Version 2 Packet.WriteByte((byte)int.Parse(Version[2])); //Version 3 Packet.WriteByte((byte)int.Parse(Version[3])); //Version 4 Args.Client.Send(Packet.ToArray()); }
public static void SendLoginRequest(LoginArgsContainer Args) { PacketStream InitialPacket = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0); InitialPacket.WriteHeader(); //ECDiffieHellmanCng PrivateKey = Args.Client.ClientEncryptor.GetDecryptionArgsContainer() // .AESDecryptArgs.PrivateKey; //IMPORTANT: Public key must derive from the private key! //byte[] ClientPublicKey = PrivateKey.PublicKey.ToByteArray(); byte[] NOnce = Args.Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce; //InitialPacket.WriteInt32(((byte)PacketHeaders.UNENCRYPTED + // /*4 is for version*/ 4 + (ClientPublicKey.Length + 1) + (NOnce.Length + 1))); SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length); byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password); PlayerAccount.Hash = HashBuf; string[] Version = GlobalSettings.Default.ClientVersion.Split('.'); InitialPacket.WriteByte((byte)int.Parse(Version[0])); //Version 1 InitialPacket.WriteByte((byte)int.Parse(Version[1])); //Version 2 InitialPacket.WriteByte((byte)int.Parse(Version[2])); //Version 3 InitialPacket.WriteByte((byte)int.Parse(Version[3])); //Version 4 //InitialPacket.WriteByte((byte)ClientPublicKey.Length); //InitialPacket.WriteBytes(ClientPublicKey); InitialPacket.WriteByte((byte)NOnce.Length); InitialPacket.WriteBytes(NOnce); Args.Client.Send(InitialPacket.ToArray()); }
/// <summary> /// Authenticate with the service client to get a token, /// Then get info about avatars & cities /// </summary> /// <param name="username"></param> /// <param name="password"></param> public void InitialConnect(string username, string password) { lock (NetworkFacade.Client) { var client = NetworkFacade.Client; LoginArgsContainer Args = new LoginArgsContainer(); Args.Username = username; Args.Password = password; //Doing the encryption this way eliminates the need to send key across the wire! :D SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length); byte[] HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password); Args.Enc = new GonzoNet.Encryption.AESEncryptor(Convert.ToBase64String(HashBuf)); Args.Client = client; client.Connect(Args); } }
static void Main(string[] args) { String isClient = ""; try { isClient = args[0]; } catch { isClient = "false"; } #region GonzoNet Initialization (Server) if (isClient.Equals("false")) { GonzoNet.PacketHandlers.Register(0x01, false, 0, new OnPacketReceive(PacketHandlers.OnLoginRequest)); GonzoNet.PacketHandlers.Register(0x02, false, 0, new OnPacketReceive(PacketHandlers.OnLoginSuccess)); GonzoNet.PacketHandlers.Register(0x04, false, 0, new OnPacketReceive(PacketHandlers.OnChallengeRecieved)); NetworkFacade.Listener.Initialize(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2223)); ss = new ServerSettings(); if (!File.Exists("blocked.txt") && ss.CensoringEnabled) { Console.WriteLine("Downloading blocked words..."); WebClient wc = new WebClient(); // I'll make a proper list, which is compressed & encrypted, closer to release wc.DownloadFileAsync(new Uri("http://www.bannedwordlist.com/lists/swearWords.txt"), "blocked.txt"); } } #endregion #region Information Console.SetWindowSize(120, 45); string externalip = new WebClient().DownloadString("http://icanhazip.com"); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Welcome to the "); Console.ForegroundColor = ConsoleColor.Green; Console.Write("TS2 Online "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("Server application!\n"); // Welcome text Console.WriteLine("IP Address: " + externalip); // IP Address Console.SetCursorPosition(0, Console.CursorTop - 1); Console.WriteLine("Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); String command = ""; Console.ForegroundColor = ConsoleColor.Yellow; PacketHandlers.OnChatMessageReceived(); #endregion #region Commands while (!command.ToLower().Equals("shutdown")) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[ "); Console.ForegroundColor = ConsoleColor.White; command = Console.ReadLine(); Console.CursorLeft = 0; Console.SetCursorPosition(0, Console.CursorTop - 1); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("[ " + command + " ]"); Console.SetCursorPosition(0, Console.CursorTop + 1); Console.ForegroundColor = ConsoleColor.Yellow; // Now read the command. if (command.ToLower().Equals("help")) { Console.WriteLine("Help: Commands:"); int i = 0; try { while (_commands.commands[i] != null) { Console.WriteLine(_commands.commands[i]); i++; } } catch { } // I'm not going to do anything here so there's no point wasting a couple of lines for some useless brackets. } else if (command.ToLower().Contains("forcekill")) { string ipaddress = command.Replace("forcekill ", ""); try { // Shutdown the client here Console.WriteLine("Client shutdown."); } catch { // Show an error message here - was the IP address connected? } } else if (command.ToLower().Contains("logoff")) { string ipaddress = command.Replace("logoff ", ""); try { // Disconnect the client here Console.WriteLine("Client disconnected."); } catch { // Show an error message here - was the IP address connected? Was it a GUID instead of an IP address? } } else if (command.ToLower().Contains("getpacketids")) { foreach (PacketIDs.PacketTypes packetName in Enum.GetValues(typeof(PacketIDs.PacketTypes))) { Console.WriteLine(packetName); Console.WriteLine("\t" + PacketIDs.PacketDescriptors(packetName) + "\n"); } } else if (command.ToLower().Contains("sendtest")) { //GonzoNet requires a log output stream to function correctly. This is built in behavior. GonzoNet.Logger.OnMessageLogged += new MessageLoggedDelegate(Logger_OnMessageLogged); NetworkFacade.Client = new NetworkClient("127.0.0.1", 2223, GonzoNet.Encryption.EncryptionMode.NoEncryption, false); NetworkFacade.Client.OnConnected += new OnConnectedDelegate(m_Client_OnConnected); LoginArgsContainer LoginArgs = new LoginArgsContainer(); LoginArgs.Enc = new AESEncryptor("test"); LoginArgs.Username = command.ToLower().Replace("sendtest ", ""); LoginArgs.Password = "******"; LoginArgs.Client = NetworkFacade.Client; SaltedHash Hash = new SaltedHash(new SHA512Managed(), LoginArgs.Username.Length); PacketHandlers.PasswordHash = Hash.ComputePasswordHash(LoginArgs.Username, LoginArgs.Password); NetworkFacade.Client.Connect(LoginArgs); NetworkFacade.Client.Disconnect(); } else if (command.ToLower().Contains("reload")) { Console.WriteLine("Reloading modules..."); Console.WriteLine("Reticulating Splines..."); Console.WriteLine("Getting all tons bacons..."); Console.WriteLine("Reload complete. See reload.log for all logged module startup messages"); StreamWriter logWriter = new StreamWriter("reload.log", true); logWriter.Write(Environment.NewLine + System.DateTime.Now.ToString() + " " + "modules currently not implemented"); logWriter.Close(); } //Put all new commands above here. else if (command.ToLower().Contains("shutdown")) { //This enables the command but because it doesn't do anything, it will shut it down because the while loop will stop. //Enabling the command means we don't get an error message like the one below } else { Console.WriteLine("Command " + command + @" not recognized; type ""help"" to get the current list of commands"); command = ""; } #endregion } }
public static void SendLoginRequest(LoginArgsContainer Args) { //Variable length... PacketStream Packet = new PacketStream((byte)PacketType.LOGIN_REQUEST, 0); Packet.WriteByte(0x00); SaltedHash Hash = new SaltedHash(new SHA512Managed(), Args.Username.Length); byte[] HashBuf = new byte[Encoding.ASCII.GetBytes(Args.Password).Length + Encoding.ASCII.GetBytes(Args.Username).Length]; MemoryStream MemStream = new MemoryStream(); DecryptionArgsContainer DecryptionArgs = Args.Enc.GetDecryptionArgsContainer(); byte[] EncKey = DecryptionArgs.ARC4DecryptArgs.EncryptionKey; MemStream.WriteByte((byte)Args.Username.Length); MemStream.Write(Encoding.ASCII.GetBytes(Args.Username), 0, Encoding.ASCII.GetBytes(Args.Username).Length); HashBuf = Hash.ComputePasswordHash(Args.Username, Args.Password); PlayerAccount.Hash = HashBuf; MemStream.WriteByte((byte)HashBuf.Length); MemStream.Write(HashBuf, 0, HashBuf.Length); MemStream.WriteByte((byte)EncKey.Length); MemStream.Write(EncKey, 0, EncKey.Length); Packet.WriteUInt16((ushort)(2 + MemStream.ToArray().Length + 4)); Packet.WriteBytes(MemStream.ToArray()); //TODO: Change this to write a global client version. Packet.WriteByte(0x00); //Version 1 Packet.WriteByte(0x00); //Version 2 Packet.WriteByte(0x00); //Version 3 Packet.WriteByte(0x01); //Version 4 Args.Client.Send(Packet.ToArray()); }