Example #1
0
 private void ChatMessageEntered(string messageText, ref bool sendToOthers)
 {
     if (ChatCommandService.ProcessClientMessage(messageText))
     {
         sendToOthers = false;
     }
 }
Example #2
0
        public override void UpdateBeforeSimulation()
        {
            frameCounter100++;
            frameCounter1000++;

            if (!_isInitialized)
            {
                return;
            }

            if (_delayedConnectionRequest)
            {
                ClientLogger.WriteInfo("Delayed Connection Request");
                _delayedConnectionRequest = false;
                MessageConnectionRequest.SendMessage(ModConfigurationConsts.ModCommunicationVersion, PrivateCommunicationKey);
            }

            ChatCommandService.UpdateBeforeSimulation();

            if (frameCounter100 >= 100)
            {
                frameCounter100 = 0;
                ChatCommandService.UpdateBeforeSimulation100();
            }

            if (frameCounter1000 >= 1000)
            {
                frameCounter1000 = 0;
                ChatCommandService.UpdateBeforeSimulation1000();
            }
        }
 public override void ProcessServer()
 {
     if (!ChatCommandService.ProcessServerMessage(SenderSteamId, IdentityId, TextCommand))
     {
         //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
     }
 }
 public override void ProcessClient()
 {
     // should only ever be sent from the server.
     if (MyAPIGateway.Multiplayer.ServerId == this.SenderSteamId)
     {
         if (!ChatCommandService.ProcessClientMessage(TextCommand))
         {
             //MyAPIGateway.Utilities.SendMessage(SenderSteamId, "CHECK", "ProcessServerMessage failed.");
         }
     }
 }
Example #5
0
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            //TextLogger.WriteGameLog($"####### {ModConfigurationConsts.ModName} INIT");

            //if (MyAPIGateway.Utilities == null)
            //    MyAPIGateway.Utilities = MyAPIUtilities.Static;

            //TextLogger.WriteGameLog($"####### TEST1 {MyAPIGateway.Utilities == null}");
            ////TextLogger.WriteGameLog($"####### TEST2 {MyAPIGateway.Utilities?.ConfigDedicated == null}");  // FAIL
            //TextLogger.WriteGameLog($"####### TEST3 {MyAPIGateway.Utilities?.GamePaths == null}");
            //TextLogger.WriteGameLog($"####### TEST3 {MyAPIGateway.Utilities?.GamePaths?.UserDataPath ?? "FAIL"}");

            //TextLogger.WriteGameLog($"####### TEST4 {MyAPIGateway.Utilities?.IsDedicated == null}");

            //TextLogger.WriteGameLog($"####### TEST5 {MyAPIGateway.Session == null}");
            ////TextLogger.WriteGameLog($"####### TEST6 {MyAPIGateway.Session?.Player == null}");    // FAIL
            //TextLogger.WriteGameLog($"####### TEST7 {MyAPIGateway.Session?.OnlineMode ?? null}");
            ////MyAPIGateway.Session.OnlineMode.Equals(MyOnlineModeEnum.OFFLINE)

            //TextLogger.WriteGameLog($"####### TEST8 {MyAPIGateway.Multiplayer == null}");
            //TextLogger.WriteGameLog($"####### TEST9 {MyAPIGateway.Multiplayer?.IsServer ?? null}");

            if (MyAPIGateway.Session.OnlineMode.Equals(MyOnlineModeEnum.OFFLINE) || MyAPIGateway.Multiplayer.IsServer)
            {
                InitServer();
            }
            if (!MyAPIGateway.Utilities.IsDedicated)
            {
                InitClient();
            }

            if (!_commandsRegistered)
            {
                // New command classes must be added in here.
                ChatCommandService.Register(new CommandScan());
                ChatCommandService.Register(new CommandScanIgnore());
                ChatCommandService.Register(new CommandScanTrack());
                ChatCommandService.Register(new CommandScanClear());
                _commandsRegistered = ChatCommandService.Init();
            }

            _isInitialized = true; // Set this first to block any other calls from UpdateAfterSimulation().

            if (_isClientRegistered)
            {
                Settings = new ScanSettings();
                Settings.Load();
            }
        }
Example #6
0
        protected override void UnloadData()
        {
            //TextLogger.WriteGameLog($"####### {ModConfigurationConsts.ModName} UNLOAD");

            ClientLogger.WriteStop("Shutting down");
            ServerLogger.WriteStop("Shutting down");

            if (_isClientRegistered)
            {
                if (DelayedConnectionRequestTimer != null)
                {
                    DelayedConnectionRequestTimer.Stop();
                    DelayedConnectionRequestTimer.Close();
                }

                if (MyAPIGateway.Utilities != null)
                {
                    MyAPIGateway.Utilities.MessageEntered -= ChatMessageEntered;
                }

                if (!_isServerRegistered) // if not the server, also need to unregister the messagehandler.
                {
                    ClientLogger.WriteStop("UnregisterMessageHandler");
                    MyAPIGateway.Multiplayer.UnregisterMessageHandler(ModConfigurationConsts.ConnectionId, _messageHandler);
                }

                ClientLogger.WriteStop("Log Closed");
                ClientLogger.Terminate();
            }

            if (_isServerRegistered)
            {
                ServerLogger.WriteStop("UnregisterMessageHandler");
                MyAPIGateway.Multiplayer.UnregisterMessageHandler(ModConfigurationConsts.ConnectionId, _messageHandler);

                ServerLogger.WriteStop("Log Closed");
                ServerLogger.Terminate();
            }

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