This class emulates the Gamespy Search Provider Server on port 29901. This server is responsible for fetching all associates accounts with the provided email and password, as well as verifying a player account ID.
Inheritance: BF2Statistics.Gamespy.Net.GamespyTcpSocket
        /// <summary>
        /// Starts the Login Server listeners, and begins accepting new connections
        /// </summary>
        public static void Start()
        {
            // Make sure we arent already running!
            if (bIsRunning)
            {
                return;
            }

            // Start the DB Connection
            using (GamespyDatabase Database = new GamespyDatabase())
            {
                // First, make sure our account table exists
                if (!Database.TablesExist)
                {
                    string message = "In order to use the Gamespy Emulation feature of this program, we need to setup a database. "
                                     + "You may choose to do this later by clicking \"Cancel\". Would you like to setup the database now?";
                    DialogResult R = MessageBox.Show(message, "Gamespy Database Setup", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (R == DialogResult.Yes)
                    {
                        SetupManager.ShowDatabaseSetupForm(DatabaseMode.Gamespy, MainForm.Instance);
                    }

                    // Call the stoOnShutdown event to Re-enable the main forms buttons
                    Stopped();
                    return;
                }
                else if (Database.NeedsUpdated)
                {
                    // We cannot run an outdated database
                    DialogResult R = MessageBox.Show(
                        String.Format(
                            "The Gamespy database tables needs to be updated to version {0} before using this feature. Would you like to do this now?",
                            GamespyDatabase.LatestVersion
                            ) + Environment.NewLine.Repeat(1) +
                        "NOTE: You should backup your gamespy account table if you are unsure as this update cannot be undone!",
                        "Gamespy Database Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                        );

                    // If the user doesnt migrate the database tables, quit
                    if (R != DialogResult.Yes)
                    {
                        // Call the stoOnShutdown event to Re-enable the main forms buttons
                        Stopped();
                        return;
                    }

                    // Do table migrations
                    Database.MigrateTables();
                }
            }

            // Bind gpcm server on port 29900
            int port = 29900;

            // Setup the DebugLog
            DebugLog.LoggingEnabled = Program.Config.GamespyServerDebug;
            if (Program.Config.GamespyServerDebug)
            {
                DebugLog.ClearLog();
            }

            try
            {
                // Begin logging
                DebugLog.Write("=== Gamespy Emulator Initializing ===");
                DebugLog.Write("Starting Client Manager");

                // Start the client manager
                ClientManager = new GpcmServer();

                // Begin logging
                DebugLog.Write("Bound to TCP port: " + port);
                DebugLog.Write("Starting Account Service Provider");

                // Start search provider server
                port++;
                SearchProvider = new GpspServer();

                // Begin logging
                DebugLog.Write("Bound to TCP port: " + port);
                DebugLog.Write("Starting Master Server");

                // Start then Master Server
                MasterServer = new MasterServer(ref port, DebugLog);

                // Start CDKey Server
                port = 29910;
                DebugLog.Write("Starting Cdkey Server");
                CDKeyServer = new CDKeyServer(DebugLog);

                // Begin logging
                DebugLog.Write("=== Gamespy Emulator Initialized ===");
            }
            catch (Exception E)
            {
                Notify.Show(
                    "Failed to Start Gamespy Servers!",
                    "Error binding to port " + port + ": " + Environment.NewLine + E.Message,
                    AlertType.Warning
                    );

                // Append log
                if (DebugLog != null)
                {
                    DebugLog.Write("=== Failed to Start Emulator Servers! ===");
                    DebugLog.Write("Error binding to port " + port + ": " + E.Message);
                }

                // Shutdown all started servers
                if (ClientManager != null && ClientManager.IsListening)
                {
                    ClientManager.Shutdown();
                }
                if (SearchProvider != null && SearchProvider.IsListening)
                {
                    SearchProvider.Shutdown();
                }
                if (MasterServer != null && MasterServer.IsRunning)
                {
                    MasterServer.Shutdown();
                }
                // Cdkey server must have throwm the exception at this point, since it starts last

                // Throw excpetion to parent
                throw;
            }

            // Let the client know we are ready for connections
            bIsRunning = true;
            Started();
        }
Esempio n. 2
0
        /// <summary>
        /// Starts the Login Server listeners, and begins accepting new connections
        /// </summary>
        public static void Start()
        {
            // Make sure we arent already running!
            if (isRunning)
                return;

            // Start the DB Connection
            try {
                Database = new GamespyDatabase();
            }
            catch (Exception E) {
                Notify.Show("Failed to Start Login Server!", E.Message, AlertType.Warning);
                throw E;
            }

            // Bind gpcm server on port 29900
            try {
                CmServer = new GpcmServer();
            }
            catch (Exception E) {
                Notify.Show(
                    "Failed to Start Login Server!",
                    "Error binding to port 29900: " + Environment.NewLine + E.Message,
                    AlertType.Warning
                );
                throw E;
            }

            // Bind gpsp server on port 29901
            try {
                SpServer = new GpspServer();
            }
            catch (Exception E) {
                Notify.Show(
                    "Failed to Start Login Server!",
                    "Error binding to port 29901: " + Environment.NewLine + E.Message,
                    AlertType.Warning
                );
                throw E;
            }

            // Let the client know we are ready for connections
            isRunning = true;
            OnStart();
        }
        /// <summary>
        /// Starts the Login Server listeners, and begins accepting new connections
        /// </summary>
        public static void Start()
        {
            // Make sure we arent already running!
            if (bIsRunning) return;

            // Start the DB Connection
            using (GamespyDatabase Database = new GamespyDatabase())
            {
                // First, make sure our account table exists
                if (!Database.TablesExist)
                {
                    string message = "In order to use the Gamespy Emulation feature of this program, we need to setup a database. "
                    + "You may choose to do this later by clicking \"Cancel\". Would you like to setup the database now?";
                    DialogResult R = MessageBox.Show(message, "Gamespy Database Setup", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (R == DialogResult.Yes)
                        SetupManager.ShowDatabaseSetupForm(DatabaseMode.Gamespy, MainForm.Instance);

                    // Call the stoOnShutdown event to Re-enable the main forms buttons
                    Stopped();
                    return;
                }
                else if (Database.NeedsUpdated)
                {
                    // We cannot run an outdated database
                    DialogResult R = MessageBox.Show(
                        String.Format(
                            "The Gamespy database tables needs to be updated to version {0} before using this feature. Would you like to do this now?",
                            GamespyDatabase.LatestVersion
                        ) + Environment.NewLine.Repeat(1) +
                        "NOTE: You should backup your gamespy account table if you are unsure as this update cannot be undone!",
                        "Gamespy Database Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                    );

                    // If the user doesnt migrate the database tables, quit
                    if (R != DialogResult.Yes)
                    {
                        // Call the stoOnShutdown event to Re-enable the main forms buttons
                        Stopped();
                        return;
                    }

                    // Do table migrations
                    Database.MigrateTables();
                }
            }

            // Bind gpcm server on port 29900
            int port = 29900;

            // Setup the DebugLog
            DebugLog.LoggingEnabled = Program.Config.GamespyServerDebug;
            if (Program.Config.GamespyServerDebug)
                DebugLog.ClearLog();

            try
            {
                // Begin logging
                DebugLog.Write("=== Gamespy Emulator Initializing ===");
                DebugLog.Write("Starting Client Manager");

                // Start the client manager
                ClientManager = new GpcmServer();

                // Begin logging
                DebugLog.Write("Bound to TCP port: " + port);
                DebugLog.Write("Starting Account Service Provider");

                // Start search provider server
                port++;
                SearchProvider = new GpspServer();

                // Begin logging
                DebugLog.Write("Bound to TCP port: " + port);
                DebugLog.Write("Starting Master Server");

                // Start then Master Server
                MasterServer = new MasterServer(ref port, DebugLog);

                // Start CDKey Server
                port = 29910;
                DebugLog.Write("Starting Cdkey Server");
                CDKeyServer = new CDKeyServer(DebugLog);

                // Begin logging
                DebugLog.Write("=== Gamespy Emulator Initialized ===");
            }
            catch (Exception E)
            {
                Notify.Show(
                    "Failed to Start Gamespy Servers!",
                    "Error binding to port " + port + ": " + Environment.NewLine + E.Message,
                    AlertType.Warning
                );

                // Append log
                if (DebugLog != null)
                {
                    DebugLog.Write("=== Failed to Start Emulator Servers! ===");
                    DebugLog.Write("Error binding to port " + port + ": " + E.Message);
                }

                // Shutdown all started servers
                if (ClientManager != null && ClientManager.IsListening) ClientManager.Shutdown();
                if (SearchProvider != null && SearchProvider.IsListening) SearchProvider.Shutdown();
                if (MasterServer != null && MasterServer.IsRunning) MasterServer.Shutdown();
                // Cdkey server must have throwm the exception at this point, since it starts last

                // Throw excpetion to parent
                throw;
            }

            // Let the client know we are ready for connections
            bIsRunning = true;
            Started();
        }