/// <summary> /// Saves the given credential store to disk, overwriting an existing one. /// </summary> /// <param name="credentialStore">Credential store to save</param> private void saveCredentialStore(CredentialStore credentialStore) { // Prevent other threads from modifying the credential store while we're using it lock (credentialStoreLock) { // Create or truncate the credentials file using (FileStream fs = File.Open(CredentialStorePath, FileMode.Create, FileAccess.Write)) { using (CodedOutputStream cos = new CodedOutputStream(fs)) { // Write the credential store to disk. credentialStore.WriteTo(cos); } } } }
public ServerAuthenticator(NetServer netServer, string serverName, string serverDescription, AuthTypes authType) { this.netServer = netServer; this.serverName = serverName; this.serverDescription = serverDescription; this.authType = authType; this.credentialStore = new CredentialStore(); this.sessions = new Dictionary <string, Session>(); this.sessionCleanupTimer = new Timer { Interval = 10000.00, // 10 seconds AutoReset = true }; this.sessionCleanupTimer.Elapsed += onSessionCleanup; this.sessionCleanupTimer.Start(); netServer.RegisterPacketHandler(MODULE_NAME, packetHandler); netServer.OnConnectionEstablished += ConnectionEstablishedHandler; netServer.OnConnectionClosed += ConnectionClosedHandler; }