public string[] GetBlacklistedSpecies() { try { using (SqlConnection cnn = new SqlConnection(ServerSettings.SpeciesDsn)) { cnn.Open(); using (SqlCommand cmd = new SqlCommand("Select AssemblyFullName From Species Where BlackListed = 1", cnn)) using (SqlDataReader dr = cmd.ExecuteReader()) { List <String> blackListedSpecies = new List <String>(); while (dr.Read()) { blackListedSpecies.Add(dr["AssemblyFullName"].ToString()); } if (blackListedSpecies.Count > 0) { return(blackListedSpecies.ToArray()); } } } } catch (Exception e) { InstallerInfo.WriteEventLog("GetBlacklistedSpecies", e.ToString()); return(null); } return(null); }
/* * Method: Start * Purpose: This method encompasses the code to interrogate the * application's web configuration file and start the timers needed * for black box genration and reporting to occur. */ public void Start() { bool exceptionOccurred = false; try { rollupExecutionTimePerformanceCounter = InstallerInfo.CreatePerformanceCounter("RollupExecution"); millisecondsToRollupData = ServerSettings.MillisecondsToRollupData; if (ServerSettings.SpeciesDsn != string.Empty) { dsn = ServerSettings.SpeciesDsn; reportingTimer = new Timer(); reportingTimer.Interval = millisecondsToRollupData; reportingTimer.Elapsed += new ElapsedEventHandler(OnReportingTimerElapsed); reportingTimer.Enabled = true; isStarted = true; } else { InstallerInfo.WriteEventLog("Report", "Can't do rollups: Couldn't find Species entry in settings section of config file."); } } catch (Exception e) { exceptionOccurred = true; InstallerInfo.WriteEventLog("Report", e.ToString()); } if (!exceptionOccurred) { InstallerInfo.WriteEventLog("Report", "NonPageServices started. Rolling up data every " + (millisecondsToRollupData / 1000).ToString() + " seconds.", EventLogEntryType.Information); } }
public DataSet GetAllSpecies(string version, string filter) { if (version == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("GetAllSpecies", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); return(null); } // Let's verify that this version is even allowed. string errorMessage = ""; PeerDiscoveryService discoveryService = new PeerDiscoveryService(); if (discoveryService.IsVersionDisabled(version, out errorMessage) == true) { return(null); } if (filter == null) { filter = string.Empty; } version = new Version(version).ToString(3); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlCommand mySqlCommand = null; switch (filter) { case "All": mySqlCommand = new SqlCommand("TerrariumGrabAllSpecies", myConnection); break; default: mySqlCommand = new SqlCommand("TerrariumGrabAllRecentSpecies", myConnection); break; } SqlDataAdapter adapter = new SqlDataAdapter(mySqlCommand); mySqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter parmVersion = mySqlCommand.Parameters.Add("@Version", SqlDbType.VarChar, 255); parmVersion.Value = version; DataSet data = new DataSet(); adapter.Fill(data); return(data); } } catch (Exception e) { InstallerInfo.WriteEventLog("GetAllSpecies", e.ToString()); return(null); } }
public int GetNumPeers(string version, string channel) { if (channel == null || version == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("GetNumPeers", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); if (discoveryAllFailuresPerformanceCounter != null) { discoveryAllFailuresPerformanceCounter.Increment(); } return(0); } version = new Version(version).ToString(3); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlCommand mySqlCommand = new SqlCommand("TerrariumGrabNumPeers", myConnection); mySqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter parmVersion = mySqlCommand.Parameters.Add("@Version", SqlDbType.VarChar, 255); parmVersion.Value = version; SqlParameter parmChannel = mySqlCommand.Parameters.Add("@Channel", SqlDbType.VarChar, 255); parmChannel.Value = channel; object count = mySqlCommand.ExecuteScalar(); if (discoveryAllPerformanceCounter != null) { discoveryAllPerformanceCounter.Increment(); } if (Convert.IsDBNull(count)) { return(0); } else { return((int)count); } } } catch (Exception e) { InstallerInfo.WriteEventLog("GetNumPeers", e.ToString()); if (discoveryAllFailuresPerformanceCounter != null) { discoveryAllFailuresPerformanceCounter.Increment(); } return(0); } }
public Byte [] ReintroduceSpecies(string name, string version, Guid peerGuid) { if (name == null || version == null || peerGuid == Guid.Empty) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("ReintroduceSpecies", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); return(null); } version = new Version(version).ToString(3); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlTransaction transaction = myConnection.BeginTransaction(); SqlCommand mySqlCommand = new SqlCommand("TerrariumCheckSpeciesExtinct", myConnection, transaction); mySqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter parmName = mySqlCommand.Parameters.Add("@Name", SqlDbType.VarChar, 255); parmName.Value = name; Object returnValue = mySqlCommand.ExecuteScalar(); if (Convert.IsDBNull(returnValue) || ((int)returnValue) == 0) { // the species has already been reintroduced transaction.Rollback(); return(null); } else { mySqlCommand = new SqlCommand("TerrariumReintroduceSpecies", myConnection, transaction); mySqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter parmNode = mySqlCommand.Parameters.Add("@ReintroductionNode", SqlDbType.UniqueIdentifier, 16); parmNode.Value = peerGuid; SqlParameter parmDateTime = mySqlCommand.Parameters.Add("@LastReintroduction", SqlDbType.DateTime, 8); parmDateTime.Value = DateTime.UtcNow; parmName = mySqlCommand.Parameters.Add("@Name", SqlDbType.VarChar, 255); parmName.Value = name; mySqlCommand.ExecuteNonQuery(); byte [] species = LoadAssembly(version, name + ".dll"); transaction.Commit(); return(species); } } } catch (Exception e) { InstallerInfo.WriteEventLog("ReintroduceSpecies", "Species Name: " + name + "\r\n" + e.ToString()); return(null); } }
/* * Method: ReportingService * Purpose: This static constructor initializes all performance * counters used by this reporting service. */ static ReportingService() { try { reportingAllPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllReporting"); reportingAllFailedPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllFailedReporting"); } catch (Exception e) { InstallerInfo.WriteEventLog("PerformanceCounters", "Could not create Performance Counter: " + e.ToString()); } }
/* * Method: SpeciesService */ /// <summary> /// This function creates the performance counters used to display performance results. /// </summary> static SpeciesService() { try { speciesAllPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllSpecies"); speciesAllFailedPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllFailedSpecies"); } catch (Exception e) { InstallerInfo.WriteEventLog("PerformanceCounters", "Could not create Performance Counter: " + e.ToString()); } }
/// <summary> /// Instantiates performance counters for the PeerDiscoveryService. /// </summary> static PeerDiscoveryService() { try { discoveryAllPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllDiscovery"); discoveryAllFailuresPerformanceCounter = InstallerInfo.CreatePerformanceCounter("AllDiscoveryErrors"); discoveryRegistrationPerformanceCounter = InstallerInfo.CreatePerformanceCounter("Registration"); discoveryRegistrationFailuresPerformanceCounter = InstallerInfo.CreatePerformanceCounter("RegistrationErrors"); } catch (Exception e) { InstallerInfo.WriteEventLog("PerformanceCounters", "could not create Performance Counter: " + e.ToString()); } }
public bool IsVersionDisabled(string version, out string errorMessage) { try { using (SqlConnection connection = new SqlConnection(ServerSettings.SpeciesDsn)) { connection.Open(); SqlCommand command = new SqlCommand("TerrariumIsVersionDisabled", connection); command.CommandType = CommandType.StoredProcedure; string fullVersion = new Version(version).ToString(4); version = new Version(version).ToString(3); SqlParameter versionParameter = command.Parameters.Add("@Version", SqlDbType.VarChar, 255); versionParameter.Value = version; SqlParameter fullVersionParameter = command.Parameters.Add("@FullVersion", SqlDbType.VarChar, 255); fullVersionParameter.Value = fullVersion; SqlDataReader reader = command.ExecuteReader(); if (reader.Read() == true) { bool disabled = Convert.ToBoolean(reader["Disabled"]); if (disabled == true) { errorMessage = Convert.ToString(reader["Message"]); } else { errorMessage = ""; } return(disabled); } else { errorMessage = ""; return(true); } } } catch (Exception e) { InstallerInfo.WriteEventLog("CheckVersion", e.ToString()); errorMessage = ""; return(true); } }
public DataSet GetExtinctSpecies(string version, string filter) { if (version == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("GetExtinctSpecies", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); return(null); } if (filter == null) { filter = string.Empty; } version = new Version(version).ToString(3); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlCommand mySqlCommand = null; switch (filter) { case "All": mySqlCommand = new SqlCommand("TerrariumGrabExtinctSpecies", myConnection); break; default: mySqlCommand = new SqlCommand("TerrariumGrabExtinctRecentSpecies", myConnection); break; } using (SqlDataAdapter adapter = new SqlDataAdapter(mySqlCommand)) { mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.Add("@Version", SqlDbType.VarChar, 255).Value = version; DataSet data = new DataSet(); adapter.Fill(data); return(data); } } } catch (Exception e) { InstallerInfo.WriteEventLog("GetExtinctSpecies", e.ToString()); return(null); } }
public Byte[] GetSpeciesAssembly(string name, string version) { if (name == null || version == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("GetSpeciesAssembly", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); return(null); } version = new Version(version).ToString(3); try { byte[] species = LoadAssembly(version, name + ".dll"); return(species); } catch (Exception e) { InstallerInfo.WriteEventLog("GetSpeciesAssembly", e.ToString()); return(null); } }
public void ReportError(DataSet data) { try { string ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); if (data.Tables["watson"].Columns["MachineName"] == null) { data.Tables["watson"].Columns.Add("MachineName", typeof(string)); } foreach (DataRow dr in data.Tables["watson"].Rows) { dr["MachineName"] = ip; } using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); // Update the history data SqlDataAdapter adapter = new SqlDataAdapter(); adapter.InsertCommand = new SqlCommand("TerrariumInsertWatson", myConnection); adapter.InsertCommand.CommandType = CommandType.StoredProcedure; adapter.InsertCommand.Parameters.Add("@LogType", SqlDbType.VarChar, 50, "LogType"); adapter.InsertCommand.Parameters.Add("@MachineName", SqlDbType.VarChar, 255, "MachineName"); adapter.InsertCommand.Parameters.Add("@OSVersion", SqlDbType.VarChar, 50, "OSVersion"); adapter.InsertCommand.Parameters.Add("@GameVersion", SqlDbType.VarChar, 50, "GameVersion"); adapter.InsertCommand.Parameters.Add("@CLRVersion", SqlDbType.VarChar, 50, "CLRVersion"); adapter.InsertCommand.Parameters.Add("@ErrorLog", SqlDbType.Text, Int32.MaxValue, "ErrorLog"); adapter.InsertCommand.Parameters.Add("@UserEmail", SqlDbType.Text, Int32.MaxValue, "UserEmail"); adapter.InsertCommand.Parameters.Add("@UserComment", SqlDbType.Text, Int32.MaxValue, "UserComment"); adapter.Update(data, "Watson"); } } catch (Exception e) { InstallerInfo.WriteEventLog("Watson", e.ToString()); } }
public void ReportUsage(UsageData data) { try { using (SqlConnection connection = new SqlConnection(ServerSettings.SpeciesDsn)) { connection.Open(); SqlCommand command = new SqlCommand("TerrariumReportUsage", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Alias", data.Alias); command.Parameters.AddWithValue("@Domain", data.Domain); command.Parameters.AddWithValue("@IPAddress", Context.Request.ServerVariables["REMOTE_ADDR"]); command.Parameters.AddWithValue("@GameVersion", data.GameVersion); command.Parameters.AddWithValue("@PeerChannel", data.PeerChannel); command.Parameters.AddWithValue("@PeerCount", data.PeerCount); command.Parameters.AddWithValue("@AnimalCount", data.AnimalCount); command.Parameters.AddWithValue("@MaxAnimalCount", data.MaxAnimalCount); command.Parameters.AddWithValue("@WorldWidth", data.WorldWidth); command.Parameters.AddWithValue("@WorldHeight", data.WorldHeight); command.Parameters.AddWithValue("@MachineName", data.MachineName); command.Parameters.AddWithValue("@OSVersion", data.OSVersion); command.Parameters.AddWithValue("@ProcessorCount", data.ProcessorCount); command.Parameters.AddWithValue("@ClrVersion", data.ClrVersion); command.Parameters.AddWithValue("@WorkingSet", data.WorkingSet); command.Parameters.AddWithValue("@MaxWorkingSet", data.MaxWorkingSet); command.Parameters.AddWithValue("@MinWorkingSet", data.MinWorkingSet); command.Parameters.AddWithValue("@ProcessorTime", data.ProcessorTimeInSeconds); command.Parameters.AddWithValue("@ProcessStartTime", data.ProcessStartTime); command.ExecuteNonQuery(); command.Dispose(); } } catch (Exception e) { InstallerInfo.WriteEventLog("ReportUsage", e.ToString()); } }
/* * Method: RunQuickWordFilter * Purpose: This method gets the array of regular expressions * from the PoliSettings class. It then tests the string against * each expression looking for a match. If a match is found the * function returns true, else the function returns false. */ public static bool RunQuickWordFilter(string text) { try { if (WordFilterSettings.WordListArray.Length > 0) { foreach (Regex r in WordFilterSettings.WordListPattern) { if (r.IsMatch(text)) { return(true); } } } } catch (Exception e) { InstallerInfo.WriteEventLog("WordFilter", e.ToString()); } return(false); }
public Boolean RegisterUser(string email) { string ipAddress = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlCommand command = new SqlCommand("TerrariumRegisterUser", myConnection); command.CommandType = CommandType.StoredProcedure; SqlParameter parmEmail = command.Parameters.Add("@Email", SqlDbType.VarChar, 255); parmEmail.Value = email; SqlParameter parmIP = command.Parameters.Add("@IPAddress", SqlDbType.VarChar, 50); parmIP.Value = ipAddress; command.ExecuteNonQuery(); if (discoveryAllPerformanceCounter != null) { discoveryAllPerformanceCounter.Increment(); } return(true); } } catch (Exception e) { InstallerInfo.WriteEventLog("RegisterUser", e.ToString()); if (discoveryAllFailuresPerformanceCounter != null) { discoveryAllFailuresPerformanceCounter.Increment(); } return(false); } }
public ReturnCode ReportPopulation(DataSet data, Guid guid, int currentTick) { try { if (data == null || guid == Guid.Empty) { InstallerInfo.WriteEventLog("Report", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); } // We need to check for blacklisted species, even if the client has been throttled. If this gets // too demanding, think about caching the results bool foundBlacklisted = false; using (SqlConnection connection = new SqlConnection(ServerSettings.SpeciesDsn)) { connection.Open(); SqlCommand command = new SqlCommand("TerrariumCheckSpeciesBlacklist", connection); command.CommandType = CommandType.StoredProcedure; SqlParameter nameParameter = command.Parameters.Add("@Name", SqlDbType.VarChar, 255); DataTable table = data.Tables["History"]; if (table != null) { foreach (DataRow row in table.Rows) { nameParameter.Value = Convert.ToString(row["SpeciesName"]); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { if (1 == Convert.ToInt32(reader["Blacklisted"])) { foundBlacklisted = true; break; } } reader.Close(); } } if (foundBlacklisted == true) { return(ReturnCode.OrganismBlacklisted); } } if (Throttle.Throttled( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "ReportPopulation3Mins")) { return(ReturnCode.Success); } if (Throttle.Throttled( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "ReportPopulation12Hour")) { return(ReturnCode.Success); } Throttle.AddThrottle( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "ReportPopulation3Mins", 1, DateTime.Now.AddMinutes(3) ); if (_lastGuid.ContainsKey(Context.Request.ServerVariables["REMOTE_ADDR"].ToString())) { if (((Guid)_lastGuid[Context.Request.ServerVariables["REMOTE_ADDR"].ToString()]) != guid) { Throttle.AddThrottle( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "ReportPopulation12Hour", 1, DateTime.Now.AddHours(12) ); _lastGuid[Context.Request.ServerVariables["REMOTE_ADDR"].ToString()] = guid; return(ReturnCode.Success); } } _lastGuid[Context.Request.ServerVariables["REMOTE_ADDR"].ToString()] = guid; DateTime contactTime = DateTime.UtcNow; DataTable historyTable = data.Tables["History"]; foreach (DataRow row in historyTable.Rows) { // Set correcttime to false on all rows that aren't the current tick because they are data that // is old, but couldn't get to the server when it was fresh. Only the data from the current tick // actually happened right now if ((int)row["TickNumber"] != currentTick) { row["CorrectTime"] = 0; } row["ContactTime"] = contactTime; } bool blackListedPeers = false; bool validRecord = true; int totalPopulation = 0; using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); // Declare all parameters, commands, etc.. right here SqlTransaction transaction = myConnection.BeginTransaction(); SqlCommand lastContact; SqlParameter parmGuid; SqlParameter parmLastContact; SqlParameter parmLastTick; SqlParameter parmReturnVal; lastContact = new SqlCommand("TerrariumTimeoutReport", myConnection, transaction); lastContact.CommandType = CommandType.StoredProcedure; parmGuid = lastContact.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier, 16); parmGuid.Value = guid; parmLastContact = lastContact.Parameters.Add("@LastContact", SqlDbType.DateTime, 8); parmLastContact.Value = contactTime; parmLastTick = lastContact.Parameters.Add("@LastTick", SqlDbType.Int, 4); parmLastTick.Value = currentTick; parmReturnVal = lastContact.Parameters.Add("@ReturnCode", SqlDbType.Int, 4); parmReturnVal.Direction = ParameterDirection.Output; try { lastContact.ExecuteNonQuery(); if (((int)parmReturnVal.Value) != 0) { if ((int)parmReturnVal.Value == 1) { return(ReturnCode.NodeTimedOut); } else if ((int)parmReturnVal.Value == 2) { return(ReturnCode.NodeCorrupted); } else { InstallerInfo.WriteEventLog("Report", "Unknown return value from TerrariumTimeoutReport"); if (reportingAllFailedPerformanceCounter != null) { reportingAllFailedPerformanceCounter.Increment(); } return(ReturnCode.ServerDown); } } } catch (Exception e) { if (e is SqlException) { InstallerInfo.WriteEventLog("Report", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString() + "\n\r" + "Sql Error Number: " + ((SqlException)e).Number + "\r\n" + e.ToString()); } else { InstallerInfo.WriteEventLog("Report", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString() + "\n\r" + e.ToString()); InstallerInfo.WriteEventLog("Report", "Unknown return value from TerrariumTimeoutReport"); } if (reportingAllFailedPerformanceCounter != null) { reportingAllFailedPerformanceCounter.Increment(); } } // Update the history data SqlCommand insertHistory = new SqlCommand("TerrariumInsertHistory", myConnection, transaction); insertHistory.CommandType = CommandType.StoredProcedure; parmGuid = insertHistory.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier, 16); SqlParameter parmSpeciesName = insertHistory.Parameters.Add("@SpeciesName", SqlDbType.VarChar, 255); SqlParameter parmContactTime = insertHistory.Parameters.Add("@ContactTime", SqlDbType.DateTime, 8); SqlParameter parmClientTime = insertHistory.Parameters.Add("@ClientTime", SqlDbType.DateTime, 8); SqlParameter parmCorrectTime = insertHistory.Parameters.Add("@CorrectTime", SqlDbType.TinyInt, 1); SqlParameter parmTickNumber = insertHistory.Parameters.Add("@TickNumber", SqlDbType.Int, 4); SqlParameter parmPopulation = insertHistory.Parameters.Add("@Population", SqlDbType.Int, 4); SqlParameter parmBirthCount = insertHistory.Parameters.Add("@BirthCount", SqlDbType.Int, 4); SqlParameter parmTeleportedToCount = insertHistory.Parameters.Add("@TeleportedToCount", SqlDbType.Int, 4); SqlParameter parmStarvedCount = insertHistory.Parameters.Add("@StarvedCount", SqlDbType.Int, 4); SqlParameter parmKilledCount = insertHistory.Parameters.Add("@KilledCount", SqlDbType.Int, 4); SqlParameter parmTeleportedFromCount = insertHistory.Parameters.Add("@TeleportedFromCount", SqlDbType.Int, 4); SqlParameter parmErrorCount = insertHistory.Parameters.Add("@ErrorCount", SqlDbType.Int, 4); SqlParameter parmTimeoutCount = insertHistory.Parameters.Add("@TimeoutCount", SqlDbType.Int, 4); SqlParameter parmSickCount = insertHistory.Parameters.Add("@SickCount", SqlDbType.Int, 4); SqlParameter parmOldAgeCount = insertHistory.Parameters.Add("@OldAgeCount", SqlDbType.Int, 4); SqlParameter parmSecurityViolationCount = insertHistory.Parameters.Add("@SecurityViolationCount", SqlDbType.Int, 4); SqlParameter parmBlackListed = insertHistory.Parameters.Add("@BlackListed", SqlDbType.Int, 4); parmBlackListed.Direction = ParameterDirection.Output; if (data.Tables["History"].Rows.Count > 600) { validRecord = false; } else { foreach (DataRow dr in data.Tables["History"].Rows) { if (((int)dr["TickNumber"]) != currentTick) { continue; } totalPopulation += ((int)dr["Population"]); if (totalPopulation > 600 || ((int)dr["Population"]) > 340 || ((int)dr["Population"]) < 0) { validRecord = false; } parmGuid.Value = dr["Guid"]; parmSpeciesName.Value = dr["SpeciesName"]; parmContactTime.Value = dr["ContactTime"]; parmClientTime.Value = dr["ClientTime"]; parmCorrectTime.Value = dr["CorrectTime"]; parmTickNumber.Value = dr["TickNumber"]; parmPopulation.Value = dr["Population"]; parmBirthCount.Value = dr["BirthCount"]; parmTeleportedToCount.Value = dr["TeleportedToCount"]; parmStarvedCount.Value = dr["StarvedCount"]; parmKilledCount.Value = dr["KilledCount"]; parmTeleportedFromCount.Value = dr["TeleportedFromCount"]; parmErrorCount.Value = dr["ErrorCount"]; parmTimeoutCount.Value = dr["TimeoutCount"]; parmSickCount.Value = dr["SickCount"]; parmOldAgeCount.Value = dr["OldAgeCount"]; parmSecurityViolationCount.Value = dr["SecurityViolationCount"]; insertHistory.ExecuteNonQuery(); if (parmBlackListed.Value != null && parmBlackListed.Value != System.DBNull.Value && ((int)parmBlackListed.Value) == 1) { blackListedPeers = true; } } } if (validRecord) { transaction.Commit(); } else { transaction.Rollback(); } } if (reportingAllPerformanceCounter != null) { reportingAllPerformanceCounter.Increment(); } if (blackListedPeers) { return(ReturnCode.OrganismBlacklisted); } return(ReturnCode.Success); } catch (Exception e) { if (e is SqlException) { InstallerInfo.WriteEventLog("Report", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString() + "\n\r" + "Sql Error Number: " + ((SqlException)e).Number + "\r\n" + e.ToString()); } else { InstallerInfo.WriteEventLog("Report", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString() + "\n\r" + e.ToString()); } if (reportingAllFailedPerformanceCounter != null) { reportingAllFailedPerformanceCounter.Increment(); } // Return success instead of ServerDown because, if the server is getting hammered, Success will tell clients to // stop retrying, where ServerDown will tell them to keep doing it. return(ReturnCode.Success); } }
public RegisterPeerResult RegisterMyPeerGetCountAndPeerList(string version, string channel, Guid guid, out DataSet peers, out int count) { peers = new DataSet(); count = 0; if (channel == null || version == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("RegisterMyPeerGetCountAndPeerList", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); if (discoveryAllFailuresPerformanceCounter != null) { discoveryAllFailuresPerformanceCounter.Increment(); } return(RegisterPeerResult.GlobalFailure); } string fullVersion = new Version(version).ToString(4); version = new Version(version).ToString(3); string ipAddress = Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlCommand command = new SqlCommand("TerrariumRegisterPeerCountAndList", myConnection); SqlDataAdapter adapter = new SqlDataAdapter(command); command.CommandType = CommandType.StoredProcedure; SqlParameter parmVersion = command.Parameters.Add("@Version", SqlDbType.VarChar, 255); parmVersion.Value = version; SqlParameter parmFullVersion = command.Parameters.Add("@FullVersion", SqlDbType.VarChar, 255); parmFullVersion.Value = fullVersion; SqlParameter parmChannel = command.Parameters.Add("@Channel", SqlDbType.VarChar, 255); parmChannel.Value = channel; SqlParameter parmIP = command.Parameters.Add("@IPAddress", SqlDbType.VarChar, 50); parmIP.Value = ipAddress; SqlParameter parmGuid = command.Parameters.Add("@Guid", SqlDbType.UniqueIdentifier, 16); parmGuid.Value = guid; SqlParameter parmDisabledError = command.Parameters.Add("@Disabled_Error", SqlDbType.Bit, 1); parmDisabledError.Direction = ParameterDirection.Output; SqlParameter parmPeerCount = command.Parameters.Add("@PeerCount", SqlDbType.Int, 4); parmPeerCount.Direction = ParameterDirection.Output; adapter.Fill(peers, "Peers"); count = (int)parmPeerCount.Value; if (discoveryAllPerformanceCounter != null) { discoveryAllPerformanceCounter.Increment(); } if (discoveryRegistrationPerformanceCounter != null) { discoveryRegistrationPerformanceCounter.Increment(); } if (((bool)parmDisabledError.Value)) { return(RegisterPeerResult.GlobalFailure); } else { return(RegisterPeerResult.Success); } } } catch (Exception e) { InstallerInfo.WriteEventLog("RegisterMyPeerGetCountAndPeerList", e.ToString()); if (discoveryRegistrationFailuresPerformanceCounter != null) { discoveryRegistrationFailuresPerformanceCounter.Increment(); } if (discoveryAllFailuresPerformanceCounter != null) { discoveryAllFailuresPerformanceCounter.Increment(); } } return(RegisterPeerResult.Failure); }
public SpeciesServiceStatus Add(string name, string version, string type, string author, string email, string assemblyFullName, byte [] assemblyCode) { if (name == null || version == null || type == null || author == null || email == null || assemblyFullName == null || assemblyCode == null) { // Special versioning case, if all parameters are not specified then we return an appropriate error. InstallerInfo.WriteEventLog("AddSpecies", "Suspect: " + Context.Request.ServerVariables["REMOTE_ADDR"].ToString()); return(SpeciesServiceStatus.VersionIncompatible); } version = new Version(version).ToString(3); bool nameInappropriate = WordFilter.RunQuickWordFilter(name); bool authInappropriate = WordFilter.RunQuickWordFilter(author); bool emailInappropriate = WordFilter.RunQuickWordFilter(email); bool inappropriate = nameInappropriate | authInappropriate | emailInappropriate; bool insertComplete = false; bool allow = !Throttle.Throttled( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "AddSpecies5MinuteThrottle" ); if (allow) { allow = !Throttle.Throttled( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "AddSpecies24HourThrottle" ); if (!allow) { return(SpeciesServiceStatus.TwentyFourHourThrottle); } } else { return(SpeciesServiceStatus.FiveMinuteThrottle); } try { using (SqlConnection myConnection = new SqlConnection(ServerSettings.SpeciesDsn)) { myConnection.Open(); SqlTransaction transaction = myConnection.BeginTransaction(); SqlCommand mySqlCommand = new SqlCommand("TerrariumInsertSpecies", myConnection, transaction); mySqlCommand.CommandType = CommandType.StoredProcedure; SqlParameterCollection cmdParms = mySqlCommand.Parameters; SqlParameter parmName = cmdParms.Add("@Name", SqlDbType.VarChar, 255); parmName.Value = name; SqlParameter parmVersion = cmdParms.Add("@Version", SqlDbType.VarChar, 255); parmVersion.Value = version; SqlParameter parmType = cmdParms.Add("@Type", SqlDbType.VarChar, 50); parmType.Value = type; SqlParameter parmAuthor = cmdParms.Add("@Author", SqlDbType.VarChar, 255); parmAuthor.Value = author; SqlParameter parmAuthorEmail = cmdParms.Add("@AuthorEmail", SqlDbType.VarChar, 255); parmAuthorEmail.Value = email; SqlParameter parmExtinct = cmdParms.Add("@Extinct", SqlDbType.TinyInt, 1); parmExtinct.Value = 0; SqlParameter parmDateAdded = cmdParms.Add("@DateAdded", SqlDbType.DateTime, 8); parmDateAdded.Value = DateTime.Now; SqlParameter parmAssembly = cmdParms.Add("@AssemblyFullName", SqlDbType.Text, Int32.MaxValue); parmAssembly.Value = assemblyFullName; SqlParameter parmBlackListed = cmdParms.Add("@BlackListed", SqlDbType.Bit, 1); parmBlackListed.Value = inappropriate; try { mySqlCommand.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException e) { // 2627 is Primary key violation if (e.Number == 2627) { return(SpeciesServiceStatus.AlreadyExists); } else { throw; } } int introductionWait = (int)ServerSettings.IntroductionWait; Throttle.AddThrottle( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "AddSpecies5MinuteThrottle", 1, DateTime.Now.AddMinutes(introductionWait) ); int introductionDailyLimit = (int)ServerSettings.IntroductionDailyLimit; Throttle.AddThrottle( Context.Request.ServerVariables["REMOTE_ADDR"].ToString(), "AddSpecies24HourThrottle", introductionDailyLimit, DateTime.Now.AddHours(24) ); insertComplete = true; SaveAssembly(assemblyCode, version, name + ".dll"); transaction.Commit(); } } catch (ApplicationException e) { InstallerInfo.WriteEventLog("AddSpecies", e.ToString()); return(SpeciesServiceStatus.AlreadyExists); } catch (Exception e) { InstallerInfo.WriteEventLog("AddSpecies", e.ToString()); if (insertComplete) { RemoveAssembly(version, name); } return(SpeciesServiceStatus.ServerDown); } if (inappropriate) { if (nameInappropriate) { return(SpeciesServiceStatus.PoliCheckSpeciesNameFailure); } if (authInappropriate) { return(SpeciesServiceStatus.PoliCheckAuthorNameFailure); } if (emailInappropriate) { return(SpeciesServiceStatus.PoliCheckEmailFailure); } return(SpeciesServiceStatus.AlreadyExists); } else { return(SpeciesServiceStatus.Success); } }
/* * Method: OnReportingTimerElapsed * Purpose: Callback function used when the reporting timer has * signalled. This function is responsible for constructing a database * call to the Terrarium reporting aggregation procedure. Once called * the latest data from clients will be rolled up to be displayed on * the stats pages. * * After rollup is complete a call to ChartBuilder.ResetSpeciesList is * made so that the latest data is shown on the website. */ protected internal void OnReportingTimerElapsed(Object src, ElapsedEventArgs args) { bool exceptionOccurred = false; DateTime startTime = DateTime.Now; try { using (SqlConnection myConnection = new SqlConnection(dsn)) { myConnection.Open(); SqlCommand command = new SqlCommand("TerrariumAggregate", myConnection); command.CommandType = CommandType.StoredProcedure; SqlParameter parmExpirationError = command.Parameters.Add("@Expiration_Error", SqlDbType.Int, 4); SqlParameter parmRollupError = command.Parameters.Add("@Rollup_Error", SqlDbType.Int, 4); SqlParameter parmTimeOutAddError = command.Parameters.Add("@Timeout_Add_Error", SqlDbType.Int, 4); SqlParameter parmTimeOutDeleteError = command.Parameters.Add("@Timeout_Delete_Error", SqlDbType.Int, 4); SqlParameter parmExtinctionError = command.Parameters.Add("@Extinction_Error", SqlDbType.Int, 4); parmExpirationError.Direction = ParameterDirection.Output; parmRollupError.Direction = ParameterDirection.Output; parmTimeOutAddError.Direction = ParameterDirection.Output; parmTimeOutDeleteError.Direction = ParameterDirection.Output; parmExtinctionError.Direction = ParameterDirection.Output; command.ExecuteNonQuery(); if (((int)parmExpirationError.Value) != 0) { InstallerInfo.WriteEventLog("Report", "Expiration Code failed: " + parmExpirationError.Value); } if (((int)parmRollupError.Value) != 0) { InstallerInfo.WriteEventLog("Report", "Rollup Code failed: " + parmRollupError.Value); } if (((int)parmTimeOutAddError.Value) != 0) { InstallerInfo.WriteEventLog("Report", "Time Out Add Code failed: " + parmTimeOutAddError.Value); } if (((int)parmTimeOutDeleteError.Value) != 0) { InstallerInfo.WriteEventLog("Report", "Time Out Delete Code failed: " + parmTimeOutDeleteError.Value); } if (((int)parmExtinctionError.Value) != 0) { InstallerInfo.WriteEventLog("Report", "Extinction Code failed: " + parmExtinctionError.Value); } } // Update the species list try { ChartBuilder.RefreshSpeciesList(); } catch (Exception e) { InstallerInfo.WriteEventLog("SpeciesList", e.ToString()); } } catch (Exception e) { exceptionOccurred = true; InstallerInfo.WriteEventLog("Report", e.ToString()); } if (rollupExecutionTimePerformanceCounter != null) { if (exceptionOccurred) { rollupExecutionTimePerformanceCounter.RawValue = 0; } else { TimeSpan executionTime = DateTime.Now.Subtract(startTime); rollupExecutionTimePerformanceCounter.RawValue = executionTime.Milliseconds; } } }