Skip to content

Commit

Permalink
docs: add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LapisBerry committed May 23, 2024
1 parent 7f6d712 commit a913bff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/lapisberry/net/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void processPacketFromClient(ClientHandler sender, ClientPacket packet) {
System.out.println("Processing packet from " + sender.getSocket().getInetAddress().getHostAddress() + ": " + packet);
if (packet instanceof JoinRequestPacket joinRequestPacket) {
serverLobby.addPlayer(sender.getClientId(), joinRequestPacket.getUsername());
// Have to make a copy of the players list to avoid shared reference
ArrayList<Pair<Integer, String>> players = new ArrayList<>(serverLobby.getPlayers());
sendPacketToAllClients(new LobbyPacket(players));
}
Expand All @@ -82,6 +83,7 @@ public void close() {
public void removeClientHandler(ClientHandler clientHandler) {
clientHandlers.remove(clientHandler);
serverLobby.removePlayer(clientHandler.getClientId());
// Have to make a copy of the players list to avoid shared reference
ArrayList<Pair<Integer, String>> players = new ArrayList<>(serverLobby.getPlayers());
sendPacketToAllClients(new LobbyPacket(players));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.io.Serial;
import java.io.Serializable;

/**
* The {@code JoinResponsePacket} class is the packet sending from server to client to response the {@code JoinRequestPacket}.
*/
public class JoinResponsePacket extends ServerPacket implements Serializable {
@Serial
private static final long serialVersionUID = -5576292645379280835L;
Expand Down

0 comments on commit a913bff

Please sign in to comment.