Example #1
0
    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);
        }
    }
Example #2
0
    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");
            }
        }
    }
Example #3
0
    public void SockOpenEventHandler(IRCEvent e)
    {
        LogText("[Connected!]");
        OutputText("[Connected!]");

        // Wait for nickname verification
        SetState(eState.verifying_nick);
    }
Example #4
0
    // 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);
        }
    }
Example #6
0
    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);
    }
Example #7
0
    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);
        }
    }
Example #8
0
    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;
        }
    }
Example #9
0
    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;
        }
    }
Example #10
0
    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;
        }
    }
Example #11
0
 private void PingEventHandler(IRCEvent e)
 {
     LogText("[ping]");
 }
Example #12
0
 // Message Events
 public void StatusMessageEventHandler(IRCEvent e)
 {
     LogText("[Status]: "+m_irc.GetLastStatusMessage());
 }
Example #13
0
    private void NickEventHandler(IRCEvent e)
    {
        IRCNickEvent nickEvent = (IRCNickEvent)e;

        LogText("[user " + nickEvent.OldUser.Nick + " changed nick to " + nickEvent.NewUser.Nick);
    }
Example #14
0
    private void NoticeEventHandler(IRCEvent e)
    {
        IRCNoticeEvent noticeEvent = (IRCNoticeEvent)e;

        LogText("[notice] " + noticeEvent.User.Nick + ": " + noticeEvent.Text);
    }
Example #15
0
    private void NickEventHandler(IRCEvent e)
    {
        IRCNickEvent nickEvent = (IRCNickEvent)e;

        LogText("[user " + nickEvent.OldUser.Nick + " changed nick to " + nickEvent.NewUser.Nick);
    }
Example #16
0
    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);
    }
Example #17
0
 private void PingEventHandler(IRCEvent e)
 {
     LogText("[ping]");
 }
Example #18
0
    public void SockOpenEventHandler(IRCEvent e)
    {
        LogText("[Connected!]");
        OutputText("[Connected!]");

        // Wait for nickname verification
        SetState(eState.verifying_nick);
    }
Example #19
0
    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 DispatchEvent(IRCEvent ircEvent)
    {
        IRCEventDelegate eventDelegate= null;

        if (m_ircEventHandlers.TryGetValue(ircEvent.EventType, out eventDelegate))
        {
            eventDelegate(ircEvent);
        }
    }
Example #21
0
 // Socket Events
 private void SockErrorEventHandler(IRCEvent e)
 {
     LogText("[Socket Error] " + m_irc.GetLastError());
     OutputText("[Socket Error]");
     SetState(eState.failed);
 }
Example #22
0
    // IRC Events
    private void WelcomeEventHandler(IRCEvent e)
    {
        LogText("[Welcome]: " + m_irc.GetLastStatusMessage());

        if (m_state == eState.verifying_nick)
        {
            SetState(eState.joining_game_channel);
        }
    }
Example #23
0
    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;
        }
    }
Example #24
0
 // Socket Events
 private void SockErrorEventHandler(IRCEvent e)
 {
     LogText("[Socket Error] "+m_irc.GetLastError());
     OutputText("[Socket Error]");
     SetState(eState.failed);
 }
Example #25
0
 // Message Events
 public void StatusMessageEventHandler(IRCEvent e)
 {
     LogText("[Status]: " + m_irc.GetLastStatusMessage());
 }
Example #26
0
    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);
        }
    }
Example #27
0
    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;
        }
    }
Example #28
0
    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);
        }
    }
Example #29
0
    private void NoticeEventHandler(IRCEvent e)
    {
        IRCNoticeEvent noticeEvent = (IRCNoticeEvent)e;

        LogText("[notice] " + noticeEvent.User.Nick + ": " + noticeEvent.Text);
    }
Example #30
0
    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");
            }
        }
    }
Example #31
0
    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;
        }
    }
Example #32
0
    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);
        }
    }