forked from LeenkxTeam/LNXSDK
94 lines
2.6 KiB
Haxe
94 lines
2.6 KiB
Haxe
package leenkx.logicnode;
|
|
#if lnx_torrent
|
|
import leenkx.network.Leenkx;
|
|
import leenkx.network.torrent.Torrent;
|
|
#end
|
|
|
|
class TorrentControlNode extends LogicNode {
|
|
public var property0:String;
|
|
var net_Url:String;
|
|
|
|
public function new(tree:LogicTree) {
|
|
super(tree);
|
|
}
|
|
|
|
override function run(from:Int) {
|
|
#if lnx_torrent
|
|
var connection = inputs[1].get();
|
|
if (connection == null) return;
|
|
var id = inputs[2].get();
|
|
if (id == null) return;
|
|
net_Url = connection._url;
|
|
|
|
var socket = Leenkx.connections[connection._url];
|
|
if (socket == null) return;
|
|
var client = socket.client;
|
|
var t = client != null ? client.get(id) : (Std.isOfType(id, Torrent) ? id : null);
|
|
var action = property0 != null ? property0 : "remove";
|
|
|
|
var file:Dynamic = inputs.length > 3 ? inputs[3].get() : null;
|
|
var t2 = t;
|
|
var startB = 0;
|
|
var endB = -1;
|
|
if (file != null) {
|
|
startB = file.offset;
|
|
endB = file.offset + file.length - 1;
|
|
if (t2 == null) t2 = file.torrent;
|
|
} else {
|
|
var sv = inputs.length > 4 ? inputs[4].get() : null;
|
|
var ev = inputs.length > 5 ? inputs[5].get() : null;
|
|
if (sv != null && Std.string(sv) != "") {
|
|
startB = Std.int(Std.parseFloat(Std.string(sv)));
|
|
}
|
|
if (ev != null && Std.string(ev) != "") {
|
|
endB = Std.int(Std.parseFloat(Std.string(ev)));
|
|
}
|
|
}
|
|
var pv = inputs.length > 6 ? inputs[6].get() : null;
|
|
var priority = pv != null && Std.string(pv) != "" ? Std.int(Std.parseFloat(Std.string(pv))) : null;
|
|
|
|
switch (action) {
|
|
case "start":
|
|
if (t != null) t.start();
|
|
case "stop":
|
|
if (t != null) t.stop();
|
|
case "select", "critical", "deselect":
|
|
if (t2 != null) {
|
|
if (endB < 0) {
|
|
endB = t2.meta != null ? t2.meta.totalLength - 1 : 0;
|
|
}
|
|
if (action == "critical") {
|
|
t2.critical(startB, endB);
|
|
} else if (action == "select") {
|
|
t2.select(startB, endB, priority);
|
|
} else {
|
|
t2.deselect(startB, endB, priority);
|
|
}
|
|
}
|
|
case "add-peer":
|
|
var peer = inputs.length > 3 ? inputs[3].get() : null;
|
|
if (t != null && peer != null) {
|
|
t.addPeer(Std.string(peer));
|
|
}
|
|
case "add-web-seed":
|
|
var url = inputs.length > 3 ? inputs[3].get() : null;
|
|
if (t != null && url != null) {
|
|
t.addWebSeed(Std.string(url));
|
|
}
|
|
case "remove", "remove-data":
|
|
var hex = t != null ? t.infoHashHex : Std.string(id);
|
|
if (hex == null) hex = Std.string(id);
|
|
if (client != null) {
|
|
client.remove(hex, action == "remove-data");
|
|
}
|
|
if (t != null && Leenkx.torrent.get(net_Url) == t) {
|
|
Leenkx.torrent.remove(net_Url);
|
|
Leenkx.file.remove(net_Url);
|
|
}
|
|
default:
|
|
}
|
|
#end
|
|
runOutput(0);
|
|
}
|
|
}
|