Exemplo n.º 1
0
        public override void ProcessMessage(Connection connection, NetworkMessage inboundMessage)
        {
            var packetType = (LoginOrManagementIncomingPacketType)inboundMessage.GetByte();

            // TODO: move this validation?
            if (packetType != LoginOrManagementIncomingPacketType.AuthenticationRequest && !connection.IsAuthenticated)
            {
                connection.Close();
                return;
            }

            var handler = HandlerFactory.CreateIncommingForType((byte)packetType);

            handler?.HandleMessageContents(inboundMessage, connection);

            if (handler?.ResponsePackets != null)
            {
                // Send any responses prepared for
                var message = new NetworkMessage();

                foreach (var outPacket in handler.ResponsePackets)
                {
                    message.AddPacket(outPacket);
                }

                connection.Send(message);
            }
        }
Exemplo n.º 2
0
        private void SendCharacterList(Connection connection, string motd, ushort premiumDays, IEnumerable <ICharacterListItem> chars)
        {
            var message = new NetworkMessage(4);

            if (motd != string.Empty)
            {
                message.AddPacket(new MessageOfTheDayPacket
                {
                    MessageOfTheDay = motd
                });
            }

            message.AddPacket(new CharacterListPacket
            {
                Characters      = chars,
                PremiumDaysLeft = premiumDays
            });

            connection.Send(message);
        }
Exemplo n.º 3
0
        private void SendDisconnect(Connection connection, string reason)
        {
            var message = new NetworkMessage(4);

            message.AddPacket(new LoginServerDisconnectPacket
            {
                Reason = reason
            });

            connection.Send(message);
        }
Exemplo n.º 4
0
        public void Send()
        {
            if (!ResponsePackets.Any())
            {
                return;
            }

            var networkMessage = new NetworkMessage(4);

            foreach (var packet in ResponsePackets)
            {
                networkMessage.AddPacket(packet);
            }

            Connection.Send(networkMessage);
            Console.WriteLine($"Sent {GetType().Name} [{EventId}] to {Connection.PlayerId} - {Connection.SourceIp}");

            // foreach (var packet in ResponsePackets)
            // {
            //    packet.CleanUp();
            // }
        }
Exemplo n.º 5
0
        public override void ProcessMessage(Connection connection, NetworkMessage inboundMessage)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            if (inboundMessage == null)
            {
                throw new ArgumentNullException(nameof(inboundMessage));
            }

            byte packetType;

            if (!connection.IsAuthenticated || connection.XTeaKey.Sum(b => b) == 0)
            {
                // this is a new connection...
                packetType = inboundMessage.GetByte();

                if (packetType != (byte)GameIncomingPacketType.PlayerLoginRequest)
                {
                    // but this is not the packet we were expecting for a new connection.
                    connection.Close();
                    return;
                }

                //if (ServiceConfiguration.GetConfiguration().ReceivedClientVersionInt > 770) {
                var os = inboundMessage.GetUInt16();
                ServiceConfiguration.GetConfiguration().ReceivedClientVersionInt = inboundMessage.GetUInt16();
                //}


                var gameConfig = ServiceConfiguration.GetConfiguration();

                // Make a copy of the message in case we fail to decrypt using the first set of keys.
                var messageCopy = NetworkMessage.Copy(inboundMessage);

                inboundMessage.RsaDecrypt(useRsa2: true);

                if (inboundMessage.GetByte() != 0)
                {
                    // means the RSA decrypt was unsuccessful, lets try with the other set of RSA keys...
                    inboundMessage = messageCopy;

                    inboundMessage.RsaDecrypt(useCipKeys: gameConfig.UsingCipsoftRsaKeys);

                    if (inboundMessage.GetByte() != 0)
                    {
                        // means the RSA decrypt was unsuccessful, lets try with the other set of RSA keys...
                        inboundMessage = messageCopy;
                        inboundMessage.RsaDecrypt(useCipKeys: !gameConfig.UsingCipsoftRsaKeys);

                        if (inboundMessage.GetByte() != 0)
                        {
                            // These RSA keys are also usuccessful... so give up.
                            connection.Close();
                            return;
                        }
                    }
                }
            }
            else
            {
                // Decrypt message using XTea
                inboundMessage.XteaDecrypt(connection.XTeaKey);
                inboundMessage.GetUInt16();
                packetType = inboundMessage.GetByte();
            }

            var handler = HandlerFactory.CreateIncommingForType(packetType);

            handler?.HandleMessageContents(inboundMessage, connection);

            if (handler?.ResponsePackets != null && handler.ResponsePackets.Any())
            {
                // Send any responses prepared for
                var message = new NetworkMessage(4);

                foreach (var outPacket in handler.ResponsePackets)
                {
                    message.AddPacket(outPacket);
                }

                connection.Send(message);
            }
        }