public static void SendPrivateInformation( ulong playerId, string infoText, string from = null ) { if ( infoText == "" ) return; ServerMessageItem MessageItem = new ServerMessageItem( ); if(from == null ) MessageItem.From = PluginSettings.Instance.ServerChatName; else if ( PluginSettings.Instance.WhisperChatPrefix ) MessageItem.From = "<whisper> " + from; else MessageItem.From = from; MessageItem.Message = infoText; string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem ); byte[ ] data = Encoding.Unicode.GetBytes( messageString ); if ( ChatManager.EnableData ) { SendDataMessage( playerId, DataMessageType.Message, data ); } else ChatManager.Instance.SendPrivateChatMessage( playerId, infoText ); ChatManager.ChatEvent chatItem = new ChatManager.ChatEvent( ); chatItem.Timestamp = DateTime.Now; chatItem.RemoteUserId = (from == null ? 0 : PlayerMap.Instance.GetSteamIdFromPlayerName( from )); chatItem.Message = (from == null ? infoText : (string.Format( "{whisper to {0}}: {1}", PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerId ), infoText ))); ChatManager.Instance.AddChatHistory( chatItem ); }
public static void HookChatMessage(Object plugin, Dictionary <Guid, IPlugin> plugins, Dictionary <Guid, bool> pluginState, ChatManager.ChatEvent chatEvent, out bool discard) { discard = false; foreach (Guid key in plugins.Keys) { object hookPlugin = plugins[key]; if (!pluginState.ContainsKey(key)) { continue; } MethodInfo hookMethod = hookPlugin.GetType( ).GetMethod("OnChatHook"); if (hookMethod != null) { const bool hookDiscard = false; object[] args = { chatEvent, plugin, hookDiscard }; hookMethod.Invoke(hookPlugin, args); discard = (bool)args[2]; } } }