コード例 #1
0
 private static void SendServerDataToMainServer(object sender, ElapsedEventArgs e)
 {
     if (EstablishedConnection)
     {
         MainServerCommsSend.ServerData(ServerName, Server.ServerState, Server.GetCurrentNumPlayers(), Server.MaxNumPlayers, Server.MapName);
     }
 }
コード例 #2
0
        public static void Update()
        {
            Console.WriteLine($"\n\t\tStarted MainServerComms Update thread.");
            DateTime TickTimer             = DateTime.Now;
            double   SendTime              = 1000;
            int      numTimesServerIsEmpty = 0;

            while (EstablishedConnection)
            {
                while (TickTimer < DateTime.Now)
                {
                    int currentNumPlayers = Server.GetCurrentNumPlayers();
                    if (currentNumPlayers == 0)
                    {
                        numTimesServerIsEmpty += 1;
                    }
                    else
                    {
                        numTimesServerIsEmpty = 0;
                    }

                    if (TimeOut != -1 && numTimesServerIsEmpty >= TimeOut)
                    {
                        Console.WriteLine("\n\t\t------------------------------------------------------------" +
                                          $"\n\t\tGameServer {ServerName} is shutting down due to no players present..." +
                                          "\n\t\t------------------------------------------------------------");
                        Environment.Exit(0);
                        EstablishedConnection = false;
                        break;
                    }

                    if (EstablishedConnection)
                    {
                        MainServerCommsSend.ServerData(ServerName, currentNumPlayers, Server.MaxNumPlayers, Server.MapName);
                    }

                    TickTimer = TickTimer.AddMilliseconds(SendTime);

                    if (TickTimer > DateTime.Now)
                    {
                        Thread.Sleep(TickTimer - DateTime.Now);
                    }
                }
            }
            Console.WriteLine($"\t\tEnding MainServerComms server: {Port}");
            Environment.Exit(1);
        }
コード例 #3
0
        private static void TCPConnectAsyncCallback(IAsyncResult asyncResult)
        {
            TcpClient client = TCPBroadCastTcpListener.EndAcceptTcpClient(asyncResult);

            Output.WriteLine($"\n\tUser {client.Client.RemoteEndPoint} is trying to connect to the discovery server...");
            TCPBeginReceiveDiscoveryClients();

            byte discoveryClientCount = 255;

            while (true)
            {
                discoveryClientCount++;

                if (ClientDictionary.ContainsKey(discoveryClientCount))
                {
                    if (ClientDictionary[discoveryClientCount].TCPClient != null)
                    {
                        continue;
                    }
                }
                else
                {
                    ClientDictionary.Add(discoveryClientCount, new DiscoveryTCPClientServer(discoveryClientCount));
                }

                break;
            }

            ClientDictionary[discoveryClientCount].Connect(client);

            //TODO: 9001 Make a seperate packet for this, that a server must hear for - like the InternetDiscoveryClientPackets listened for
            string serverName         = Server.ServerName;
            int    currentPlayerCount = Server.GetCurrentNumPlayers();
            int    maxPlayerCount     = Server.MaxNumPlayers;
            string mapName            = Server.MapName;

            //TODO: Actually get ping value for
            int ping = 10;

            ClientDictionary[discoveryClientCount].SendServerData(serverName, currentPlayerCount, maxPlayerCount, mapName, ping);
            Output.WriteLine($"\tSent Server Data packet to: {client.Client.RemoteEndPoint}");
        }