示例#1
0
        /// <summary>
        /// Starts up the core on the server
        /// </summary>
        public override void initialize()
        {
            if (MyAPIGateway.Session == null || m_Initialized)
                return;

            if (s_Logger == null)
                s_Logger = new Logger("Conquest Core", "Server");
            log("Conquest core (Server) started");

            s_Settings = ConquestSettings.getInstance();
            s_DelayedSettingWrite = s_Settings.WriteFailed;
            // Start round timer
            m_RoundTimer = new MyTimer(s_Settings.CPPeriod * 1000, roundEnd);
            m_RoundTimer.Start();
            log("Round timer started with " + s_Settings.CPPeriod + " seconds");

            // Start save timer
            m_SaveTimer = new MyTimer(Constants.SaveInterval * 1000, saveTimer);
            m_SaveTimer.Start();
            log("Save timer started");

            m_MailMan = new RequestProcessor();

            // If the server is a player (non-dedicated) they also need to receive notifications
            if (!MyAPIGateway.Utilities.IsDedicated) {
                m_LocalReceiver = new ResponseProcessor(false);
                m_MailMan.localMsgSent += m_LocalReceiver.incomming;
                m_CmdProc = new CommandProcessor(m_LocalReceiver);
                m_CmdProc.initialize();
                m_LocalReceiver.requestSettings();
            }

            // Subscribe events
            GridEnforcer.OnPlacementViolation += eventPlacementViolation;
            GridEnforcer.OnCleanupViolation += eventCleanupViolation;
            GridEnforcer.OnCleanupTimerStart += eventCleanupTimerStart;
            GridEnforcer.OnCleanupTimerEnd += eventCleanupTimerEnd;
            ControlPoint.OnRewardsDistributed += notifyPlayersOfCPResults;

            m_Initialized = true;
        }
示例#2
0
        protected StartupResultEnum Startup(uint maxConnections, ushort port, string host)
        {
            StartupResultEnum result = m_peer.Startup(maxConnections, port, host);

            if (result == StartupResultEnum.RAKNET_STARTED)
            {
                m_timerAction = new Action(ReceiveMessageInternal);
                m_timer = new MyTimer(1, m_timerAction);
                m_timer.Start();
            }

            return result;
        }
示例#3
0
        /// <summary>
        /// Starts or resumes the derelict timer
        /// </summary>
        /// <returns>Returns false if dereliction is disabled</returns>
        public bool start()
        {
            int seconds = ConquestSettings.getInstance().CleanupPeriod;
            int settingsTimerLength = seconds * 1000;
            log("Starting timer with settings start value of " + seconds + " seconds.",
                "start", Logger.severity.TRACE);
            if (seconds < 0) {
                log("Dereliction timers disabled.  No timer started.", "start");
                return false;
            }

            // Check if there is a timer to resume for this entity
            DT_INFO existing = StateTracker.getInstance().findActiveDerelictTimer(m_Grid.EntityId);
            if (existing != null) {
                // Resuming an existing timer
                log("Resuming existing timer", "start");

                m_TimerInfo = existing;

                // If the settings Timer Length has changed, update this timer accordingly
                if (m_TimerInfo.TimerLength != settingsTimerLength) {
                    log("Timer length has changed from " + m_TimerInfo.TimerLength +
                        "ms to " + settingsTimerLength + "ms", "start");

                    int savedMillis = m_TimerInfo.MillisRemaining;
                    decimal lengthRatio = (decimal)settingsTimerLength / (decimal)m_TimerInfo.TimerLength;
                    int correctedMillis = (int)(savedMillis * lengthRatio);

                    log("Changing this timer from " + savedMillis + "ms to " + correctedMillis +
                        "ms using ratio " + lengthRatio, "start");

                    m_TimerInfo.MillisRemaining = correctedMillis;
                    m_TimerInfo.TimerLength = settingsTimerLength;
                }

                m_Timer = new MyTimer(m_TimerInfo.MillisRemaining, timerExpired);
                m_Timer.Start();
                log("Timer resumed with " + m_TimerInfo.MillisRemaining + "ms", "start");
            } else {
                // Starting a new timer
                log("Starting new timer", "start");

                m_TimerInfo = new DT_INFO();
                m_TimerInfo.GridID = m_Grid.EntityId;
                m_TimerInfo.Phase = DT_INFO.PHASE.INITIAL;
                m_TimerInfo.TimerLength = seconds * 1000;
                m_TimerInfo.MillisRemaining = m_TimerInfo.TimerLength;
                m_TimerInfo.LastUpdated = DateTime.UtcNow;

                m_Timer = new MyTimer(m_TimerInfo.MillisRemaining, timerExpired);
                m_Timer.Start();
                log("Timer started with " + m_TimerInfo.MillisRemaining + "ms", "start");

                StateTracker.getInstance().addNewDerelictTimer(m_TimerInfo);
            }

            return true;
        }
示例#4
0
        public MyReceiveQueue(int channel, Mode readMode = Mode.Synchronized, int defaultMessageCount = 1, Func<TimeSpan> timestampProvider = null)
        {
#if !XB1
            Trace.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#else // XB1
            System.Diagnostics.Debug.Assert(readMode != Mode.Spin, "Spin mode should be used only for testing purposes, it keeps CPU under heavy load!");
#endif // XB1

            Disposed = false;
            Channel = channel;
            ReadMode = readMode;

            m_messagePool = new MyConcurrentPool<Message>(defaultMessageCount, true);
            m_receiveQueue = new MyConcurrentQueue<Message>(defaultMessageCount);
            m_timestampProvider = timestampProvider;

            if (readMode == Mode.Spin)
            {
                m_readThread = new Thread(ReceiveThread);
                m_readThread.CurrentCulture = CultureInfo.InvariantCulture;
                m_readThread.CurrentUICulture = CultureInfo.InvariantCulture;
                m_readThread.Start();
            }
            else if (readMode == Mode.Timer)
            {
                m_timerAction = new Action(ReceiveTimer);
                m_timer = new MyTimer(1, m_timerAction);
                m_timer.Start();
            }
        }
示例#5
0
        /// <summary>
        /// Starts up the core on the server
        /// </summary>
        public override void initialize()
        {
            if (MyAPIGateway.Session == null || m_Initialized)
                return;

            if (s_Logger == null)
                s_Logger = new Logger("Conquest Core", "Server");
            log("Conquest core (Server) started");

            s_TokenBuilder = new MyObjectBuilder_Component() { SubtypeName = "ShipLicense" };
            s_TokenDef = new VRage.ObjectBuilders.SerializableDefinitionId(
                typeof(MyObjectBuilder_InventoryItem), "ShipLicense");
            s_Sorter = new GridSorter();

            s_Settings = ConquestSettings.getInstance();
            s_DelayedSettingWrite = s_Settings.WriteFailed;
            // Start round timer
            m_RoundTimer = new MyTimer(s_Settings.CPPeriod * 1000, roundEnd);
            m_RoundTimer.Start();
            log("Round timer started");

            // Start save timer
            m_SaveTimer = new MyTimer(Constants.SaveInterval * 1000, saveTimer);
            m_SaveTimer.Start();
            log("Save timer started");

            m_MailMan = new RequestProcessor();

            // If the server is a player (non-dedicated) they also need to receive notifications
            if (!MyAPIGateway.Utilities.IsDedicated) {
                m_LocalReceiver = new ResponseProcessor(false);
                m_MailMan.localMsgSent += m_LocalReceiver.incomming;
                m_CmdProc = new CommandProcessor(m_LocalReceiver);
                m_CmdProc.initialize();
                m_LocalReceiver.requestSettings();
            }

            // Subscribe events
            GridEnforcer.OnPlacementViolation += eventPlacementViolation;
            GridEnforcer.OnCleanupViolation += eventCleanupViolation;
            GridEnforcer.OnCleanupTimerStart += eventCleanupTimerStart;
            GridEnforcer.OnCleanupTimerEnd += eventCleanupTimerEnd;

            m_Initialized = true;
        }