Exemplo n.º 1
0
        /// <summary>
        /// Starts the irc client with the given parameters in the constructor
        /// </summary>
        /// <returns>true or false depending if it starts succesfully</returns>
        public bool StartClient()
        {
            if (IrcClient != null)
            {
                if (!IrcClient.IsConnectionEstablished())
                {
                    IrcClient.Connect();

                    int timeout = 0;
                    while (!IrcClient.IsClientRunning())
                    {
                        Thread.Sleep(1);
                        if (timeout >= 3000)
                        {
                            return(false);
                        }
                        timeout++;
                    }
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sends a raw message to irc server
 /// </summary>
 /// <param name="message">message to send</param>
 /// <returns>true/false depending if sending was succesfull</returns>
 public bool SendRawMessage(string message)
 {
     return(IrcClient.SendRawMsg(message));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Sends a message to a specific channel.
 /// </summary>
 /// <param name="message">message to send</param>
 /// <param name="channel">channel for destination</param>
 /// <returns>true/false depending if sending was succesfull</returns>
 public bool SendMessageToChannel(string message, string channel)
 {
     return(IrcClient.SendMessageToChannel(message, channel));
 }
Exemplo n.º 4
0
 /// <summary>
 ///send message to all channels
 /// </summary>
 /// <param name="message">message to send</param>
 /// <returns>true if succesfully send</returns>
 public bool SendMessageToAll(string message)
 {
     return(IrcClient.SendMessageToAll(message));
 }
Exemplo n.º 5
0
 /// <summary>
 ///get users in different channel, parameter is the channel name of type string (example: "#yourchannel")
 /// </summary>
 /// <param name="channel"></param>
 public void GetUsersInDifferentChannel(string channel)
 {
     IrcClient.GetUsersInChannel(channel);
 }
Exemplo n.º 6
0
 /// <summary>
 ///get users in current channel
 /// </summary>
 public void GetUsersInCurrentChannel()
 {
     IrcClient.GetUsersInChannel();
 }
Exemplo n.º 7
0
 /// <summary>
 ///returns true or false upon calling this method, for telling you if the downlaod has been stopped or not
 /// </summary>
 /// <returns></returns>
 public bool CheckIfDownload()
 {
     return(IrcClient.CheckIfDownloading());
 }
Exemplo n.º 8
0
 /// <summary>
 ///returns true or false upon calling this method, for telling you if the downlaod has been stopped or not
 /// </summary>
 /// <returns></returns>
 public bool StopXDCCDownload()
 {
     return(IrcClient.StopXDCCDownload());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Checks if the client is running.
 /// </summary>
 /// <returns>true or false</returns>
 public bool IsClientRunning()
 {
     return(IrcClient.IsClientRunning());
 }
Exemplo n.º 10
0
 /// <summary>
 /// Sets the download directory for dcc downloads.
 /// </summary>
 /// <param name="downloaddir"> Requires a path to a directory of type string as parameter.</param>
 public void SetCustomDownloadDir(string downloaddir)
 {
     DownloadDir = downloaddir;
     IrcClient.SetDownloadDirectory(downloaddir);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Add a new Download to the queue
        /// </summary>
        /// <param name="ircData">The irc command.</param>
        /// <param name="downloadDirectory">The download directory.</param>
        /// <param name="bot">The bot.</param>
        /// <param name="packageNumber">The package number.</param>
        /// <param name="client">The client.</param>
        /// <returns>The created Download.</returns>
        public Download StartDownload(string ircData, string downloadDirectory, string bot, string packageNumber, IrcClient client)
        {
            var download = new Download(ircData, downloadDirectory, bot, packageNumber, client, _tokenSource.Token);

            download.OnDccDebugMessage += (sender, args) => OnDccDebugMessage?.Invoke(sender, args);
            download.OnDccEvent        += (sender, args) => OnDccEvent?.Invoke(sender, args);

            _downloadQueue.TryAdd(download, 0, _tokenSource.Token);

            return(download);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Starts a downloader by parsing the received message from the irc server on information
        /// </summary>
        /// <param name="dccString">message from irc server</param>
        /// <param name="downloaddir">download directory</param>
        /// <param name="bot">bot where the file came from</param>
        /// <param name="pack">pack on bot where the file came from</param>
        /// <param name="client">irc client used the moment it received the dcc message, used for sending abort messages when download fails unexpectedly</param>
        public void StartDownloader(string dccString, string downloaddir, string bot, string pack, IrcClient client)
        {
            if ((dccString ?? downloaddir ?? bot ?? pack) != null && dccString.Contains("SEND") && !IsDownloading)
            {
                NewDccString    = dccString;
                _curDownloadDir = downloaddir;
                BotName         = bot;
                PackNum         = pack;
                _ircClient      = client;

                //parsing the data for downloader thread

                UpdateStatus("PARSING");
                bool isParsed = ParseData(dccString);

                //try to set the necesary information for the downloader
                if (isParsed)
                {
                    _shouldAbort = false;
                    //start the downloader thread
                    _downloader = new Thread(new ThreadStart(this.Downloader));
                    _downloader.IsBackground = true;
                    _downloader.Start();
                }
                else
                {
                    OnDccDebugMessage?.Invoke(this,
                                              new DCCDebugMessageArgs(
                                                  "Can't parse dcc string and start downloader, failed to parse data, removing from que\n", "DCC STARTER"));
                    _ircClient.SendMessageToAll("/msg " + BotName + " xdcc remove " + PackNum);
                    _ircClient.SendMessageToAll("/msg " + BotName + " xdcc cancel");
                }
            }
            else
            {
                if (IsDownloading)
                {
                    OnDccDebugMessage?.Invoke(this,
                                              new DCCDebugMessageArgs("You are already downloading! Ignore SEND request\n", "DCC STARTER"));
                }
                else
                {
                    OnDccDebugMessage?.Invoke(this,
                                              new DCCDebugMessageArgs("DCC String does not contain SEND and/or invalid values for parsing! Ignore SEND request\n", "DCC STARTER"));
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Constructor, sets up bot ircclient and dccclient, so that users can register event handlers.
 /// </summary>
 public SimpleIRC()
 {
     IrcClient = new IrcClient();
     DccClient = new DCCClient();
 }
Exemplo n.º 14
0
 /// <summary>
 /// Stops the client
 /// </summary>
 /// <returns>true or false depending on succes</returns>
 internal void StopClient()
 {
     IrcClient.Dispose();
     IrcClient.StopXDCCDownload();
 }