Added Documentation to some undocumented methods
This commit is contained in:
parent
535edcc54c
commit
ef0eba6825
@ -1,13 +1,21 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
/* This class is built to contain the usernames of all players in a single string.
|
||||
/**
|
||||
* This class is built to contain the usernames of all players in a single string.
|
||||
* This allows a duplicate check (--> ClientHandler) when a new player chooses
|
||||
* a name: does the string with all the previous names contain the new player's
|
||||
* desired username? If yes, he is being assigned a random name. If no, he can keep
|
||||
* his desired name. */
|
||||
* his desired name.
|
||||
* **/
|
||||
|
||||
public class AllClientNames {
|
||||
static StringBuilder names = new StringBuilder();
|
||||
|
||||
/**
|
||||
* Safes a new name to the List of all Names
|
||||
* @param currentName the new name to be added
|
||||
* @return All names adding the new currentName
|
||||
*/
|
||||
public static String allNames(String currentName) {
|
||||
return names.append(currentName).toString();
|
||||
}
|
||||
|
||||
@ -98,6 +98,10 @@ public class ClientHandler implements Runnable {
|
||||
return clientUserName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets the client change their respective username, if the username is already taken, a similar option is chosen
|
||||
* @param newName The desired new name to replace the old one with.
|
||||
*/
|
||||
public void changeUsername(String newName) {
|
||||
if (AllClientNames.allNames("").contains(newName)) {
|
||||
newName = NameGenerator.randomName(newName);
|
||||
@ -108,12 +112,23 @@ public class ClientHandler implements Runnable {
|
||||
broadcastMessage(h +" have changed their nickname to " + clientUserName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a Message to all active clients in the form "Username: msg"
|
||||
* @param msg the Message to be broadcasted
|
||||
*/
|
||||
|
||||
public void broadcastMessage(String msg) {
|
||||
for (ClientHandler client : connectedClients) {
|
||||
client.sendMsgToClient("CHATM:" + clientUserName + ": \"" + msg + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Documentation
|
||||
/**
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
|
||||
public void sendMsgToClient(String msg) {
|
||||
try {
|
||||
out.write(msg);
|
||||
|
||||
@ -2,9 +2,14 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
// Creates a String beginning with "player_" followed by 4 random letters
|
||||
|
||||
public class NameGenerator {
|
||||
|
||||
/**
|
||||
* Creates a random alteration of a Name by adding 4 numbers at the end of the Name that shall be alterd
|
||||
* @param username the to be altered username
|
||||
* @return username + four numbers
|
||||
*/
|
||||
static String randomName(String username) {
|
||||
StringBuilder name;
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user