Ejemplo n.º 1
0
 private static void SendServerDataToMainServer(object sender, ElapsedEventArgs e)
 {
     if (EstablishedConnection)
     {
         MainServerCommsSend.ServerData(ServerName, Server.ServerState, Server.GetCurrentNumPlayers(), Server.MaxNumPlayers, Server.MapName);
     }
 }
Ejemplo n.º 2
0
        public static void Welcome(Packet packet)
        {
            MainServerComms.EstablishedConnection = true;
            Thread updateThread = new Thread(new ThreadStart(MainServerComms.Update));

            updateThread.Start();
            MainServerCommsSend.WelcomeReceived(MainServerComms.ServerName);
            Console.WriteLine("\n\t\tGameServer recieved welcome packet from MainServer");
        }
Ejemplo n.º 3
0
        public static void Welcome(Packet _)
        {
            Output.WriteLine("\t\tGameServer reading welcome packet from MainServer");
            MainServerComms.EstablishedConnection = true;

            //Thread updateThread = new Thread(new ThreadStart(MainServerComms.Update));
            //updateThread.Start();
            MainServerComms.StartSendingServerData();

            MainServerCommsSend.WelcomeReceived(MainServerComms.ServerName);
            Output.WriteLine("\t\tGameServer recieved welcome packet from MainServer");
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static void Disconnect()
        {
            if (EstablishedConnection)
            {
                try
                {
                    tCP.Socket.Close();
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"\n\t\tError, tried to close TCP sockets of MainServerComms:\n{exception}");
                }
                EstablishedConnection = false;
                MainServerCommsSend.ShuttingDown(ServerName);

                Console.WriteLine($"\n\t\tMainServerComms: {Port} has disconnected.");
            }
        }