private void ChatMessageEntered(string messageText, ref bool sendToOthers) { if (ChatCommandService.ProcessClientMessage( new ChatData( MyAPIGateway.Session.Player.SteamUserId, MyAPIGateway.Session.Player.DisplayName, (int)MyAPIGateway.Session.Config.Language, MyAPIGateway.Session.Player.IdentityId, messageText))) { sendToOthers = false; } }
protected sealed 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; } ClientLogger.WriteStop("UnregisterMessageHandler"); MyAPIGateway.Multiplayer.UnregisterMessageHandler(ClientConnectionId, _clientMessageHandler); ClientUnload(); ClientLogger.WriteInfo("Log Closed"); ClientLogger.Terminate(); } if (_isServerRegistered) { ServerLogger.WriteStop("UnregisterMessageHandler"); MyAPIGateway.Multiplayer.UnregisterMessageHandler(ServerConnectionId, _serverMessageHandler); ServerUnload(); ServerLogger.WriteInfo("Log Closed"); ServerLogger.Terminate(); } if (_commandsRegistered) { ChatCommandService.DisposeCommands(); } }
public sealed override void UpdateBeforeSimulation() { _frameCounter100++; _frameCounter1000++; if (!_isInitialized) { return; } if (_delayedConnectionRequest) { ClientLogger.WriteInfo("Delayed Connection Request"); _delayedConnectionRequest = false; PullConnectionRequest.SendMessage(ModCommunicationVersion, PrivateCommunicationKey); } if (!_calledFirstFrame && IsConnected) { _calledFirstFrame = true; FirstFrame(); } UpdateBeforeFrame(); ChatCommandService.UpdateBeforeSimulation(); if (_frameCounter100 >= 100) { _frameCounter100 = 0; UpdateBeforeFrame100(); ChatCommandService.UpdateBeforeSimulation100(); } if (_frameCounter1000 >= 1000) { _frameCounter1000 = 0; UpdateBeforeFrame1000(); ChatCommandService.UpdateBeforeSimulation1000(); } }
public sealed override void Init(MyObjectBuilder_SessionComponent sessionComponent) { InitModSettings(out ModCommunicationVersion, out ServerConnectionId, out ServerLoggingLevel, out ServerLogFileName, out ClientConnectionId, out ClientLoggingLevel, out ClientLogFileName, out ModName, out ModTitle, out ExperimentalCreatorList); Guard.IsNotZero(ModCommunicationVersion, "SEModCore: InitModSettings must supply ModCommunicationVersion."); Guard.IsNotZero(ServerConnectionId, "SEModCore: InitModSettings must supply ServerConnectionId."); Guard.IsNotEmpty(ServerLogFileName, "SEModCore: InitModSettings must supply ServerLogFileName."); Guard.IsNotZero(ClientConnectionId, "SEModCore: InitModSettings must supply ClientConnectionId."); Guard.IsNotEmpty(ClientLogFileName, "SEModCore: InitModSettings must supply ClientLogFileName."); Guard.IsNotEmpty(ModName, "SEModCore: InitModSettings must supply ModName."); Guard.IsNotEmpty(ModTitle, "SEModCore: InitModSettings must supply ModTitle."); Guard.IsNotEqual(ServerConnectionId, ClientConnectionId, $"SEModCore: ServerConnectionId [{ServerConnectionId}] and ClientConnectionId [{ClientConnectionId}] must not be the same."); //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}"); VRage.Utils.MyLog.Default.WriteLine($"CHECK1. #########################################"); VRage.Utils.MyLog.Default.WriteLine($"CHECK2. OnlineMode===== {MyAPIGateway.Session.OnlineMode} "); VRage.Utils.MyLog.Default.WriteLine($"CHECK3. IsServer===== {MyAPIGateway.Multiplayer.IsServer}"); VRage.Utils.MyLog.Default.WriteLine($"CHECK4. IsDedicated==== {MyAPIGateway.Utilities.IsDedicated}"); if (MyAPIGateway.Multiplayer.IsServer || MyAPIGateway.Utilities.IsDedicated) { InitServer(); } if (!MyAPIGateway.Utilities.IsDedicated) { InitClient(); } if (!_commandsRegistered) { foreach (ChatCommand command in GetAllChatCommands()) { ChatCommandService.Register(command); } _commandsRegistered = ChatCommandService.Init(); } _isInitialized = true; if (_isServerRegistered) { ServerLoad(); } if (_isClientRegistered) { ClientLoad(); } ServerLogger.WriteInfo($"{ModName} Server is ready."); // Client is only `ready` after it has received the ClientConfigResponse. We log that in MessageClientConfig. }