fCraft.IPBanList.Save C# (CSharp) Method

Save() static private method

static private Save ( ) : void
return void
        internal static void Save()
        {
            if ( !IsLoaded )
                return;
            Logger.Log( LogType.Debug,
                        "IPBanList.Save: Saving IP ban list ({0} records).", Bans.Count );
            const string tempFile = Paths.IPBanListFileName + ".temp";

            lock ( BanListLock ) {
                using ( StreamWriter writer = File.CreateText( tempFile ) ) {
                    writer.WriteLine( "{0} {1}", FormatVersion, Header );
                    foreach ( IPBanInfo entry in Bans.Values ) {
                        writer.WriteLine( entry.Serialize() );
                    }
                }
            }
            try {
                Paths.MoveOrReplace( tempFile, Paths.IPBanListFileName );
            } catch ( Exception ex ) {
                Logger.Log( LogType.Error,
                            "IPBanList.Save: An error occured while trying to save ban list file: {0}", ex );
            }
        }

Usage Example

Example #1
0
        // Disconnect all players
        public void ShutDown()
        {
            try {
                log.Log("Server shutting down.", LogType.SystemActivity);
                keepGoing = false;
                if (mainThread != null && mainThread.IsAlive)
                {
                    mainThread.Join();
                }

                if (heartbeat != null)
                {
                    heartbeat.ShutDown();
                }
                if (tasks != null)
                {
                    tasks.ShutDown();
                }

                lock ( playerListLock ) {
                    for (int i = 1; i < players.Length; i++)
                    {
                        if (players[i] != null)
                        {
                            players[i].session.Kick("Server shutting down.");
                        }
                        players[i] = null;
                    }
                    playerCount = 0;
                }

                if (config.GetBool("SaveOnShutdown") && map != null)
                {
                    map.Save();
                }

                if (db != null)
                {
                    db.Save();
                }
                if (bans != null)
                {
                    bans.Save();
                }
                if (server != null)
                {
                    server.ShutDown();
                }
            } catch (Exception ex) {
                log.Log("Error occured while trying to shut down: {0}", LogType.FatalError, ex.Message);
            }
        }
All Usage Examples Of fCraft.IPBanList::Save