Exemplo n.º 1
0
 /// <inheritdoc />
 public virtual void Deserialize(INetPacketStream packet)
 {
     SlotIndex   = packet.Read <byte>();
     Type        = (ShortcutType)packet.Read <uint>();
     ObjectId    = packet.Read <uint>();
     ObjectType  = (ShortcutObjectType)packet.Read <uint>();
     ObjectIndex = packet.Read <uint>();
     UserId      = packet.Read <uint>();
     ObjectData  = packet.Read <uint>();
     Text        = Type == ShortcutType.Chat ? packet.Read <string>() : string.Empty;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new <see cref="PartyAddMemberPacket"/> object.
 /// </summary>
 /// <param name="packet">Incoming packet</param>
 public PartyAddMemberPacket(INetPacketStream packet)
 {
     this.LeaderId    = packet.Read <uint>();
     this.LeaderLevel = packet.Read <int>();
     this.LeaderJob   = packet.Read <int>();
     this.LeaderSex   = packet.Read <uint>();
     this.MemberId    = packet.Read <uint>();
     this.MemberLevel = packet.Read <int>();
     this.MemberJob   = packet.Read <int>();
     this.MemberSex   = packet.Read <uint>();
 }
Exemplo n.º 3
0
        public static void OnDeletePlayer(ClusterClient client, INetPacketStream packet)
        {
            var pak = new DeletePlayerPacket(packet);

            using (var database = DependencyContainer.Instance.Resolve <IDatabase>())
            {
                DbUser dbUser = database.Users.Get(x =>
                                                   x.Username.Equals(pak.Username, StringComparison.OrdinalIgnoreCase) &&
                                                   x.Password.Equals(pak.Password, StringComparison.OrdinalIgnoreCase));

                // Check if user exist and with good password in database.
                if (dbUser == null)
                {
                    Logger.LogWarning($"[SECURITY] Unable to delete character id '{pak.CharacterId}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                      "Reason: bad presented credentials compared to the database.");
                    client.Disconnect();
                    return;
                }

                // Check if given password match confirmation password.
                if (!string.Equals(pak.Password, pak.PasswordConfirmation, StringComparison.OrdinalIgnoreCase))
                {
                    Logger.LogWarning($"Unable to delete character id '{pak.CharacterId}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                      "Reason: passwords entered do not match.");
                    ClusterPacketFactory.SendError(client, ErrorType.WRONG_PASSWORD);
                    return;
                }

                DbCharacter dbCharacter = database.Characters.Get(pak.CharacterId);

                // Check if character exist.
                if (dbCharacter == null)
                {
                    Logger.LogWarning($"[SECURITY] Unable to delete character id '{pak.CharacterId}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                      "Reason: user doesn't have any character with this id.");
                    client.Disconnect();
                    return;
                }

                if (dbCharacter.IsDeleted)
                {
                    Logger.LogWarning($"[SECURITY] Unable to delete character id '{pak.CharacterId}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                      "Reason: character is already deleted.");
                    return;
                }

                database.Characters.Delete(dbCharacter);
                database.Complete();
                Logger.LogInformation("Character '{0}' has been deleted successfully for user '{1}' from {2}.",
                                      dbCharacter.Name, pak.Username, client.RemoteEndPoint);

                ClusterPacketFactory.SendPlayerList(client, pak.AuthenticationKey, dbUser.Characters);
            }
        }
Exemplo n.º 4
0
        public override void Send(INetPacketStream packet)
        {
            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Send {0} packet to {1}.",
                             (PacketType)BitConverter.ToUInt32(packet.Buffer, 5),
                             this.RemoteEndPoint);
            }

            base.Send(packet);
        }
 public void Serialize(INetPacketStream packet)
 {
     packet.Write(Count);
     for (int i = 0; i < MaxCapacity; i++)
     {
         if (Shortcuts[i] != null && Shortcuts[i].Type != ShortcutType.None)
         {
             Shortcuts[i].Serialize(packet);
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Handles an incoming message.
        /// </summary>
        /// <param name="packet">Incoming message.</param>
        public override void HandleMessage(INetPacketStream packet)
        {
            var packetHeader = (ChatPacketType)packet.Read <byte>();

            switch (packetHeader)
            {
            case ChatPacketType.ChatAnswer:
                this.OnChatAnswer(packet);
                break;
            }
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 public void Deserialize(INetPacketStream packet)
 {
     LeaderId    = packet.Read <uint>();
     LeaderLevel = packet.Read <int>();
     LeaderJob   = packet.Read <int>();
     LeaderSex   = packet.Read <uint>();
     MemberId    = packet.Read <uint>();
     MemberLevel = packet.Read <int>();
     MemberJob   = packet.Read <int>();
     MemberSex   = packet.Read <uint>();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Receive messages from the client.
        /// </summary>
        /// <param name="packet"></param>
        public override void HandleMessage(INetPacketStream packet)
        {
            var value = packet.Read <string>();

            Console.WriteLine("Received '{1}' from {0}", this.Id, value);

            using (var p = new NetPacket())
            {
                p.Write(string.Format("OK: '{0}'", value));
                this.Server.SendToAll(p);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Creates a new <see cref="InGuildCombatPacket"/> object.
 /// </summary>
 /// <param name="packet">Incoming packet</param>
 public InGuildCombatPacket(INetPacketStream packet)
 {
     this.GuildCombatType = (GuildCombatType)packet.Read <int>();
     if (GuildCombatType == GuildCombatType.GC_IN_APP)
     {
         this.Penya = packet.Read <uint>();
     }
     else
     {
         this.Penya = null;
     }
 }
Exemplo n.º 10
0
        /// <inheritdoc />
        public void Deserialize(INetPacketStream packet)
        {
            while (!packet.IsEndOfStream)
            {
                int skillId    = packet.Read <int>();
                int skillLevel = packet.Read <int>();

                if (skillId != -1)
                {
                    _skills.TryAdd(skillId, skillLevel);
                }
            }
        }
Exemplo n.º 11
0
 /// <inheritdoc />
 public void Deserialize(INetPacketStream packet)
 {
     BeginPosition       = new Vector3(packet.Read <float>(), packet.Read <float>(), packet.Read <float>());
     DestinationPosition = new Vector3(packet.Read <float>(), packet.Read <float>(), packet.Read <float>());
     Angle        = packet.Read <float>();
     State        = packet.Read <uint>();
     StateFlag    = packet.Read <uint>();
     Motion       = packet.Read <uint>();
     MotionEx     = packet.Read <int>();
     Loop         = packet.Read <int>();
     MotionOption = packet.Read <uint>();
     TickCount    = packet.Read <long>();
 }
Exemplo n.º 12
0
 /// <inheritdoc />
 public void Deserialize(INetPacketStream packet)
 {
     try
     {
         Time      = packet.Read <int>();
         IsTimeOut = false;
     }
     catch (Exception)
     {
         Time      = 0;
         IsTimeOut = true;
     }
 }
Exemplo n.º 13
0
        public static void OnPlayerSetDestObject(WorldClient client, INetPacketStream packet)
        {
            var targetObjectId = packet.Read <uint>();
            var distance       = packet.Read <float>();
            var followEvent    = new FollowEventArgs(targetObjectId, distance);

            // Cancel current item usage action and SFX
            client.Player.NotifySystem <SpecialEffectSystem>(new SpecialEffectBaseMotionEventArgs(StateModeBaseMotion.BASEMOTION_OFF));
            client.Player.Delayer.CancelAction(client.Player.Inventory.ItemInUseActionId);
            client.Player.Inventory.ItemInUseActionId = Guid.Empty;

            client.Player.NotifySystem <FollowSystem>(followEvent);
        }
Exemplo n.º 14
0
        public override void HandleMessage(INetPacketStream packet)
        {
            base.HandleMessage(packet);

            var buffer = packet.ReadArray <byte>(packet.Size).Skip(4).ToArray();

            using (var p = new FlyClientPacket(FlyProxContext.Instance.ProxyClusterClient.SessionId))
            {
                p.Write(buffer, 0, buffer.Length);

                FlyProxContext.Instance.ProxyClusterClient.Send(p);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a new <see cref="PlayerBehaviorPacket"/> object.
 /// </summary>
 /// <param name="packet">Incoming packet</param>
 public PlayerBehaviorPacket(INetPacketStream packet)
 {
     this.BeginPosition       = new Vector3(packet.Read <float>(), packet.Read <float>(), packet.Read <float>());
     this.DestinationPosition = new Vector3(packet.Read <float>(), packet.Read <float>(), packet.Read <float>());
     this.Angle        = packet.Read <float>();
     this.State        = packet.Read <uint>();
     this.StateFlag    = packet.Read <uint>();
     this.Motion       = packet.Read <uint>();
     this.MotionEx     = packet.Read <int>();
     this.Loop         = packet.Read <int>();
     this.MotionOption = packet.Read <uint>();
     this.TickCount    = packet.Read <long>();
 }
Exemplo n.º 16
0
 public PingPacket(INetPacketStream packet)
 {
     try
     {
         this.Time      = packet.Read <int>();
         this.IsTimeOut = false;
     }
     catch (Exception)
     {
         this.Time      = 0;
         this.IsTimeOut = true;
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates a new <see cref="PartyChangeTroupPacket"/> object.
 /// </summary>
 /// <param name="packet">Incoming packet</param>
 public PartyChangeTroupPacket(INetPacketStream packet)
 {
     this.PlayerId = packet.Read <uint>();
     this.SendName = packet.Read <int>() == 1;
     if (this.SendName)
     {
         Name = packet.Read <string>();
     }
     else
     {
         Name = null;
     }
 }
Exemplo n.º 18
0
        public override void HandleMessage(INetPacketStream packet)
        {
            base.HandleMessage(packet);

            var data = packet.Read <byte>(packet.Size);

            using (var p = new PhotonPacket())
            {
                var b = "fb000000720001f3060000010178000000605bc64a01ae3daf0a34bc84fe47a16f1bdf7a2744e9075317d236c483e807829908849fb713d3a8fd6f732066080634f8dcfb811d092b7fe489ffe71362c87df370c5eb47a4efa55dc833cfc0f746f1ed6013cc10b1967b1bd5451046f7bb96ac".ToArray();
                p.Write(b, 0, b.Length);
                Send(p);
            }
        }
Exemplo n.º 19
0
        public override INetPacketStream Handle(NetUser connection, INetPacketStream stream)
        {
            if (stream.Read <bool>())
            {
                Logger.Get <RegisterGameServerHandler>().LogInformation("GameServer registration has been granted.");
            }
            else
            {
                Logger.Get <RegisterGameServerHandler>().LogWarning("GameServer registration has been refused.");
            }

            return(null);
        }
Exemplo n.º 20
0
        public static void OnPreJoin(ClusterClient client, INetPacketStream packet)
        {
            var         pak = new PreJoinPacket(packet);
            var         clusterConfiguration = DependencyContainer.Instance.Resolve <ClusterConfiguration>();
            DbCharacter dbCharacter          = null;

            using (var database = DependencyContainer.Instance.Resolve <IDatabase>())
                dbCharacter = database.Characters.Get(pak.CharacterId);

            // Check if character exist.
            if (dbCharacter == null)
            {
                Logger.LogWarning($"[SECURITY] Unable to prejoin character id '{pak.CharacterName}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  $"Reason: no character with id {pak.CharacterId}.");
                client.Disconnect();
                return;
            }

            // Check if the character is deleted.
            if (dbCharacter.IsDeleted)
            {
                Logger.LogWarning($"[SECURITY] Unable to prejoin with character '{dbCharacter.Name}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  "Reason: character is deleted.");
                return;
            }

            // Check if given username is the real owner of this character.
            if (!pak.Username.Equals(dbCharacter.User.Username, StringComparison.OrdinalIgnoreCase))
            {
                Logger.LogWarning($"[SECURITY] Unable to prejoin character '{dbCharacter.Name}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  "Reason: character is not owned by this user.");
                client.Disconnect();
                return;
            }

            // Check if presented bank code is correct.
            if (clusterConfiguration.EnableLoginProtect &&
                LoginProtect.GetNumPadToPassword(client.LoginProtectValue, pak.BankCode) != dbCharacter.BankCode)
            {
                Logger.LogWarning($"Unable to prejoin character '{dbCharacter.Name}' for user '{pak.Username}' from {client.RemoteEndPoint}. " +
                                  "Reason: bad bank code.");
                client.LoginProtectValue = new Random().Next(0, 1000);
                ClusterPacketFactory.SendLoginProtect(client, client.LoginProtectValue);
                return;
            }

            // Finally, we connect the player.
            ClusterPacketFactory.SendJoinWorld(client);
            Logger.LogInformation("Character '{0}' has prejoin successfully the game for user '{1}' from {2}.",
                                  dbCharacter.Name, pak.Username, client.RemoteEndPoint);
        }
Exemplo n.º 21
0
        public static void OnCloseExistingConnection(LoginClient client, INetPacketStream packet)
        {
            var loginServer           = DependencyContainer.Instance.Resolve <ILoginServer>();
            var closeConnectionPacket = new CloseConnectionPacket(packet);
            var otherConnectedClient  = loginServer.GetClientByUsername(closeConnectionPacket.Username);

            if (otherConnectedClient == null)
            {
                Logger.LogWarning($"Cannot find user with username '{closeConnectionPacket.Username}'.");
                return;
            }

            // TODO: disconnect client from server and ISC.
        }
Exemplo n.º 22
0
        public override void HandleMessage(INetPacketStream packet)
        {
            var header = (PacketHeaderType)packet.Read <int>();

            switch (header)
            {
            case PacketHeaderType.QueryData:
                string uniqueId = packet.Read <string>();
                string data     = packet.Read <string>();

                Task.Run(async() => await QueryData(uniqueId, data));
                break;
            }
        }
Exemplo n.º 23
0
        public void CreateNetPacketStreamFromDefaultProcessorTest()
        {
            string randomString = this._faker.Lorem.Sentence(3);

            byte[] messageData = BitConverter.GetBytes(randomString.Length).Concat(Encoding.UTF8.GetBytes(randomString)).ToArray();

            INetPacketStream packetStream = this._packetProcessor.CreatePacket(messageData);

            Assert.NotNull(packetStream);
            string packetStreamString = packetStream.Read <string>();

            Assert.NotNull(packetStreamString);
            Assert.Equal(randomString, packetStreamString);
        }
 public NetServerClientTests()
 {
     _randomizer          = new Randomizer((int)DateTime.UtcNow.Ticks);
     _serverConfiguration = new NetServerConfiguration("127.0.0.1", 4444);
     _serverMock          = new NetServerMock <CustomClient>(_serverConfiguration);
     _customClient        = new CustomClient(null)
     {
         Server = _serverMock.Object
     };
     _otherClient       = new CustomClient(null);
     _customClientsList = Enumerable.Repeat(new CustomClient(null), _randomizer.Byte());
     _packet            = new NetPacket();
     _packet.Write(_randomizer.String(_randomizer.Byte()));
 }
Exemplo n.º 25
0
 public void Serialize(INetPacketStream packet)
 {
     packet.Write(Count);
     for (int level = 0; level < TaskbarSystem.MaxTaskbarItemLevels; level++)
     {
         for (int slot = 0; slot < TaskbarSystem.MaxTaskbarItems; slot++)
         {
             if (Shortcuts[level][slot] != null && Shortcuts[level][slot].Type != ShortcutType.None)
             {
                 packet.Write(level);
                 Shortcuts[level][slot].Serialize(packet);
             }
         }
     }
 }
Exemplo n.º 26
0
        public void Serialize(INetPacketStream packet)
        {
            packet.Write(SlotIndex);
            packet.Write((uint)Type);
            packet.Write(ObjectId);
            packet.Write((uint)ObjectType);
            packet.Write(ObjectIndex);
            packet.Write(UserId);
            packet.Write(ObjectData);

            if (Type == ShortcutType.Chat)
            {
                packet.Write(Text);
            }
        }
Exemplo n.º 27
0
        public AddTaskbarAppletPacket(INetPacketStream packet)
        {
            SlotIndex   = packet.Read <byte>();
            Type        = (ShortcutType)packet.Read <uint>();
            ObjectId    = packet.Read <uint>();
            ObjectType  = (ShortcutObjectType)packet.Read <uint>();
            ObjectIndex = packet.Read <uint>();
            UserId      = packet.Read <uint>();
            ObjectData  = packet.Read <uint>();
            Text        = null;

            if (Type == ShortcutType.Chat)
            {
                Text = packet.Read <string>();
            }
        }
Exemplo n.º 28
0
        public CertifyPacket(INetPacketStream packet, bool useEncryptedPassword)
        {
            this.BuildVersion      = packet.Read <string>();
            this.Username          = packet.Read <string>();
            this.Password          = null;
            this.EncryptedPassword = null;

            if (useEncryptedPassword)
            {
                this.EncryptedPassword = packet.ReadArray <byte>(16 * 42);
            }
            else
            {
                this.Password = packet.Read <string>();
            }
        }
Exemplo n.º 29
0
        public override void HandleMessage(INetPacketStream packet)
        {
            var jsonValue = packet.Read <string>();

            try
            {
                var value = InkAction.Deserialize(jsonValue);

                Console.WriteLine($"[{this.Id}] Processing action " + value.InkActionType.ToString());
                HandleMessageAsync(value).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Deserialization exception: " + ex.ToString());
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Creates a new <see cref="JoinPacket"/> object.
 /// </summary>
 /// <param name="packet">Incoming packet</param>
 public JoinPacket(INetPacketStream packet)
 {
     this.WorldId           = packet.Read <int>();
     this.PlayerId          = packet.Read <int>();
     this.AuthenticationKey = packet.Read <int>();
     this.PartyId           = packet.Read <int>();
     this.GuildId           = packet.Read <int>();
     this.GuildWarId        = packet.Read <int>();
     this.IdOfMulti         = packet.Read <int>(); // what is this?
     this.Slot           = packet.Read <byte>();
     this.PlayerName     = packet.Read <string>();
     this.Username       = packet.Read <string>();
     this.Password       = packet.Read <string>();
     this.MessengerState = packet.Read <int>();
     this.MessengerCount = packet.Read <int>();
 }