Server - ogrady/inf3project GitHub Wiki
The server is the central point, where all information over the current state of the game are gathered and distributed to the connected clients.
You will connect to the server by establishing a TCP-connection to the machine the server-application is running on by using the IP and port. Once connected, you are represented by a pawn in game with the name "PlayerX", where X is an arbitrary number. You can then proceed to interact with the server by issueing the client-commands. Whatever a client does, the course always goes like this:
/ [server declines request] -> [send "no" or "inv" to client] [client asks to perform an action] - ♦ \ [server accepts request] -> [send "ok" to client] -> [broadcast changes]
So if you wanted to move your pawn one tile to the left, you would ask the server if you are allowed to by sending "ask:mv:lft". If the server determines, that you are fine to move he will move your server-sided entity and broadcast this change in position to all connected players (including yourself) so that all clients are up to date. Say you are trying to move into a wall or are not allowed to move at all because you are currently marked as "busy" (playing a minigame) the server will deny your request. Sure, you can locally move your figure around in your GUI. But this change will neither be visible to other connected players, nor will it be a valid action. So always wait for the server to confirm your request before you update your GUI.
If you are writing a client in class, your lecturer will probably have set up a server and given you the IP and port the application runs on. It is always recommended to use this live server, as it is more fun to test your clients with fellow students from other groups.
But in some cases you might want to test something independently, fiddle with the configuration or just dive into the code of the server.
In that case, just clone this git-repository and import it as a Java-project to eclipse.
You can then proceed to run the server from eclipse (server/server/Server.java
is the main-class) or export a jar-file and run it via your command-prompt with java -jar server.jar PORT MAP
, assuming that you exported the project as "server.jar". PORT
specifies the port, the server should run on. MAP
is the path to a bitmap-file that serves as template for the map. Ommiting one of those parameters will result in using the values from the file "config.properties", which will be looked for in the same directory as the jar itself. A template for this file can be found in the root-directory of the project. Not having such a file will create an empty configuration-file and use default-settings, as specified in common/util/Configuration.java
.
When connecting to your local server, you can always use the IP 127.0.0.1
(aka localhost).
Whoever runs the server dictates the map that is being used. I recommend you to use a rather small map (20x20 tiles) as sending the map to a player is quite some work for the server because each tile has to be sent independently. But you are free to create bigger maps of any size and shape. For that, you just create a new bitmap-file and colour the pixels for different types of terrain. Every pixel will represent one tile on the map.
- Green (0x00ff00): forest
- Blue (0x0000ff): water
- Black (0x000000): wall
- White (0xffffff): walkable
Then use that bitmap as map as specified above (as second parameter or via an entry in the config).
There are also some commands you can issue from within the server-console for very basic administration. Just type them into your prompt and hit enter.
- help - list all available server-commands
- kick:id:ID - kick the client with the specified ID
- kick:name:NAME - kick the client with the specified name
- list:player - generate a list with all connected players
- list:entities - generate a list with all entities (including players and dragons)
-
list:client - generate a list with all connected clients. This differs from
list:player
as you can rather see IP and port, instead of position and ID - stop - stops the server gracefully
- info:id - displays detailed information for player with the given ID
- spawn - spawns a dragon at a random position
- reload - reloads the configuration on the fly
- logger:add:MESSAGETYPE - adds a messagetype to the console-output of the server (GENERIC, NOTIFICATION, INFO, ERROR, DEBUG, INPUT, OUTPUT)
- logger:rmv:MESSAGETYPE - removes a messagetype from the console-output of the server (GENERIC, NOTIFICATION, INFO, ERROR, DEBUG, INPUT, OUTPUT)