protected override ServerConnectionEventArgs ParseCommand(string line) { var command = new ServerConnectionEventArgs(); command.ServerConnection = this; if (line != null) { var args = line.Split('|'); // split arguments command.Command = args[0]; command.Result = ServerConnectionEventArgs.ResultTypes.Success; command.Parameters = new string[args.Length - 1]; for (int j = 1; j < args.Length; ++j) command.Parameters[j - 1] = MyUnescape(args[j]); } else { command.Result = ServerConnectionEventArgs.ResultTypes.NetworkError; command.Parameters = new string[] {}; command.Command = ""; } return command; }
protected override ServerConnectionEventArgs ParseCommand(string line) { var command = new ServerConnectionEventArgs(); command.ServerConnection = this; if (line != null) { var args = line.Split('|'); // split arguments command.Command = args[0]; command.Result = ServerConnectionEventArgs.ResultTypes.Success; command.Parameters = new string[args.Length - 1]; for (int j = 1; j < args.Length; ++j) { command.Parameters[j - 1] = MyUnescape(args[j]); } } else { command.Result = ServerConnectionEventArgs.ResultTypes.NetworkError; command.Parameters = new string[] {}; command.Command = ""; } return(command); }
private void ProcessCommandRecieved(ServerConnectionEventArgs e) { try { if (e.Result == ServerConnectionEventArgs.ResultTypes.Success) { switch (e.Command) { case "T+": { int hash = int.Parse(e.Parameters[0]); string type = e.Parameters[2]; string name = e.Parameters[1]; if (!serverTorrentList.ContainsKey(hash)) { var ti = new ShortTorrentInfo(name, hash, type); serverTorrentList.Add(hash, ti); if (TorrentAdded != null) { TorrentAdded(this, ti); } } } break; case "T-": { int hash = int.Parse(e.Parameters[0]); ShortTorrentInfo ti; if (serverTorrentList.TryGetValue(hash, out ti)) { serverTorrentList.Remove(hash); if (TorrentRemoved != null) { TorrentRemoved(this, ti); } } } break; case "M+": { int hash = int.Parse(e.Parameters[0]); List <string> mirrors = new List <string>(); for (int i = 1; i < e.Parameters.Length; ++i) { if (e.Parameters[i] != "") { mirrors.Add(e.Parameters[i]); } } if (LinksRecieved != null) { LinksRecieved(this, new ResourceLinks(hash, mirrors)); } } break; case "TLISTDONE": IsTorrentListDone = true; if (TorrentListDone != null) { TorrentListDone(this, EventArgs.Empty); } break; case "PING": lastPing = DateTime.Now; con.SendCommand("PING"); break; } } } catch (Exception ex) { ErrorHandling.HandleException(ex, "error recieving data from P2P server"); } }
private void con_CommandRecieved(object sender, ServerConnectionEventArgs e) { ProcessCommandRecieved(e); }
private void ProcessCommandRecieved(ServerConnectionEventArgs e) { try { if (e.Result == ServerConnectionEventArgs.ResultTypes.Success) { switch (e.Command) { case "T+": { int hash = int.Parse(e.Parameters[0]); string type = e.Parameters[2]; string name = e.Parameters[1]; if (!serverTorrentList.ContainsKey(hash)) { var ti = new ShortTorrentInfo(name, hash, type); serverTorrentList.Add(hash, ti); if (TorrentAdded != null) TorrentAdded(this, ti); } } break; case "T-": { int hash = int.Parse(e.Parameters[0]); ShortTorrentInfo ti; if (serverTorrentList.TryGetValue(hash, out ti)) { serverTorrentList.Remove(hash); if (TorrentRemoved != null) TorrentRemoved(this, ti); } } break; case "M+": { int hash = int.Parse(e.Parameters[0]); List<string> mirrors = new List<string>(); for (int i = 1; i < e.Parameters.Length; ++i) if (e.Parameters[i] != "") mirrors.Add(e.Parameters[i]); if (LinksRecieved != null) LinksRecieved(this, new ResourceLinks(hash, mirrors)); } break; case "TLISTDONE": IsTorrentListDone = true; if (TorrentListDone != null) TorrentListDone(this, EventArgs.Empty); break; case "PING": lastPing = DateTime.Now; con.SendCommand("PING"); break; } } } catch (Exception ex) { ErrorHandling.HandleException(ex, "error recieving data from P2P server"); } }
private void con_CommandRecieved(object sender, ServerConnectionEventArgs e) { ProcessCommandRecieved(e); }