Commit 365d5bb0 authored by Jesse Bakker's avatar Jesse Bakker

Add chat, challenge and leaderboard extensions

parent 548af903
......@@ -180,7 +180,7 @@ class JoinRoomParams {
Examples:
- [Without team](examples/joinRoom__withoutteam_request.json)
- [Without team](examples/joinRoom_withoutteam_request.json)
- [With team](examples/joinRoom_withteam_request.json)
_Errors_:
......@@ -293,10 +293,197 @@ Examples:
```java
class ErrorCodes {
// Core protocol errors
int ERROR_ROOM_FULL = 0;
int ERROR_TEAM_FULL = 1;
int ERROR_INVALID_LANCE = 2;
int ERROR_INVALID_MOVE = 3;
int ERROR_ROOM_INVALID = 4;
// Extension errors
int ERROR_PLAYER_NOT_AVAILABLE = 104;
int ERROR_LEADERBOARD_NOT_FOUND = 105;
}
```
## Extensions
### Chat
Identifier: 'chat'
#### Send message
Client -> Server
Chat messages can only be sent when in a room. If not in a room, sending a message has no effect.
_Notification_
- method: 'sendMessage'
- params: 'SendMessageParams'
```java
class SendMessageParams {
String message;
}
```
#### Receive message
Server -> Clients
- method: 'receiveMessage'
- params: 'ReceivedMessageParams'
```java
class ReceivedMessageParams {
String message;
int sendingPlayer;
}
```
### Challenge
Identifier: 'challenge'
For simplicity, the protocol only supports challenging *one* other player to a 2-player game.
After a challenged player accepts the challenge, both players receive a `startGame` notification and the game starts.
#### Get available players
You can only challenge players that have a client that supports challenges.
Therefor, the response to this request only returns players using supporting clients.
Also, if a player is already in a room, we do not want them to be challenged, so those players are excluded as well.
_Request_
- method: 'getAvailablePlayers'
_Response_
- result: 'AvailablePlayersResult'
```java
class AvailablePlayersResult {
Player[] availablePlayers;
}
```
#### Challenge player
_Request_
- method: 'challengePlayer'
- params: 'ChallengePlayerParams'
```java
class ChallengePlayerParams {
int playerId;
}
```
_Response_
- result: 'ChallengePlayerResult'
```java
class ChallengePlayerResult {
boolean accepted;
}
```
_Errors_
- Player is not available: `ERROR_PLAYER_NOT_AVAILABLE`
#### Receiving a challenge
When a client makes a 'challengePlayer' request, the server then sends a request to the client to which they can respond to accept/decline the challenge.
The server sends the name of the challenging player along with the request so that the client does not have to get that from the server separately.
_Request_
- method: 'respondToChallenge'
- params: 'RespondToChallengeParams'
```java
class RespondToChallengeParams {
int challengingPlayerId;
String challengingPlayerName;
```
_Response_
- result: 'RespondToChallengeResult'
```java
class RespondToChallengeResult {
boolean accept;
```
### Leaderboard
Identifier: 'leaderboard'
There are many different leaderboard one could implement. We leave it up to the server to define these and just let the clients query them
#### Get available leaderboards
Leaderboards are described an id and a name. The name should be descriptive, e.g. "Top scores of all time" or "Best this week".
_Request_
- method: 'getLeaderboards'
_Response_
- result: 'GetLeaderboardsResult'
```java
class GetLeaderboardsResult {
Leaderboard[] leaderboards;
}
class Leaderboard {
int id;
String name;
}
```
#### Get leaderboard
_Request_
- method: 'getLeaderboard'
- params: 'GetLeaderboardParams'
```java
class GetLeaderboardParams {
int leaderboardId;
}
```
_Response_
- result: 'GetLeaderboardResult'
```java
class GetLeaderboardResult {
LeaderboardEntry[] entries;
}
class LeaderboardEntry {
int score;
String[] playerNames;
String date;
}
```
Here `date` is formatted according to the [`java.time.LocalDateTime.toString()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalDateTime.html#toString()) method.
This format can be parsed using the [`java.time.LocalDateTime.parse()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalDateTime.html#parse()] method.
_Errors_
- Leaderboard does not exist: `ERROR_LEADERBOARD_NOT_FOUND`
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment