/
NetworkHostNode.hx
70 lines (64 loc) · 2.44 KB
/
NetworkHostNode.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package armory.logicnode;
import armory.network.Connect;
import iron.object.Object;
class NetworkHostNode extends LogicNode {
public var property0: Bool;
public var net_Url: String;
public function new(tree:LogicTree) {
super(tree);
}
override function run(from:Int) {
#if sys
if(property0 == false) {
final net_Object: Object = tree.object;
var net_Domain: String = inputs[1].get();
var net_Port: Int = inputs[2].get();
var max_Conn: Int = inputs[3].get();
net_Url = "ws://" + net_Domain + ":" + net_Port;
if (Host.connections[net_Url] != null) return;
try{
var server = new Host(net_Domain, net_Port, max_Conn, net_Object);
if (Host.connections[net_Url] == null) return;
Host.connections[net_Url].start();
runOutput(0);
} catch(err){
trace("Failed to start server with the following error: " + err + ". Check if there is a system process occupying the port.");
}
} else {
final net_Object: Object = tree.object;
var net_Domain: String = inputs[1].get();
var net_Port: Int = inputs[2].get();
var max_Conn: Int = inputs[3].get();
var net_Cert: String = inputs[4].get();
var net_Key: String = inputs[5].get();
net_Url = "wss://" + net_Domain + ":" + net_Port;
if (SecureHost.connections[net_Url] != null) return;
try{
var server = new SecureHost(net_Domain, net_Port, max_Conn, net_Object, net_Cert, net_Key);
if (SecureHost.connections[net_Url] == null) return;
SecureHost.connections[net_Url].start();
runOutput(0);
} catch(err){
trace("Failed to start server with the following error: " + err + ". Check if there is a system process occupying the port.");
}
}
#end
}
#if sys
override function get(from: Int): Dynamic {
if(property0 == false) {
return switch (from) {
case 1: Host.connections[net_Url];
case 2: Host.data[net_Url];
default: throw "Unreachable";
}
} else {
return switch (from) {
case 1: SecureHost.connections[net_Url];
case 2: SecureHost.data[net_Url];
default: throw "Unreachable";
}
}
}
#end
}