/// <summary> /// When a server connects, it needs to be validated. Once that happens, this /// method is called, and it allows the server to bee seen in the Serverlist /// </summary> /// <param name="remote">The remote IP of the server</param> private void ValidateServer(IPEndPoint remote) { string key = String.Format("{0}:{1}", remote.Address, remote.Port); GameServer server; // try to fetch the existing server if (!Servers.TryGetValue(key, out server)) { // If the key exists, then what gives? if (Servers.ContainsKey(key) && !Servers.TryGetValue(key, out server)) { Program.ErrorLog.Write("NOTICE: [MasterServer.ValidateServer] Unable to fetch a connected server."); } return; } // Server is valid server.IsValidated = true; server.LastRefreshed = DateTime.Now; server.LastPing = DateTime.Now; // Update or add the new server if (Debugging) { DebugLog.Write("Adding Validated Server to Serverlist: " + key); } Servers.AddOrUpdate(key, server, (k, old) => { return(server); }); // Update the Dababase try { using (MasterDatabase Driver = new MasterDatabase()) { Driver.AddOrUpdateServer(server); } } catch (Exception e) { Program.ErrorLog.Write("ERROR: [MasterDatabase.AddOrUpdateServer] " + e.Message); } }
/// <summary> /// When a server connects, it needs to be validated. Once that happens, this /// method is called, and it allows the server to bee seen in the Serverlist /// </summary> /// <param name="remote">The remote IP of the server</param> private void ValidateServer(IPEndPoint remote) { string key = String.Format("{0}:{1}", remote.Address, remote.Port); GameServer server; // try to fetch the existing server, if its not here... we have bigger problems if (!Servers.TryGetValue(key, out server)) { Program.ErrorLog.Write("NOTICE: [MasterServer.ValidateServer] We encountered a strange error trying to fetch a connected server."); return; } // Server is valid server.IsValidated = true; server.LastRefreshed = DateTime.Now; server.LastPing = DateTime.Now; // Update or add the new server if (Debugging) { DebugLog.Write("Adding Validated Server to Serverlist: " + key); } Servers.AddOrUpdate(key, server, (k, old) => { return(server); }); // Update the Dababase try { using (MasterDatabase Driver = new MasterDatabase()) { Driver.AddOrUpdateServer(server); } } catch (Exception e) { Program.ErrorLog.Write("ERROR: [MasterDatabase.AddOrUpdateServer] " + e.Message); } }