Game Server implementation consists of 2 parts:
- Web-socket server for game events and players interaction: useful in all event-driven cases.
- REST API for receiving data (like statistic) and authorization: useful in data-driven cases and request-response logic.
All messages based on player actions or game related events. Messages are JSON. Common format for client messages is:
{
"authKey": "<authKey>",
"eventType": "<eventName>",
"eventData": {
// fields with event data
}
}
Common format for server messages is:
{
"initiator": "<player>",
"eventType": "<eventName>",
"eventData": {
// fields with event data
}
}
Channel for authentication related actions.
{
"initiator": "<player>",
"eventType": "<eventName>",
"eventData": {
// fields with event data
}
}
All wss-routes prefixed with /wss/v1
. Server provide next routes:
This channel provide events about new games.
{
"eventType": "CreateNewRoom",
"eventData": {
"numberOfPlayers": 2,
"boardType": "<hex|square>",
"boardSize": 8, // e.g. 8x8
}
}
{
"eventType": "RoomsListRequest",
"eventData": {
"numberOfPlayers": 2, // optional, can be undefined for include without limit by players
"boardType": "<hex|square>", // optional, can be undefined for include without limit by board
"boardSize": 8, // e.g. 8x8, optional, can be undefined for include without limit by players
}
}
{
"eventType": "RoomsListRequest",
"eventData": {
"rooms": [
{
"numberOfPlayers": 2,
"boardType": "<hex|square>",
"boardSize": 8, // e.g. 8x8
"players": [
{
"id": "<playerId>",
"login": "<playerLogin>",
"color": "#FFFFFF"
}
]
}
]
}
}
{
"eventType": "PlayerJoinedToRoom",
"eventData": {
"roomId": "<roomId>",
"player": {
"id": "<playerId>",
"login": "<playerLogin",
"color": "#FFFFFF" // RGB color of player
}
}
}
{
"eventType": "RoomFilled",
"eventData": {
"gameId": "<gameId>" // id of new game, connect to its channel (see below)
}
}
{
"eventType": "NewRoomCreated",
"eventData": {
"roomId": "<roomId>",
"numberOfPlayers": 2,
"boardType": "<hex|square>",
"boardSize": 8, // e.g. 8x8
}
}
This channel provide all events in game, like player actions.
{
"eventType": "AssaultCastle",
"eventData": {
// TBD
}
}
{
"eventType": "BuildCastle",
"eventData": {
"tileCoordinate": "<tileCoordinate>" // coordinate of tile in "1-1" format, where first number is row, and second is column, started from 1.
}
}
{
"eventType": "MergeArmy",
"eventData": {
// TBD
}
}
{
"eventType": "MoveArmy",
"eventData": {
"sourceTileCoordinate": "<tileCoordinate>",
"targetTileCoordinate": "<tileCoordinate>",
"units": 10 // number of units for movement
}
}
{
"eventType": "ReplenishGarrison",
"eventData": {
"tileCoordinate": "<tileCoordinate>"
}
}
{
"eventType": "TakeOffEnemyGarrison",
"eventData": {
"tileCoordinate": "<tileCoordinate>"
}
}
Server re-send all client messages to every player in game as is. Client must update board state with action from other players.
Send when previous player make all moves, and active player switched.
{
"eventType": "SwitchActivePlayer",
"eventData": {
"activePlayerId": "<playerId>"
}
}
All REST routes prefixed with /api/v1
. REST API provide next routes:
...TBD...