Browse Source

Wrote more code

proto
Thomas Johnson 2 years ago
parent
commit
02415ab5c4
  1. 3
      proto/ProtoHandler.java
  2. 2
      proto/ProtoID.java
  3. 19
      proto/ProtoIn.java

3
proto/ProtoHandler.java

@ -4,6 +4,7 @@ public interface ProtoHandler
{
void handleJoin(String username);
void handlePart(String username);
void handleListing(String names[]);
void handleListing(String username, String names[]);
void handleListingRequest(String username);
void handleUnknownCommand(byte id);
}

2
proto/ProtoID.java

@ -1,6 +1,6 @@
package proto;
// This file is mo
// This file is more of a reference than code that will actually be used
// As agreed upon when designing the protocol
public enum ProtoID

19
proto/ProtoIn.java

@ -2,6 +2,7 @@ package proto;
import java.io.DataInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
public class ProtoIn
{
@ -34,9 +35,23 @@ public class ProtoIn
switch (id)
{
case 3:
short nlen = dis.readShort();
String username = readname();
if (length == 0)
{
Thread t = new Thread(() -> handler.handleListingRequest(username));
t.start();
} else
{
ArrayList<String> names = new ArrayList<>();
int a = 0;
while (a < length)
{
String name = readname();
a += name.length();
names.add(name);
}
handler.handleListing(username, (String[]) names.toArray());
}
break;
default:
Thread t = new Thread(() -> handler.handleUnknownCommand(id));

Loading…
Cancel
Save