private ConnectionTesterStatus run_test(int timeout)
 {
     if(testDone)
     {
         testDone = false;
         countdown = PurpleCountdown.NewInstance ("ConnectionTesterStatus");
         countdown.CountdownRunEvent += test_connection;
         countdown.CountdownDoneEvent += reset_connection;
         countdown.CountDown (timeout);
     }
     return testResult;
 }
        // TESTER FUNCTIONS /////////////////////////
        // TODO: MOVE
        /*
        public bool Test(List <ServerReference> serverList)
        {
            // check all server availabilities
            bool returnValue = true;
            foreach(ServerReference sr in serverList)
            {
                ServerReference newSR = new ServerReference();
                bool pingReturn = Test(sr, out newSR);
                sr.ReferencePingNote = newSR.ReferencePingNote;
                sr.ServerState = newSR.ServerState;
                sr.ReferenceLastSeen = newSR.ReferenceLastSeen;

                if(returnValue)
                    returnValue = pingReturn;
            }
            return returnValue;
        }
        */
        /*
        public static ServerReference Test(ServerReference reference)
        {
            return Ping (reference.ServerHost);
        }

        public static ServerReference Test(ServerReference reference)
        {
            string pingMessage = String.Empty;
            ServerReference newRefernece = reference;
            bool pingReturn = Ping(reference.ServerHost, out pingMessage);

            newRefernece.ReferencePingNote = pingMessage;
            if(pingReturn)
            {
                newRefernece.ServerState = ServerStates.Online;
                newRefernece.ReferenceLastSeen = DateTime.Now;
            }
            else
            {
                newRefernece.ServerState = ServerStates.Offline;
            }
            return newRefernece;
        }

        public bool Test(ServerReference reference, out string pingMessage)
        {
            return Ping (reference.ServerHost, out pingMessage);
        }
        */
        private void server_sanity_check()
        {
            server_sanity_database = false;
            server_sanity_network_ip = false;
            server_sanity_network_reachable = false;

            int testTime = 30;

            PurpleDebug.Log("ServerSanityCheck: Start...", 1);
            PurpleDebug.Log("ServerSanityCheck: Initialize Calls...");
            run_test (testTime-2);
            string ipAddress = Network.player.ipAddress;
            string externalIP = Network.player.externalIP;

            PurpleDebug.Log("ServerSanityCheck: Start Database Check...");
            if(test_current_database_connection (ipAddress, externalIP))
            {
                PurpleDebug.Log("ServerSanityCheck: Database OK");
                server_sanity_database = true;
            }
            else
            {
                PurpleDebug.LogError("ServerSanityCheck: Database ERROR", 1);
            }

            PurpleDebug.Log("ServerSanityCheck: Start Network Check...");
            PurpleDebug.Log("ServerSanityCheck: Local IP Address " + ipAddress);
            PurpleDebug.Log("ServerSanityCheck: External IP Address " + externalIP);
            if(!string.IsNullOrEmpty(externalIP)
               && !externalIP.StartsWith("0.")
               && !externalIP.StartsWith("127.")
               && !externalIP.StartsWith("192.")
               && !externalIP.Contains("UNASSIGNED_SYSTEM_ADDRESS"))
            {
                server_sanity_network_ip = true;
            }

            sanityCountdown = PurpleCountdown.NewInstance ("SanityCheck");
            sanityCountdown.TriggerEvent += server_sanity_check_periodical;
            sanityCountdown.Trigger (5, testTime/10);

            sanityCountdownDone = PurpleCountdown.NewInstance ("SanityCheckKill");
            sanityCountdownDone.CountdownDoneEvent += server_sanity_check_done;
            sanityCountdownDone.CountDown (testTime);
        }
        private void stop_server(int seconds, string message, string doneMessage)
        {
            shutdownNotificationMessage = message;
            shutdownNotificationDoneMessage = doneMessage;

            countdown = PurpleCountdown.NewInstance ();
            countdown.CountdownDoneEvent += stop_server_done;
            countdown.CountdownRunEvent += stop_server_run;
            countdown.CountDown (seconds);
        }