A simple way to temporarily hook into fCraft's Logger. Make sure to dispose this class when you are done recording. The easiest way to ensure that is with a using(){...} block.
Inheritance: IDisposable
Exemplo n.º 1
0
        void Init( object sender, EventArgs args ) {
            Server.InitLibrary( Environment.GetCommandLineArgs() );
            Config.Load( false, false );

            rankList = RankManager.Ranks.Select( r => r.Prefix + r.Name ).ToArray();
            cFromRank.Items.AddRange( rankList );
            cToRank.Items.AddRange( rankList );

            using( LogRecorder recorder = new LogRecorder() ) {
                AutoRankManager.Init();
                if( recorder.HasMessages ) {
                    MessageBox.Show( recorder.MessageString, "Loading autorank.xml..." );
                }
            }

            if( AutoRankManager.HasCriteria ) {
                foreach( Criterion crit in AutoRankManager.Criteria ) {
                    ActionNode newNode = new ActionNode {
                        Action = ActionType.Automatic,
                        FromRank = crit.FromRank,
                        ToRank = crit.ToRank
                    };

                    if( crit.Condition is ConditionAND ) {
                        newNode.Op = GroupNodeType.AND;
                    } else if( crit.Condition is ConditionOR ) {
                        newNode.Op = GroupNodeType.OR;
                    } else if( crit.Condition is ConditionNAND ) {
                        newNode.Op = GroupNodeType.NAND;
                    } else if( crit.Condition is ConditionNOR ) {
                        newNode.Op = GroupNodeType.NOR;
                    } else {
                        throw new FormatException();
                    }

                    foreach( Condition subCondition in crit.Condition.Conditions ) {
                        ImportCondition( newNode, subCondition );
                    }
                    treeData.Nodes.Add( newNode );
                    newNode.UpdateLabel();
                }
            } else {
                treeData.Nodes.Add( new ActionNode() );
            }
            treeData.ExpandAll();
            treeData.SelectedNode = treeData.Nodes[0];
        }
        static void ReloadHandler( Player player, Command cmd )
        {
            string whatToReload = cmd.Next();
            if( whatToReload == null ) {
                CdReload.PrintUsage( player );
                return;
            }

            whatToReload = whatToReload.ToLower();

            using( LogRecorder rec = new LogRecorder() ) {
                bool success;

                switch( whatToReload ) {
                    case "config":
                        success = Config.Load( true, true );
                        break;

                    case "autorank":
                        success = AutoRankManager.Init();
                        break;

                    case "salt":
                        Heartbeat.Salt = Server.GetRandomString( 32 );
                        player.Message( "&WNote: Until server synchronizes with Minecraft.net, " +
                                        "connecting players may have trouble verifying names." );
                        success = true;
                        break;

                    default:
                        CdReload.PrintUsage( player );
                        return;
                }

                if( rec.HasMessages ) {
                    foreach( string msg in rec.MessageList ) {
                        player.Message( msg );
                    }
                }

                if( success ) {
                    player.Message( "Reload: reloaded {0}.", whatToReload );
                } else {
                    player.Message( "&WReload: Error(s) occured while reloading {0}.", whatToReload );
                }
            }
        }
Exemplo n.º 3
0
 void SaveEverything() {
     using( LogRecorder applyLogger = new LogRecorder() ) {
         SaveConfig();
         if( applyLogger.HasMessages ) {
             MessageBox.Show( applyLogger.MessageString, "Some problems were encountered with the selected values." );
             return;
         }
     }
     using( LogRecorder saveLogger = new LogRecorder() ) {
         if( Config.Save( false ) ) {
             bApply.Enabled = false;
         }
         if( saveLogger.HasMessages ) {
             MessageBox.Show( saveLogger.MessageString, "Some problems were encountered while saving." );
         }
     }
 }
Exemplo n.º 4
0
        static void ReloadHandler( Player player, CommandReader cmd ) {
            string whatToReload = cmd.Next();
            if( whatToReload == null ) {
                CdReload.PrintUsage( player );
                return;
            }

            whatToReload = whatToReload.ToLower();

            using( LogRecorder rec = new LogRecorder() ) {
                bool success;

                switch( whatToReload ) {
                    case "config":
                        try {
                            Config.Reload( false );
                            success = true;
                        } catch( Exception ex ) {
                            Logger.Log( LogType.Error, "Error reloading config: {0}", ex );
                            player.Message( "An error occurred while trying to reload config: {0}: {1}", ex.GetType().Name, ex.Message );
                            success = false;
                        }
                        break;

                    case "salt":
                        Heartbeat.Salt = Server.GetRandomString( 32 );
                        player.Message( "&WNote: Until server synchronizes with Minecraft.net, " +
                                        "connecting players may have trouble verifying names." );
                        success = true;
                        break;

                    default:
                        CdReload.PrintUsage( player );
                        return;
                }

                if( rec.HasMessages ) {
                    foreach( string msg in rec.MessageList ) {
                        player.Message( msg );
                    }
                }

                if( success ) {
                    player.Message( "Reload: reloaded {0}.", whatToReload );
                } else {
                    player.Message( "&WReload: Error(s) occurred while reloading {0}.", whatToReload );
                }
            }
        }
Exemplo n.º 5
0
        static void ReloadHandler( Player player, CommandReader cmd ) {
            string whatToReload = cmd.Next();
            if( whatToReload == null ) {
                CdReload.PrintUsage( player );
                return;
            }

            whatToReload = whatToReload.ToLower();

            using( LogRecorder rec = new LogRecorder() ) {
                bool success;

                switch( whatToReload ) {
                    case "config":
                        try {
                            Config.Load( true, true );
                            success = true;
                        } catch( Exception ex ) {
                            Logger.LogAndReportCrash( "Config failed to reload", "ConfigGUI", ex, false );
                            success = false;
                        }
                        break;

                    case "autorank":
                        success = AutoRankManager.Init();
                        AutoRankManager.DoAutoRankAll( player, PlayerDB.PlayerInfoList, false, "(AutoRanked)" );
                        break;

                    case "salt":
                        Heartbeat.Salt = Server.GetRandomString( 32 );
                        player.Message( "&WNote: Until server synchronizes with Minecraft.net, " +
                                        "connecting players may have trouble verifying names." );
                        success = true;
                        break;

                    default:
                        CdReload.PrintUsage( player );
                        return;
                }

                if( rec.HasMessages ) {
                    foreach( string msg in rec.MessageList ) {
                        player.Message( msg );
                    }
                }

                if( success ) {
                    player.Message( "Reload: reloaded {0}.", whatToReload );
                } else {
                    player.Message( "&WReload: Error(s) occurred while reloading {0}.", whatToReload );
                }
            }
        }