/// <inheritdoc /> public void SendMessageAsSelf(string message) { if (MyMultiplayer.Static != null) { if (Sandbox.Engine.Platform.Game.IsDedicated) { var scripted = new ScriptedChatMsg() { Author = "Server", Font = MyFontEnum.Red, Text = message, Target = 0 }; MyMultiplayerBase.SendScriptedChatMessage(ref scripted); } else { MyMultiplayer.Static.SendChatMessage(message); } } else if (HasHud) { MyHud.Chat.ShowMessage(MySession.Static.LocalHumanPlayer?.DisplayName ?? "Player", message); } }
#pragma warning restore 649 /// <inheritdoc /> public void SendMessageAsOther(string author, string message, string font, ulong targetSteamId = 0) { if (targetSteamId == Sync.MyId) { RaiseMessageRecieved(new TorchChatMessage(author, message, font)); return; } if (MyMultiplayer.Static == null) { if ((targetSteamId == MyGameService.UserId || targetSteamId == 0) && HasHud) { MyHud.Chat?.ShowMessage(author, message, font); } return; } var scripted = new ScriptedChatMsg() { Author = author ?? Torch.Config.ChatName, Text = message, Font = font ?? Torch.Config.ChatColor, Target = Sync.Players.TryGetIdentityId(targetSteamId) }; _chatLog.Info($"{author} (to {GetMemberName(targetSteamId)}): {message}"); MyMultiplayerBase.SendScriptedChatMessage(ref scripted); }
/// <inheritdoc /> public void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Red) { if (string.IsNullOrEmpty(message)) { return; } ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, message)); if (_commandManager.IsCommand(message)) { var response = _commandManager.HandleCommandFromServer(message); ChatHistory.Add(new ChatMessage(DateTime.Now, 0, author, response)); } else { var msg = new ScriptedChatMsg { Author = author, Font = font, Target = playerId, Text = message }; MyMultiplayerBase.SendScriptedChatMessage(ref msg); var character = MySession.Static.Players.TryGetIdentity(playerId)?.Character; var steamId = GetSteamId(playerId); if (character == null) { return; } var addToGlobalHistoryMethod = typeof(MyCharacter).GetMethod("OnGlobalMessageSuccess", BindingFlags.Instance | BindingFlags.NonPublic); _networkManager.RaiseEvent(addToGlobalHistoryMethod, character, steamId, steamId, message); } }
public static void SendFactionClientMessage(ulong playerSteamId, string message) { string from; if (PluginSettings.Instance.FactionChatPrefix) { from = "<faction> " + PlayerMap.Instance.GetFastPlayerNameFromSteamId(playerSteamId); } else { from = PlayerMap.Instance.GetFastPlayerNameFromSteamId(playerSteamId); } foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers) { if (Player.CheckPlayerSameFaction(playerSteamId, steamId)) { ScriptedChatMsg msg = new ScriptedChatMsg { Author = from, Font = MyFontEnum.Red, Text = message, Target = PlayerMap.Instance.GetFastPlayerIdFromSteamId(steamId), }; var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static); ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, msg); } } ChatManager.Instance.AddChatHistory(new ChatManager.ChatEvent(DateTime.Now, playerSteamId, "{faction message}: " + message)); }
/// <inheritdoc /> public void SendMessageAsSelf(string message) { if (MyMultiplayer.Static != null) { if (Sandbox.Engine.Platform.Game.IsDedicated) { // Sending invalid color to clients will crash them. KEEEN var color = Torch.Config.ChatColor; if (!StringUtils.IsFontEnum(Torch.Config.ChatColor)) { _log.Warn("Invalid chat font color! Defaulting to 'Red'"); color = MyFontEnum.Red; } var scripted = new ScriptedChatMsg() { Author = Torch.Config.ChatName, Font = color, Text = message, Target = 0 }; MyMultiplayerBase.SendScriptedChatMessage(ref scripted); } else { throw new NotImplementedException("Chat system changes broke this"); } //MyMultiplayer.Static.SendChatMessage(message); } else if (HasHud) { MyHud.Chat.ShowMessage(MySession.Static.LocalHumanPlayer?.DisplayName ?? "Player", message); } }
public static void SendPublicInformation(string infoText) { if (string.IsNullOrEmpty(infoText)) { return; } ScriptedChatMsg msg = new ScriptedChatMsg { Author = PluginSettings.Instance.ServerChatName, Font = MyFontEnum.Red, Text = infoText, }; var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static); ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, msg); ChatManager.Instance.ScanGPSAndAdd(infoText); //ServerMessageItem MessageItem = new ServerMessageItem( ); //MessageItem.From = PluginSettings.Instance.ServerChatName; //MessageItem.Message = infoText; //string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem ); //byte[ ] data = Encoding.UTF8.GetBytes( messageString ); //if ( ChatManager.EnableData ) //{ // BroadcastDataMessage( DataMessageType.Message, data ); //} //else // ChatManager.Instance.SendPublicChatMessage( infoText ); ChatManager.Instance.AddChatHistory(new ChatManager.ChatEvent(DateTime.Now, 0, infoText)); }
/// <summary> /// Send a message in chat. /// </summary> public void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Red) { var msg = new ScriptedChatMsg { Author = author, Font = font, Target = playerId, Text = message }; MyMultiplayerBase.SendScriptedChatMessage(ref msg); }
/// <summary> /// Sends message directly through SE's API instead of Torch /// (current Torch public build doesn't work) /// </summary> /// <param name="author"></param> /// <param name="message"></param> /// <param name="authorColor"></param> public static void SendMessageNative(string author, string message, Color?authorColor = null) { var scripted = new ScriptedChatMsg() { Author = author, Text = message, Font = MyFontEnum.White, Color = authorColor ?? Color.Red, Target = 0 }; MyMultiplayerBase.SendScriptedChatMessage(ref scripted); }
/// <summary> /// Sends the specified message and prefix to the player /// </summary> /// <param name="player"></param> /// <param name="message"></param> /// <param name="prefix"></param> /// <param name="args"></param> public void Message(IMyPlayer player, string message, string prefix, params object[] args) { message = args.Length > 0 ? string.Format(Formatter.ToPlaintext(message), args) : Formatter.ToPlaintext(message); var msg = new ScriptedChatMsg { Text = prefix != null ? $"{prefix} {message}" : message, Author = "server", Target = player.IdentityId, Font = "Green" }; MyMultiplayerBase.SendScriptedChatMessage(ref msg); }
public void SendMessageTo(string authorName, string message, Color color, ulong targetSteamId) { var msg = new ScriptedChatMsg { Author = authorName, Text = message, Font = MyFontEnum.White, Color = color, Target = Sync.Players.TryGetIdentityId(targetSteamId), }; MyMultiplayerBase.SendScriptedChatMessage(ref msg); }
public static void SendMessage(string author, string message, Color color, ulong steamID) { Logger _chatLog = LogManager.GetLogger("Chat"); ScriptedChatMsg scriptedChatMsg1 = new ScriptedChatMsg(); scriptedChatMsg1.Author = author; scriptedChatMsg1.Text = message; scriptedChatMsg1.Font = "White"; scriptedChatMsg1.Color = color; scriptedChatMsg1.Target = Sync.Players.TryGetIdentityId(steamID); ScriptedChatMsg scriptedChatMsg2 = scriptedChatMsg1; MyMultiplayerBase.SendScriptedChatMessage(ref scriptedChatMsg2); }
public static void Send(string response, ulong Target) { var scripted = new ScriptedChatMsg() { Author = Author, Text = response, Font = MyFontEnum.White, Color = ChatColor, Target = Sync.Players.TryGetIdentityId(Target) }; Log.Info($"{Author} (to {Torch.Managers.ChatManager.ChatManagerServer.GetMemberName(Target)}): {response}"); MyMultiplayerBase.SendScriptedChatMessage(ref scripted); }
public static void SendMessageTemp(string author, string message, Color color) { Logger _chatLog = LogManager.GetLogger("Chat"); ScriptedChatMsg scriptedChatMsg1 = new ScriptedChatMsg(); scriptedChatMsg1.Author = author; scriptedChatMsg1.Text = message; scriptedChatMsg1.Font = "White"; scriptedChatMsg1.Color = color; scriptedChatMsg1.Target = 0L; ScriptedChatMsg scriptedChatMsg2 = scriptedChatMsg1; MyMultiplayerBase.SendScriptedChatMessage(ref scriptedChatMsg2); _chatLog.Info($"{author} (to {ChatManagerServer.GetMemberName(0)}): {message}"); }
/// <summary> /// Sends a chat message to the player /// </summary> /// <param name="player"></param> /// <param name="message"></param> /// <param name="prefix"></param> public void Message(IMyPlayer player, string message, string prefix = null) { if (string.IsNullOrEmpty(message)) { return; } var msg = new ScriptedChatMsg { Text = string.IsNullOrEmpty(prefix) ? message : (string.IsNullOrEmpty(message) ? prefix : $"{prefix}: {message}"), Author = "server", Target = player.IdentityId, Font = "Green" }; MyMultiplayerBase.SendScriptedChatMessage(ref msg); }
public static void SendPrivateInformation(ulong playerId, string infoText, string from = null) { if (string.IsNullOrEmpty(infoText)) { return; } ulong steamId = from == null ? 0 : PlayerMap.Instance.GetSteamIdFromPlayerName(from); if (from == null) { from = PluginSettings.Instance.ServerChatName; } else if (PluginSettings.Instance.WhisperChatPrefix) { from = "<whisper> " + from; } ScriptedChatMsg msg = new ScriptedChatMsg { Author = from, Font = MyFontEnum.Red, Text = infoText, Target = PlayerMap.Instance.GetFastPlayerIdFromSteamId(playerId), }; if (msg.Target != 0) { var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static); ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, msg); ChatManager.Instance.ScanGPSAndAdd(infoText, msg.Target); } ChatManager.ChatEvent chatItem = new ChatManager.ChatEvent( ); chatItem.Timestamp = DateTime.Now; chatItem.RemoteUserId = steamId; chatItem.Message = (from == null ? infoText : ($"{{whisper}} to {PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerId )}: {infoText}")); ChatManager.Instance.AddChatHistory(chatItem); }
/// <inheritdoc /> public void SendMessageAsSelf(string message) { if (MyMultiplayer.Static != null) { if (Sandbox.Engine.Platform.Game.IsDedicated) { var scripted = new ScriptedChatMsg() { Author = Torch.Config.ChatName, Text = message, Target = 0 }; var color = Torch.Config.ChatColor; if (StringUtils.IsFontEnum(color)) { scripted.Font = color; } else { scripted.Font = MyFontEnum.White; } scripted.Color = ColorUtils.TranslateColor(color); MyMultiplayerBase.SendScriptedChatMessage(ref scripted); } else { throw new NotImplementedException("Chat system changes broke this"); } //MyMultiplayer.Static.SendChatMessage(message); } else if (HasHud) { MyHud.Chat.ShowMessage(MySession.Static.LocalHumanPlayer?.DisplayName ?? "Player", message); } }
public static async Task RunTask(Action Invoker, ulong?SteamID = null) { if (!Hangar.ServerRunning || !MySession.Static.Ready) { return; } if (SteamID.HasValue && SteamID.Value != 1 && Dictionary.TryGetValue(SteamID.Value, out Task RunningTask)) { if (RunningTask.Status == TaskStatus.Running) { ScriptedChatMsg A = new ScriptedChatMsg(); A.Author = "Hangar"; A.Target = MySession.Static.Players.TryGetIdentityId(SteamID.Value); A.Text = "Your previous command has yet to finish! Please wait!"; A.Font = "Blue"; A.Color = VRageMath.Color.Yellow; MyMultiplayerBase.SendScriptedChatMessage(ref A); //Log.Warn("Aborted Action!"); return; } StringBuilder Builder = new StringBuilder(); Builder.AppendLine($"Task is being removed! Status: {RunningTask.Status}"); foreach (Exception ex in RunningTask.Exception.InnerExceptions) { Builder.AppendLine(ex.ToString()); } Log.Error(Builder.ToString()); Dictionary.TryRemove(SteamID.Value, out _); } /* * if (!SteamID.HasValue) * { * //Log.Info(" Running Admin command!"); * * try * { * Invoker.Invoke(); * } * catch (Exception ex) * { * Log.Error(ex); * } * return; * } */ if (!SteamID.HasValue) { SteamID = 1; } if (SteamID.Value != 1) { Action Completed = delegate { RemoveAfterCompletion(SteamID.Value); }; Invoker += Completed; Dictionary.TryAdd(SteamID.Value, null); await Task.Run(() => Invoker); return; } if (SteamID.Value == 1) { //Log.Warn("PP"); await Task.Run(() => Invoker); return; } }
public static void RunTask(Action Invoker, ulong?SteamID = null) { if (!Hangar.ServerRunning || !MySession.Static.Ready) { return; } if (SteamID.HasValue && SteamID.Value != 1 && Dictionary.TryGetValue(SteamID.Value, out Task RunningTask)) { if (RunningTask.Status == TaskStatus.Running) { ScriptedChatMsg A = new ScriptedChatMsg(); A.Author = "Hangar"; A.Target = MySession.Static.Players.TryGetIdentityId(SteamID.Value); A.Text = "Your previous command has yet to finish! Please wait!"; A.Font = "Blue"; A.Color = VRageMath.Color.Yellow; MyMultiplayerBase.SendScriptedChatMessage(ref A); //Log.Warn("Aborted Action!"); return; } Log.Error("Task is being removed! Status: " + RunningTask.Status + " Errors: " + RunningTask.Exception.Message); Dictionary.TryRemove(SteamID.Value, out _); } if (!SteamID.HasValue) { //Log.Info(" Running Admin command!"); try { Invoker.Invoke(); } catch (Exception ex) { Log.Error(ex); } return; } if (SteamID.Value != 1) { Action Completed = delegate { RemoveAfterCompletion(SteamID.Value); }; Invoker += Completed; Task Run = new Task(Invoker); Run.Start(); Dictionary.TryAdd(SteamID.Value, Run); return; } if (SteamID.Value == 1) { //Log.Warn("PP"); Task Run = new Task(Invoker); Run.Start(); return; } }
private static void ReceivePacket(ushort HandlerId, byte[] Data, ulong SteamID, bool FromServer) { // Only consider trusted server messages, i.e. from Nexus itself, not untrusted player messages. if (!FromServer) { return; } NexusHangarMessage msg; try { msg = MyAPIGateway.Utilities.SerializeFromBinary <NexusHangarMessage>(Data); } catch (Exception ex) { Log.Error(ex, "Invalid Nexus cross-server message for Quantum Hangar"); return; } switch (msg.Type) { case NexusHangarMessageType.Chat: var chat = new ScriptedChatMsg() { Author = msg.Sender, Text = msg.Response, Font = MyFontEnum.White, Color = msg.Color, Target = msg.ChatIdentityID }; MyMultiplayerBase.SendScriptedChatMessage(ref chat); return; case NexusHangarMessageType.SendGPS: gpsSender.SendGps(msg.Position, msg.Name, msg.EntityID); return; case NexusHangarMessageType.LoadGrid: var chatOverNexus = new Chat((text, color, sender) => { NexusHangarMessage m = new NexusHangarMessage { Type = NexusHangarMessageType.Chat, IdentityID = msg.IdentityID, Response = text, Color = color, Sender = sender, }; API.SendMessageToServer(msg.ServerID, MyAPIGateway.Utilities.SerializeToBinary <NexusHangarMessage>(m)); }); var gpsOverNexus = new GpsSender((position, name, entityID) => { NexusHangarMessage m = new NexusHangarMessage { Type = NexusHangarMessageType.SendGPS, Name = name, Position = position, EntityID = entityID, }; API.SendMessageToServer(msg.ServerID, MyAPIGateway.Utilities.SerializeToBinary <NexusHangarMessage>(m)); }); PlayerChecks User = new PlayerChecks(chatOverNexus, gpsOverNexus, msg.SteamID, msg.IdentityID, msg.PlayerPosition); User.LoadGrid(msg.LoadGridID.ToString(), msg.LoadNearPlayer); return; } Log.Error("Invalid Nexus cross-server message for Quantum Hangar (unrecognized type: " + msg.Type + ")"); }