Esempio n. 1
0
        /// <inheritdoc />
        protected override void OnClientConnected(WorldClient client)
        {
            base.OnClientConnected(client);

            SelectionScreenManagers.Add(client.Id, new SelectionScreenManager(client));
            client.OnPacketArrived += Client_OnPacketArrived;
        }
Esempio n. 2
0
        private async void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is HandshakePacket)
            {
                var handshake = (HandshakePacket)packet;
                (sender as WorldClient).SetClientUserID(handshake.UserId);

                // As soon as we change id, we should update id in dictionary.
                clients.TryRemove(sender.Id, out var client);
                SelectionScreenManagers.Remove(sender.Id, out var manager);

                // Now give client new id.
                client.Id = handshake.SessionId;

                // Return client back to dictionary.
                clients.TryAdd(client.Id, client);
                SelectionScreenManagers.Add(client.Id, manager);

                // Send request to login server and get client key.
                using var requestPacket = new Packet(PacketType.AES_KEY_REQUEST);
                requestPacket.Write(sender.Id.ToByteArray());
                InterClient.SendPacket(requestPacket);
            }

            if (packet is PingPacket)
            {
                // TODO: implement disconnect, if client is not sending ping packet.
            }

            if (packet is CashPointPacket)
            {
                // TODO: implement cash point packet.
                using var dummyPacket = new Packet(PacketType.CASH_POINT);
                dummyPacket.Write(0);
                sender.SendPacket(dummyPacket);
            }

            if (packet is LogOutPacket)
            {
                // TODO: For sure, here should be timer!
                await Task.Delay(1000 * 10); // 10 seconds * 1000 milliseconds

                if (sender.IsDispose)
                {
                    return;
                }

                using var logoutPacket = new Packet(PacketType.LOGOUT);
                sender.SendPacket(logoutPacket);

                sender.CryptoManager.UseExpandedKey = false;

                SelectionScreenManagers[sender.Id].SendSelectionScrenInformation(((WorldClient)sender).UserID);
            }
        }