26
26
import com .jagrosh .discordipc .entities .Packet ;
27
27
import com .jagrosh .discordipc .entities .User ;
28
28
import com .jagrosh .discordipc .exceptions .NoDiscordClientException ;
29
+ import org .slf4j .Logger ;
30
+ import org .slf4j .LoggerFactory ;
29
31
30
32
import java .io .File ;
31
33
import java .io .IOException ;
32
34
import java .util .HashMap ;
33
35
import java .util .UUID ;
34
36
35
37
public abstract class Pipe {
38
+ private static final Logger LOGGER = LoggerFactory .getLogger (Pipe .class );
36
39
private static final int VERSION = 1 ;
37
40
// a list of system property keys to get IPC file from different unix systems.
38
41
private final static String [] unixPaths = {"XDG_RUNTIME_DIR" , "TMPDIR" , "TMP" , "TEMP" };
@@ -62,14 +65,14 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
62
65
for (int i = 0 ; i < 10 ; i ++) {
63
66
String location = getPipeLocation (i );
64
67
if (ipcClient .isDebugMode ()) {
65
- ipcClient . getLogger () .info (String .format ("[DEBUG] Searching for IPC Pipe: \" %s\" " , location ));
68
+ LOGGER .info (String .format ("[DEBUG] Searching for IPC Pipe: \" %s\" " , location ));
66
69
}
67
70
68
71
try {
69
72
File fileLocation = new File (location );
70
73
if (fileLocation .exists ()) {
71
74
if (ipcClient .isDebugMode ()) {
72
- ipcClient . getLogger () .info (String .format ("[DEBUG] Found valid file, attempting connection to IPC: \" %s\" " , location ));
75
+ LOGGER .info (String .format ("[DEBUG] Found valid file, attempting connection to IPC: \" %s\" " , location ));
73
76
}
74
77
pipe = createPipe (ipcClient , callbacks , fileLocation );
75
78
@@ -99,14 +102,14 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
99
102
);
100
103
101
104
if (ipcClient .isDebugMode ()) {
102
- ipcClient . getLogger () .info (String .format ("[DEBUG] Found a valid client (%s) with packet: %s" , pipe .build .name (), p ));
103
- ipcClient . getLogger () .info (String .format ("[DEBUG] Found a valid user (%s) with id: %s" , pipe .currentUser .getName (), pipe .currentUser .getId ()));
105
+ LOGGER .info (String .format ("[DEBUG] Found a valid client (%s) with packet: %s" , pipe .build .name (), p ));
106
+ LOGGER .info (String .format ("[DEBUG] Found a valid user (%s) with id: %s" , pipe .currentUser .getName (), pipe .currentUser .getId ()));
104
107
}
105
108
106
109
// we're done if we found our first choice
107
110
if (pipe .build == preferredOrder [0 ] || DiscordBuild .ANY == preferredOrder [0 ]) {
108
111
if (ipcClient .isDebugMode ()) {
109
- ipcClient . getLogger () .info (String .format ("[DEBUG] Found preferred client: %s" , pipe .build .name ()));
112
+ LOGGER .info (String .format ("[DEBUG] Found preferred client: %s" , pipe .build .name ()));
110
113
}
111
114
break ;
112
115
}
@@ -119,7 +122,7 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
119
122
}
120
123
} else {
121
124
if (ipcClient .isDebugMode ()) {
122
- ipcClient . getLogger () .info (String .format ("[DEBUG] Unable to locate IPC Pipe: \" %s\" " , location ));
125
+ LOGGER .info (String .format ("[DEBUG] Unable to locate IPC Pipe: \" %s\" " , location ));
123
126
}
124
127
}
125
128
} catch (IOException | JsonParseException ex ) {
@@ -133,7 +136,7 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
133
136
for (int i = 1 ; i < preferredOrder .length ; i ++) {
134
137
DiscordBuild cb = preferredOrder [i ];
135
138
if (ipcClient .isDebugMode ()) {
136
- ipcClient . getLogger () .info (String .format ("[DEBUG] Looking for client build: %s" , cb .name ()));
139
+ LOGGER .info (String .format ("[DEBUG] Looking for client build: %s" , cb .name ()));
137
140
}
138
141
139
142
if (open [cb .ordinal ()] != null ) {
@@ -150,7 +153,7 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
150
153
} else pipe .build = cb ;
151
154
152
155
if (ipcClient .isDebugMode ()) {
153
- ipcClient . getLogger () .info (String .format ("[DEBUG] Found preferred client: %s" , pipe .build .name ()));
156
+ LOGGER .info (String .format ("[DEBUG] Found preferred client: %s" , pipe .build .name ()));
154
157
}
155
158
break ;
156
159
}
@@ -170,7 +173,7 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,
170
173
// This isn't really important to applications and better
171
174
// as debug info
172
175
if (ipcClient .isDebugMode ()) {
173
- ipcClient . getLogger () .info (String .format ("[DEBUG] Failed to close an open IPC pipe: %s" , ex ));
176
+ LOGGER .info (String .format ("[DEBUG] Failed to close an open IPC pipe: %s" , ex ));
174
177
}
175
178
}
176
179
}
@@ -252,13 +255,13 @@ public void send(Packet.OpCode op, JsonObject data, Callback callback) {
252
255
callbacks .put (nonce , callback );
253
256
write (p .toBytes ());
254
257
if (ipcClient .isDebugMode ()) {
255
- ipcClient . getLogger () .info (String .format ("[DEBUG] Sent packet: %s" , p .toDecodedString ()));
258
+ LOGGER .info (String .format ("[DEBUG] Sent packet: %s" , p .toDecodedString ()));
256
259
}
257
260
258
261
if (listener != null )
259
262
listener .onPacketSent (ipcClient , p );
260
263
} catch (IOException ex ) {
261
- ipcClient . getLogger (). severe ("Encountered an IOException while sending a packet and disconnected!" );
264
+ LOGGER . error ("Encountered an IOException while sending a packet and disconnected!" );
262
265
status = PipeStatus .DISCONNECTED ;
263
266
}
264
267
}
@@ -285,7 +288,7 @@ public Packet receive(Packet.OpCode op, byte[] data) {
285
288
Packet p = new Packet (op , packetData , ipcClient .getEncoding ());
286
289
287
290
if (ipcClient .isDebugMode ()) {
288
- ipcClient . getLogger () .info (String .format ("[DEBUG] Received packet: %s" , p ));
291
+ LOGGER .info (String .format ("[DEBUG] Received packet: %s" , p ));
289
292
}
290
293
291
294
if (listener != null )
0 commit comments