Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -105,6 +105,7 @@ public class Client {
|
||||
|
||||
/**
|
||||
* Tells user to enter a position to vote for passenger at that position
|
||||
* @param msg the message containing the position
|
||||
*/
|
||||
public void positionSetter(String msg) {
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ public class MessageFormatter {
|
||||
* handle it (see Protocol.java). May need to be redesigned once the game uses a GUI.
|
||||
*
|
||||
* @param msg the Messaged to be reformatted
|
||||
* @param position the position the client is in
|
||||
* @return the reformatted message in the form HEADR$msg
|
||||
*/
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public class ClientPinger implements Runnable {
|
||||
/**
|
||||
* @param socket the socket the Client is connected to which is used to end the thread if the
|
||||
* connection is lost.
|
||||
* @param client the client the pinger is related to
|
||||
*/
|
||||
public ClientPinger(Client client, Socket socket) {
|
||||
gotPingBack = false;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Protocol {
|
||||
public static final String clientQuitRequest = "QUITR";
|
||||
|
||||
/**
|
||||
* Client sends this message when they want to create a new lobby (& automatically join it).
|
||||
* Client sends this message when they want to create a new lobby (and automatically join it).
|
||||
* Client issues this command in {@link ch.unibas.dmi.dbis.cs108.multiplayer.client.MessageFormatter}
|
||||
* using "/g".
|
||||
* First a lobby {@link Lobby} is created of which the requesting client is the admin of.
|
||||
|
||||
@@ -27,6 +27,7 @@ public class ServerPinger implements Runnable {
|
||||
/**
|
||||
* @param socket the socket the ClientHandler is connected to; used to end the thread if the
|
||||
* connection is closed.
|
||||
* @param c the ClientHandler handeling the Client this pinger pings to
|
||||
*/
|
||||
public ServerPinger(Socket socket, ClientHandler c) {
|
||||
gotPingBack = false;
|
||||
|
||||
@@ -156,6 +156,7 @@ public class ClientHandler implements Runnable {
|
||||
/**
|
||||
* Returns the Lobby this ClientHandler is in. If this ClientHandler is not in a Lobby, it returns
|
||||
* null.
|
||||
* @return the Lobby this clientHandler lives in
|
||||
*/
|
||||
public Lobby getLobby() {
|
||||
try {
|
||||
@@ -205,7 +206,7 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a chat Message to all clients across all lobbies & clients who are not in a lobby in
|
||||
* Broadcasts a chat Message to all clients across all lobbies and clients who are not in a lobby in
|
||||
* the form "Username: @msg"
|
||||
*
|
||||
* @param msg the Message to be broadcast
|
||||
@@ -260,6 +261,7 @@ public class ClientHandler implements Runnable {
|
||||
* sent the message that it has been sent. Syntax:
|
||||
*
|
||||
* @param target MUST NOT BE NULL!
|
||||
* @param msg the message being whisperd
|
||||
*/
|
||||
public void whisper(String msg, ClientHandler target) {
|
||||
target.sendMsgToClient(
|
||||
@@ -367,13 +369,14 @@ public class ClientHandler implements Runnable {
|
||||
* Sends an announcement to just this client. Essentially the same as broadcastAnnouncementToAll
|
||||
* except it only sends an announcement to just this client instead of everyone. Can be used for
|
||||
* private non-chat messages (e.g. "You are now a ghost").
|
||||
* @param msg the message being announced
|
||||
*/
|
||||
public void sendAnnouncementToClient(String msg) {
|
||||
sendMsgToClient(Protocol.printToClientConsole + "$" + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes & disconnects the client. To be used if a severe connection loss is detected (i.e. if
|
||||
* Removes and disconnects the client. To be used if a severe connection loss is detected (i.e. if
|
||||
* trying to send / receive a message throws an exception, not just if ping-pong detects a
|
||||
* connection loss). This is very similar to removeClientOnLogout(), however
|
||||
* removeClientOnLogout() should only be used for regular quitting, since removeClientOnLogout()
|
||||
|
||||
@@ -102,6 +102,8 @@ public class Lobby {
|
||||
* Returns the lobby with the desired LobbyID.
|
||||
* For example, getLobbyFromID(5) returns the lobby whose LobbyID is 5.
|
||||
* If no such lobby exists, it returns null.
|
||||
* @param i the Lobby ID you are looking for
|
||||
* @return the Lobby with i as its ID
|
||||
*/
|
||||
public static Lobby getLobbyFromID(int i) {
|
||||
for (Lobby l: lobbies) {
|
||||
@@ -148,6 +150,8 @@ public class Lobby {
|
||||
/**
|
||||
* Returns the ID of the lobby that the client is in. If the client is not in any
|
||||
* lobby, it returns -1.
|
||||
* @param h ClientHandler that the corresponding Lobby is searched for
|
||||
* @return the Lobby ID
|
||||
*/
|
||||
public static int clientIsInLobby(ClientHandler h) {
|
||||
for (Lobby l: lobbies) {
|
||||
@@ -164,6 +168,7 @@ public class Lobby {
|
||||
* Adds a player to the lobby. Returns true if successful.
|
||||
* TODO: add an appropriate response. Currently hardcoded.
|
||||
* @param client who wants to join the lobby.
|
||||
* @return true if successful
|
||||
*/
|
||||
public synchronized boolean addPlayer(ClientHandler client) {
|
||||
if (getLobbyIsOpen()) {
|
||||
@@ -204,6 +209,7 @@ public class Lobby {
|
||||
|
||||
/**
|
||||
* Adds game to list of running games and sets its lobby's gameIsRunning to true.
|
||||
* @param game the game to be added
|
||||
*/
|
||||
public void addGameToRunningGames(Game game) {
|
||||
game.getLobby().gameIsRunning = true;
|
||||
@@ -212,6 +218,7 @@ public class Lobby {
|
||||
|
||||
/**
|
||||
* Removes game from list of running games and sets its lobby's gameIsRunning to false.
|
||||
* @param game the game to be removed
|
||||
*/
|
||||
public void removeGameFromRunningGames(Game game) {
|
||||
game.getLobby().gameIsRunning = false;
|
||||
|
||||
@@ -52,6 +52,8 @@ public class nameDuplicateChecker {
|
||||
* If that name is already used by some other ClientHandler, it returns the name with some suffix.
|
||||
* Also, any ":" or "$" are removed, so they can be used for whisper chat.
|
||||
* Also, if the name is empty, it assigns a default value ("U.N. Owen").
|
||||
* @param name the name that is checked for
|
||||
* @return returns either just the name or added some suffix
|
||||
*/
|
||||
public static String checkName(String name) {
|
||||
String tempname = name; //if this line is used, only duplicate names get a suffix.
|
||||
|
||||
Reference in New Issue
Block a user