Advertisement
Blizzardo1

Blizzeta Bootstrapper

Aug 31st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.88 KB | None | 0 0
  1.               /// <summary>
  2.         /// Pre-Initialization checks of the Program before continuing
  3.         /// </summary>
  4.         private static void SanityCheck ( )
  5.         {
  6.             ConnectedIrcNetworks = new Dictionary<string, Irc> ( );
  7.             if ( File.Exists ( Settingsf ) )
  8.                 return;
  9.             Trace.Warning ( "{0} does not exist; Creating new configuration...", Path.GetFileName ( Settingsf ) );
  10.             var net = new Network
  11.             {
  12.                 AuthenticationService = "NickServ",
  13.                 AutoConnect = true,
  14.                 Color = ConsoleColor.Green,
  15.                 Id = Guid.NewGuid ( ),
  16.                 Ident = Name,
  17.                 IdentifyOnConnect = true,
  18.                 LastKnownCode = ReplyCode.ErrUnknowncode,
  19.                 Nick = "BlizzetaZero",
  20.                 NickServPass = Global.GenerateKey( "Aa0", 42 ),
  21.                 Owner = "-Your Name Here-",
  22.                 Email = "johndoe@seriouslynotarealemail.com",
  23.                 QuitMessage = Irc.VersionReply,
  24.                 RealName = "BlizzetaZero",
  25.                 ServerHost = "coruscant.r-type.ca",
  26.                 ServerPassword = "",
  27.                 ServerPort = 6667,
  28.                 SetupChannel = "#blizzeta",
  29.                 SetupChannelKey = "",
  30.                 Ssl = false
  31.             };
  32.  
  33.             Trace.Info ( "Default Settings are as follows" );
  34.             Trace.Info ( "AuthenticationService = {0}", net.AuthenticationService );
  35.             Trace.Info ( "AutoConnect           = {0}", net.AutoConnect );
  36.             Trace.Info ( "Color                 = {0}", net.Color );
  37.             Trace.Info ( "ID                    = {0}", net.Id );
  38.             Trace.Info ( "Ident                 = {0}", net.Ident );
  39.             Trace.Info ( "IdentifyOnConnect     = {0}", net.IdentifyOnConnect );
  40.             Trace.Info ( "LastKnownCode         = {0}", net.LastKnownCode );
  41.             Trace.Info ( "Nick                  = {0}", net.Nick );
  42.             Trace.Info ( "NickServPass          = {0}", net.NickServPass );
  43.             Trace.Info ( "Owner                 = {0}", net.Owner );
  44.             Trace.Info ( "Email                 = {0}", net.Email );
  45.             Trace.Info ( "QuitMessage           = {0}", net.QuitMessage );
  46.             Trace.Info ( "RealName              = {0}", net.RealName );
  47.             Trace.Info ( "ServerHost            = {0}", net.ServerHost );
  48.             Trace.Info ( "ServerPassword        = {0}", net.ServerPassword );
  49.             Trace.Info ( "ServerPort            = {0}", net.ServerPort );
  50.             Trace.Info ( "SetupChannel          = {0}", net.SetupChannel );
  51.             Trace.Info ( "SetupChannelKey       = {0}", net.SetupChannelKey );
  52.             Trace.Info ( "SSL                   = {0}", net.Ssl );
  53.             Trace.Info ( "Press any key to Accept the new settings, or Escape to cancel..." );
  54.             if ( Console.ReadKey ( true ).Key == ConsoleKey.Escape )
  55.                 Environment.Exit ( -1 );
  56.             File.Create ( Settingsf ).Close ( );
  57.             GlobalSettings = new Settings ( );
  58.             GlobalSettings.Networks.Add ( net );
  59.             SaveSettings ( );
  60.         }
  61.  
  62.     /// <summary>
  63.         /// Defines the entry point of the application.
  64.         /// </summary>
  65.         private static void Main ( )
  66.         {
  67.             StartUptime ( );
  68.             BeanApi.InitializeGlobal ( );
  69.             IrcQueue = new Queue< Irc >();
  70.             ShowHeader ( );
  71.  
  72.             Console.Title = FullName;
  73.             Console.WindowWidth += 60;
  74.             Console.WindowHeight += 30;
  75.  
  76.             SanityCheck ( );
  77.             LoadSettings ( );
  78.            
  79.             CoreCommands.IncludeBuiltInCommands ( GlobalSettings.SuppressIncludeMessage );
  80.             SetCharSet ( Encoding.UTF8 );
  81.  
  82.             if ( GlobalSettings == null )
  83.             {
  84.                 Trace.Error (
  85.                     "{0} encountered an error parsing your configuration file in path: {1} and cannot proceed.", Name,
  86.                     Settingsf );
  87.                 Console.ReadLine ( );
  88.                 Environment.Exit ( 0 );
  89.             }
  90.  
  91.             foreach ( Network net in GlobalSettings.Networks.Where ( net => net.Id == Guid.Empty ) )
  92.             {
  93.                 net.Id = Guid.NewGuid ( );
  94.                 RehashSettings(  );
  95.             }
  96.  
  97.             ( new Root( ) ).Execute( null, null, null, Permissions.Root, new object[] { "server", "connect", "*ALL*"} );
  98.  
  99.             while ( ConnectedIrcNetworks.Count > 0 )
  100.             {
  101.                 // Wait forever until all connected irc networks are cleared
  102.             }
  103.             Console.WriteLine( "Press any key to exit {0}", FullName );
  104.             Console.ReadKey ( true );
  105.             Cleanup ( );
  106.         }
  107.  
  108.         /// <summary>
  109.         /// Load a new set of settings
  110.         /// </summary>
  111.         public static void LoadSettings ( )
  112.         {
  113.             Console.WriteLine( "Loading Settings..." );
  114.             try
  115.             {
  116.                 var r = new StreamReader ( Settingsf );
  117.                 string res = r.ReadToEnd ( );
  118.                 r.Close ( );
  119.                 GlobalSettings = JsonConvert.DeserializeObject< Settings >( res );
  120.             }
  121.                 // File is Empty........
  122.             catch ( Exception ex )
  123.             {
  124.                 IrcReply.FormatMessage( string.Format("Error! Type: {0}", ex.Data) );
  125.             }
  126.             Console.WriteLine( "End Block" );
  127.         }
  128.  
  129. /* Output
  130. Bean Counter has been initialized!
  131. Blizzeta Zero 0.42.5721.26235 Beta
  132. Copyright (c) 2009, 2014 - 2015 Blizzardo1
  133. Built on 31-Aug-15 14:34:30
  134. Loading Settings...
  135. End Block
  136.  
  137. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
  138.    at BlizzetaZero.Kernel.Program.Main() in F:\BreakerDev Suite 2012\Blizzeta Zero rev2\Blizzeta Zero rev2\Kernel\Program.cs:line 241
  139. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement