-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibsuix.java
94 lines (70 loc) · 2.2 KB
/
libsuix.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.OutputStream;
import java.io.InputStream;
//Library for holding all the client commands and shit {WIP}
public class libsuix
{
//OutputStream for the socket
public static OutputStream outStream;
//InputStream for the socket
public static InputStream inStream;
//Get the current username.
//Returns the username else `null` if some really bad shit happened.
public static String getUsername()
{
IO.sendCommand(outStream, "GET_USERNAME");
String username = IO.readCommand(inStream);
return username;
}
//Get the current channel.
//Returns the username else `null` if some really bad shit happened.
public static String getChannel()
{
IO.sendCommand(outStream, "GET_CHANNEL");
String channel = IO.readCommand(inStream);
return channel;
}
//List all channels available on this server.
//Returns the username else `null` if some really bad shit happened.
public static String[] listChannels()
{
IO.sendCommand(outStream, "LIST_CHANNEL");
int channelListLength = Integer.parseInt(IO.readCommand(inStream));
String[] channels = new String[channelListLength];
//Read each channel into the array
for(int i = 0; i < channelListLength; i++)
{
channels[i] = IO.readCommand(inStream);
}
return channels;
}
//Returns the username else `null` if some really bad shit happened.
public static String[] listUsers()
{
IO.sendCommand(outStream, "LIST_USERS");
int userListLength = Integer.parseInt(IO.readCommand(inStream));
String[] users = new String[userListLength];
//Read each user into the array
for(int i = 0; i < userListLength; i++)
{
users[i] = IO.readCommand(inStream);
}
return users;
}
//Set the username
public static void setUsername(String username)
{
IO.sendCommand(outStream,"SET_USERNAME");
IO.sendCommand(outStream,username);
}
//Send the given message `message`.
//Returns "MESSAGE_SENT" on successful sending of message.
//"MESSAGE_SEND_FAILED" if not successful.
//And if some really bad shit happened then `null`.
public static String sendMessage(String message)
{
IO.sendCommand(outStream,"SEND_MESSAGE");
IO.sendCommand(outStream,message);
String errorReturn = IO.readCommand(inStream);
return errorReturn;
}
}