#region GameServer|AuthServer private static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj) { if (obj.Connector == null) { obj.Disconnect(); } else { GameState connector = obj.Connector as GameState; if (connector.Exchange) { connector.Exchange = false; connector.Action = (byte)1; EgyXos.Network.Cryptography.GameCryptography gameCryptography = new EgyXos.Network.Cryptography.GameCryptography(Encoding.Default.GetBytes(Constants.GameCryptographyKey)); byte[] numArray = new byte[length]; Array.Copy((Array)buffer, (Array)numArray, length); gameCryptography.Decrypt(numArray, length); bool flag = false; int offset = 0; for (int x = 0; x < 80; x++) { if (BitConverter.ToInt32(numArray, x) == 128) { if (length >= 205) { offset = x; flag = true; connector.Cryptography.Decrypt(buffer, length - 40); } else { offset = x; connector.Cryptography.Decrypt(buffer, length); } } } int int32 = BitConverter.ToInt32(buffer, offset); int index1 = offset + 4; if (int32 != 128) { connector.Disconnect(true); } else { byte[] bytes = new byte[128]; int index2 = 0; while (index2 < int32) { bytes[index2] = buffer[index1]; ++index2; ++index1; } string PublicKey = Encoding.Default.GetString(bytes); connector.Cryptography = connector.DHKeyExchange.HandleClientKeyPacket(PublicKey, connector.Cryptography); if (!flag) return; byte[] buffer1 = new byte[40]; Buffer.BlockCopy((Array)buffer, length - 40, (Array)buffer1, 0, 40); processData(buffer1, 40, connector); } } else processData(buffer, length, connector); } } private static void processData(byte[] buffer, int length, Client.GameState Client) { Client.Cryptography.Decrypt(buffer, length); Client.Queue.Enqueue(buffer, length); if (Client.Queue.CurrentLength > 1224) { Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength); Client.Disconnect(); return; } while (Client.Queue.CanDequeue()) { byte[] data = Client.Queue.Dequeue(); Network.PacketHandler.HandlePacket(data, Client); } } static void GameServer_OnClientConnect(ClientWrapper obj) { Client.GameState client = new Client.GameState(obj); client.Send(client.DHKeyExchange.CreateServerKeyPacket()); obj.Connector = client; } static void GameServer_OnClientDisconnect(ClientWrapper obj) { if (obj.Connector != null) (obj.Connector as Client.GameState).Disconnect(); else obj.Disconnect(); } public static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3) { var player = arg3.Connector as Client.AuthClient; AuthClient authClient = arg3.Connector as AuthClient; player.Cryptographer.Decrypt(buffer, length); player.Queue.Enqueue(buffer, length); while (player.Queue.CanDequeue()) { byte[] packet = player.Queue.Dequeue(); ushort len = BitConverter.ToUInt16(packet, 0); if (len == 312) { player.Info = new EgyXos.Network.AuthPackets.Authentication(); player.Info.Deserialize(packet); player.Account = new AccountTable(player.Info.Username); if (!LoginBruteForce.AcceptJoin(arg3.IP)) { Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" })); arg3.Disconnect(); break; } Forward Fw = new Forward(); //Console.WriteLine("UserName: {0} Password: {1} ServerName: {2} Online", player.Info.Username, player.Info.Password, player.Info.Server); if (player.Account.Username == player.Info.Username && player.Account.exists) { if (player.Account.Password == player.Info.Password && player.Account.exists) { Fw.Identifier = player.Account.GenerateKey(); Kernel.AwaitingPool[Fw.Identifier] = player.Account; Fw.IP = GameIP; Fw.Port = GamePort; } else { LoginBruteForce.ClientRegistred(arg3.IP); Fw.Type = Forward.ForwardType.InvalidInfo; } } else { Fw.Type = Forward.ForwardType.WrongAccount; } player.Send(Fw); } } } static void AuthServer_OnClientDisconnect(ClientWrapper obj) { obj.Disconnect(); } static void AuthServer_OnClientConnect(ClientWrapper obj) { Client.AuthClient authState; obj.Connector = (authState = new Client.AuthClient(obj)); authState.Cryptographer = new Network.Cryptography.AuthCryptography(); Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed(); pcs.Seed = Kernel.Random.Next(); authState.PasswordSeed = pcs.Seed; authState.Send(pcs); // Protection.LoaderProgram.CLientsPass.Clear();//////// //Protection.LoaderProgram.CLientsPass.Add(authState.PasswordSeed, ""); } internal static Client.GameState FindClient(string name) { return GamePool.FirstOrDefault(p => p.Entity.LoweredName == name); } #endregion
[/code]