Skip to content
Adrian Herzog edited this page Dec 11, 2016 · 60 revisions

Basics

If you send a message which the server cannot parse, you will receive a BAD_MESSAGE with your sent message as payload:

{
	"type" : "BAD_MESSAGE",
	"data" : {the message you sent}
}

If the client sends a message which can be parsed, but has a required property missing or an unexpected value in it the server sends another BAD_MESSAGE to the client. The data payload in this case will be an object with the properties which have errors containing those errors as Strings in an Array like this:

{
	"type" : "BAD_MESSAGE",
	"data" : {<attribute>: [<error>, <error>, ...]}
}

Join a game

Connect to the Server using Websockets

Choose player name

The server asks the client for the player name:

{
	"type" : "REQUEST_PLAYER_NAME"
}

The client answers with this message:

{
	"type" : "CHOOSE_PLAYER_NAME",
	"data" : "Client 1"
}

data: Player name as string

Join a Game (aka Session)

Server asks client for session:

{
	"type" : "REQUEST_SESSION_CHOICE",
	"data" : []
}

data: Existing sessions (games) as array of strings.

The client joins a session by sending:

{
	"type" : "CHOOSE_SESSION",
	"data" : {
		"sessionChoice" : "CREATE_NEW",
		"sessionName" : "Session 1",
		"sessionType" : "SINGLE_GAME"
	}
}

For tournaments use:

{
	"type" : "CHOOSE_SESSION",
	"data" : {
		"sessionChoice" : "AUTOJOIN",
		"sessionType" : "TOURNAMENT"
	}
}

sessionChoice can be: undefined, CREATE_NEW, AUTOJOIN or JOIN_EXISTING. When using AUTOJOIN the session is automatically created if it does not exist yet.

If a new session is created the optional field sessionType can either be SINGLE_GAME or TOURNAMENT. If omitted it defaults to SINGLE_GAME.

After joining a session all connected clients will receive a BROADCAST_SESSION_JOINED.

{
	"type" : "BROADCAST_SESSION_JOINED",
	"data" : {
		"sessionName" : "The IT Crowd",
		"player" : {
			"id" : "0cd50a12-09cd-7214-4733-b37e5c216e62",
			"seatId" : 3,
			"name" : "Moss"
		},
		"playersInSession" : [{
				"id" : "4060e397-c95f-e172-9e6f-0389cfdf9d15",
				"seatId" : 0,
				"name" : "Jen"
			}, {
				"id" : "dccfec39-404f-ea71-3bce-f57a84484f7d",
				"seatId" : 1,
				"name" : "Roy"
			}, {
				"id" : "a9d1f5a3-d3fc-cb45-2fe1-b6bd0d4d3690",
				"seatId" : 2,
				"name" : "Douglas"
			}, {
				"id" : "0cd50a12-09cd-7214-4733-b37e5c216e62",
				"seatId" : 3,
				"name" : "Moss"
			}
		]
	}
}

Play the Game

Receive teams

The first thing the server broadcasts when starting a game is the array of teams and players:

{
	"type" : "BROADCAST_TEAMS",
	"data" : [{
			"name" : "Team 1 Jen Douglas",
			"players" : [{
					"name" : "Jen",
					"id" : "4060e397-c95f-e172-9e6f-0389cfdf9d15",
					"seatId" : 0
				}, {
					"name" : "Douglas",
					"id" : "a9d1f5a3-d3fc-cb45-2fe1-b6bd0d4d3690",
					"seatId" : 2
				}
			]
		}, {
			"name" : "Team 2 Roy Moss",
			"players" : [{
					"name" : "Roy",
					"id" : "dccfec39-404f-ea71-3bce-f57a84484f7d",
					"seatId" : 1
				}, {
					"name" : "Moss",
					"id" : "0cd50a12-09cd-7214-4733-b37e5c216e62",
					"seatId" : 3
				}
			]
		}
	]
}

Receive cards

The server deals cards and sends 9 cards to each player:

{
	"type" : "DEAL_CARDS",
	"data" : [{
			"number" : 13,
			"color" : "SPADES"
		}, {
			"number" : 9,
			"color" : "DIAMONDS"
		}, {
			"number" : 12,
			"color" : "HEARTS"
		}, {
			"number" : 11,
			"color" : "HEARTS"
		}, {
			"number" : 10,
			"color" : "HEARTS"
		}, {
			"number" : 8,
			"color" : "CLUBS"
		}, {
			"number" : 11,
			"color" : "SPADES"
		}, {
			"number" : 9,
			"color" : "HEARTS"
		}, {
			"number" : 9,
			"color" : "CLUBS"
		}
	]
}

Choose trumpf

One player receives the REQUEST_TRUMPF message. He has to choose a trumpf by sending back the CHOOSE_TRUMPF message.

{
	"type" : "REQUEST_TRUMPF",
	"data" : false
}
{
	"type" : "CHOOSE_TRUMPF",
	"data" : {
		"mode" : "TRUMPF",
		"trumpfColor" : "SPADES"
	}
}

Note: mode can be: "TRUMPF", "OBEABE", "UNDEUFE" or "SCHIEBE". trumpfColor is mandatory for mode TRUMPF

When the player chooses SCHIEBE as trumpf, a BROADCAST_TRUMPF message will be sent to all clients:

{
	"type" : "BROADCAST_TRUMPF",
	"data" : {
		"mode" : "SCHIEBE"
	}
}

His partner player receives the REQUEST_TRUMPF message, this time with data set to true to indicate that he can not use SCHIEBE again and actually has to choose a trumpf.

{
	"type" : "REQUEST_TRUMPF",
	"data" : true
}

When the trumpf is chosen, it is broadcasted to all players:

{
	"type" : "BROADCAST_TRUMPF",
	"data" : {
		"mode" : "TRUMPF",
		"trumpfColor" : "SPADES"
	}
}

Play cards

The server asks each player for a card.

{
	"type" : "REQUEST_CARD",
	"data" : []
}

The players respond with their card choice:

{
	"type" : "CHOOSE_CARD",
	"data" : {
		"number" : 13,
		"color" : "SPADES"
	}
}

If for any reason, the card is invalid, the player will receive a REJECT_CARD followed by another REQUEST_CARD where he can try another CHOOSE_CARD.

{
	"type" : "REJECT_CARD",
	"data" : {
		"number" : 13,
		"color" : "SPADES"
	}
}

The played card is then broadcasted to all players:

{
	"type" : "PLAYED_CARDS",
	"data" : [{
			"number" : 13,
			"color" : "SPADES"
		}
	]
}

The subsequent card requests from the server to the players contain the cards that are already on the table.

{
	"type" : "REQUEST_CARD",
	"data" : [{
			"number" : 13,
			"color" : "SPADES"
		}
	]
}

When all four players have played their card, the server sends out a broadcast announcing the trick.

{
	"type" : "BROADCAST_STICH",
	"data" : {
		"name" : "Jen",
		"id" : "4060e397-c95f-e172-9e6f-0389cfdf9d15",
		"seatId" : 0,
		"playedCards" : [{
				"number" : 14,
				"color" : "DIAMONDS"
			}, {
				"number" : 12,
				"color" : "DIAMONDS"
			}, {
				"number" : 10,
				"color" : "DIAMONDS"
			}, {
				"number" : 8,
				"color" : "DIAMONDS"
			}
		],
		"teams" : [{
				"name" : "Team 1 Jen Douglas",
				"points" : 48,
				"currentRoundPoints" : 48
			}, {
				"name" : "Team 2 Roy Moss",
				"points" : 0,
				"currentRoundPoints" : 0
			}
		]
	}
}

When all 9 rounds are played, the server sends a broadcast to all players.

{
	"type" : "BROADCAST_GAME_FINISHED",
	"data" : [{
			"name" : "Team 2",
			"points" : 2178,
			"currentRoundPoints" : 2128
		}, {
			"name" : "Team 2",
			"points" : 2178,
			"currentRoundPoints" : 2128
		}
	]
}

When a team has reached 2500 points, the winner is announced to all players.

{
	"type" : "BROADCAST_WINNER_TEAM",
	"data" : {
		"name" : "Team 1",
		"points" : 2532,
		"currentRoundPoints" : 2432
	}
}
Clone this wiki locally