This commit is contained in:
Steven Tracey 2024-01-11 06:32:18 -06:00
parent 3906c463fd
commit 521f38468b
2 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

View File

@ -5,6 +5,7 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class MessageDistributer extends OutputStream {
private static Map<String, OutputStream> userStreams = new HashMap<>();
@ -30,6 +31,11 @@ public class MessageDistributer extends OutputStream {
}
public void registerStream(String username, OutputStream os) {
Set<String> usernames = userStreams.keySet();
while (usernames.contains(username)) {
username += ".imposter";
}
userStreams.put(username, os);
try {
this.write(("SERVER> Welcome, " + username + "!\n").getBytes(StandardCharsets.UTF_8));