public void DebuffPlayer(ref Player playerToFill)
        {
            playerToFill.PlayerName = ReadUnicode(Constants.PLAYER_NAME_LENGTH);
            playerToFill.sex = (byte)ReadLong();
            playerToFill.playerClass = ReadLong();

            playerToFill.sprite = ReadLong();
            playerToFill.level = (byte)ReadLong();
            playerToFill.exp = ReadLong();
            playerToFill.access = ReadByte();
            playerToFill.isPK = ReadByte();
            readOffset += 2;

            playerToFill.hair = ReadLong();
            playerToFill.eyes = ReadLong();

            playerToFill.ryo = ReadLong();
            playerToFill.vitals[(int)Vitals.HP] = ReadLong();
            playerToFill.vitals[(int)Vitals.MP] = ReadLong();

            for (int i = 0; i < (int)Stats.counter; i++)
            {
                playerToFill.stats[i] = ReadInteger();
            }
            readOffset += 2;

            playerToFill.points = ReadLong();
            //Inventory
            for (int i = 0; i < (int)Equipment.counter; i++)
            {
                playerToFill.equipment[i] = ReadLong();
            }

            for (int i = 0; i < Constants.MAX_INV; i++)
            {
                playerToFill.inventory[i].id = ReadLong();
                playerToFill.inventory[i].amount = ReadLong();
            }
            //Spells
            for (int i = 0; i < Constants.MAX_PLAYER_SPELLS; i++)
            {
                playerToFill.spells[i] = ReadLong();
            }

            //Hotbar
            for (int i = 0; i < Constants.MAX_HOTBAR; i++)
            {
                playerToFill.hotbar[i].slot = ReadLong();
                playerToFill.hotbar[i].sType = (byte)ReadLong();
            }

            //Map
            playerToFill.currentMap = ReadLong();
            playerToFill.x = ReadByte();
            playerToFill.y = ReadByte();
            playerToFill.dir = ReadByte();

            //Switches
            for (int i = 0; i < Constants.MAX_SWITCHES; i++)
            {
                playerToFill.switches[i] = ReadByte();
            }

            //Variables
            for (int i = 0; i < Constants.MAX_VARIABLES; i++)
            {
                playerToFill.variables[i] = ReadLong();
            }
            //PlayerQuests
            for (int i = 0; i < Constants.MAX_PLAYER_QUESTS; i++)
            {
                playerToFill.quests[i].currentObjective = ReadByte();

                playerToFill.quests[i].completed[0] = ReadByte();
                playerToFill.quests[i].completed[1] = ReadByte();
                playerToFill.quests[i].completed[2] = ReadByte();

                playerToFill.quests[i].id = ReadLong();

                playerToFill.quests[i].counter[0] = ReadLong();
                playerToFill.quests[i].counter[1] = ReadLong();
                playerToFill.quests[i].counter[2] = ReadLong();
            }
            //Completed Quest
            for (int i = 0; i < Constants.MAX_QUESTS; i++)
            {
                playerToFill.completedQuest[i] = ReadLong();
            }
            //Guild
            playerToFill.guild = ReadLong();

            playerToFill.minutes = ReadLong();
            playerToFill.hours = ReadLong();
            playerToFill.attackAnimation = ReadLong();

            //Friends
            for (int i = 0; i < Constants.MAX_PLAYER_FRIENDS; i++)
            {
                playerToFill.friends[i].name = ReadUnicode(Constants.PLAYER_NAME_LENGTH);
            }
            //Elements
            for (int i = 0; i < Constants.MAX_ELEMENTS; i++)
            {
                playerToFill.elements[i] = ReadByte();
            }

            playerToFill.isMuted = ReadByte();
            playerToFill.IsDonor = ReadByte();

            readOffset += 1;

            //HasChar
            Int16 hasChar = ReadInteger();
            playerToFill.HasChar = (hasChar == (-1) ? true : false);
        }
        public void BufferPlayer(ref Player player)
        {
            WriteBytes(Encoding.Unicode.GetBytes(player.PlayerName));
            WriteLong(player.sex);
            WriteLong(player.playerClass);
            WriteLong(player.sprite);
            WriteLong(player.level);
            WriteLong(player.exp);
            WriteByte(player.access);
            WriteByte(player.isPK);
            WriteBytes(new byte[] { 0, 0 });//padding, yp to 4 bytes

            WriteLong(player.hair);
            WriteLong(player.eyes);

            WriteLong(player.ryo);
            WriteLong(player.vitals[(int)Vitals.HP]);
            WriteLong(player.vitals[(int)Vitals.MP]);

            for (int i = 0; i < (int)Stats.counter; i++)
            {
                WriteInteger(player.stats[i]);
            }
            WriteBytes(new byte[] { 0, 0 });//padding?

            WriteLong(player.points);
            //Inventory
            for (int i = 0; i < (int)Equipment.counter; i++)
            {
                WriteLong(player.equipment[i]);
            }

            for (int i = 0; i < Constants.MAX_INV; i++)
            {
                WriteLong(player.inventory[i].id);
                WriteLong(player.inventory[i].amount);
            }
            //Spells
            for (int i = 0; i < Constants.MAX_PLAYER_SPELLS; i++)
            {
                WriteLong(player.spells[i]);
            }

            //Hotbar
            for (int i = 0; i < Constants.MAX_HOTBAR; i++)
            {
                WriteLong(player.hotbar[i].slot);
                WriteLong(player.hotbar[i].sType);
            }

            //Map
            WriteLong(player.currentMap);
            WriteByte(player.x);
            WriteByte(player.y);
            WriteByte(player.dir);

            //Switches
            for (int i = 0; i < Constants.MAX_SWITCHES; i++)
            {
                WriteByte(player.switches[i]);
            }

            //Variables
            for (int i = 0; i < Constants.MAX_VARIABLES; i++)
            {
                WriteLong(player.variables[i]);
            }
            //PlayerQuests
            for (int i = 0; i < Constants.MAX_PLAYER_QUESTS; i++)
            {
                WriteByte(player.quests[i].currentObjective);

                WriteByte(player.quests[i].completed[0]);
                WriteByte(player.quests[i].completed[1]);
                WriteByte(player.quests[i].completed[2]);

                WriteLong(player.quests[i].id);

                WriteLong(player.quests[i].counter[0]);
                WriteLong(player.quests[i].counter[1]);
                WriteLong(player.quests[i].counter[2]);
            }
            //Completed Quest
            for (int i = 0; i < Constants.MAX_QUESTS; i++)
            {
                WriteLong(player.completedQuest[i]);
            }
            //Guild
            WriteLong(player.guild);

            WriteLong(player.minutes);
            WriteLong(player.hours);
            WriteLong(player.attackAnimation);

            //Friends
            //Completed Quest
            for (int i = 0; i < Constants.MAX_PLAYER_FRIENDS; i++)
            {
                WriteBytes(Encoding.Unicode.GetBytes(player.friends[i].name));
            }
            //Elements
            for (int i = 0; i < Constants.MAX_ELEMENTS; i++)
            {
                WriteByte(player.elements[i]);
            }

            WriteByte(player.isMuted);
            WriteByte(player.IsDonor);

            //Empty Byte for alignement
            WriteByte(0);

            //HasChar?
            WriteInteger(player.HasChar ? -1 : 0);
            string test = BitConverter.ToString(sendPacket.ToArray(), 0);
        }
        public bool LoadPlayer(string loginName, ref Player playerToLoad)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "data\\accounts\\" + loginName + ".bin";

            if (File.Exists(path))
            {
                while (IsFileLocked(path))
                {
                    System.Threading.Thread.Sleep(100);
                }

                using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    playerToLoad.PlayerName = Encoding.Default.GetString(reader.ReadBytes(Constants.PLAYER_NAME_LENGTH));
                    playerToLoad.sex = reader.ReadByte();
                    playerToLoad.playerClass = reader.ReadInt32();
                    playerToLoad.sprite = reader.ReadInt32();
                    playerToLoad.level = reader.ReadByte();
                    playerToLoad.exp = reader.ReadInt32();
                    playerToLoad.access = reader.ReadByte();
                    playerToLoad.isPK = reader.ReadByte();
                    playerToLoad.hair = reader.ReadInt32();
                    playerToLoad.eyes = reader.ReadInt32();
                    //Currency
                    playerToLoad.ryo = reader.ReadInt32();

                    //Vitals
                    int test = (int)Vitals.HP;
                    playerToLoad.vitals[test] = reader.ReadInt32();
                    playerToLoad.vitals[(int)Vitals.MP] = reader.ReadInt32();

                    //Stats
                    for (int i = 0; i < (int)Stats.counter; i++)
                    {
                        playerToLoad.stats[i] = reader.ReadInt16();
                    }
                    playerToLoad.points = reader.ReadInt32();

                    //Worn equipment
                    for (int i = 0; i < (int)Equipment.counter; i++)
                    {
                        playerToLoad.equipment[i] = reader.ReadInt32();
                    }

                    //Inventory
                    for (int i = 0; i < Constants.MAX_INV; i++)
                    {
                        playerToLoad.inventory[i].id = reader.ReadInt32();
                        playerToLoad.inventory[i].amount = reader.ReadInt32();
                    }

                    //Spells
                    for (int i = 0; i < Constants.MAX_PLAYER_SPELLS; i++)
                    {
                        playerToLoad.spells[i] = reader.ReadInt32();
                    }

                    //Hotbar
                    for (int i = 0; i < Constants.MAX_HOTBAR; i++)
                    {
                        playerToLoad.hotbar[i].slot = reader.ReadInt32();
                        playerToLoad.hotbar[i].sType = reader.ReadByte();
                    }
                    //Position
                    playerToLoad.currentMap = reader.ReadInt32();
                    playerToLoad.x = reader.ReadByte();
                    playerToLoad.y = reader.ReadByte();
                    playerToLoad.dir = reader.ReadByte();

                    //Switches
                    for (int i = 0; i < Constants.MAX_SWITCHES; i++)
                    {
                        playerToLoad.switches[i] = reader.ReadByte();
                    }

                    //Variables
                    for (int i = 0; i < Constants.MAX_VARIABLES; i++)
                    {
                        playerToLoad.variables[i] = reader.ReadInt32();
                    }

                    //Quests
                    for (int i = 0; i < Constants.MAX_PLAYER_QUESTS; i++)
                    {
                        playerToLoad.quests[i].currentObjective = reader.ReadByte();
                        for (int j = 0; j < 3; j++)
                        {
                            playerToLoad.quests[i].completed[j] = reader.ReadByte();
                        }
                        playerToLoad.quests[i].id = reader.ReadInt32();

                        for (int j = 0; j < 3; j++)
                        {
                            playerToLoad.quests[i].counter[j] = reader.ReadInt32();
                        }
                    }
                    //Completed Quest
                    for (int i = 0; i < Constants.MAX_QUESTS; i++)
                    {
                        playerToLoad.completedQuest[i] = reader.ReadInt32();
                    }

                    //Guild ID
                    playerToLoad.guild = reader.ReadInt32();

                    //Play time
                    playerToLoad.minutes = reader.ReadInt32();
                    playerToLoad.hours = reader.ReadInt32();

                    playerToLoad.attackAnimation = reader.ReadInt32();

                    //Friends List
                    for (int i = 0; i < Constants.MAX_PLAYER_FRIENDS; i++)
                    {
                        //Its only true fro VB6, it stores size of string that are next to it in 16 vyte variable
                        playerToLoad.friends[i].name = Encoding.Default.GetString(reader.ReadBytes(Constants.PLAYER_NAME_LENGTH));
                    }

                    //Elements
                    for (int i = 0; i < Constants.MAX_ELEMENTS; i++)
                    {
                        playerToLoad.elements[i] = reader.ReadByte();

                    }

                    playerToLoad.isMuted = reader.ReadByte();
                    playerToLoad.IsDonor = reader.ReadByte();

                    playerToLoad.HasChar = reader.ReadInt16() == -1 ? true : false;
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        public void SavePlayer(string loginName, ref Player playerToSave)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "data\\accounts\\" + loginName + ".bin";

            while (IsFileLocked(path))
            {
                System.Threading.Thread.Sleep(100);
            }

            using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
            {
                writer.Write(Encoding.UTF8.GetBytes(playerToSave.PlayerName));
                writer.Write(playerToSave.sex) ;
                writer.Write(playerToSave.playerClass);
                writer.Write(playerToSave.sprite);
                writer.Write(playerToSave.level);
                writer.Write(playerToSave.exp);
                writer.Write(playerToSave.access);
                writer.Write(playerToSave.isPK);
                writer.Write(playerToSave.hair);
                writer.Write(playerToSave.eyes);
                //Currency
                writer.Write(playerToSave.ryo);

                //Vitals
                writer.Write(playerToSave.vitals[(int)Vitals.HP]);
                writer.Write(playerToSave.vitals[(int)Vitals.MP]);

                //Stats
                for (int i = 0; i < (int)Stats.counter; i++)
                {
                    writer.Write(BitConverter.GetBytes(playerToSave.stats[i]));
                }
                writer.Write(playerToSave.points);

                //Worn equipment
                for (int i = 0; i < (int)Equipment.counter; i++)
                {
                    writer.Write(playerToSave.equipment[i]);
                }

                //Inventory
                for (int i = 0; i < Constants.MAX_INV; i++)
                {
                    writer.Write(playerToSave.inventory[i].id);
                    writer.Write(playerToSave.inventory[i].amount);
                }

                //Spells
                for (int i = 0; i < Constants.MAX_PLAYER_SPELLS; i++)
                {
                    writer.Write(playerToSave.spells[i]);
                }

                //Hotbar
                for (int i = 0; i < Constants.MAX_HOTBAR; i++)
                {
                    writer.Write(playerToSave.hotbar[i].slot);
                    writer.Write(playerToSave.hotbar[i].sType);
                }
                //Position
                writer.Write(playerToSave.currentMap);
                writer.Write(playerToSave.x);
                writer.Write(playerToSave.y);

                writer.Write(playerToSave.dir);

                //Switches
                for (int i = 0; i < Constants.MAX_SWITCHES; i++)
                {
                    writer.Write(playerToSave.switches[i]);
                }

                //Variables
                for (int i = 0; i < Constants.MAX_VARIABLES; i++)
                {
                    writer.Write(playerToSave.variables[i]);
                }

                //Quests
                for (int i = 0; i < Constants.MAX_PLAYER_QUESTS; i++)
                {
                    writer.Write(playerToSave.quests[i].currentObjective);
                    for (int j = 0; j < 3; j++)
                    {
                        writer.Write(playerToSave.quests[i].completed[j]);
                    }
                    writer.Write(playerToSave.quests[i].id);

                    for (int j = 0; j < 3; j++)
                    {
                        writer.Write(playerToSave.quests[i].counter[j]);
                    }
                }
                //Completed Quest
                for (int i = 0; i < Constants.MAX_QUESTS; i++)
                {
                    writer.Write(playerToSave.completedQuest[i]);
                }

                //Guild ID
                writer.Write(playerToSave.guild);

                //Play time
                writer.Write(playerToSave.minutes);
                writer.Write(playerToSave.hours);

                writer.Write(playerToSave.attackAnimation);

                //Friends List
                for (int i = 0; i < Constants.MAX_PLAYER_FRIENDS; i++)
                {
                    //Its only true fro VB6, it stores size of string that are next to it in 16 vyte variable
                    //Int16 friendNameSize = (Int16)playerToSave.friends[i].name.Length;
                    //writer.Write(friendNameSize);
                    byte[] nameBytes = Encoding.UTF8.GetBytes(playerToSave.friends[i].name);
                    if (nameBytes.Length > 0)
                    {
                        writer.Write(nameBytes);
                    }
                }

                //Elements
                for (int i = 0; i < Constants.MAX_ELEMENTS; i++)
                {
                    writer.Write(playerToSave.elements[i]);

                }

                writer.Write(playerToSave.isMuted);
                writer.Write(playerToSave.IsDonor);

                Int16 hasChar = playerToSave.HasChar ? (Int16)(-1) : (Int16)0;
                writer.Write(hasChar);
            }
        }
예제 #5
0
        private static void PreSavePlayer(PacketContent pc)
        {
            //byte[] temp = data.getContent();
            //AccountsManager.SavePacket("davemax", ref temp);
            AccountsManager file = new AccountsManager(_form);
            string playerLoginName = pc.ReadString();
            Player playerToSave = new Player(0);
            DebuffPlayer(pc, ref playerToSave);
            file.SavePlayer(playerLoginName, ref playerToSave);

            Bank bankToSave = new Bank(0);
            DebuffBank(pc, ref bankToSave);
            file.SavePlayerBank(playerLoginName, ref bankToSave);

            if (!updatingPlayers) appendLog(playerLoginName + "'s account & bank saved.");
            else updatedPlayerList += playerLoginName + ", ";
        }
예제 #6
0
        public static bool SendServer_RegisterPlayer(ServerDetails server, string loginName, string loginToken, ref Player player, ref Bank playerBank)
        {
            PacketsProcessor sendBuffer = new PacketsProcessor((int)GameSendPackets.RegisterNewPlayer);
            sendBuffer.WriteString(loginToken);
            sendBuffer.WriteString(loginName);
            sendBuffer.BufferPlayer(ref player);
            sendBuffer.BufferPlayerBank(ref playerBank);
            sendBuffer.FinishPacking();
            //Testing packet
            //byte[] temp = sendBuffer.GetSendBytes();
            //AccountsManager.SavePacket("davemax", ref temp);

            return SendPacket(sendBuffer, server.socket);
        }
예제 #7
0
 public static bool RegisterNewPlayer(int serverIndex, string loginName, string loginToken, ref Player player, ref Bank playerBank)
 {
     ServerDetails server = AuthenticationServer.GetServerByIndex(serverIndex);
     if (server == null) return false;
     return SendServer_RegisterPlayer(server, loginName, loginToken, ref player, ref playerBank);
 }