using System; using System.Diagnostics; using System.IO; using System.ServiceModel; using TGServiceInterface.Components; namespace TGServerService { //I know the fact that this is one massive partial class is gonna trigger everyone //There really was no other succinct way to do it (<= He's lying through his teeth, don't listen to him) //this line basically says take one instance of the service, use it multithreaded for requests, and never delete it /// /// The class which holds all interface components. There are no safeguards for call race conditions so these must be guarded against internally /// [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)] sealed partial class ServerInstance : IDisposable, ITGConnectivity, ITGInstance { /// /// Used to assign the instance to event IDs /// public readonly byte LoggingID; /// /// The configuration settings for the instance /// readonly IInstanceConfig Config; /// /// Constructs and a /// public ServerInstance(IInstanceConfig config, byte logID) { LoggingID = logID; Config = config; FindTheDroidsWereLookingFor(); InitEventHandlers(); InitChat(); InitRepo(); InitByond(); InitCompiler(); InitDreamDaemon(); } /// /// Cleans up the /// void RunDisposals() { DisposeDreamDaemon(); DisposeCompiler(); DisposeByond(); DisposeRepo(); DisposeChat(); DisposeAdministration(); Config.Save(); } /// /// Writes information to the Windows event log /// /// The log message /// The of the message void WriteInfo(string message, EventID id) { Service.WriteEntry(message, id, EventLogEntryType.Information, LoggingID); } /// /// Writes an error to the Windows event log /// /// The log message /// The of the message void WriteError(string message, EventID id) { Service.WriteEntry(message, id, EventLogEntryType.Error, LoggingID); } /// /// Writes a warning to the Windows event log /// /// The log message /// The of the message void WriteWarning(string message, EventID id) { Service.WriteEntry(message, id, EventLogEntryType.Warning, LoggingID); } /// /// Writes an access event to the Windows event log /// /// The (un)authenticated Windows user's name /// if authenticated sucessfully, otherwise void WriteAccess(string username, bool authSuccess) { Service.WriteEntry(String.Format("Access from: {0}", username), EventID.Authentication, authSuccess ? EventLogEntryType.SuccessAudit : EventLogEntryType.FailureAudit, LoggingID); } /// /// Converts relative paths to full directory paths /// /// string RelativePath(string path) { return Path.Combine(Config.Directory, path); } /// public string Version() { return Service.VersionString; } /// public void VerifyConnection() { } /// public void Reattach(bool silent) { Config.ReattachRequired = true; if(!silent) SendMessage("SERVICE: Update started...", MessageType.DeveloperInfo); } /// public string ServerDirectory() { return Config.Directory; } /// /// Sets of to /// public void Offline() { Config.Enabled = false; } //mostly generated code with a call to RunDisposals() //you don't need to open this #region IDisposable Support /// /// To detect redundant calls /// private bool disposedValue = false; /// /// Implements the pattern. Calls /// /// if was called manually, if it was from the finalizer void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { RunDisposals(); // TODO: dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } } // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. // ~TGStationServer() { // // Do not change this code. Put cleanup code in Dispose(bool disposing) above. // Dispose(false); // } // This code added to correctly implement the disposable pattern. /// /// Implements the pattern /// public void Dispose() { // Do not change this code. Put cleanup code in Dispose(bool disposing) above. Dispose(true); // TODO: uncomment the following line if the finalizer is overridden above. // GC.SuppressFinalize(this); } #endregion } }