Esempio n. 1
0
        public void startIrc(string address, string username, string channels)
        {
            SharedData.joinedChannel = false;
            Debug.WriteLine("IRCDEBUG-IRCHANDLER: STARTING CONNECTION TO IRC SERVER!");
            int i = 0;

            while (!SharedData.joinedChannel && !isBussyConnecting)
            {
                isBussyConnecting = true;
                try
                {
                    irc.stopXDCCDownload();
                    irc.stopClient();
                }
                catch (Exception e) { Debug.WriteLine("DEBUG-IRCHANDLER: ERROR: Could not shut down IRC client: " + e.ToString()); }
                if (username == "")
                {
                    username = "******" + usefullstuff.RandomString(6);
                }
                irc.setupIrc(address, 6667, username, "", channels, chatOutputCallback);
                irc.setDebugCallback(debugOutputCallback);
                irc.setDownloadStatusChangeCallback(downloadStatusCallback);
                irc.setUserListReceivedCallback(userListReceivedCallback);
                irc.setCustomDownloadDir(SharedData.currentDownloadLocation);
                irc.startClient();

                int x = 3;
                while (x > 0)
                {
                    if (shouldStopClient)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                    x--;
                }

                if (shouldStopClient)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: SHOULD STOP RETRYING!");
                    shouldStopClient = false;
                    break;
                }


                if (!SharedData.joinedChannel)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: DID NOT JOIN CHANNEL, RETRY!");
                }
                else
                {
                    JsonIrcUpdate update = new JsonIrcUpdate();
                    update.connected        = true;
                    update.downloadlocation = SharedData.currentDownloadLocation;
                    update.server           = irc.newIP + ":" + irc.newPort;
                    update.user             = irc.newUsername;
                    update.channel          = irc.newChannel;
                    update.local            = isLocal;
                    SharedData.AddToMessageList(JsonConvert.SerializeObject(update, Formatting.Indented));
                    break;
                }
                i++;
                if (i > 10)
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: I AM DONE TRYING TO CONNECT!");
                    break;
                }
                else
                {
                    Debug.WriteLine("DEBUG-IRCHANDLER: NOT CONNECTED TO IRC SERVER");
                }
            }
            isBussyConnecting = false;
        }