private static void ServerPacketsProcessor(AuthenticationServer ui)
        {
            //TODO: make it work for multiple servers, we need a list holding fragments for different servers and logic to manage it.
            Fragmentation fragment = new Fragmentation(8192);

            while (_continueServerProcessing)
            {
                PacketContainer cont;
                if (_queuedServerPackets.TryDequeue(out cont))
                {

                    PacketsProcessor dataProcessor = new PacketsProcessor();
                    dataProcessor.ExtractPackets(cont, ref fragment);
                    foreach (PacketContent p in cont.extractedPackets)
                    {
                        GameServer.Received(ui, p, GetServerByIndex(cont.serverID));
                    }
                }
                else
                {
                    Thread.Sleep(5);
                }
            }
        }
        public static void SendServer_SaveConfirmation(ServerDetails server)
        {
            PacketsProcessor sendBuffer = new PacketsProcessor((int)GameSendPackets.SaveConfirmation);
            sendBuffer.FinishPacking();

            SendPacket(sendBuffer, server.socket);
        }
 private static bool SendPacket(PacketsProcessor sendBuffer, Socket s)
 {
     // Begin sending the data to the remote device.
     //byte[] test = sendBuffer.GetSendBytes();
     //AccountsManager.SavePacket("davemax", ref test);
     try
     {
         s.BeginSend(sendBuffer.GetSendBytes(), 0, sendBuffer.GetSendBytes().Length, 0, new AsyncCallback(SendCallback), s);
         return true;
     }
     catch (Exception ex)
     {
         appendLog("Exception in: GameServer - SendPacket ->" + ex.Message);
         return false;
         //MessageBox.Show(ex.Message, "GameServer - SendCallback", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        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);
        }