protected override void OnMessage(MessageEventArgs e) { var json = JsonConvert.DeserializeObject <dynamic>(e.Data); Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: " + ((object)JsonConvert.SerializeObject(json)).ToString()); switch (json.action.ToString()) { case "get_irc_data": getIrcData(); break; case "get_downloads": getDownloads(); break; case "add_download": addDownload(json.extra); break; case "abort_download": abortDownload(); break; case "delete_file": deleteDownload(json.extra); break; case "open_download_directory": openDownloadDirectory(); break; case "set_download_directory": string path = json.extra.path; setDownloadDirectoryV2(path); break; case "open_file": openFile(json.extra); break; case "get_directories": if (json.extra.path != null) { if (json.extra.path.ToString() == "DRIVES" || json.extra.path.ToString() == "/") { Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DRIVES"); getDrives(); } else { Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DIRECTORIES"); string pathtoset = json.extra.path.ToString(); getDirectories(pathtoset); } } else { Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: GETTING DRIVES"); getDrives(); } break; case "create_directory": string pathtocreate = json.extra.path; createDirectory(pathtocreate); break; case "connect_irc": connectIrc(json.extra); break; case "disconnect_irc": disconnectIrc(); break; case "enablechat_irc": SharedData.enableIrcChat = true; break; case "disablechat_irc": SharedData.enableIrcChat = false; break; case "getuserlist_irc": JsonIRCUsersList newuserlist = new JsonIRCUsersList(); newuserlist.users = SharedData.userList; SharedData.AddToMessageList(JsonConvert.SerializeObject(newuserlist, Formatting.Indented)); break; case "sendmessage_irc": SharedData.ircHandler.sendMessage(json.extra.message); break; case "close": closeEverything(); break; default: Debug.WriteLine("DEBUG-WEBSOCKETHANDLER: RECEIVED UNKNOWN JSON ACTION: " + ((object)json.action).ToString()); break; } }
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; }