public HandtoolCache()
        {
            _cache = new Dictionary <IMyPlayer, IMyEngineerToolBase>();
            _uninitializedHandTools = new List <IMyEngineerToolBase>();

            // as the conditions of "FindPlayer(...)" aren't very safe (players could be very near),
            // we'll check the cache from time to time in order to prevent it from ´containing wrong data
            var safetyChecker = new ThreadsafeTimer(5000);

            safetyChecker.Elapsed += Safety_Elapsed;
            safetyChecker.Start();

            MyAPIGateway.Entities.OnEntityAdd    += Entities_OnEntityAdd;
            MyAPIGateway.Entities.OnEntityRemove += Entities_OnEntityRemove;
        }
Exemple #2
0
        private void Init()
        {
            _isInitialized = true; // Set this first to block any other calls from UpdateBeforeSimulation().
            Logger.Init();
            MyAPIGateway.Utilities.MessageEntered += Utilities_MessageEntered;
            Logger.Debug("Attach MessageEntered");
            VRage.Utils.MyLog.Default.WriteLine("##Mod## Admin Helper Client Initialisation");


            _timer100          = new ThreadsafeTimer(100);
            _timer100.Elapsed += TimerOnElapsed100;
            _timer100.Start();
            // Attach any other events here.

            if (!_commandsRegistered)
            {
                foreach (ChatCommand command in GetAllChatCommands())
                {
                    ChatCommandService.Register(command);
                }
                _commandsRegistered = true;

                ChatCommandService.Init();
            }

            //MultiplayerActive is false when initializing host... extreamly weird
            if (MyAPIGateway.Multiplayer.MultiplayerActive || ServerCfg != null) //only need this in mp
            {
                MyAPIGateway.Session.OnSessionReady += Session_OnSessionReady;
                Logger.Debug("Attach Session_OnSessionReady");
                if (ServerCfg == null) // if the config is already present, the messagehandler is also already registered
                {
                    MyAPIGateway.Multiplayer.RegisterMessageHandler(ConnectionHelper.ConnectionId, MessageHandler);
                    Logger.Debug("Registered ProcessMessage");
                }
                ConnectionHelper.Client_MessageCache.Clear();
                BlockCommandExecution           = true;
                PermissionRequestTimer          = new ThreadsafeTimer(10000);
                PermissionRequestTimer.Elapsed += PermissionRequestTimer_Elapsed;
                PermissionRequestTimer.Start();
                // tell the server that we need everything now, permissions, protection, etc.
                ConnectionHelper.SendMessageToServer(new MessageConnectionRequest());
            }
        }
Exemple #3
0
        public static void Init_Server()
        {
            if (_isInitialized)
            {
                return;
            }

            _isInitialized = true;
            _isServer      = true;
            Config         = new ProtectionConfig();
            Load();

            _sentFailedMessage = new Dictionary <IMyPlayer, DateTime>();
            // every 30 seconds
            _cleanupTimer          = new ThreadsafeTimer(30000);
            _cleanupTimer.Elapsed += CleanUp;
            _cleanupTimer.Start();
            MyAPIGateway.Session.DamageSystem.RegisterBeforeDamageHandler(0, DamageHandler_Server);
            ChatCommandLogic.Instance.AllowBuilding = true;
        }