Example #1
0
        /// <summary>
        ///     Begins running the thread.
        /// </summary>
        public void Run(Settings settings)
        {
            // Abort any old threads.
            if (m_thread != null)
            {
                m_thread.Abort();
                m_thread = null;
            }

            // Initialize our new thread.
            m_settings  = settings;
            m_suspended = false;
            m_aborting  = false;

            m_thread = new Thread(EntryPoint);
            //m_thread.Priority = ThreadPriority.AboveNormal;
            m_thread.SetApartmentState(ApartmentState.STA);
            m_thread.IsBackground = true;
            m_thread.Start();
        }
 /// <summary>
 ///     Constructs an arbitrator with the given settings.
 /// </summary>
 /// <param name="settings">Settings used to construct arbitrator class.</param>
 /// <param name="host">Arbitratory host to connect to.</param>
 /// <param name="port">Arbitratory port to connect to.</param>
 public GameClientService(Settings settings, string host, ushort port)
 {
     m_settings          = settings;
     m_arbitratorHost    = host;
     m_arbitratorPort    = port;
 }
        /// <summary>
        ///     Deinitializes the master server, releasing resources and disconnecting from everything.
        /// </summary>
        public void Deinitialize()
        {
            Logger.Info("Begining cleanup of game client ...", LoggerVerboseLevel.High);

            // Save states of all super-peers. This is just being polite. If we disconnect
            // ungracefully the game will be fine, the peers will just have to wait a few seconds
            // until this peer is registered as disconnected and the other superpeers storage
            // requests are validated.
            foreach (SuperPeer peer in m_superPeers)
            {
                Zone zone = m_zoneGrid.GetZoneByID(peer.ZoneID);
                if (peer.IsActive == true)
                {
                    foreach (SuperPeerToClientConnection conn in peer.RegisteredPeers)
                    {
                        conn.StoreAccount("Deinitializing SuperPeer ID="+peer.ID+", Total SuperPeers=" + (zone != null ? zone.SuperPeers.Count.ToString() : "???"));
                    }
                }
            }

            // Send graceful disconnect message and wait till we get the reply before exiting.
            // This way we know the account stores above have gone through.
            GracefulDisconnectPacket p = new GracefulDisconnectPacket();
            m_arbitratorConnection.SendPacket(p);

            while (m_arbitratorConnection.Connected)
            {
                Packet packet = m_arbitratorConnection.DequeuePacket();
                if (packet != null &&
                    packet is GracefulDisconnectReplyPacket)
                {
                    break;
                }

                Thread.Sleep(100);
            }

            // Close down listening connection.
            if (m_listenConnection != null)
            {
                m_listenConnection.DisconnectAsync(false).Wait();
            }

            // Close down arbitrator connection.
            if (m_arbitratorConnection != null)
            {
                m_arbitratorConnection.DisconnectAsync(false).Wait();
            }

            // Dispose of settings class.
            m_settings = null;

            Logger.Info("Cleaned up game client successfully.", LoggerVerboseLevel.High);
        }
Example #4
0
        /// <summary>
        ///     Starts the simulator using the given settings.
        /// </summary>
        public void Start(Settings settings)
        {
            if (m_running == true)
            {
                return;
            }

            m_threads.Clear();
            m_settings = settings;

            // Try and setup database connection.
            Task<bool> task = SetupDBConnection();
            task.Wait();

            if (task.Result == false)
            {
                return;
            }

            // Any remenants of old networks?
            DBResults results1 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_ACTIVE_ARBITRATORS);
            DBResults results2 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_ACTIVE_CLIENTS);
            DBResults results3 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_REPLICATED_SETTINGS);
            DBResults results4 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_ZONES);
            DBResults results5 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_ZONE_SUPERPEERS);
            DBResults results6 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_ACCOUNTS);
            DBResults results7 = m_databaseConnection.Query("SELECT * FROM {0}",
                                                           Settings.DB_TABLE_PENDING_STORE_REQUESTS);

            if (results1.RowsAffected > 0 || results2.RowsAffected > 0 || 
                results3.RowsAffected > 0 || results4.RowsAffected > 0 || 
                results5.RowsAffected > 0 || results6.RowsAffected > 0 ||
                results7.RowsAffected > 0)
            {
                if (MessageBox.Show("There are currently several entries in the database for active arbitrators and active clients.\n\nEither these are remnants of an old, improperly terminated simulation, or you are running multiple simulators.\n\nIf these are old remnants then click Yes to purge them, No to ignore.", "Database Remnants", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    DisposeDatabase();
                }
            }

            // Cleanup the database.
            CleanupDatabase();

            m_running   = true;
            m_paused    = false;
            m_aborting  = false;
        }
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="settings">Initial value of configurable settings.</param>
 public NewSimulationForm(Settings settings)
 {
     m_simulationSettings = settings;
     InitializeComponent();
 }
Example #6
0
        /// <summary>
        ///     Loads account default settings for this user account.
        /// </summary>
        /// <param name="settings">Settings used to get account settings from.</param>
        private void LoadDefaults(Settings settings)
        {
            if (settings.ClientStartX == 0)
            {
                m_persistent_state.X = RandomHelper.RandomInstance.Next(0, settings.WorldWidth - 1);
            }
            else
            {
                m_persistent_state.X = settings.ClientStartX;
            }

            if (settings.ClientStartY == 0)
            {
                m_persistent_state.Y = RandomHelper.RandomInstance.Next(0, settings.WorldHeight - 1);
            }
            else
            {
                m_persistent_state.Y = settings.ClientStartY;
            }
        }
Example #7
0
        /// <summary>
        ///     Create a user account with the given information.
        /// </summary>
        /// <param name="settings">Settings used to initialize this account.</param>
        /// <param name="database">Database to load username from.</param>
        /// <param name="username">Username of account to load.</param>
        /// <returns>Account loaded, or null if one dosen't exist.</returns>
        public static UserAccount CreateAccount(Settings settings, DBConnection database, string username, string password, string email)
        {
            DBResults results = database.Query(@"SELECT id FROM {0} WHERE LOWER(`username`)='{1}'",
                                                Settings.DB_TABLE_ACCOUNTS,
                                                StringHelper.Escape(username.ToLower()));

            if (results.RowsAffected <= 0)
            {
                UserAccount account = new UserAccount();
                account.m_id                    = (int)results.LastInsertID;
                account.m_username              = username;
                account.m_password              = password;
                account.m_email                 = email;
                account.m_last_login_timestamp  = 0;
                account.m_persistent_state      = new UserAccountPersistentState();

                account.LoadDefaults(settings);

                account.Serialize(database);

                return account;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        ///     Deinitializes the master server, releasing resources and disconnecting from everything.
        /// </summary>
        public void Deinitialize()
        {
            Logger.Info("Begining cleanup of arbitrator server ...", LoggerVerboseLevel.High);

            // Remove arbitrator from database list.
            DeregisterArbitrator();

            // Close down listening connection.
            if (m_listenConnection != null)
            {
                m_listenConnection.DisconnectAsync(false).Wait();
            }

            // Close down database connection.
            if (m_databaseConnection != null)
            {
                m_databaseConnection.DisconnectAsync().Wait();
            }

            // Dispose of settings class.
            m_settings = null;

            Logger.Info("Cleaned up arbitrator server successfully.", LoggerVerboseLevel.High);
        }
 /// <summary>
 ///     Constructs an arbitrator with the given settings.
 /// </summary>
 /// <param name="settings">Settings used to construct arbitrator class.</param>
 public ArbitratorService(Settings settings)
 {
     m_settings = settings;
 }
Example #10
0
 /// <summary>
 ///     Invoked when the user clicks the start simulation button.
 /// </summary>
 /// <param name="sender">Object that sent this event.</param>
 /// <param name="e">Arguments describing this event.</param>
 private void startSimulationToolStripButton_Click(object sender, EventArgs e)
 {
     if (m_simulator.IsPaused == true)
     {
         BeginSimulation();
     }
     else
     {
         NewSimulationForm sim = new NewSimulationForm(m_simulationSettings);
         if (sim.ShowDialog(this) == DialogResult.OK)
         {
             m_simulationSettings = sim.SimulationSettings;
             BeginSimulation();
         }
     }
 }