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
        public override void UpdateBeforeSimulation()
        {
            Instance = this;
            // This needs to wait until the MyAPIGateway.Session.Player is created, as running on a Dedicated server can cause issues.
            // It would be nicer to just read a property that indicates this is a dedicated server, and simply return.
            if (!_isInitialized && MyAPIGateway.Session != null && MyAPIGateway.Session.Player != null)
            {
                Debug = MyAPIGateway.Session.Player.IsExperimentalCreator();

                if (!MyAPIGateway.Session.OnlineMode.Equals(MyOnlineModeEnum.OFFLINE) && MyAPIGateway.Multiplayer.IsServer && !MyAPIGateway.Utilities.IsDedicated)
                {
                    InitServer();
                }
                Init();
            }
            if (!_isInitialized && MyAPIGateway.Utilities != null && MyAPIGateway.Multiplayer != null &&
                MyAPIGateway.Session != null && MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer)
            {
                InitServer();
                return;
            }

            base.UpdateBeforeSimulation();

            ChatCommandService.UpdateBeforeSimulation();
            ProtectionHandler.UpdateBeforeSimulation();
            TimerRegistry.Update();
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var brief = messageText.StartsWith("/?", StringComparison.InvariantCultureIgnoreCase);

            var match = Regex.Match(messageText, @"(/help|/?)\s{1,}(?<Key>[^\s]+)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var ret = ChatCommandService.Help(steamId, match.Groups["Key"].Value, brief);
                if (!ret)
                {
                    MyAPIGateway.Utilities.ShowMessage("help", "could not find specified command.");
                }
                return(true);
            }

            if (ChatCommandService.UserSecurity == ChatCommandSecurity.User)
            {
                // Split help details. Regular users, get one list.
                var commands = new List <string>(ChatCommandService.GetListCommands(steamId));
                commands.Sort();

                if (brief)
                {
                    MyAPIGateway.Utilities.ShowMessage("help", string.Join(", ", commands));
                }
                else
                {
                    MyAPIGateway.Utilities.ShowMissionScreen("Admin Helper Commands", "Help : Available commands", " ", "Commands: " + string.Join(", ", commands), null, "OK");
                }
            }
            else
            {
                // Split help details. Admins users, get two lists.
                var commands = new List <string>(ChatCommandService.GetUserListCommands(steamId));
                commands.Sort();

                var nonUserCommands = new List <string>(ChatCommandService.GetNonUserListCommands(steamId));
                nonUserCommands.Sort();

                if (brief)
                {
                    MyAPIGateway.Utilities.ShowMessage("user help", string.Join(", ", commands));
                    MyAPIGateway.Utilities.ShowMessage("help", string.Join(", ", nonUserCommands));
                }
                else
                {
                    MyAPIGateway.Utilities.ShowMissionScreen("Admin Helper Commands", "Help : Available commands", " ",
                                                             string.Format("User commands:\r\n{0}\r\n\r\nAdmin commands:\r\n{1}", string.Join(", ", commands), string.Join(", ", nonUserCommands))
                                                             , null, "OK");
                }
            }

            return(true);
        }
        protected override void UnloadData()
        {
            Logger.Debug("Closing...");
            DetachEvents();

            if (_commandsRegistered)
            {
                ChatCommandService.DisposeCommands();
            }

            Logger.Terminate();
            base.UnloadData();
        }
Example #5
0
        private void TimerOnElapsed100(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _timerCounter++;

            if (_timerCounter % 10 == 0)
            {
                ChatCommandService.UpdateBeforeSimulation1000();
            }

            if (_timerCounter == 100)
            {
                _timerCounter = 0;
            }

            ChatCommandService.UpdateBeforeSimulation100();
        }
Example #6
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());
            }
        }
Example #7
0
 private void Utilities_MessageEntered(string messageText, ref bool sendToOthers)
 {
     if (ChatCommandService.ProcessClientMessage(messageText))
     {
         sendToOthers = false;
     }
     else
     {
         var globalMessage = new MessageGlobalMessage {
             ChatMessage = new ChatMessage {
                 Text   = messageText,
                 Sender = new Player {
                     SteamId    = MyAPIGateway.Session.Player.SteamUserId,
                     PlayerName = MyAPIGateway.Session.Player.DisplayName
                 },
             }
         };
         ConnectionHelper.SendMessageToServer(globalMessage);
     }
 }