private void OnIRCPrivateMessage(string[] tokens, string message) { IRCPrivmsgEvent pmsg = new IRCPrivmsgEvent(); pmsg.Channel = tokens[2]; pmsg.User = IRCUser.GetUserFromAddress(tokens[0].Substring(1)); pmsg.Message = message; DispatchEvent(pmsg); }
// Outbound Chat or a Console Command public void OnInput(IRCPrivmsgEvent privmsgEvent, PostProcessChatDelegate postProcessChat) { int n = privmsgEvent.Message.IndexOf("/"); int n2 = privmsgEvent.Message.IndexOf("me", 0); //no action? if (n == 0 && n2 != 1) // this is a little hack because /me is not handled like a command { try { ProcessInput(privmsgEvent.Message); } catch (Exception e) { m_lastActiveMessage = e.Message; DispatchEvent(new IRCEvent(IRCEvent.EVENT_ACTIVEMESSAGE)); } } else { IRCPrivmsgEvent newPrivmsgEvent = new IRCPrivmsgEvent(); string str = ""; string finalMesg = ""; if (n2 != 1) { // message finalMesg = (postProcessChat != null) ? postProcessChat(privmsgEvent.Message) : privmsgEvent.Message; str = "PRIVMSG " + privmsgEvent.Channel + " :" + finalMesg; newPrivmsgEvent.Message = finalMesg; } else { // action string sourceMesg = privmsgEvent.Message.Substring(4); str = "PRIVMSG " + privmsgEvent.Channel + " :\u0001ACTION " + sourceMesg + "\u0001"; newPrivmsgEvent.Message = "\u0001ACTION " + sourceMesg + "\u0001"; } m_socket.SendString(str); newPrivmsgEvent.Channel = privmsgEvent.Channel; newPrivmsgEvent.User = new IRCUser(); newPrivmsgEvent.User.Nick = m_nickName; newPrivmsgEvent.User.Ident = ""; newPrivmsgEvent.User.Host = ""; DispatchEvent(newPrivmsgEvent); } }
public void SendGameEvent(GameEvent gameEvent) { string eventString = gameEvent.ToObject().ToJson(); if (m_irc.IsConnected && ChannelOpen) { IRCPrivmsgEvent privmsgEvent = new IRCPrivmsgEvent(); privmsgEvent.Channel = "#" + m_ircChannelName; privmsgEvent.Message = GAME_EVENT_PREFIX + eventString; m_irc.OnInput(privmsgEvent, EncryptAndBase64Encode); } else { LogText("[failed to game event message]: " + eventString); OutputText("[failed to game event message]: " + eventString); } }
public void SendChat(String message) { if (m_irc.IsConnected && ChannelOpen) { IRCPrivmsgEvent privmsgEvent = new IRCPrivmsgEvent(); // Nuder any commands by stripping off the "/" if (message.IndexOf("/") == 0) { message = message.Substring(1); } privmsgEvent.Channel = "#" + m_ircChannelName; privmsgEvent.Message = message; m_irc.OnInput(privmsgEvent, EncryptAndBase64Encode); } else { LogText("[failed to send message]: " + message); OutputText("[failed to send message]: " + message); } }
private void PrivmsgEventHandler(IRCEvent e) { IRCPrivmsgEvent privmsgEvent = (IRCPrivmsgEvent)e; string resultMessage = privmsgEvent.Message; string properChannelName = "#" + m_ircChannelName; if (privmsgEvent.Channel == properChannelName) { // If the encryptor is active, assume that the incoming chat is encrypted if (m_encryptor != null) { try { resultMessage = Base64DecodeAndDecrypt(privmsgEvent.Message); } catch (Exception) { resultMessage = "(UNENCRYPTED)" + privmsgEvent.Message; } } // Decode game events smuggled through IRC if (resultMessage.IndexOf(GAME_EVENT_PREFIX) == 0) { string gameEventString = resultMessage.Substring(GAME_EVENT_PREFIX.Length); JsonData gameEventObject = null; try { gameEventObject = JsonMapper.ToObject(gameEventString); } catch (Exception ex) { Debug.LogException(ex); gameEventObject = null; } if (gameEventObject != null) { GameEvent gameEvent = GameEvent.FromObject(gameEventObject); if (gameEvent != null) { GameEventHandler(privmsgEvent.User.Nick, gameEvent); } else { LogText("Error parsing game event object: " + gameEventString); } } else { LogText("Malformed game event JSON string: " + gameEventString); } } // All other text gets emitted as chat from some user else { OutputText("[" + privmsgEvent.User.Nick + "] " + resultMessage); } } else { LogText("[private mesg] " + privmsgEvent.User.Nick + ": " + privmsgEvent.Message); } }
// Outbound Chat or a Console Command public void OnInput( IRCPrivmsgEvent privmsgEvent, PostProcessChatDelegate postProcessChat) { int n = privmsgEvent.Message.IndexOf( "/" ); int n2 = privmsgEvent.Message.IndexOf( "me", 0 ); //no action? if ( n == 0 && n2 != 1 ) // this is a little hack because /me is not handled like a command { try { ProcessInput( privmsgEvent.Message ); } catch ( Exception e ) { m_lastActiveMessage = e.Message; DispatchEvent( new IRCEvent( IRCEvent.EVENT_ACTIVEMESSAGE ) ); } } else { IRCPrivmsgEvent newPrivmsgEvent = new IRCPrivmsgEvent(); string str= ""; string finalMesg= ""; if ( n2 != 1 ) { // message finalMesg = (postProcessChat != null) ? postProcessChat(privmsgEvent.Message) : privmsgEvent.Message; str = "PRIVMSG " + privmsgEvent.Channel + " :" + finalMesg; newPrivmsgEvent.Message = finalMesg; } else { // action string sourceMesg = privmsgEvent.Message.Substring( 4 ); str = "PRIVMSG " + privmsgEvent.Channel + " :\u0001ACTION " + sourceMesg + "\u0001"; newPrivmsgEvent.Message = "\u0001ACTION " + sourceMesg + "\u0001"; } m_socket.SendString( str ); newPrivmsgEvent.Channel = privmsgEvent.Channel; newPrivmsgEvent.User = new IRCUser(); newPrivmsgEvent.User.Nick = m_nickName; newPrivmsgEvent.User.Ident = ""; newPrivmsgEvent.User.Host = ""; DispatchEvent( newPrivmsgEvent ); } }
public void SendGameEvent(GameEvent gameEvent) { string eventString = gameEvent.ToObject().ToJson(); if (m_irc.IsConnected && ChannelOpen) { IRCPrivmsgEvent privmsgEvent = new IRCPrivmsgEvent(); privmsgEvent.Channel = "#" + m_ircChannelName; privmsgEvent.Message = GAME_EVENT_PREFIX + eventString; m_irc.OnInput(privmsgEvent, EncryptAndBase64Encode); } else { LogText("[failed to game event message]: "+eventString); OutputText("[failed to game event message]: "+eventString); } }
public void SendChat(String message) { if (m_irc.IsConnected && ChannelOpen) { IRCPrivmsgEvent privmsgEvent = new IRCPrivmsgEvent(); // Nuder any commands by stripping off the "/" if (message.IndexOf("/") == 0) { message = message.Substring(1); } privmsgEvent.Channel = "#" + m_ircChannelName; privmsgEvent.Message = message; m_irc.OnInput(privmsgEvent, EncryptAndBase64Encode); } else { LogText("[failed to send message]: "+message); OutputText("[failed to send message]: "+message); } }