Esempio n. 1
0
        private void OnCharacterListRequest(NetPacketBase packet)
        {
            var buildDate = packet.Read <string>();
            var authKey   = packet.Read <int>();
            var username  = packet.Read <string>();
            var password  = packet.Read <string>();
            var serverId  = packet.Read <int>();
            var account   = this.GetUserAccount(username, password);

            if (account == null)
            {
                Log.Warning("Unknow account for username '{0}'.", username);
                this.Server.RemoveClient(this);
                return;
            }

            this.Id = account.Id;
            this.selectedServerId = serverId;
            var characters = from x in DatabaseService.Characters.GetAll(c => c.Items)
                             where x.AccountId == account.Id
                             select x;

            this.SendWorldIp(this.GetWorldIpBySelectedServerId());
            this.SendCharacterList(authKey, characters.ToList());

            if (this.Server.ClusterConfiguration.EnableLoginProtect)
            {
                this.SendLoginNumPad();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the server list.
        /// </summary>
        /// <param name="packet"></param>
        private void OnUpdateServerList(NetPacketBase packet)
        {
            LoginServer.Clusters.Clear();
            var clusterCount = packet.Read <int>();

            for (int i = 0; i < clusterCount; ++i)
            {
                var clusterId   = packet.Read <int>();
                var clusterIp   = packet.Read <string>();
                var clusterName = packet.Read <string>();

                var cluster = new ClusterServerInfo(clusterId, clusterIp, clusterName);

                var worldsCount = packet.Read <int>();

                for (int j = 0; j < worldsCount; ++j)
                {
                    var worldId               = packet.Read <int>();
                    var worldIp               = packet.Read <string>();
                    var worldName             = packet.Read <string>();
                    var worldCapacity         = packet.Read <int>();
                    var worldConnectedPlayers = packet.Read <int>();

                    cluster.Worlds.Add(new WorldServerInfo(worldId, cluster.Id, worldCapacity, worldIp, worldName, worldConnectedPlayers));
                }

                LoginServer.Clusters.Add(cluster);
            }
        }
Esempio n. 3
0
        public void OnPlayerSetFollowTarget(NetPacketBase packet)
        {
            var moverId = packet.Read <uint>();

            this.Player.FollowDistance = packet.Read <float>();

            if (moverId == this.Player.ObjectId)
            {
                this.Player.Target(this.Player);
                return;
            }

            var targetMover = this.Player.GetSpawnedObjectById <Mover>((int)moverId);

            if (targetMover == null)
            {
                Log.Error("[PLAYERSETDESTOBJ]: Cannot target mover ID: {0}", moverId);
                return;
            }

            this.Player.IsFollowing = true;
            this.Player.MovingFlags = ObjectState.OBJSTA_FMOVE;
            this.Player.Target(targetMover);
            this.Player.DestinationPosition = targetMover.Position.Clone();
            this.Player.SendFollowTarget(this.Player.FollowDistance);
        }
Esempio n. 4
0
        private void OnPlayerBehavior(NetPacketBase packet)
        {
            var startPositionX = packet.Read <float>();
            var startPositionY = packet.Read <float>();
            var startPositionZ = packet.Read <float>();
            var startPosition  = new Vector3(startPositionX, startPositionY, startPositionZ);

            var directionX      = packet.Read <float>();
            var directionY      = packet.Read <float>();
            var directionZ      = packet.Read <float>();
            var directionVector = new Vector3(directionX, directionY, directionZ);

            var angle = packet.Read <float>();

            this.Player.MovingFlags = (ObjectState)packet.Read <uint>();
            this.Player.MotionFlags = (StateFlags)packet.Read <int>();
            this.Player.ActionFlags = packet.Read <int>();
            var motionEx     = packet.Read <int>();
            var loop         = packet.Read <int>();
            var motionOption = packet.Read <int>();
            var tick         = packet.Read <long>();

            this.Player.Position  = startPosition.Clone();
            this.Player.Position += directionVector;
            this.Player.DestinationPosition.Reset();

            this.Player.IsMovingWithKeyboard = this.Player.MovingFlags.HasFlag(ObjectState.OBJSTA_FMOVE);

            this.Player.SendMoverBehavior(directionVector, motionEx, loop, motionOption, tick);
        }
Esempio n. 5
0
        private void OnPlayerAngle(NetPacketBase packet)
        {
            var startPositionX = packet.Read <float>();
            var startPositionY = packet.Read <float>();
            var startPositionZ = packet.Read <float>();
            var startPosition  = new Vector3(startPositionX, startPositionY, startPositionZ);

            var directionX      = packet.Read <float>();
            var directionY      = packet.Read <float>();
            var directionZ      = packet.Read <float>();
            var directionVector = new Vector3(directionX, directionY, directionZ);

            var   angle    = packet.Read <float>();
            var   angleY   = packet.Read <float>();
            float flySpeed = packet.Read <float>();

            this.Player.TurnAngle = packet.Read <float>();
            var tick = packet.Read <long>();

            this.Player.Angle    = angle;
            this.Player.AngleFly = angle;
            this.Player.Position = startPosition.Clone();

            if (directionVector.IsZero())
            {
                this.Player.DestinationPosition = this.Player.Position.Clone();
            }

            this.Player.SendMoverAngle(directionVector, tick, this.Player.TurnAngle);
        }
Esempio n. 6
0
        private void OnPlayerMoved2(NetPacketBase packet)
        {
            var startPositionX = packet.Read <float>();
            var startPositionY = packet.Read <float>();
            var startPositionZ = packet.Read <float>();
            var startPosition  = new Vector3(startPositionX, startPositionY, startPositionZ);

            var directionX      = packet.Read <float>();
            var directionY      = packet.Read <float>();
            var directionZ      = packet.Read <float>();
            var directionVector = new Vector3(directionX, directionY, directionZ);

            if (directionVector.IsZero())
            {
                this.Player.DestinationPosition = startPosition.Clone();
            }

            this.Player.Angle    = packet.Read <float>();
            this.Player.AngleFly = packet.Read <float>();
            var flySpeed  = packet.Read <float>();
            var turnAngle = packet.Read <float>();

            this.Player.MovingFlags = (ObjectState)packet.Read <uint>();
            this.Player.MotionFlags = (StateFlags)packet.Read <int>();
            this.Player.ActionFlags = packet.Read <int>();
            var motionEx     = packet.Read <int>();
            var loop         = packet.Read <int>();
            var motionOption = packet.Read <int>();
            var tick         = packet.Read <long>();
            var frame        = packet.Read <byte>();

            this.Player.IsFlying = this.Player.MovingFlags.HasFlag(ObjectState.OBJSTA_FMOVE);

            this.Player.SendMoverMoved(directionVector, motionEx, loop, motionOption, tick, frame, turnAngle);
        }
Esempio n. 7
0
 /// <summary>
 /// Send to a collection of clients.
 /// </summary>
 /// <param name="clients">Clients</param>
 /// <param name="packet">Packet to send</param>
 public static void SendTo(ICollection <NetConnection> clients, NetPacketBase packet)
 {
     foreach (var client in clients)
     {
         client.Send(packet);
     }
 }
Esempio n. 8
0
 public virtual void SendToVisible(NetPacketBase packet)
 {
     foreach (Player player in this.SpawnedObjects.Where(x => x is Player))
     {
         player.Send(packet);
     }
 }
Esempio n. 9
0
        private void OnItemMoveInInventory(NetPacketBase packet)
        {
            var itemType   = packet.Read <byte>();
            var sourceSlot = packet.Read <byte>();
            var destSlot   = packet.Read <byte>();

            this.Player.Inventory.Move(sourceSlot, destSlot);
        }
Esempio n. 10
0
        public override void HandleMessage(NetPacketBase packet)
        {
            // -- Create datablock from string
            DataBlock dataBlock = new DataBlock(Encoding.ASCII.GetBytes(packet.Read <string>()));

            // -- Pass datablock to datablock controller
            NetworkManager.GetInstance().ProcessDataBlock(dataBlock, this);
        }
Esempio n. 11
0
        /// <summary>
        /// Process the result of the authentication.
        /// </summary>
        /// <param name="packet"></param>
        private void OnAuthenticationResult(NetPacketBase packet)
        {
            var result = packet.Read <bool>();

            if (result == false)
            {
                Environment.Exit(0);
            }
        }
Esempio n. 12
0
        private void OnJoin(NetPacketBase packet)
        {
            var worldId        = packet.Read <int>();
            var playerId       = packet.Read <int>();
            var authKey        = packet.Read <int>();
            var partyId        = packet.Read <int>();
            var guildId        = packet.Read <int>();
            var guildWarId     = packet.Read <int>();
            var idOfMulti      = packet.Read <int>(); // what is this?
            var slot           = packet.Read <byte>();
            var playerName     = packet.Read <string>();
            var username       = packet.Read <string>();
            var password       = packet.Read <string>();
            var messengerState = packet.Read <int>();
            var messengerCount = packet.Read <int>();

            // Not using messenger yet

            this.CurrentUser = DatabaseService.Users.Get(x =>
                                                         x.Username.ToLower() == username.ToLower() &&
                                                         x.Password.ToLower() == password.ToLower() &&
                                                         x.Authority > 0);

            if (this.CurrentUser == null)
            {
                Log.Warning("Unknow account: '{0}'.", username);
                this.Server.RemoveClient(this);
                return;
            }

            DbCharacter character = DatabaseService.Characters.Get(x =>
                                                                   x.AccountId == this.CurrentUser.Id &&
                                                                   x.Name.ToLower() == playerName.ToLower() &&
                                                                   x.Id == playerId, includes => includes.Items); // TODO: include more

            if (character == null)
            {
                Log.Warning("Cannot find character '{0}' with id {1} for account '{2}'.", playerName, playerId, this.CurrentUser.Id);
                this.Server.RemoveClient(this);
                return;
            }

            this.Player = new Player(this, character);
            this.Player.SendPlayerSpawn();

            Map playerMap = WorldServer.MapManager[this.Player.MapId];

            if (playerMap == null)
            {
                Log.Error("Invalid MapId: {0}", this.Player.MapId);
                this.Server.RemoveClient(this);
                return;
            }

            playerMap.AddObject(this.Player);
        }
Esempio n. 13
0
 /// <summary>
 /// Send a packet to the player.
 /// </summary>
 /// <param name="packet"></param>
 public void Send(NetPacketBase packet)
 {
     try
     {
         if (this.Client.Socket != null && this.Client.Socket.Connected)
         {
             this.Client.Send(packet);
         }
     }
     catch { }
 }
Esempio n. 14
0
        public void OnQueryGetDestObj(NetPacketBase packet)
        {
            var objectId = packet.Read <int>();
            var mover    = this.Player.GetSpawnedObjectById <Mover>(objectId);

            if (mover != null)
            {
                Log.Debug("Mover {0} arrived to destination", mover.Name);
                mover.Position = mover.DestinationPosition.Clone();
            }
        }
Esempio n. 15
0
        protected override void HandleMessage(NetPacketBase packet)
        {
            var header = packet.Read <int>();

            switch (header)
            {
            case 0:
                var message = packet.Read <string>();
                Console.WriteLine("Received: {0}", message);
                break;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Receive messages from the client.
        /// </summary>
        /// <param name="packet"></param>
        public override void HandleMessage(NetPacketBase packet)
        {
            string 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.Send(p);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Handle incoming packets.
        /// </summary>
        /// <param name="packet">Incoming packet</param>
        public override void HandleMessage(NetPacketBase packet)
        {
            packet.Position += 13;
            var packetHeaderNumber = packet.Read <uint>();
            var packetHeader       = (PacketType)packetHeaderNumber;
            var pak = packet as FFPacket;

            if (!FFPacketHandler.Invoke(this, packetHeader, packet))
            {
                FFPacket.UnknowPacket <PacketType>(packetHeaderNumber, 2);
            }
        }
Esempio n. 18
0
        private void OnItemUnequip(NetPacketBase packet)
        {
            var itemUniqueId = packet.Read <int>();
            var item         = this.Player.Inventory.GetItemByUniqueId(itemUniqueId);

            if (item == null)
            {
                return;
            }

            this.Player.Inventory.Unequip(item);
        }
Esempio n. 19
0
        /// <summary>
        /// Process the player moves.
        /// </summary>
        /// <param name="packet"></param>
        private void OnSnapshotDestPos(NetPacketBase packet)
        {
            var posX    = packet.Read <float>();
            var posY    = packet.Read <float>();
            var posZ    = packet.Read <float>();
            var forward = packet.Read <byte>();

            this.Player.IsMovingWithKeyboard = false;
            this.Player.MovingFlags          = ObjectState.OBJSTA_NONE;
            this.Player.MovingFlags         |= ObjectState.OBJSTA_FMOVE;
            this.Player.DestinationPosition  = new Vector3(posX, posY, posZ);
            this.Player.SendMoverMoving();
        }
Esempio n. 20
0
        /// <summary>
        /// Handle incoming packets.
        /// </summary>
        /// <param name="packet">Incoming packet</param>
        public override void HandleMessage(NetPacketBase packet)
        {
            packet.Position = 17;

            var packetHeaderNumber = packet.Read <uint>();
            var packetHeader       = (PacketType)packetHeaderNumber;

            Log.Debug("Recieve World packet: {0}", packetHeader);

            if (!FFPacketHandler.Invoke(this, packetHeader, packet))
            {
                FFPacket.UnknowPacket <PacketType>(packetHeaderNumber, 8);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Handles the incoming messages.
        /// </summary>
        /// <param name="packet"></param>
        public override void HandleMessage(NetPacketBase packet)
        {
            var packetHeaderNumber = packet.Read <int>();
            var packetHeader       = (InterHeaders)packetHeaderNumber;

            switch (packetHeader)
            {
            case InterHeaders.Authentication: this.OnAuthenticate(packet); break;

            default:
                Log.Warning("Unknow packet: 0x{0}", packetHeaderNumber.ToString("X2"));
                break;
            }
        }
Esempio n. 22
0
    protected override void HandleMessage(NetPacketBase packet)
    {
        try
        {
            // -- Create datablock from string
            DataBlock dataBlock = new DataBlock(Encoding.ASCII.GetBytes(packet.Read <string>()));

            // -- Pass datablock to datablock controller
            _networkManager.ProcessDataBlock(dataBlock);
        }
        catch (Exception e)
        {
            Logger.Log(LogLevel.L4_RecoverableError, "Error handling messge in NetworkSocket: " + e.StackTrace, "NetworkMessages.FromServer");
        }
    }
Esempio n. 23
0
        /// <summary>
        /// Handles the incoming data.
        /// </summary>
        /// <param name="packet">Incoming packet</param>
        public override void HandleMessage(NetPacketBase packet)
        {
            var packetHeaderNumber = packet.Read <int>();
            var packetHeader       = (InterHeaders)packetHeaderNumber;

            Log.Debug("Recieved: {0}", packetHeader);

            switch (packetHeader)
            {
            case InterHeaders.CanAuthticate: this.Authenticate(); break;

            case InterHeaders.AuthenticationResult: this.OnAuthenticationResult(packet); break;

            default: Log.Warning("Unknow packet header: 0x{0}", packetHeaderNumber.ToString("X2")); break;
            }
        }
Esempio n. 24
0
        private void OnChat(NetPacketBase packet)
        {
            var chatMessage = packet.Read <string>();

            if (string.IsNullOrEmpty(chatMessage))
            {
                return;
            }

            if (chatMessage.StartsWith("/"))
            {
                this.Player.Chat.CommandChat(chatMessage);
            }
            else
            {
                this.Player.SendNormalChat(chatMessage);
            }
        }
Esempio n. 25
0
        private void OnItemUsage(NetPacketBase packet)
        {
            var itemUniqueId = (packet.Read <int>() >> 16) & 0xFFFF;
            var objectId     = packet.Read <int>();
            var equipPart    = packet.Read <int>();

            var item = this.Player.Inventory.GetItemByUniqueId(itemUniqueId);

            if (item != null && item.Id > 0)
            {
                if (item.Data.Parts > 0)
                {
                    this.Player.Inventory.Equip(item);
                }
                //else
                //    this.Player.Inventory.UseItem(item);
            }
        }
Esempio n. 26
0
        private void OnMoveByKeyboard(NetPacketBase packet)
        {
            this.Player.IsFollowing = false;

            var startPositionX = packet.Read <float>();
            var startPositionY = packet.Read <float>();
            var startPositionZ = packet.Read <float>();
            var startPosition  = new Vector3(startPositionX, startPositionY, startPositionZ);

            var directionX      = packet.Read <float>();
            var directionY      = packet.Read <float>();
            var directionZ      = packet.Read <float>();
            var directionVector = new Vector3(directionX, directionY, directionZ);

            this.Player.Position    = startPosition.Clone();
            this.Player.Position   += directionVector;
            this.Player.Angle       = packet.Read <float>();
            this.Player.MovingFlags = (ObjectState)packet.Read <uint>();
            this.Player.MotionFlags = (StateFlags)packet.Read <int>();
            this.Player.ActionFlags = packet.Read <int>();
            var motionEx     = packet.Read <int>();
            var loop         = packet.Read <int>();
            var motionOption = packet.Read <int>();
            var tick         = packet.Read <long>();

            this.Player.DestinationPosition.Reset();

            if (this.Player.MovingFlags.HasFlag(ObjectState.OBJSTA_FMOVE) ||
                this.Player.MovingFlags.HasFlag(ObjectState.OBJSTA_BMOVE))
            {
                this.Player.IsMovingWithKeyboard = true;
            }
            else
            {
                this.Player.IsMovingWithKeyboard = false;
            }

            this.Player.DestinationPosition = this.Player.Position.Clone();

            this.Player.SendMoveByKeyboard(directionVector, motionEx, loop, motionOption, tick);
        }
Esempio n. 27
0
        /// <summary>
        /// Sends a packet through the network.
        /// </summary>
        /// <param name="packet"></param>
        public void Send(NetPacketBase packet)
        {
            if (!this.IsConnected)
            {
                throw new SocketException();
            }

            byte[] buffer = packet.Buffer;

            if (buffer.Length <= 0)
            {
                return;
            }

            this._socketSendArgs.SetBuffer(buffer, 0, buffer.Length);

            if (this.Socket != null)
            {
                this.Socket.SendAsync(this._socketSendArgs);
            }
        }
Esempio n. 28
0
        private void OnDeleteCharacter(NetPacketBase packet)
        {
            var username             = packet.Read <string>();
            var password             = packet.Read <string>();
            var passwordVerification = packet.Read <string>();
            var characterId          = packet.Read <int>();
            var authKey = packet.Read <int>();
            var account = this.GetUserAccount(username, password);

            if (account == null)
            {
                Log.Warning("Unknow account for username '{0}'.", username);
                this.Server.RemoveClient(this);
                return;
            }

            if (password.ToLower() != passwordVerification.ToLower())
            {
                Log.Error("Password doesn't match for client '{0}' with id {1}", account.Username, account.Id);
                this.SendClusterError(ErrorType.WRONG_PASSWORD);
                return;
            }

            var character = DatabaseService.Characters.Get(x => x.Id == characterId);

            if (character == null)
            {
                Log.Warning("Unknow character with Id: {0}", characterId);
                return;
            }

            DatabaseService.Characters.Delete(character);
            Log.Info("Character '{0}' has been deleted.", character.Name);

            var characters = from x in DatabaseService.Characters.GetAll()
                             where x.AccountId == account.Id
                             select x;

            this.SendCharacterList(authKey, characters.ToList());
        }
Esempio n. 29
0
        private void OnSnapshot(NetPacketBase packet)
        {
            var snapshotCount = packet.Read <byte>();

            while (snapshotCount != 0)
            {
                var snapshotHeaderNumber = packet.Read <short>();
                var snapshotHeader       = (SnapshotType)snapshotHeaderNumber;

                Log.Debug("Recieve snapshot: {0}", snapshotHeader);

                switch (snapshotHeader)
                {
                case SnapshotType.DESTPOS: this.OnSnapshotDestPos(packet); break;

                default: FFPacket.UnknowPacket <SnapshotType>((uint)snapshotHeaderNumber, 4); break;
                }
                ;

                snapshotCount--;
            }
        }
Esempio n. 30
0
        private void OnUpdateWorldServerList(NetPacketBase packet)
        {
            var worldServerCount = packet.Read <int>();

            for (int i = 0; i < worldServerCount; ++i)
            {
                var worldId               = packet.Read <int>();
                var worldIp               = packet.Read <string>();
                var worldName             = packet.Read <string>();
                var worldCapacity         = packet.Read <int>();
                var worldConnectedPlayers = packet.Read <int>();
                var worldServer           = new WorldServerInfo(
                    worldId,
                    this.clusterServer.ClusterConfiguration.ClusterId,
                    worldCapacity,
                    worldIp,
                    worldName,
                    worldConnectedPlayers);

                this.clusterServer.ConnectedWorldServers.Add(worldServer);
            }
        }