Package pacManReloaded.server
Class Server
- java.lang.Object
-
- pacManReloaded.server.Server
-
- All Implemented Interfaces:
java.lang.Runnable
public class Server extends java.lang.Object implements java.lang.Runnable
-
-
Constructor Summary
Constructors Constructor Description Server(int port)
Constructor of the server, opens a new socket
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
broadcast(ServerThread thread, ChatMessage chatMessage)
handles the broadcast of a message in the server, sends the message to all clients connected to the serverLobby
findLobby(ServerThread thread)
method to find a lobbyjava.lang.String
getAndSetName(ServerThread thread, java.lang.String myName, java.lang.String suffix)
Gets the Nickname that should be used.java.lang.String
getClientInfoString()
get the names of the connected clients in a stringjava.lang.String
getHighScoreString()
method which makes the highscore of the file to a readable stringjava.lang.String
getLobbyInfoString()
"getter" for the info of the lobbyjava.lang.String
getManualText()
"getter" for the manual text as stringjava.lang.String
getToReadableTime(long timeInms)
Getter for the function toReadableTime.void
handleChatWithAddress(ServerThread thread, ChatWithAddress msg)
handles private messages "NotInLobby" is reserved as keywordJoinLobbyResult
joinLobby(ServerThread thread, java.lang.String lobbyName)
method which handles the accession into a lobbyvoid
playerWon(java.lang.String playerName, int score)
includes the player who won into the highscore txt filevoid
remove(ServerThread threadToTerminate)
method which handles the removal of a client,void
run()
when the run method starts, the server is accepting connection at it's socket, then starts a ClientThread, which handles the Client and afterwards accepts new connections
-
-
-
Method Detail
-
run
public void run()
when the run method starts, the server is accepting connection at it's socket, then starts a ClientThread, which handles the Client and afterwards accepts new connections- Specified by:
run
in interfacejava.lang.Runnable
-
remove
public void remove(ServerThread threadToTerminate)
method which handles the removal of a client,- Parameters:
threadToTerminate
- - thread which will be removed/terminated
-
getAndSetName
public java.lang.String getAndSetName(ServerThread thread, java.lang.String myName, java.lang.String suffix)
Gets the Nickname that should be used. Checks the uniqueness of it and sets the unique Nickname of the Client.- Parameters:
thread
- - Thread of the Server.myName
- - The Nickname that should be set.suffix
- - The suffix for the Nickname.- Returns:
- the set Nickname of the Client.
-
getHighScoreString
public java.lang.String getHighScoreString()
method which makes the highscore of the file to a readable string- Returns:
- the highscore as a readable string
-
getLobbyInfoString
public java.lang.String getLobbyInfoString()
"getter" for the info of the lobby- Returns:
- - info of the lobby
-
getClientInfoString
public java.lang.String getClientInfoString()
get the names of the connected clients in a string- Returns:
- the connected users
-
getManualText
public java.lang.String getManualText()
"getter" for the manual text as string- Returns:
- the manual as a string
-
broadcast
public void broadcast(ServerThread thread, ChatMessage chatMessage)
handles the broadcast of a message in the server, sends the message to all clients connected to the server- Parameters:
thread
- - thread of the serverchatMessage
- - message which has to be broadcasted
-
handleChatWithAddress
public void handleChatWithAddress(ServerThread thread, ChatWithAddress msg)
handles private messages "NotInLobby" is reserved as keyword- Parameters:
thread
- - thread of the servermsg
- - the private message
-
getToReadableTime
public java.lang.String getToReadableTime(long timeInms)
Getter for the function toReadableTime.- Parameters:
timeInms
- - the time that should be brought in a Readable time format in Milli-seconds.- Returns:
- the Return value of the function toReadableTime in the wished time format.
-
joinLobby
public JoinLobbyResult joinLobby(ServerThread thread, java.lang.String lobbyName)
method which handles the accession into a lobby- Parameters:
thread
- - thread of the serverlobbyName
- - name of the lobby- Returns:
- - state of the accession result
-
findLobby
public Lobby findLobby(ServerThread thread)
method to find a lobby- Parameters:
thread
- - thread of the server- Returns:
- - the lobby
-
playerWon
public void playerWon(java.lang.String playerName, int score)
includes the player who won into the highscore txt file- Parameters:
playerName
- the name of the plasyer who won the game
-
-