Пример #1
0
        private void AcceptServer(IAsyncResult ar)
        {
            bool restarted = false;
            try
            {
                Socket tempServer = _serversListener.EndAccept(ar);
                _serversListener.BeginAccept(new AsyncCallback(AcceptServer), null);
                restarted = true;
                if (servers.Count < Constants.MAX_SERVERS)
                {
                    ServerDetails newServer = new ServerDetails();
                    servers.Add(newServer);

                    newServer.socket = tempServer;

                    newServer.buffer = new byte[newServer.socket.ReceiveBufferSize];
                    newServer.socket.BeginReceive(newServer.buffer, 0, newServer.buffer.Length, SocketFlags.None, new AsyncCallback(OnServerReceive), newServer);
                }
                else RejectConnection("Rejecting Server -> too many servers registered...", tempServer);

            }
            catch (Exception ex)
            {
                if (!restarted) _serversListener.BeginAccept(new AsyncCallback(AcceptServer), null);
                appendLog("Exception in: Server Listener - AcceptServer() ->" + ex.Message);
                //MessageBox.Show(ex.Message, "Server Listener - AcceptServer()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
 private void RemoveServer(ServerDetails server)
 {
     if (server.socket != null && SocketConnected(server.socket))
     {
         server.socket.Shutdown(SocketShutdown.Both);
         server.socket.Close();
     }
     servers.Remove(server);
     DisconnectClientsForThisServer(server);
 }
Пример #3
0
 public void DisconnectClientsForThisServer(ServerDetails server)
 {
     foreach (Candidate c in clients)
     {
         if (c != null)
         {
             if (c.selectedServerIndex == server.serverIndex)
             {
                 RemoveClient(c);
             }
         }
     }
 }
Пример #4
0
 private static void RegisterServer(PacketContent pc, ServerDetails serverDetails)
 {
     appendLog(".::Received server connection::. ");
     serverDetails.serverIndex = pc.ReadLong();
     serverDetails.name = pc.ReadString();
     serverDetails.ip = pc.ReadString();
     serverDetails.port = pc.ReadLong();
     serverDetails.location = pc.ReadString();
     serverDetails.donorOnly = pc.ReadFlag();
     serverDetails.registered = true;
     appendLog(".::Name: " + serverDetails.name);
     appendLog(".::IP: " + serverDetails.ip);
     appendLog(".::Port: " + serverDetails.port);
 }
Пример #5
0
        public static void SendServer_SaveConfirmation(ServerDetails server)
        {
            PacketsProcessor sendBuffer = new PacketsProcessor((int)GameSendPackets.SaveConfirmation);
            sendBuffer.FinishPacking();

            SendPacket(sendBuffer, server.socket);
        }
Пример #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 void Received(AuthenticationServer form, PacketContent pc, ServerDetails serverDetails)
 {
     _form = form;
     GameRecvPackets msgType = (GameRecvPackets)pc.GetMsgType();
     switch (msgType)
     {
         case GameRecvPackets.RegisterServer:
             RegisterServer(pc, serverDetails);
             break;
         case GameRecvPackets.UpdatePlayer:
             PreSavePlayer(pc);
             break;
         case GameRecvPackets.PlayerAcknowledged:
             CheckAdmission(pc);
             break;
         case GameRecvPackets.BeginPlayerUpdate:
             updatingPlayers = true;
             break;
         case GameRecvPackets.FinishPlayerUpdate:
             if (updatedPlayerList.Length == 0) return;
             updatedPlayerList = updatedPlayerList.Remove(updatedPlayerList.Length - 2, 2);
             appendLog("Saved accounts & banks for:\n" + updatedPlayerList);
             updatingPlayers = false;
             updatedPlayerList = "";
             SendServer_SaveConfirmation(serverDetails);
             break;
         default:
             break;
     }
 }