コード例 #1
0
    public IRCSession(
        string serverAddress,
        uint port,
        string nick,
        string user,
        string ident,
        string channel,
        byte[] encryptionKey)
    {
        m_ircServerAddress      = serverAddress;
        m_ircServerPort         = port;
        m_ircPrimaryChannelName = channel;
        m_ircChannelName        = m_ircPrimaryChannelName;
        m_ircPrimaryNick        = nick;
        m_ircNick         = m_ircPrimaryNick;
        m_ircUser         = user;
        m_ircFullIdentity = ident;

        m_irc = new IRCEventDispatcher();

        m_irc.AddEventListener(IRCEvent.EVENT_STATUSMESSAGE, StatusMessageEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_SOCKOPEN, SockOpenEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_ERROR, ErrorEventHandler);

        m_irc.AddEventListener(IRCEvent.EVENT_SOCKERROR, SockErrorEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_ACTIVEMESSAGE, ActiveMessageEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_PING, PingEventHandler);

        m_irc.AddEventListener(IRCEvent.EVENT_WELCOME, WelcomeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_NOTICE, NoticeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_JOIN, JoinEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_PRIVMSG, PrivmsgEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_TOPIC, TopicEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_MODE, ModeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_NICK, NickEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_KICK, KickEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_QUIT, QuitEventHandler);

        if (encryptionKey != null)
        {
            // TODO: Generate a real random number for IV, pass it to other clients
            // Blowfish needs an initialization vector.
            // Normally this would be a cryptographically secure random number.
            // This value can be transmitted in public somehow, but I don't feel
            // like doing the plumbing for that yet.
            // So, for now, we make a pseudo-random IV seeded by the IRC port.
            System.Random rng = new System.Random((int)port);
            byte[]        initialization_vector = new byte[8];

            rng.NextBytes(initialization_vector);
            m_encryptor    = new Blowfish(encryptionKey);
            m_encryptor.IV = initialization_vector;

            // The IRC channel key all users use to access the channel is the
            // channel name encrypted using the IRC encryption key in Base64 encoding
            m_ircChannelKey = EncryptAndBase64Encode(channel);
        }
        else
        {
            m_ircChannelKey = "";
        }

        m_outputStreams    = new List <OutputStreamDelegate>();
        m_gameEventStreams = new List <GameEventStreamDelegate>();
        m_loggingStreams   = new List <LogStreamDelegate>();

        m_state = eState.disconnected;

        ClearIrcNickToCharacterIdMap();
    }
コード例 #2
0
ファイル: IRCSession.cs プロジェクト: ltloibrights/AsyncRPG
    public IRCSession(
        string serverAddress, 
		uint port, 
		string nick, 
		string user, 
		string ident, 
		string channel, 
		byte[] encryptionKey)
    {
        m_ircServerAddress = serverAddress;
        m_ircServerPort = port;
        m_ircPrimaryChannelName = channel;
        m_ircChannelName = m_ircPrimaryChannelName;
        m_ircPrimaryNick = nick;
        m_ircNick = m_ircPrimaryNick;
        m_ircUser = user;
        m_ircFullIdentity = ident;

        m_irc = new IRCEventDispatcher();

        m_irc.AddEventListener(IRCEvent.EVENT_STATUSMESSAGE, StatusMessageEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_SOCKOPEN, SockOpenEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_ERROR, ErrorEventHandler);

        m_irc.AddEventListener(IRCEvent.EVENT_SOCKERROR, SockErrorEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_ACTIVEMESSAGE, ActiveMessageEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_PING, PingEventHandler);

        m_irc.AddEventListener(IRCEvent.EVENT_WELCOME, WelcomeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_NOTICE, NoticeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_JOIN, JoinEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_PRIVMSG, PrivmsgEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_TOPIC, TopicEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_MODE, ModeEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_NICK, NickEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_KICK, KickEventHandler);
        m_irc.AddEventListener(IRCEvent.EVENT_QUIT, QuitEventHandler);

        if (encryptionKey != null)
        {
            // TODO: Generate a real random number for IV, pass it to other clients
            // Blowfish needs an initialization vector.
            // Normally this would be a cryptographically secure random number.
            // This value can be transmitted in public somehow, but I don't feel
            // like doing the plumbing for that yet.
            // So, for now, we make a pseudo-random IV seeded by the IRC port.
            System.Random rng = new System.Random((int)port);
            byte[] initialization_vector= new byte[8];

            rng.NextBytes(initialization_vector);
            m_encryptor = new Blowfish(encryptionKey);
            m_encryptor.IV= initialization_vector;

            // The IRC channel key all users use to access the channel is the
            // channel name encrypted using the IRC encryption key in Base64 encoding
            m_ircChannelKey = EncryptAndBase64Encode(channel);
        }
        else
        {
            m_ircChannelKey = "";
        }

        m_outputStreams = new List<OutputStreamDelegate>();
        m_gameEventStreams = new List<GameEventStreamDelegate>();
        m_loggingStreams = new List<LogStreamDelegate>();

        m_state = eState.disconnected;

        ClearIrcNickToCharacterIdMap();
    }