protected bool RaiseMessageRecieved(TorchChatMessage msg) { var consumed = false; MessageRecieved?.Invoke(msg, ref consumed); return(consumed); }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { if (!Config.Enabled) { return; } if (msg.AuthorSteamId != null) { switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.Faction: IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name); break; } } else if (Config.ServerToDiscord && msg.Channel.Equals(ChatChannel.Global) && !msg.Message.StartsWith(Config.CommandPrefix) && msg.Target.Equals(0)) { DDBridge.SendChatMessage(msg.Author, msg.Message); } }
public void HandleCommand(TorchChatMessage msg, ref bool consumed) { if (msg.AuthorSteamId.HasValue) { HandleCommand(msg.Message, msg.AuthorSteamId.Value, ref consumed); } }
public Message(TorchChatMessage m, ulong channel) { Author = m.Author; Content = m.Message; IsBot = false; ChannelId = channel; }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { if (msg.AuthorSteamId != null) { DDBridge.SendChatMessage(msg.Author, msg.Message); } }
private static void MessageProcessing(TorchChatMessage msg, ref bool consumed) { var infoCommands = EssentialsPlugin.Instance.Config.InfoCommands; if (infoCommands == null) { return; } var c = infoCommands.FirstOrDefault(i => i.Command?.Equals(msg.Message) == true); if (c == null) { return; } consumed = true; long playerId = MySession.Static.Players.TryGetIdentityId(msg.AuthorSteamId.Value); if (!string.IsNullOrEmpty(c.ChatResponse)) { EssentialsPlugin.Instance.Torch.CurrentSession?.Managers?.GetManager <IChatManagerServer>()?.SendMessageAsOther("Server", c.ChatResponse, MyFontEnum.Blue, msg.AuthorSteamId.Value); } if (!string.IsNullOrEmpty(c.DialogResponse)) { ModCommunication.SendMessageTo(new DialogMessage(c.Command, content: c.DialogResponse), msg.AuthorSteamId.Value); } if (!string.IsNullOrEmpty(c.URL)) { MyVisualScriptLogicProvider.OpenSteamOverlay($"https://steamcommunity.com/linkfilter/?url={c.URL}", playerId); } }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(MyMultiplayer.Static?.GetMemberName(message.Author) ?? $"user_{message.Author}", message.Author, message.Text); MessageProcessing?.Invoke(torchMsg, ref consumed); }
private void ScriptedMessageReceived(string content, string author, string font, Color color) { //Log.Info($"Scripted Message: {author}: {content}"); var msg = new TorchChatMessage(author, Sync.MyId, content, ChatChannel.GlobalScripted, 0); bool c = false; MessageReceived?.Invoke(msg, ref c); }
private void Multiplayer_ScriptedChatMessageReceived(string message, string author, string font) { var torchMsg = new TorchChatMessage(author, message, font); if (!RaiseMessageRecieved(torchMsg) && HasHud) { _hudChatScriptedMessageReceived.Invoke(MyHud.Chat, author, message, font); } }
private void Multiplayer_ChatMessageReceived(ulong steamUserId, string messageText, ChatChannel channel, long targetId, string customAuthorName) { var torchMsg = new TorchChatMessage(steamUserId, messageText, channel, targetId, (steamUserId == MyGameService.UserId) ? MyFontEnum.DarkBlue : MyFontEnum.Blue); if (!RaiseMessageRecieved(torchMsg) && HasHud) { _hudChatMessageReceived.Invoke(MyHud.Chat, steamUserId, messageText, channel, targetId, customAuthorName); } }
private void Multiplayer_ChatMessageReceived(ulong steamUserId, string message) { var torchMsg = new TorchChatMessage(steamUserId, message, (steamUserId == MyGameService.UserId) ? MyFontEnum.DarkBlue : MyFontEnum.Blue); if (!RaiseMessageRecieved(torchMsg) && HasHud) { _hudChatMessageReceived.Invoke(MyHud.Chat, steamUserId, message); } }
private void ChatService_MessageReceived(TorchChatMessage msg, ref bool consumed) { //Log.Warn($"INCOMING CHAT {msg.Message}"); if (consumed || Commands.IsCommand(msg.Message)) { //Log.Info("Caught command"); return; } _chatQueue.Enqueue(new Message(msg, Config.GlobalChannel)); }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text); MessageProcessing?.Invoke(torchMsg, ref consumed); if (!consumed) { _chatLog.Info($"{torchMsg.Author}: {torchMsg.Message}"); } }
/// <inheritdoc /> protected override bool OfflineMessageProcessor(TorchChatMessage msg) { if (MyMultiplayer.Static != null) { return(false); } var consumed = false; MessageProcessing?.Invoke(msg, ref consumed); return(consumed); }
private void ReceiveGameMessageTask(TorchChatMessage msg, ref bool consumed) { if (consumed || msg.Channel != ChatChannel.Global) { return; } var gameChat = _gameChatFormat .Replace("{name}", msg.Author ?? msg.AuthorSteamId?.ToString() ?? "Unknown") .Replace("{message}", msg.Message); ProcessGameMessage(gameChat); }
/// <inheritdoc /> public override void Respond(string message, string sender = null, string font = null) { if (sender == "Server") { sender = null; font = null; } var msg = new TorchChatMessage(sender ?? TorchBase.Instance.Config.ChatName, message, font ?? TorchBase.Instance.Config.ChatColor); Responses.Add(msg); OnResponse?.Invoke(msg); }
private async void SendAsync(TorchChatMessage msg) { try { if (!Config.Enabled) { return; } if (msg.AuthorSteamId != null && !ChatManager.MutedUsers.Contains((ulong)msg.AuthorSteamId)) { if (DEBUG) { Log.Info($"Recieved messages with valid SID {msg.Author} | {msg.Message} | {msg.Target} | {msg.AuthorSteamId}"); } switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.Faction: if (msg.AuthorSteamId.ToString().StartsWith("7")) { IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name); } break; } } else if (Config.ServerToDiscord && msg.Channel.Equals(ChatChannel.Global) && !msg.Message.StartsWith(Config.CommandPrefix) && msg.Target.Equals(0)) { if (DEBUG) { Log.Info($"Recieved messages with no SID {msg.Author} | {msg.Message} | {msg.Target}"); } DDBridge.SendChatMessage(msg.Author, msg.Message); } } catch (Exception e) { Log.Fatal(e); } }
private void OfflineMessageReciever(string messageText, ref bool sendToOthers) { if (!sendToOthers) { return; } var torchMsg = new TorchChatMessage(MySession.Static.LocalHumanPlayer?.DisplayName ?? "Player", Sync.MyId, messageText, ChatChannel.Global, 0); bool consumed = RaiseMessageRecieved(torchMsg); if (!consumed) { consumed = OfflineMessageProcessor(torchMsg); } sendToOthers = !consumed; }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text, (ChatChannel)message.Channel, message.TargetId); if (_muted.Contains(message.Author)) { consumed = true; _chatLog.Warn($"MUTED USER: [{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}"); return; } MessageProcessing?.Invoke(torchMsg, ref consumed); if (!consumed) { _chatLog.Info($"[{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}"); } }
private void MessageProcessing(TorchChatMessage msg, ref bool consumed) { Log.Warn($"Message: {msg.AuthorSteamId} - {msg.Author}: {msg.Message} - {consumed} :: {msg.Channel}"); if (consumed) { return; } if (Utilities.CheckDuplicate(msg.Message)) { return; } if (msg.Channel == ChatChannel.Global || msg.Channel == ChatChannel.GlobalScripted) { MessageReceived?.Invoke(msg, ref consumed); } }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { if (msg.AuthorSteamId != null) { switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.Faction: IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name); break; } } }
private void InsertMessage(TorchChatMessage msg) { if (Dispatcher.CheckAccess()) { bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight; var span = new Span(); span.Inlines.Add($"{msg.Timestamp} "); switch (msg.Channel) { case ChatChannel.Faction: span.Inlines.Add(new Run($"[{MySession.Static.Factions.TryGetFactionById(msg.Target)?.Tag ?? "???"}] ") { Foreground = Brushes.Green }); break; case ChatChannel.Private: span.Inlines.Add(new Run($"[to {MySession.Static.Players.TryGetIdentity(msg.Target)?.DisplayName ?? "???"}] ") { Foreground = Brushes.DeepPink }); break; } span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) }); span.Inlines.Add($": {msg.Message}"); span.Inlines.Add(new LineBreak()); ChatItems.Inlines.Add(span); if (atBottom) { ChatScroller.ScrollToBottom(); } } else { Dispatcher.InvokeAsync(() => InsertMessage(msg)); } }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { try { if (!Config.Enabled) { return; } if (msg.AuthorSteamId != null) { switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message); break; case ChatChannel.Faction: IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name); break; } } else if (Config.ServerToDiscord && msg.Channel.Equals(ChatChannel.Global) && !msg.Message.StartsWith(Config.CommandPrefix) && msg.Target.Equals(0)) { // Run in a new Thread to do not freeze the server // GetAllMembersAsync need to run in a new thread if called from Torch GUI or from main thread Task.Run(() => DDBridge.SendChatMessage(msg.Author, msg.Message)); } } catch (Exception e) { Log.Fatal(e); } }
private async void SendAsync(TorchChatMessage msg) { try { if (!Config.Enabled) { return; } bool Console = msg.AuthorSteamId == null; if (msg.AuthorSteamId != null) { switch (msg.Channel) { case ChatChannel.Global: DDBridge.SendChatMessage(msg.Author, msg.Message, Console); break; case ChatChannel.GlobalScripted: DDBridge.SendChatMessage(msg.Author, msg.Message, Console); break; case ChatChannel.Faction: IMyFaction fac = MySession.Static.Factions.TryGetFactionById(msg.Target); DDBridge.SendFacChatMessage(msg.Author, msg.Message, fac.Name, Console); break; } } else if (Config.ServerToDiscord && msg.Channel.Equals(ChatChannel.Global) && !msg.Message.StartsWith(Config.CommandPrefix) && msg.Target.Equals(0)) { DDBridge.SendChatMessage(msg.Author, msg.Message, Console); } } catch (Exception e) { Log.Fatal(e); } }
private void InsertMessage(TorchChatMessage msg) { if (Dispatcher.CheckAccess()) { bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight; var span = new Span(); span.Inlines.Add($"{msg.Timestamp} "); span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) }); span.Inlines.Add($": {msg.Message}"); span.Inlines.Add(new LineBreak()); ChatItems.Inlines.Add(span); if (atBottom) { ChatScroller.ScrollToBottom(); } } else { Dispatcher.InvokeAsync(() => InsertMessage(msg)); } }
private void OnMessageRecieved(TorchChatMessage msg, ref bool consumed) { InsertMessage(msg); }
private void MessageRecieved(TorchChatMessage msg, ref bool consumed) { Task.Run(async() => SendAsync(msg)); }
public static void DoChatMessage(TorchChatMessage msg, ref bool consumed) { if (msg.AuthorSteamId == null) { return; } if (msg.Channel == Sandbox.Game.Gui.ChatChannel.Private || msg.Channel == Sandbox.Game.Gui.ChatChannel.Faction) { return; } if (msg.Message.StartsWith("!")) { return; } if (PeopleInAllianceChat.ContainsKey((ulong)msg.AuthorSteamId)) { MyIdentity identity; if (IdentityIds.ContainsKey((ulong)msg.AuthorSteamId)) { identity = MySession.Static.Players.TryGetIdentity(IdentityIds[(ulong)msg.AuthorSteamId]); } else { identity = AlliancePlugin.GetIdentityByNameOrId(msg.AuthorSteamId.ToString()); } if (identity == null) { return; } MyFaction fac = MySession.Static.Factions.GetPlayerFaction(identity.IdentityId); if (fac == null) { bool noFac = true; if (AlliancePlugin.GetIdentityByNameOrId(msg.Author) != null) { if (MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId) != null) { noFac = false; fac = MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId); } } if (noFac) { PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); AlliancePlugin.SendChatMessage("Failsafe", "Faction null"); } return; } if (AlliancePlugin.GetAllianceNoLoading(fac) == null) { PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); AlliancePlugin.SendChatMessage("Failsafe", "Alliance null"); return; } consumed = true; Guid allianceId = PeopleInAllianceChat[(ulong)msg.AuthorSteamId]; List <ulong> OtherMembers = new List <ulong>(); Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceId); // ShipyardCommands.SendMessage(msg.Author, "You are in alliance chat", Color.BlueViolet, (long)msg.AuthorSteamId); if (alliance.GetTitle((ulong)msg.AuthorSteamId).Equals("")) { SendChatMessage(allianceId, msg.Author, msg.Message, true, identity.IdentityId); } else { SendChatMessage(allianceId, alliance.GetTitle((ulong)msg.AuthorSteamId) + " | " + msg.Author, msg.Message, true, identity.IdentityId); } } else { // PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId); } }
/// <summary> /// Callback used to process offline messages. /// </summary> /// <param name="msg"></param> /// <returns>true if the message was consumed</returns> protected virtual bool OfflineMessageProcessor(TorchChatMessage msg) { return(false); }