From 10b903956ef1bdb443a60e4ad37429c8b9c55f7f Mon Sep 17 00:00:00 2001
From: David Mehren <git@herrmehren.de>
Date: Mon, 4 Sep 2023 21:56:17 +0200
Subject: [PATCH] Add docs

---
 ERRORCODES.md |  64 ++++++++++++++++++
 PROTOCOL.md   | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++
 README.md     |   3 +
 3 files changed, 243 insertions(+)
 create mode 100644 ERRORCODES.md
 create mode 100644 PROTOCOL.md
 create mode 100644 README.md

diff --git a/ERRORCODES.md b/ERRORCODES.md
new file mode 100644
index 0000000..386bec0
--- /dev/null
+++ b/ERRORCODES.md
@@ -0,0 +1,64 @@
+# Error codes
+
+Sometimes you will get error codes from the server.  
+Here is a small documentation of those error codes.
+
+## ERROR_SPAM
+You are spamming the server.  
+
+## ERROR_PACKET_OVERFLOW
+You are sending more than 1024 bytes to the server.
+
+## ERROR_NO_MOVE
+You didnt send a move packet.
+
+## ERROR_MAX_CONNECTIONS
+Your ip is already connected. IPv6 may workarounds this but please dont flood the server with connections :(
+
+## ERROR_JOIN_TIMEOUT
+You didnt send the join packet.
+
+## ERROR_EXPECTED_JOIN
+Instead of join you sent some other packet.
+
+## ERROR_INVALID_USERNAME
+You used an invalid username. (e.g. not a string)
+
+## ERROR_USERNAME_TOO_SHORT
+Username is too short.
+
+## ERROR_USERNAME_TOO_LONG
+Username is too long.
+
+## ERROR_USERNAME_INVALID_SYMBOLS
+You used invalid symbols for the username.
+
+## ERROR_INVALID_PASSWORD
+You used an invalid password. (e.g. not a string)
+
+## ERROR_PASSWORD_TOO_SHORT
+Password is too short.
+
+## ERROR_PASSWORD_TOO_LONG
+Password is too long.
+
+## ERROR_NO_PERMISSION
+You should not do this :^) (e.g. hijack bots)
+
+## ERROR_WRONG_PASSWORD
+Your password was wrong.
+
+## ERROR_ALREADY_CONNECTED
+You are already connected with this player.
+
+## WARNING_UNKNOWN_MOVE
+You did not send a valid move packet.
+
+## ERROR_DEAD_CANNOT_CHAT
+You are dead so shush :^)
+
+## ERROR_INVALID_CHAT_MESSAGE
+Something is wrong with your chat message.
+
+## ERROR_UNKNOWN_PACKET
+Server does not know what you want :D
diff --git a/PROTOCOL.md b/PROTOCOL.md
new file mode 100644
index 0000000..0567a09
--- /dev/null
+++ b/PROTOCOL.md
@@ -0,0 +1,176 @@
+# Protocol
+
+The protocol is string based.  
+Every packet will end with a newline (\n), but the Hackathon wrapper handles them for you.  
+E.g: `pos|10|50|5`  
+
+## Packet structure
+
+The general packet structure looks like this:  
+\<packet type\>\<...arguments\>  
+E.g: `game|5|1|2|3`  
+Where game is the packet type, 5 the first argument, 1 the second, 2 the third and 3 the fourth
+
+## Packet types
+
+### motd
+
+The motd packet is sent by the server when you connect to it.  
+motd means "Message of the day".
+
+**Name:** motd  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type | Description |
+|---|--------|------------------------|
+| 1 | String | The message of the day |
+
+**Example:** `motd|Hello how are you? :)`
+
+### join
+
+The join packet is the first packet the client has to send to the server when connecting.  
+Remember the password otherwise you cant use the username again!
+
+**Name:** join  
+**Sender:** Client  
+**Arguments:**  
+
+| # | Type   | Description  |
+|---|--------|--------------|
+| 1 | String | The username |
+| 2 | String | The password |
+
+**Example:** `join|Cool Guy|mysupersecret`
+
+### error
+
+The error packet is sent by the server if something went wrong.
+
+**Name:** error  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description                                           |
+|---|--------|-------------------------------------------------------|
+| 1 | String | The error according to [ERRORCODES.md](ERRORCODES.md) |
+
+**Example:** `error|INVALID_USERNAME`
+
+### game
+
+The game packet is sent by the server to inform the client about the new game round.  
+It contains information about the map size and the current player id.
+
+**Name:** game  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description                   |
+|---|--------|-------------------------------|
+| 1 | Number | The width of the current map  |
+| 2 | Number | The height of the current map |
+| 3 | Number | The current player id         |
+
+**Example:** `game|100|100|5`
+
+### pos
+
+The pos packet is sent by the server to inform the client about a players current position.
+
+**Name:** pos  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description              |
+|---|--------|--------------------------|
+| 1 | Number | The player id            |
+| 2 | Number | x position of the player |
+| 3 | Number | y position of the player |
+
+**Example:** `pos|5|3|8`
+
+### player
+
+The player packet is sent by the server to share informations of an player.
+
+**Name:** player  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description            |
+|---|--------|------------------------|
+| 1 | Number | The player id          |
+| 2 | String | The name of the player |
+
+**Example:** `player|3|Coolguy`
+
+### tick
+
+The tick packet is sent by the server after a turn has been done. Its the best to send a move packet after this!
+
+**Name:** tick  
+**Sender:** Server  
+**Arguments:**  None
+
+**Example:** `tick`
+
+### die
+
+The die packet is sent by the server to inform the client about a players who died.
+
+**Name:** die  
+**Sender:** Server  
+**Arguments:**  
+
+| #    | Type   | Description   |
+|------|--------|---------------|
+| 1... | Number | The player id |
+
+**Example (1 dead player):** `die|5`  
+**Example (4 dead player):** `die|5|8|9|13`
+
+### move
+
+The move packet is sent by the client to decide where to move.
+
+**Name:** move  
+**Sender:** Client  
+**Arguments:**  
+
+| # | Type   | Description             |
+|---|--------|-------------------------|
+| 1 | String | up, right, down or left |
+
+**Example:** `move|up`
+
+### win
+
+The win packet is sent by the server to inform the client they won.
+
+**Name:** win  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description      |
+|---|--------|------------------|
+| 1 | Number | amount of wins   |
+| 2 | Number | amount of losses |
+
+**Example:** `win|1|20`
+
+### lose
+
+The lose packet is sent by the server to inform the client they lost.
+
+**Name:** lose  
+**Sender:** Server  
+**Arguments:**  
+
+| # | Type   | Description      |
+|---|--------|------------------|
+| 1 | Number | amount of wins   |
+| 2 | Number | amount of losses |
+
+**Example:** `lose|1|20`
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ffba2f3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Hackatron Demo Client
+
+This is a simple Java client implementation for the FOSS-AG Hackatron.
-- 
GitLab