Example #1
0
        /// <summary>
        /// Server side initialization.
        /// </summary>
        private void InitServer()
        {
            //Debug = true;
            _isInitialized = true; // Set this first to block any other calls from UpdateBeforeSimulation().
            Logger.Init();
            Logger.Debug("Server Logger started");
            VRage.Utils.MyLog.Default.WriteLine("##Mod## Admin Helper Server Initialisation");

            // TODO: restructure the ChatCommandLogic to encapsulate ChatCommandService on the server side.
            // Required to check security for user calls on the Server side, and call the UpdateBeforeSimulation...() methods for each command.
            if (!_commandsRegistered)
            {
                foreach (ChatCommand command in GetAllChatCommands())
                {
                    ChatCommandService.Register(command);
                }
                _commandsRegistered = true;

                ChatCommandService.Init();
            }

            AdminNotificator.Init();
            ProtectionHandler.Init_Server();
            MyAPIGateway.Multiplayer.RegisterMessageHandler(ConnectionHelper.ConnectionId, MessageHandler);
            Logger.Debug("Registered ProcessMessage");

            ConnectionHelper.Server_MessageCache.Clear();

            ServerCfg = new ServerConfig(GetAllChatCommands());
        }
Example #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());
            }
        }