コード例 #1
0
ファイル: Simulator.cs プロジェクト: HampsterEater/Dynammo
        /// <summary>
        ///     Loads clients from the database.
        /// </summary>
        private void LoadClients()
        {
            DBConnection db = m_databaseConnection;
            DBResults results = null;

            results = db.Query("SELECT id, arbitrator_id, ip_address, port, last_active_timestamp, account_id, listening, listen_port, zone_id FROM {0}",
                                Settings.DB_TABLE_ACTIVE_CLIENTS);

            // Delete Old Rows.
            foreach (SimulatorClientState subState in m_clientStates.ToList())
            {
                bool found = false;

                for (int i = 0; i < results.RowsAffected; i++)
                {
                    if ((int)results[i]["id"] == (int)subState.DatabaseSettings["id"])
                    {
                        found = true;
                        break;
                    }
                }

                if (found == false)
                {
                    m_clientStates.Remove(subState);
                }
            }

            // Add New Rows / Update Old Rows.
            for (int i = 0; i < results.RowsAffected; i++)
            {
                DBRow row = results[i];
                SimulatorClientState state = null;

                foreach (SimulatorClientState subState in m_clientStates)
                {
                    if ((string)subState.DatabaseSettings["ip_address"] == (string)row["ip_address"] &&
                        (int)subState.DatabaseSettings["port"]          == (int)row["port"])
                    {
                        state = subState;
                        break;
                    }
                }

                if (state == null)
                {
                    state = new SimulatorClientState();
                    m_clientStates.Add(state);
                }

                // Copy over all settings.
                foreach (string key in row.ColumnNames)
                {
                    state.DatabaseSettings[key] = row[key];
                }

                // Update client account?
                if (row["account_id"] != null)
                {
                    if (state.Account != null)
                    {
                        if ((int)row["account_id"] != state.Account.ID)
                        {
                            state.Account = UserAccount.LoadByID(m_databaseConnection, (int)row["account_id"]);
                        }
                    }
                    else
                    {
                        state.Account = UserAccount.LoadByID(m_databaseConnection, (int)row["account_id"]);
                    }
                }
                else
                {
                    state.Account = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Gets position information about a given client state.
        /// </summary>
        private bool GetStateInfo(SimulatorClientState state, out bool registering, out bool unregistering, out float x, out float y, out ClientSimulatorThread realClientThread)
        {
            bool found = false;

            registering = false;
            unregistering = false;
            x = state.Account.PeristentState.X;
            y = state.Account.PeristentState.Y;
            realClientThread = null;

            if (state.LastClientState != null)
            {
                x = state.LastClientState.X;
                y = state.LastClientState.Y;
            }

            foreach (SimulatorThread thread in m_simulator.Threads)
            {
                ClientSimulatorThread clientThread = (thread as ClientSimulatorThread);
                if (clientThread == null || clientThread.Service == null)
                {
                    continue;
                }

                if (clientThread.Service.CurrentZone == null ||
                    clientThread.Service.CurrentZone.ID != (int)state.DatabaseSettings["zone_id"])
                {
                    continue;
                }

                if (clientThread.Service.ClientID == (int)state.DatabaseSettings["id"])
                {
                    registering = clientThread.Service.RegisteringWithSuperPeers;
                    unregistering = clientThread.Service.UnregisteringWithSuperPeers;
                    realClientThread = clientThread;
                }

                // Look to see if the position information for this peer is in this clients world state.
                if (clientThread.Service.WorldState != null)
                {
                    foreach (SuperPeerWorldStatePlayerInfo peerInfo in clientThread.Service.WorldState.Peers)
                    {
                        if (peerInfo.ClientID == (int)state.DatabaseSettings["id"])
                        {
                            x = peerInfo.Account.PeristentState.X;
                            y = peerInfo.Account.PeristentState.Y;
                            state.LastClientState = peerInfo.Account.PeristentState;
                            found = true;
                            break;
                        }
                    }
                }
            }

            return found;
        }