public void sendItems(int interfaceId, int childId, int type, Item[] inventory)
        {
            PacketBuilder pb = new PacketBuilder().setId(105).setSize(Packet.Size.VariableShort);

            pb.addInt((interfaceId << 16) + childId);
            pb.addUShort(type);
            pb.addUShort(inventory.Length);
            for (int i = 0; i < inventory.Length; i++)
            {
                Item item = inventory[i];
                int  id = -1, amount = 0;
                if (inventory[i] != null)
                {
                    id     = item.getItemId();
                    amount = item.getItemAmount();
                }
                if (amount > 254)
                {
                    pb.addByteS(255);
                    pb.addInt(amount);
                }
                else
                {
                    pb.addByteS(amount);
                }
                pb.addUShort(id + 1);
            }
            connection.SendPacket(pb.toPacket());
        }
 private static void appendUnknownMask(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addByteC(1);
     updateBlock.addLEShort(65465);
     updateBlock.addByteA(21);
     updateBlock.addUShort(434454);
 }
        public void setArrowOnEntity(int type, int id)
        {
            PacketBuilder pb     = new PacketBuilder().setId(217);
            int           offset = pb.curLength;

            pb.addByte((byte)type);                   // 10 player, 1 npc
            pb.addByte((byte)((id < 32768) ? 0 : 1)); // arrowtype
            pb.addUShort(id);
            pb.curLength += 3;
            pb.addUShort(65535);
            for (int i = (pb.curLength - offset); i < 9; i++)
            {
                pb.addByte((byte)0);
            }
            connection.SendPacket(pb.toPacket());
        }
        public void setArrowOnPosition(int x, int y, int height)
        {
            PacketBuilder pb     = new PacketBuilder().setId(217);
            int           offset = pb.curLength;

            pb.addByte((byte)2);
            pb.addByte((byte)0);
            pb.addUShort(x);
            pb.addUShort(y);
            pb.addByte((byte)height);
            pb.addUShort(65535);
            for (int i = (pb.curLength - offset); i < 9; i++)
            {
                pb.addByte((byte)0);
            }
            connection.SendPacket(pb.toPacket());
        }
        private static void appendFaceLocationUpdate(Player p, PacketBuilder updateBlock)
        {
            int x = p.getFaceLocation().getX();
            int y = p.getFaceLocation().getY();

            updateBlock.addUShort(x  = 2 * x + 1);
            updateBlock.addUShortA(y = 2 * y + 1);
        }
        private static void appendFaceLocationUpdate(Npc Npc, PacketBuilder updateBlock)
        {
            Location loc = Npc.getFaceLocation();
            int      x   = loc.getX();
            int      y   = loc.getY();

            updateBlock.addShortA(x = 2 * x + 1);
            updateBlock.addUShort(y = 2 * y + 1);
        }
        private static void appendAnimationUpdate(Npc Npc, PacketBuilder updateBlock)
        {
            Animation anim = Npc.getLastAnimation();

            if (anim != null)
            {
                updateBlock.addUShort(anim.getId());
                updateBlock.addByte((byte)anim.getDelay());
            }
        }
        public void sendMapRegion()
        {
            player.getUpdateFlags().setLastRegion((Location)player.getLocation().Clone());
            if (player.getLocation().getX() >= 19000)
            {
                sendFightCaveMapdata();
                return;
            }
            PacketBuilder pb        = new PacketBuilder().setId(162).setSize(Packet.Size.VariableShort);
            bool          forceSend = true;

            if (((((player.getLocation().getRegionX() / 8) == 48) || ((player.getLocation().getRegionX() / 8) == 49)) && ((player.getLocation().getRegionY() / 8) == 48)) ||
                (((player.getLocation().getRegionX() / 8) == 48) && ((player.getLocation().getRegionY() / 8) == 148)))
            {
                forceSend = false;
            }
            pb.addShortA(player.getLocation().getLocalX());

            for (int xCalc = (player.getLocation().getRegionX() - 6) / 8; xCalc <= ((player.getLocation().getRegionX() + 6) / 8); xCalc++)
            {
                for (int yCalc = (player.getLocation().getRegionY() - 6) / 8; yCalc <= ((player.getLocation().getRegionY() + 6) / 8); yCalc++)
                {
                    int region = yCalc + (xCalc << 8);
                    if (forceSend || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147) && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47))))
                    {
                        int[] mapData = MapData.getData(region);
                        if (mapData == null)
                        {
                            pb.addInt2(0);
                            pb.addInt2(0);
                            pb.addInt2(0);
                            pb.addInt2(0);
                        }
                        else
                        {
                            pb.addInt2(mapData[0]);
                            pb.addInt2(mapData[1]);
                            pb.addInt2(mapData[2]);
                            pb.addInt2(mapData[3]);
                        }
                    }
                }
            }
            pb.addByteS(player.getLocation().getZ());
            pb.addUShort(player.getLocation().getRegionX());
            pb.addShortA(player.getLocation().getRegionY());
            pb.addShortA(player.getLocation().getLocalY());
            connection.SendPacket(pb.toPacket());
            Server.getGroundItems().refreshGlobalItems(player);
            Server.getGlobalObjects().refreshGlobalObjects(player);
        }
        public void newClanMessage(Clan c, ChatMessage chatMessage)
        {
            PacketBuilder pb = new PacketBuilder();

            pb.setId(54).setSize(Packet.Size.VariableByte);
            pb.addLong(chatMessage.getPlayer().getLoginDetails().getLongName());
            pb.addByte((byte)1); // dummy
            pb.addLong(misc.playerNameToLong(c.getClanName()));
            pb.addUShort(0);     // some message counter bs
            string message        = chatMessage.getChatText();
            int    messageCounter = player.getFriends().getNextUniqueId();

            pb.addThreeBytes(messageCounter);
            pb.addByte((byte)chatMessage.getPlayer().getRights());
            pb.addBytes(chatMessage.getPacked());
            connection.SendPacket(pb.toPacket());
        }
        private static void appendHitUpdate(Player p, PacketBuilder updateBlock)
        {
            int ratio = p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255 / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS);

            if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS))
            {
                ratio = p.getSkills().getMaxLevel(3) * 255 / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS);
            }
            if (p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort]
            {
                updateBlock.addByte((byte)p.getHits().getHitDamage1());
            }
            else
            {
                updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000);
            }
            updateBlock.addByteA((byte)p.getHits().getHitType1());
            updateBlock.addByteS(ratio);
        }
        public void updateClan(Clan c)
        {
            PacketBuilder pb = new PacketBuilder();

            pb.setId(55).setSize(Packet.Size.VariableShort);
            pb.addLong(misc.playerNameToLong(c.getClanOwner()));
            pb.addLong(misc.playerNameToLong(c.getClanName()));
            pb.addByte((byte)c.getKickRights());
            pb.addByte((byte)c.getUserList().Count);
            foreach (ClanUser list in c.getUserList())
            {
                Player p = list.getClanMember();
                pb.addLong(p.getLoginDetails().getLongName());
                pb.addUShort(p.getWorld());
                int rights = Convert.ToInt32(list.getClanRights());
                pb.addByte((byte)rights);
                pb.addString("Server " + p.getWorld());
            }
            connection.SendPacket(pb.toPacket());
        }
        public void sendFightCaveMapdata()
        {
            lastX = lastX == 0 ? 2413 : (player.getLocation().getX() - (20000 + (200 * player.getIndex())));
            lastY = lastY == 0 ? 5116 : (player.getLocation().getY() - 20000);
            PacketBuilder pb = new PacketBuilder().setId(214).setSize(Packet.Size.VariableShort);

            pb.addUShortA(player.getLocation().getLocalX());
            pb.addUShortA(player.getLocation().getRegionX());
            pb.addByteS(player.getLocation().getZ());
            pb.addUShortA(player.getLocation().getLocalY());
            pb.initBitAccess();
            for (int height = 0; height < 4; height++)
            {
                for (int xCalc = ((lastX >> 3) - 6); xCalc <= ((lastX >> 3) + 6); xCalc++)
                {
                    for (int yCalc = ((lastY >> 3) - 6); yCalc <= ((lastY >> 3) + 6); yCalc++)
                    {
                        int region = yCalc / 8 + (xCalc / 8 << 8);
                        if (height == player.getLocation().getZ() && region == 9551)
                        {
                            pb.addBits(1, 1);
                            pb.addBits(26, (xCalc << 14) | (yCalc << 3) | (0 << 1) | (0 << 24));
                        }
                        else
                        {
                            pb.addBits(1, 0);
                        }
                    }
                }
            }
            pb.finishBitAccess();
            int[] sent      = new int[4 * 13 * 13];
            int   sentIndex = 0;

            for (int xCalc = (((lastX >> 3) - 6) / 8); xCalc <= (((lastX >> 3) + 6) / 8); xCalc++)
            {
outer:
                for (int yCalc = (((lastY >> 3) - 6) / 8); yCalc <= (((lastY >> 3) + 6) / 8); yCalc++)
                {
                    int region = yCalc + (xCalc << 8);
                    if (region != 9551)
                    {
                        continue;
                    }
                    for (int i = 0; i < sentIndex; i++)
                    {
                        if (sent[i] == region)
                        {
                            goto outer;
                        }
                    }
                    sent[sentIndex] = region;
                    sentIndex++;
                    int[] mapData = MapData.getData(region);
                    if (mapData == null)
                    {
                        pb.addInt2(0);
                        pb.addInt2(0);
                        pb.addInt2(0);
                        pb.addInt2(0);
                    }
                    else
                    {
                        pb.addInt2(mapData[0]);
                        pb.addInt2(mapData[1]);
                        pb.addInt2(mapData[2]);
                        pb.addInt2(mapData[3]);
                    }
                }
            }
            pb.addUShort(player.getLocation().getRegionY());
            connection.SendPacket(pb.toPacket());
        }
Exemple #13
0
 private static void appendUnknownMask(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addByteC(1);
     updateBlock.addLEShort(65465);
     updateBlock.addByteA(21);
     updateBlock.addUShort(434454);
 }
Exemple #14
0
 private static void appendFaceLocationUpdate(Player p, PacketBuilder updateBlock)
 {
     int x = p.getFaceLocation().getX();
     int y = p.getFaceLocation().getY();
     updateBlock.addUShort(x = 2 * x + 1);
     updateBlock.addUShortA(y = 2 * y + 1);
 }
Exemple #15
0
 private static void appendHitUpdate(Player p, PacketBuilder updateBlock)
 {
     int ratio = p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255 / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS);
     if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS))
     {
         ratio = p.getSkills().getMaxLevel(3) * 255 / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS);
     }
     if(p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort]
         updateBlock.addByte((byte)p.getHits().getHitDamage1());
     else
         updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000);
     updateBlock.addByteA((byte)p.getHits().getHitType1());
     updateBlock.addByteS(ratio);
 }
Exemple #16
0
        private static void appendAppearanceUpdate(Player p, PacketBuilder updateBlock)
        {
            PacketBuilder playerProps = new PacketBuilder().setSize(Packet.Size.Bare);

            Appearance app = p.getAppearance();
            playerProps.addByte((byte) (app.getGender() & 0xFF));
            if((app.getGender() & 0x2) == 2) {
                playerProps.addByte((byte) 0);
                playerProps.addByte((byte) 0);
            }
            playerProps.addByte((byte) p.getPrayers().getPkIcon());
            playerProps.addByte((byte) p.getPrayers().getHeadIcon());
            if (!app.isInvisible()) {
                if(!app.isNpc()) {
                    for(int i = 0; i < 4; i++) {
                        if(p.getEquipment().getItemInSlot((ItemData.EQUIP)i) != -1) {
                            playerProps.addUShort(32768 + p.getEquipment().getSlot((ItemData.EQUIP)i).getDefinition().getEquipId());
                        } else {
                            playerProps.addByte((byte) 0);
                        }
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CHEST) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.CHEST).getDefinition().getEquipId());
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.AMULET));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.SHIELD) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.SHIELD).getDefinition().getEquipId());
                    } else {
                        playerProps.addByte((byte) 0);
                    }
                    Item chest = p.getEquipment().getSlot(ItemData.EQUIP.CHEST);
                    if (chest != null && chest.getDefinition() != null)
                    {
                        if(!ItemData.isFullBody(chest.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                        } else {
                            playerProps.addByte((byte) 0);
                        }
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.LEGS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.LEGS).getDefinition().getEquipId());
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.SHIELD));
                    }
                    Item hat = p.getEquipment().getSlot(ItemData.EQUIP.HAT);
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if(!ItemData.isFullHat(hat.getDefinition()) && !ItemData.isFullMask(hat.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                        } else {
                            playerProps.addByte((byte) 0);
                        }
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.HANDS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.HANDS).getDefinition().getEquipId());
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CHEST));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.FEET) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.FEET).getDefinition().getEquipId());
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(6));
                    }
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if(!ItemData.isFullMask(hat.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                        } else {
                            playerProps.addByte((byte) 0);
                        }
                    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                    }
                } else {
                    playerProps.addUShort(-1);
                    playerProps.addUShort(app.getNpcId());
                    playerProps.addByte((byte) 255);
                }
            } else {
                for (int i = 0; i < 12; i++) {
                    playerProps.addByte((byte) 0);
                }
            }
            foreach(int colour in app.getColoursArray()) {
                playerProps.addByte((byte) colour);
            }
            playerProps.addUShort(p.getEquipment().getStandWalkAnimation());
            playerProps.addLong(p.getLoginDetails().getLongName());
            playerProps.addByte((byte) p.getSkills().getCombatLevel());
            playerProps.addUShort(0);
            playerProps.addByte((byte) 0);
            updateBlock.addByteA((byte) (playerProps.getLength() & 0xFF));
            updateBlock.addBytes(playerProps.toPacket().getData(), 0, playerProps.getLength());
        }
Exemple #17
0
 private static void appendAnimationUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addUShort(p.getLastAnimation().getId());
     updateBlock.addByte((byte)p.getLastAnimation().getDelay());
 }
        private static void appendAppearanceUpdate(Player p, PacketBuilder updateBlock)
        {
            PacketBuilder playerProps = new PacketBuilder().setSize(Packet.Size.Bare);

            Appearance app = p.getAppearance();

            playerProps.addByte((byte)(app.getGender() & 0xFF));
            if ((app.getGender() & 0x2) == 2)
            {
                playerProps.addByte((byte)0);
                playerProps.addByte((byte)0);
            }
            playerProps.addByte((byte)p.getPrayers().getPkIcon());
            playerProps.addByte((byte)p.getPrayers().getHeadIcon());
            if (!app.isInvisible())
            {
                if (!app.isNpc())
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (p.getEquipment().getItemInSlot((ItemData.EQUIP)i) != -1)
                        {
                            playerProps.addUShort(32768 + p.getEquipment().getSlot((ItemData.EQUIP)i).getDefinition().getEquipId());
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CHEST) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.CHEST).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.AMULET));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.SHIELD) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.SHIELD).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addByte((byte)0);
                    }
                    Item chest = p.getEquipment().getSlot(ItemData.EQUIP.CHEST);
                    if (chest != null && chest.getDefinition() != null)
                    {
                        if (!ItemData.isFullBody(chest.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.LEGS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.LEGS).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.SHIELD));
                    }
                    Item hat = p.getEquipment().getSlot(ItemData.EQUIP.HAT);
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if (!ItemData.isFullHat(hat.getDefinition()) && !ItemData.isFullMask(hat.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.HANDS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.HANDS).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CHEST));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.FEET) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.FEET).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(6));
                    }
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if (!ItemData.isFullMask(hat.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                    }
                }
                else
                {
                    playerProps.addUShort(-1);
                    playerProps.addUShort(app.getNpcId());
                    playerProps.addByte((byte)255);
                }
            }
            else
            {
                for (int i = 0; i < 12; i++)
                {
                    playerProps.addByte((byte)0);
                }
            }
            foreach (int colour in app.getColoursArray())
            {
                playerProps.addByte((byte)colour);
            }
            playerProps.addUShort(p.getEquipment().getStandWalkAnimation());
            playerProps.addLong(p.getLoginDetails().getLongName());
            playerProps.addByte((byte)p.getSkills().getCombatLevel());
            playerProps.addUShort(0);
            playerProps.addByte((byte)0);
            updateBlock.addByteA((byte)(playerProps.getLength() & 0xFF));
            updateBlock.addBytes(playerProps.toPacket().getData(), 0, playerProps.getLength());
        }
 private static void appendAnimationUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addUShort(p.getLastAnimation().getId());
     updateBlock.addByte((byte)p.getLastAnimation().getDelay());
 }
Exemple #20
0
        public void loadSaveThread()
        {
            while (true)
            {
                try
                {
                    Thread.Sleep(30);
                }
                catch (ThreadInterruptedException)
                {
                    forceSaveAllPlayers();
                    break;
                }

                lock(playersToLoad) {
                    if(playersToLoad.Count > 0) {

                        Connection connection = null;
                        while(playersToLoad.Count > 0) {
                            connection = playersToLoad.Dequeue();
                            if (connection != null) {
                                ReturnCode returnCode = loadPlayer(connection);
                                PacketBuilder pb = new PacketBuilder().setSize(Packet.Size.Bare);
                                int slot = -1;
                                if (returnCode == ReturnCode.LOGIN_OK)
                                {
                                    slot = Server.register(connection);
                                    if(slot == -1) {
                                        returnCode = ReturnCode.WORLD_FULL;
                                    }
                                }
                                pb.addByte((byte) returnCode);
                                if (returnCode == ReturnCode.LOGIN_OK) {
                                    pb.addByte((byte)connection.getPlayer().getRights()); // rights
                                    pb.addByte((byte)0); //1
                                    pb.addByte((byte)0);//Flagged, will genrate mouse packets
                                    pb.addByte((byte)0); //3
                                    pb.addByte((byte)0); //4
                                    pb.addByte((byte)0); //5
                                    pb.addByte((byte)0); // Generates packets
                                    pb.addUShort(slot);//PlayerID
                                    pb.addByte((byte)1); // membership flag #1?..this one enables all GE boxes
                                    pb.addByte((byte)1); // membership flag #2?
                                    connection.SendPacket(pb.toPacket());
                                    connection.getPlayer().getPackets().sendMapRegion();
                                    connection.getPlayer().setActive(true);
                                    Console.WriteLine("Loaded " + connection.getPlayer().getLoginDetails().getUsername() + "'s game: returncode = " + returnCode + ".");
                                } else {
                                    connection.SendPacket(pb.toPacket());
                                }
                            }
                        }
                    }
                }
                lock(playersToSave) {
                    if(playersToSave.Count > 0) {
                        Player p = null;
                        while(playersToSave.Count > 0) {
                            p = playersToSave.Dequeue();
                            if(p != null) {
                                if(savePlayer(p)) {
                                    Console.WriteLine("Saved " + p.getLoginDetails().getUsername() + "'s game.");
                                } else {
                                    Console.WriteLine("Could not save " +  p.getLoginDetails().getUsername() + "'s game.");
                                }
                            }
                        }
                    }
                }
            }
        }