private void getIrcData() { JsonIrcUpdate update = new JsonIrcUpdate(); update.connected = SharedData.irc.isClientRunning(); update.downloadlocation = SharedData.currentDownloadLocation; try { update.server = SharedData.irc.newIP + ":" + SharedData.irc.newPort; update.user = SharedData.irc.newUsername; update.channel = SharedData.irc.newChannel; } catch (Exception e) { Debug.WriteLine("WSDEBUG-WEBSOCKETHANDLER: no irc connection yet."); update.server = ""; update.user = ""; update.channel = ""; } update.local = isLocal; SharedData.AddToMessageList(JsonConvert.SerializeObject(update, Formatting.Indented)); }
public void startIrc(string address, string username, string channels) { channelcount = channels.Split(',').Length; shouldStopClient = false; SharedData.joinedChannel = false; SharedData.userList.Clear(); 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 { isConnected = true; 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; }