Example #1
0
        private void OnJoin(Packet packet)
        {
            //TODO: Use all fields.

            var characterId  = packet.ReadInt32();
            var patchVersion = packet.ReadByte();
            var hdInfo       = packet.ReadString();

            Character = User.Characters.FirstOrDefault(c => c.Id == characterId);

            if (Character != null)
            {
                Console.WriteLine(Character.GetHashCode());

                InventoryItems = new ItemContainer <InventoryItem>(Character, Character.InventoryItems, (byte)Define.MAX_INVENTORY, (byte)Define.MAX_HUMAN_PARTS, Constants.InventorySlots);
                QuestItems     = new ItemContainer <QuestItem>(Character, Character.QuestItems, (byte)Define.MAX_INVENTORY, 0, Constants.QuestSlots);

                StorageItems = new ItemContainer <StorageItem>(Character, Character.StorageItems, 0, 0, new byte[] { });                //TODO: Implement storage items.

                var response = new Packet(Opcode.JOIN_RIGHT);

                response.WriteInt32(characterId);

                response.WriteInt32(Character.WorldId);
                response.WritePosition(Character.Position);

                response.WriteBoolean(false);           //Is festival
                response.WriteInt32(0);                 //Festival 'yday'

                Send(response);

                var joinSnapshot = new Snapshot();

                joinSnapshot.SetType(SnapshotType.UPDATE_SERVER_TIME);
                joinSnapshot.WriteInt32(DateTime.UtcNow.GetUnixTimestamp());

                WriteObjectData(joinSnapshot, Character, true);

                Send(joinSnapshot);

                var spawnNearPlayers = new Snapshot();
                foreach (var player in NearPlayers)
                {
                    WriteObjectData(spawnNearPlayers, player.Character);
                }

                Send(spawnNearPlayers);

                var spawnNewPlayer = new Snapshot();
                WriteObjectData(spawnNewPlayer, Character);

                SendNearPlayers(spawnNewPlayer);
            }
            else
            {
                //NOTE: In theory, it's possible to send JOIN_ERROR and an error code, but the client doesn't seem to use it.

                Disconnect();
            }
        }
Example #2
0
        private void OnJoin(Packet packet)
        {
            //TODO: Use all fields.

            var characterId = packet.ReadInt32();
            var patchVersion = packet.ReadByte();
            var hdInfo = packet.ReadString();

            Character = User.Characters.FirstOrDefault(c => c.Id == characterId);

            if (Character != null)
            {
                Console.WriteLine(Character.GetHashCode());

                InventoryItems = new ItemContainer<InventoryItem>(Character, Character.InventoryItems, (byte) Define.MAX_INVENTORY, (byte) Define.MAX_HUMAN_PARTS, Constants.InventorySlots);
                QuestItems = new ItemContainer<QuestItem>(Character, Character.QuestItems, (byte) Define.MAX_INVENTORY, 0, Constants.QuestSlots);

                StorageItems = new ItemContainer<StorageItem>(Character, Character.StorageItems, 0, 0, new byte[] { }); //TODO: Implement storage items.

                var response = new Packet(Opcode.JOIN_RIGHT);

                response.WriteInt32(characterId);

                response.WriteInt32(Character.WorldId);
                response.WritePosition(Character.Position);

                response.WriteBoolean(false); //Is festival
                response.WriteInt32(0); //Festival 'yday'

                Send(response);

                var joinSnapshot = new Snapshot();

                joinSnapshot.SetType(SnapshotType.UPDATE_SERVER_TIME);
                joinSnapshot.WriteInt32(DateTime.UtcNow.GetUnixTimestamp());

                WriteObjectData(joinSnapshot, Character, true);

                Send(joinSnapshot);

                var spawnNearPlayers = new Snapshot();
                foreach (var player in NearPlayers)
                    WriteObjectData(spawnNearPlayers, player.Character);

                Send(spawnNearPlayers);

                var spawnNewPlayer = new Snapshot();
                WriteObjectData(spawnNewPlayer, Character);

                SendNearPlayers(spawnNewPlayer);
            }
            else
            {
                //NOTE: In theory, it's possible to send JOIN_ERROR and an error code, but the client doesn't seem to use it.

                Disconnect();
            }
        }
Example #3
0
        private void OnCertify(Packet packet)
        {
            var name     = packet.ReadString();
            var password = packet.ReadString();

            //TODO: Find out what all the unused fields are and use them.

            var hdsn        = packet.ReadString();
            var ipKey       = packet.ReadBytes(21);
            var version     = packet.ReadUInt32();
            var realVersion = packet.ReadUInt32();
            var opFlag      = packet.ReadByte();
            var otpPassword = packet.ReadString();

            var user = Database.Users.FirstOrDefault(c => c.Name == name);

            //TODO: Add ECard.

            if (user != null)
            {
                if (user.Password == password)
                {
                    if (!Server.Connections.Any(c => c.User != null && c.User.Name == user.Name))
                    {
                        if (realVersion == Constants.Version)
                        {
                            User = user;

                            var result = new Packet(Opcode.CERTIFYRESULT);
                            result.WriteInt32((int)Error.CERT_OK);
                            result.WriteInt32(0);                             //Not required to fill in real name.
                            result.WriteBoolean(false);                       //Expansion
                            Send(result);

                            CharacterList();
                        }
                        else
                        {
                            var result = new Packet(Opcode.CERTIFYRESULT);
                            result.WriteInt32((int)(realVersion < Constants.Version ? Error.ERR_VERSION_TOO_LOW : Error.ERR_VERSION_MAINTAIN));
                            Send(result);

                            Disconnect();
                        }
                    }
                    else
                    {
                        var result = new Packet(Opcode.CERTIFYRESULT);
                        result.WriteInt32((int)Error.ERR_ACCOUNT_EXIST);
                        Send(result);

                        Disconnect();
                    }
                }
                else
                {
                    var result = new Packet(Opcode.CERTIFYRESULT);
                    result.WriteInt32((int)((uint)Error.CERT_CHARGE_CERTIFY_FAILED << 16));
                    Send(result);
                }
            }
            else
            {
                var result = new Packet(Opcode.CERTIFYRESULT);
                result.WriteInt32((int)((uint)Error.CERT_CHARGE_CERTIFY_FAILED << 16 | 1));
                Send(result);
            }
        }
Example #4
0
        private void OnCertify(Packet packet)
        {
            var name = packet.ReadString();
            var password = packet.ReadString();

            //TODO: Find out what all the unused fields are and use them.

            var hdsn = packet.ReadString();
            var ipKey = packet.ReadBytes(21);
            var version = packet.ReadUInt32();
            var realVersion = packet.ReadUInt32();
            var opFlag = packet.ReadByte();
            var otpPassword = packet.ReadString();

            var user = Database.Users.FirstOrDefault(c => c.Name == name);

            //TODO: Add ECard.

            if (user != null)
            {
                if(user.Password == password)
                {
                    if (!Server.Connections.Any(c => c.User != null && c.User.Name == user.Name))
                    {
                        if (realVersion == Constants.Version)
                        {
                            User = user;

                            var result = new Packet(Opcode.CERTIFYRESULT);
                            result.WriteInt32((int) Error.CERT_OK);
                            result.WriteInt32(0); //Not required to fill in real name.
                            result.WriteBoolean(false); //Expansion
                            Send(result);

                            CharacterList();
                        }
                        else
                        {
                            var result = new Packet(Opcode.CERTIFYRESULT);
                            result.WriteInt32((int) (realVersion < Constants.Version ? Error.ERR_VERSION_TOO_LOW : Error.ERR_VERSION_MAINTAIN));
                            Send(result);

                            Disconnect();
                        }
                    }
                    else
                    {
                        var result = new Packet(Opcode.CERTIFYRESULT);
                        result.WriteInt32((int) Error.ERR_ACCOUNT_EXIST);
                        Send(result);

                        Disconnect();
                    }
                }
                else
                {
                    var result = new Packet(Opcode.CERTIFYRESULT);
                    result.WriteInt32((int) ((uint) Error.CERT_CHARGE_CERTIFY_FAILED << 16));
                    Send(result);
                }
            }
            else
            {
                var result = new Packet(Opcode.CERTIFYRESULT);
                result.WriteInt32((int) ((uint)Error.CERT_CHARGE_CERTIFY_FAILED << 16 | 1));
                Send(result);
            }
        }