예제 #1
0
        private void OnHotkeyChange(Packet packet)
        {
            var count = packet.ReadInt32();

            for (var i = 0; i < count; i++)
                Character.SetHotkey(packet.ReadInt32(), packet.ReadInt32(), packet.ReadInt32());
        }
예제 #2
0
파일: Join.cs 프로젝트: phjon04/XinFeiFei
        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();
            }
        }
예제 #3
0
파일: States.cs 프로젝트: phjon04/XinFeiFei
        private void OnStateMessage(Packet packet)
        {
            var msg = (StateMessage) packet.ReadByte();
            var state = (StateType) packet.ReadUInt16();
            var group = packet.ReadByte();

            switch (msg)
            {
                case StateMessage.SYS_SET_STATE:
                    switch (state)
                    {
                        case StateType.STATE_MOVE_TO:
                            var unknown = packet.ReadInt32(); //TODO: Figure out what this is.

                            var x = packet.ReadInt32();
                            var y = packet.ReadInt32();
                            var z = packet.ReadInt32();

                            //TODO: Add some basic checking.
                            Character.Position.X = x / 1000f;
                            Character.Position.Y = y / 1000f;
                            Character.Position.Z = z / 1000f;

                            var update = new Snapshot();
                            update.SetType((SnapshotType) 23);
                            update.WriteInt32(Character.GetHashCode());
                            update.WriteBytes(new byte[] { 0x00, 0x0E, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); //TODO: Figure out how this works.
                            update.WriteInt32(x);
                            update.WriteInt32(y);
                            update.WriteInt32(z);

                            SendNearPlayers(update);
                            break;

                        default:
                            Console.WriteLine("OnStateMessage() => StateType not implemented yet! (msg: {0}, state: {1})", msg, state);
                            return;
                    }
                    break;

                default:
                    Console.WriteLine("OnStateMessage() => Message not implemented yet! (msg: {0}, state: {1})", msg, state);
                    return;
            }
        }
예제 #4
0
        private void OnUpdateTaskbar(Packet packet)
        {
            var taskBar = packet.ReadInt32(); //ar:WriteInt(rgn)
            var line = packet.ReadInt32(); //ar:WriteInt(data_line)
            var grid = packet.ReadInt32(); //ar:WriteInt(grid)

            var shortcut = packet.ReadInt32(); //ar:WriteInt(self.m_short_cut)
            var id = packet.ReadInt32(); //ar:WriteInt(self.m_id)
            var type = packet.ReadInt32(); //ar:WriteInt(self.m_type)
            var index = packet.ReadInt32(); //ar:WriteInt(self.m_index)
            var userId = packet.ReadInt32(); //ar:WriteInt(self.m_user_id)
            var data = packet.ReadInt32(); //ar:WriteInt(self.m_data)
            var shortcutString = packet.ReadString(); //ar:WriteString(self.m_string)

            var oldTaskBarItem =
                Character.TaskBarItems.FirstOrDefault(i => i.TaskBar == taskBar && i.Line == line && i.Grid == grid);

            if (oldTaskBarItem != null)
            {
                if (shortcut == 0)
                    Program.Database.DeleteObject(oldTaskBarItem);
                else
                {
                    oldTaskBarItem.Shortcut = shortcut;
                    oldTaskBarItem.ShortcutId = id;
                    oldTaskBarItem.Type = type;
                    oldTaskBarItem.Index = index;
                    oldTaskBarItem.UserId = userId;
                    oldTaskBarItem.Data = data;
                    oldTaskBarItem.String = shortcutString;
                }
            }
            else
            {
                Character.TaskBarItems.Add(new TaskBarItem
                                           {
                                               TaskBar = taskBar,
                                               Line = line,
                                               Grid = grid,
                                               Shortcut = shortcut,
                                               ShortcutId = id,
                                               Type = type,
                                               Index = index,
                                               UserId = userId,
                                               Data = data,
                                               String = shortcutString
                                           });
            }
        }
예제 #5
0
파일: Misc.cs 프로젝트: phjon04/XinFeiFei
        private void OnCollectClientLog(Packet packet)
        {
            var playerId = packet.ReadInt32();
            var systemId = packet.ReadByte();
            var logString = packet.ReadString();

            if (Character != null && Character.Id == playerId)
                Character.LogEntries.Add(new LogEntry {SystemId = systemId, LogString = logString, DateTime = DateTime.Now});
            else
                Disconnect();
        }
예제 #6
0
        private void OnCreatePlayer(Packet packet)
        {
            var result = new Packet(Opcode.CREATEPLAYERRESULT);

            var name = packet.ReadString();
            var hdHash = packet.ReadString();
            var slot = packet.ReadInt32();
            var job = packet.ReadByte();
            var gender = packet.ReadByte();
            var hairMesh = packet.ReadByte();
            var hairColor = packet.ReadUInt32();
            var headMesh = packet.ReadByte();
            var city = packet.ReadInt32();
            var zodiacSign = packet.ReadInt32();
            var country = packet.ReadByte();
            var snCard = packet.ReadString();
            var cardType = packet.ReadInt32();
            var hdSerialNumber = packet.ReadString();
            var binAccount = packet.ReadString();
            var clothList = new int[5];
            for (var i = 0; i < 5; i++)
                clothList[i] = packet.ReadInt32();

            if (!Constants.CharacterCreationEnabled)
            {
                result.WriteInt32((int) Error.ERR_NOCREATE_ALL);
            }
            else if (Database.Characters.Any(c => c.Name == name))
            {
                result.WriteInt32((int) Error.ERR_PLAYER_EXIST);
            }
            else if (User.Characters.Count(c => !c.Deleted && !c.Blocked) > 3 || User.Characters.Count > 10 || User.Characters.Any(c => c.Slot == slot)) //TODO: Check items.
            {
                result.WriteInt32((int) Error.ERR_NOCREATE);
            }
            else
            {
                var character = new Character
                {
                    Name = name,
                    Slot = slot,
                    Job = job,
                    Gender = gender,
                    Appearance = new CharacterAppearance
                    {
                        HairMesh = hairMesh,
                        HairColor = (int) hairColor,
                        HeadMesh = headMesh
                    },
                    PersonalInformation = new PersonalInformation
                    {
                        City = city,
                        ZodiacSign = zodiacSign
                    },
                    Closet = new Closet()
                };

                for (var i = 0; i < 5; i++)
                {
                    if (clothList[i] == 0) continue;

                    character.Closet.Items.Add(new ClosetItem
                                                 {
                                                     ItemId = clothList[i],
                                                     Index = i + 1,
                                                     DateTime = DateTime.UtcNow,
                                                     Equipped = true
                                                 });
                }

                User.Characters.Add(character);

                User.AcceptedAgreement = true;

                Database.SaveChanges(); //TODO: Fix this, shouldn't do a full DB update for this...

                result.WriteInt32((int) Error.ERR_SUCCESS);

                Send(result);

                var playerSlot = new Packet(Opcode.PLAYERSLOT);

                playerSlot.WriteInt32(character.Slot);

                playerSlot.WriteString(character.Name);
                playerSlot.WriteInt32(character.Id);

                playerSlot.WriteInt32(character.WorldId);
                playerSlot.WriteByte(character.Gender);
                playerSlot.WritePosition(character.Position);

                playerSlot.WriteInt32(character.Level);
                playerSlot.WriteInt32(character.Job);

                playerSlot.WriteInt32(character.Stats.STR);
                playerSlot.WriteInt32(character.Stats.STA);
                playerSlot.WriteInt32(character.Stats.DEX);
                playerSlot.WriteInt32(character.Stats.INT);
                playerSlot.WriteInt32(character.Stats.SPI);

                playerSlot.WriteInt32(character.Appearance.HairMesh);
                playerSlot.WriteUInt32((uint) character.Appearance.HairColor);
                playerSlot.WriteInt32(character.Appearance.HeadMesh);

                playerSlot.WriteInt32(character.Blocked ? 1 : 0);
                playerSlot.WriteInt32(character.BlockTime);

                //TODO: Clean this up.

                var container = new ItemContainer<InventoryItem>(character, character.InventoryItems, (byte) Define.MAX_INVENTORY, (byte) Define.MAX_HUMAN_PARTS, Constants.InventorySlots);

                var equipmentItems = container.EquippedItems.ToList();

                playerSlot.WriteInt32(equipmentItems.Count); //TODO: Implement non-fashion items.

                //  for i = 1, count do
                //    parts = LAr:ReadByte(ar)
                //    item_id = LAr:ReadDword(ar)
                //    flag = LAr:ReadDword(ar)
                //    attr = LAr:ReadInt(ar)
                //  end

                foreach (var fashionItem in character.Closet.Items.Where(item => item.Equipped))
                    playerSlot.WriteInt32(fashionItem.ItemId);

                playerSlot.WriteInt32(User.Characters.Count(c => c.Deleted));

                Send(playerSlot);

                return;
            }

            Send(result);
        }