Exemple #1
0
 /// <summary>
 /// The handler for sending a message
 /// </summary>
 /// <param name="sender">the object sending the event, usually 'this'</param>
 /// <param name="e">The IRC Message to send over the connection</param>
 public void SendMessageHandler(Object sender, IRCMessage e)
 {
     if (e.Channel == String.Empty)
     {
         Log(e);
     }
     if (e.Command == "JOIN")
     {
         var channels = e.Parameters [0].Split(',');
         foreach (var item in channels)
         {
             bool alreadyExists = false;
             foreach (var channel in Channels)
             {
                 if (channel.ChannelName == item)
                 {
                     alreadyExists = true;
                     break;
                 }
             }
             if (!alreadyExists)
             {
                 var _channel = new IRCChannel(item);
                 Channels.Add(_channel);
                 MessageReceived += new EventHandler <IRCMessage> (_channel.HandleReceiveMessages);
                 MessageSent     += new EventHandler <IRCMessage> (_channel.HandleSendMessages);
             }
         }
     }
     else if (e.Command == "PART")
     {
         var channels = e.Parameters [0].Split(',');
         foreach (var item in channels)
         {
             var channelsToRemove = new  List <IRCChannel> ();
             foreach (var item2 in Channels)
             {
                 if (item2.ChannelName == item)
                 {
                     channelsToRemove.Add(item2);
                 }
             }
             foreach (var item2 in channelsToRemove)
             {
                 Channels.Remove(item2);
                 MessageReceived -= item2.HandleReceiveMessages;
                 MessageSent     -= item2.HandleSendMessages;
             }
             channelsToRemove.Clear();
         }
     }
     writer.WriteLine(e.ToIRCString());
     writer.Flush();
 }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WolfyBot.Core.IRCServer"/> class.
 /// </summary>
 /// <param name="host">Hostname of the IRC Server</param>
 /// <param name="port">Port to try to connect on</param>
 /// <param name="channels">List of Channels to connect to seperated by spaces</param>
 /// <param name="nick">Nickname of the bot</param>
 /// <param name="ssl">If set to <c>true</c> ssl is enable for this connection.</param>
 /// <param name="password">Password to connect to the IRC server.</param>
 public IRCServer(String host, int port, String[] channels, String nick, bool ssl, String password = "")
 {
     Host     = host;
     Port     = port;
     Nick     = nick;
     SSL      = ssl;
     Password = password;
     Channels = new List <IRCChannel> ();
     foreach (var item in channels)
     {
         var _channel = new IRCChannel(item);
         Channels.Add(_channel);
         MessageReceived += new EventHandler <IRCMessage> (_channel.HandleReceiveMessages);
         MessageSent     += new EventHandler <IRCMessage> (_channel.HandleSendMessages);
     }
     Logging = false;
 }
Exemple #3
0
        static bool CheckPermissions(IBotCommand command, IRCMessage message, IRCServer server)
        {
            //If SecureLevel is the Bot, then it's an "internal" command for the bot, such as
            //ponging a server
            if (command.SecureLevel == SecureLevelEnum.Bot)
            {
                return(true);
            }
            //If the "Channel" is empty then it is a message from the server
            if (message.Channel == String.Empty)
            {
                return(true);
            }

            IRCChannel _channel = null;

            foreach (var channel in server.Channels)
            {
                if (channel.ChannelName == message.Channel)
                {
                    _channel = channel;
                    break;
                }
            }

            //should not happen
            if (_channel == null)
            {
                return(false);
            }
            //Check if the channel is muted and the command is interactive
            if (_channel.Muted && command.Interactive)
            {
                return(false);
            }
            var user = _channel.FindUser(message.Sender);

            //if the user's nick is the owner nick of the bot set the mode
            //for the channel to be Owner
            if (user.Nick == ownerNick)
            {
                user.Mode = SecureLevelEnum.Owner;
            }
            return(user.Mode >= command.SecureLevel);
        }