Skip to content

Commit 5e77568

Browse files
committed
refactor: create SignlinkNode.Type
1 parent e7dca50 commit 5e77568

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

src/main/java/org/runejs/client/util/Signlink.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ public void killSignlinkThread() {
116116
}
117117

118118
public SignlinkNode method386(Class[] argumentTypes, String functionName, Class functionType) {
119-
return putNode(0, 9, new Object[]{functionType, functionName, argumentTypes});
119+
return putNode(0, SignlinkNode.Type.METHOD, new Object[]{functionType, functionName, argumentTypes});
120120

121121
}
122122

123123
public SignlinkNode addType4Node(URL url) {
124-
return putNode(0, 4, url);
124+
return putNode(0, SignlinkNode.Type.DATA_INPUT_STREAM, url);
125125
}
126126

127-
public SignlinkNode putNode(int integerData, int type, Object objectData) {
127+
public SignlinkNode putNode(int integerData, SignlinkNode.Type type, Object objectData) {
128128
SignlinkNode signlinkNode = new SignlinkNode();
129129
signlinkNode.objectData = objectData;
130130
signlinkNode.integerData = integerData;
@@ -183,23 +183,23 @@ public void run() {
183183
}
184184
}
185185
try {
186-
int type = currentNode.type;
187-
if (type == 1) {
186+
SignlinkNode.Type type = currentNode.type;
187+
if (type == SignlinkNode.Type.SOCKET) {
188188
// Create connection
189189
currentNode.value = new Socket(netAddress, currentNode.integerData);
190-
} else if(type == 2) {
190+
} else if(type == SignlinkNode.Type.THREAD) {
191191
// Start thread
192192
Thread thread = new Thread((Runnable) currentNode.objectData);
193193
thread.setDaemon(true);
194194
thread.start();
195195
thread.setPriority(currentNode.integerData);
196196
currentNode.value = thread;
197-
} else if(type == 4)
197+
} else if(type == SignlinkNode.Type.DATA_INPUT_STREAM)
198198
currentNode.value = new DataInputStream(((URL) currentNode.objectData).openStream());
199-
else if(type == 9) {
199+
else if(type == SignlinkNode.Type.METHOD) {
200200
Object[] objects = (Object[]) currentNode.objectData;
201201
currentNode.value = ((Class) objects[0]).getDeclaredMethod((String) objects[1], (Class[]) objects[2]);
202-
} else if(type == 10) {
202+
} else if(type == SignlinkNode.Type.FIELD) {
203203
Object[] objects = (Object[]) currentNode.objectData;
204204
currentNode.value = ((Class) objects[0]).getDeclaredField((String) objects[1]);
205205
} else {
@@ -215,20 +215,20 @@ else if(type == 9) {
215215
}
216216

217217
public SignlinkNode createType10Node(Class variableType, String variableName) {
218-
return putNode(0, 10, new Object[]{ variableType, variableName });
218+
return putNode(0, SignlinkNode.Type.FIELD, new Object[]{ variableType, variableName });
219219
}
220220

221221
// TODO this will just throw an exception, since type 3 isn't handled
222222
public SignlinkNode createExceptionNode(int arg1) {
223-
return putNode(arg1, 3, null);
223+
return putNode(arg1, SignlinkNode.Type.EXCEPTION, null);
224224
}
225225

226226
public SignlinkNode createThreadNode(int nodeId, Runnable runnableClass) {
227-
return putNode(nodeId, 2, runnableClass);
227+
return putNode(nodeId, SignlinkNode.Type.THREAD, runnableClass);
228228
}
229229

230230
public SignlinkNode createSocketNode(int port) {
231-
return putNode(port, 1, null);
231+
return putNode(port, SignlinkNode.Type.SOCKET, null);
232232
}
233233

234234
public SignlinkNode method396(int arg0) {

src/main/java/org/runejs/client/util/SignlinkNode.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@ public int getValue() {
1717
}
1818
}
1919

20+
public enum Type {
21+
/**
22+
* Create connection, save the socket to value
23+
*/
24+
SOCKET(1),
25+
/**
26+
* Start the thread with objectData, save the thread to value
27+
*/
28+
THREAD(2),
29+
/**
30+
* Throw an Exception
31+
*/
32+
EXCEPTION(3),
33+
/**
34+
* Create a data input stream, save the stream to value
35+
*/
36+
DATA_INPUT_STREAM(4),
37+
/**
38+
* Get a declared method from a class
39+
*/
40+
METHOD(9),
41+
/**
42+
* Get a declared field from a class
43+
*/
44+
FIELD(10);
45+
46+
private final int value;
47+
48+
Type(int value) {
49+
this.value = value;
50+
}
51+
52+
public int getValue() {
53+
return value;
54+
}
55+
}
56+
2057
public int integerData;
2158

2259
/**
@@ -27,7 +64,7 @@ public int getValue() {
2764
* 10 = Call a class constructor dynamically from objectData, where objectData[0] is the class and objectData[1] is a string param
2865
* Other values will throw an Exception.
2966
*/
30-
public int type;
67+
public Type type;
3168

3269
public volatile Status status = Status.NOT_INITIALIZED;
3370

0 commit comments

Comments
 (0)