private void KickEventHandler(IRCEvent e) { IRCKickEvent kickEvent = (IRCKickEvent)e; string victimNick = kickEvent.Victim.Nick; string properChannelName = "#" + m_ircChannelName; LogText("[" + kickEvent.Agressor.Nick + " kicked " + victimNick + " from " + kickEvent.Channel + "] " + kickEvent.Reason); if (kickEvent.Channel == properChannelName) { if (victimNick == m_ircNick) { // We got kicked. // Try to re-connect to the game channel m_reconnectionAttempts = 0; SetState(eState.failed); } else { // Someone else got kicked PostOtherPlayerLeftGameChannel(victimNick); } OutputText("[" + kickEvent.Agressor.Nick + " kicked " + m_ircNick + " from game] " + kickEvent.Reason); } }
private void JoinEventHandler(IRCEvent e) { IRCJoinEvent joinEvent = (IRCJoinEvent)e; string properChannelName = "#" + m_ircChannelName; LogText("[" + joinEvent.User.Nick + " joined channel" + joinEvent.Channel + "]"); // Ignore the redundant ops user join if (joinEvent.User.Nick[0] != '@') { if (joinEvent.User.Nick == m_ircNick) { if (m_state == eState.joining_game_channel && joinEvent.Channel == properChannelName) { SetState(eState.in_game_channel); // Notify other players with a game event to ping the server state since we joined PostThisPlayerJoinedGameChannel(); } } if (joinEvent.Channel == properChannelName) { OutputText(joinEvent.User.Nick + " joined the game"); } } }
public void SockOpenEventHandler(IRCEvent e) { LogText("[Connected!]"); OutputText("[Connected!]"); // Wait for nickname verification SetState(eState.verifying_nick); }
// IRC Events private void WelcomeEventHandler(IRCEvent e) { LogText("[Welcome]: " + m_irc.GetLastStatusMessage()); if (m_state == eState.verifying_nick) { SetState(eState.joining_game_channel); } }
private void DispatchEvent(IRCEvent ircEvent) { IRCEventDelegate eventDelegate = null; if (m_ircEventHandlers.TryGetValue(ircEvent.EventType, out eventDelegate)) { eventDelegate(ircEvent); } }
private void QuitEventHandler(IRCEvent e) { IRCQuitEvent quitEvent = (IRCQuitEvent)e; string nick = quitEvent.User.Nick; PostOtherPlayerLeftGameChannel(nick); LogText("[" + nick + " quit] " + quitEvent.Message); OutputText("[" + nick + " quit] " + quitEvent.Message); }
private void ModeEventHandler(IRCEvent e) { IRCModeEvent modeEvent = (IRCModeEvent)e; if (modeEvent.User != null) { LogText("[Mode " + modeEvent.Mode + " set by " + modeEvent.User.Nick + " in channel " + modeEvent.Channel); } else { LogText("[Mode " + modeEvent.Mode + "set in channel " + modeEvent.Channel); } }
private void TopicEventHandler(IRCEvent e) { IRCTopicEvent topicEvent = (IRCTopicEvent)e; switch (topicEvent.Mode) { case IRCTopicEvent.eModeType.set_by: LogText("[mod set, channel=" + topicEvent.Channel + "] " + topicEvent.Message); break; case IRCTopicEvent.eModeType.no_topic: LogText("[no topic set, channel=" + topicEvent.Channel + "] " + topicEvent.Message); break; case IRCTopicEvent.eModeType.topic: LogText("[topic set, channel=" + topicEvent.Channel + "] " + topicEvent.Message); break; } }
public void ActiveMessageEventHandler(IRCEvent e) { LogText("[Active Message]: " + m_irc.GetLastActiveMessage()); switch (m_state) { case eState.verifying_nick: OutputText("[Can't Verify Nick] " + m_irc.GetLastActiveMessage()); m_ircNick = m_ircNick + "_"; // Try changing the nick we use in case some jerk already took it SetState(eState.failed); break; case eState.joining_game_channel: OutputText("[Can't Join Channel] " + m_irc.GetLastActiveMessage()); m_ircChannelName = m_ircChannelName + "_"; // Try changing the channel name in case some jerk already took it. SetState(eState.failed); break; } }
public void ErrorEventHandler(IRCEvent e) { IRCErrorEvent errorEvent = (IRCErrorEvent)e; LogText("[General Error]" + errorEvent.Message); switch (m_state) { case eState.verifying_nick: OutputText("[Can't Verify Nick] " + errorEvent.Message); m_ircNick = m_ircNick + "_"; // Try changing the nick we use in case some jerk already took it SetState(eState.failed); break; case eState.joining_game_channel: OutputText("[Can't Join Channel] " + errorEvent.Message); m_ircChannelName = m_ircChannelName + "_"; // Try changing the channel name in case some jerk already took it. SetState(eState.failed); break; } }
private void PingEventHandler(IRCEvent e) { LogText("[ping]"); }
// Message Events public void StatusMessageEventHandler(IRCEvent e) { LogText("[Status]: "+m_irc.GetLastStatusMessage()); }
private void NickEventHandler(IRCEvent e) { IRCNickEvent nickEvent = (IRCNickEvent)e; LogText("[user " + nickEvent.OldUser.Nick + " changed nick to " + nickEvent.NewUser.Nick); }
private void NoticeEventHandler(IRCEvent e) { IRCNoticeEvent noticeEvent = (IRCNoticeEvent)e; LogText("[notice] " + noticeEvent.User.Nick + ": " + noticeEvent.Text); }
private void QuitEventHandler(IRCEvent e) { IRCQuitEvent quitEvent= (IRCQuitEvent)e; string nick = quitEvent.User.Nick; PostOtherPlayerLeftGameChannel(nick); LogText("[" + nick + " quit] " + quitEvent.Message); OutputText("[" + nick + " quit] " + quitEvent.Message); }
private void DispatchEvent(IRCEvent ircEvent) { IRCEventDelegate eventDelegate= null; if (m_ircEventHandlers.TryGetValue(ircEvent.EventType, out eventDelegate)) { eventDelegate(ircEvent); } }
// Socket Events private void SockErrorEventHandler(IRCEvent e) { LogText("[Socket Error] " + m_irc.GetLastError()); OutputText("[Socket Error]"); SetState(eState.failed); }
// Socket Events private void SockErrorEventHandler(IRCEvent e) { LogText("[Socket Error] "+m_irc.GetLastError()); OutputText("[Socket Error]"); SetState(eState.failed); }
// Message Events public void StatusMessageEventHandler(IRCEvent e) { LogText("[Status]: " + m_irc.GetLastStatusMessage()); }
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); } }
public void ErrorEventHandler(IRCEvent e) { IRCErrorEvent errorEvent= (IRCErrorEvent)e; LogText("[General Error]" + errorEvent.Message); switch(m_state) { case eState.verifying_nick: OutputText("[Can't Verify Nick] " + errorEvent.Message); m_ircNick = m_ircNick+"_"; // Try changing the nick we use in case some jerk already took it SetState(eState.failed); break; case eState.joining_game_channel: OutputText("[Can't Join Channel] " + errorEvent.Message); m_ircChannelName = m_ircChannelName + "_"; // Try changing the channel name in case some jerk already took it. SetState(eState.failed); break; } }
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); } }
public void ActiveMessageEventHandler(IRCEvent e) { LogText("[Active Message]: " + m_irc.GetLastActiveMessage()); switch(m_state) { case eState.verifying_nick: OutputText("[Can't Verify Nick] " + m_irc.GetLastActiveMessage()); m_ircNick = m_ircNick+"_"; // Try changing the nick we use in case some jerk already took it SetState(eState.failed); break; case eState.joining_game_channel: OutputText("[Can't Join Channel] " + m_irc.GetLastActiveMessage()); m_ircChannelName = m_ircChannelName + "_"; // Try changing the channel name in case some jerk already took it. SetState(eState.failed); break; } }