Example #1
0
        private bool InitSlave(string[] args)
        {
            String configFilename;
            bool   bInitialized = false;
            int    argc         = getNumArgs(args);

            // Default into SLAVE mode
            configFilename = "";

            // Parse command line options
            if (args.Length > 0)
            {
                foreach (String arg in args)
                {
                    if (arg.IndexOf("mog=") != -1)
                    {
                        configFilename = arg.Substring(arg.IndexOf("=") + 1);
                        FileInfo file = new FileInfo(configFilename);
                        if (!file.Exists)
                        {
                            MessageBox.Show(String.Concat("MOG Configutation file (", configFilename, ") does not exist! Exiting..."), "INI Error");
                            Shutdown();
                            return(false);
                        }
                    }
                }
            }

            // Check command-line argument #2
            if (argc >= 2)
            {
                MessageBox.Show("Command line arguments are not yet supported.");
            }
            else
            {
                // Use the specified config file
                if (argc >= 2)
                {
                    configFilename = args[1];
                }

                try
                {
                    // Attempt to initialize the Slave?
                    if (MOG_Main.Init_Slave(configFilename, "Slave"))
                    {
                        // Make sure we obtain a valid NetworkID before continuing
                        if (MOG_ControllerSystem.RequireNetworkIDInitialization())
                        {
                            bInitialized = true;
                            this.niconSystemTrayIcon.Text = RefreshConnectionToolText();
                        }
                        else
                        {
                            // This is a great place to kill the application because there is already another server running
                            MOG_Report.ReportMessage("Mog Initialization Error", "Slave was unable to obtain a NetworkID from the server.", "", MOG_ALERT_LEVEL.ALERT);
                            MOG_Main.Shutdown();
                            return(false);
                        }
                    }
                    else
                    {
                        // The server was shutdown
                        Bitmap DisconnectedIcon = new Bitmap(SlaveIconsImageList.Images[1]);
                        niconSystemTrayIcon.Icon = System.Drawing.Icon.FromHandle(DisconnectedIcon.GetHicon());
                        niconSystemTrayIcon.Text = "Server is disconnected!";

                        // This is a great place to kill the application because there is already another server running
                        MOG_Report.ReportMessage("Mog Initialization Error", "Slave was unable to initialize.", "", MOG_ALERT_LEVEL.ALERT);
                        MOG_Main.Shutdown();
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    MOG_Report.ReportMessage("Mog Initialization Error", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
                    MOG_Main.Shutdown();
                    return(false);
                }
            }

            return(bInitialized);
        }