public static void register_base_handler() { baseHandlerTick = PurpleCountdown.NewInstance ("BaseHandlerTick"); baseHandlerTick.TriggerEvent += periodically_validate_player; baseHandlerTick.Trigger (60, PurpleServer.CurrentConfig.ClientAuthentificationTimeout/4); if(PurpleServer.CurrentConfig.SanityPeriodical > 0) { int period = PurpleServer.CurrentConfig.SanityPeriodical*60; period = (period < 600) ? 600 : period; baseHandlerSanity = PurpleCountdown.NewInstance ("BaseHandlerSanity"); baseHandlerSanity.TriggerEvent += periodically_sanity_check; baseHandlerSanity.Trigger (period, period); } PurpleNetwork.AddListener("server_broadcast", server_broadcast_handler); PurpleNetwork.AddListener("client_ping", client_ping_handler); PurpleNetwork.AddListener("client_get_version", client_get_version_handler); PurpleNetwork.AddListener("client_authenticate", client_authenticate_handler); //PurpleNetwork.AddListener("client_authenticate_switch", client_authenticate_switch_handler); // TODO PurpleNetwork.AddListener("client_generate_token", client_generate_token_handler); PurpleNetwork.AddListener("client_logout", client_logout_handler); PurpleNetwork.PurplePlayerConnected += on_player_connected; PurpleNetwork.PurplePlayerDisconnected += on_player_disconnected; PurpleNetwork.DisconnectedFromPurpleServer += remove_base_handler; }
// 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); }