Пример #1
0
        private static async void AcceptClientActionAsync(TcpClient rawClient)
        {
            Console.WriteLine("Accepting Realm Client");
            var client = new RealmRemoteClient(rawClient);

            var clientGuid = Guid.Empty;

            Console.WriteLine($"Using realm seed: 0x{client.Seed:x}");

            try
            {
                clientGuid = RealmServices.RemoteClients.AddClient(client);

                var packet = new RealmPacket(true)
                {
                    Opcode = 0x1ec
                };

                packet.WriteUInt32(1); // unk1
                packet.WriteUInt32(client.Seed);
                packet.WriteUInt32(0); // unk2
                packet.WriteUInt32(0); // unk3
                packet.WriteUInt32(0); // unk4
                packet.WriteUInt32(0); // unk5

                Task.Run(async() =>
                {
                    // Give us time to start listening
                    await Task.Delay(500);
                    await client.SendDataAsync(new RealmMetaPacket(packet.FinalizePacket()));
                }).RunAsync();

                await client.ListenForDataTask();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unhandled exception in {nameof(AcceptClientActionAsync)}: {ex}");
            }
            finally
            {
                if (clientGuid != Guid.Empty)
                {
                    RealmServices.RemoteClients.RemoveClient(clientGuid);
                }
                Console.WriteLine($"Client disconnected");
            }
        }