Browse Source

Merge branch 'proto'

proto
Thomas Johnson 2 years ago
parent
commit
ce667898f8
  1. 15
      proto/ProtoOut.java

15
proto/ProtoOut.java

@ -43,6 +43,15 @@ public class ProtoOut
out.write(nameBytes);
}
synchronized public void sendError(String username, byte message[]) throws IOException
{
out.writeByte(ProtoID.ERROR.b);
out.writeInt(message.length);
writeUserName(username);
out.write(message);
commit();
}
synchronized public void sendJoin(String username) throws IOException
{
out.writeByte(ProtoID.JOIN.b);
@ -67,11 +76,11 @@ public class ProtoOut
commit(); // Make it so!
}
synchronized public void giveUserListing(String username, String names[]) throws IOException
synchronized public void giveUserListing(String username, ArrayList<String> names) throws IOException
{
out.writeByte(ProtoID.LISTING.b);
// I can recognize bad code when I write it, and this is bad code.
out.writeInt(Arrays.asList(names).stream().collect(Collectors.summingInt((s) -> s.getBytes().length)));
out.writeInt(names.stream().collect(Collectors.summingInt((s) -> s.getBytes().length)));
writeUserName(username);
for (String n : names)
{
@ -87,6 +96,7 @@ public class ProtoOut
out.writeInt(msgb.length);
writeUserName(username);
out.write(msgb);
commit();
}
synchronized public void sendFile(String username, String filename, byte data[]) throws IOException
@ -100,6 +110,7 @@ public class ProtoOut
out.writeByte(fnb.length);
out.write(fnb);
out.write(data);
commit();
}
synchronized public void sendInfo(String username) throws IOException

Loading…
Cancel
Save