Académique Documents
Professionnel Documents
Culture Documents
BaseFunctions
Index:
URL:/
Method:GET
Parameters:None
Response:renderspublic/index.html
UserFunctions
Getusers:
URL:/users
Method:GET
Parameters:None
Response:application/json{users:[listofuserswithdata]}
Adduser:
URL:/users
Method:PUT
Parameters:{username:username_string}
Response:
success:201HTTPResponse(Created)
failed: 409HTTPresponse(Conflict)
Getuserdata:
URL:/user/:username/data
Method:GET
Parameters:username
Response:{user_data:
{username:user_name,
wins:num_wins,
losses:num_losses,
rating:player_rating,
status:player_status*
}
}
*playerstatusisoneofthefollowing:[AVAILABLE,PENDING_INVITE,IN_GAME**]
**IN_GAMEusersareneverreturnedwiththiscall
InviteFunctions
Sendinvite:
{
function:send,
target:target_username
}
Response:
{
status:success/failed
}
Receivinginvite:
{
sender:user_inviting_player
}
Acceptinginvite:
{
function:joining_game/create_game,
target:inviting_user
gameID:game_id_string<<onlysentwithjoining_game>>
}
create_gameissenttotheinvitinguser,joining_gametothetarget
Declininginvite:
{
function:decline,
target:inviting_user
}
Responsetoinviter:
{
status:declined
}
Cancellinginvite:
{
function:cancel,
target:user_to_invite
}
Response:
{
status:cancelled
}
Forbothusers.
GameFunctions
Getboardstate:
{
function:board_state
}
Response
{
state:game_state_name<<seeclassdiagramforlist>>
}
Getmoves:
{
function:get_moves
}
Response:
{[
{name:piece_name,
position:current_position
moves:[
move:next_position
],},
}]
Makemove:
{
function:make_move,
move:{
fromPos:{
rowcol:row_letter_col_number
},
toPos:{
rowcol:row_letter_col_number
}
}
}
Response
Onvalidmove:
{
function:success,<<onlysenttoplayerwhomademove>>
state:game_board_state,
updated_board:board_json<<onlysenttootherplayer>>
}
Oninvalidmove:
{
function:error,
status:invalid_move
}
Forfeit:
{
function:forfeit
}
Response:
{
function:request_forfeit,
username:username_string
}
Gameover:
{
function:game_over,
reason:[DRAW,FORFEIT,CHECKMATE]
}
Response:
{
function:game_ended
Websocketclosed:
{
status:disconnected,
username:username_string
}
Processes
Invitingaplayer:
Sendaninvitewithawebsocketcall.Assumingyoursocketobjectis`ws`:
ws.send(JSON.stringify({
function:send,
target:username_to_invite
})
Theserverwillsendback:
{
status:success[failediftheuserisnotavailable]
}
Receivinganinvite:
Theserverwillsendawsmessagethatshouldbehandled:
{
sender:username_who_invited
}
Rejectinganinvite:
Theclientsendsamessagewiththeformat:
{
function:decline,
target:inviter_to_decline
}
Bothusersarenowmarkedasavailable.
Acceptinganinvite:
Ifauserpressesacceptonaninvite,theclientwillsendamessage:
{
function:accept,
target:inviter_to_accept
}
TheserverwillsetbothusersstatusestoIN_GAMEandsendareplytotheinvited
user
{
function:create_game,
}
Creatingagame:
Whenauseracceptsaninvite,anajaxcallismade:
{
method:PUT,
url:/game,
data:{player2:inviting_player}
}
response:
{
gameID:gameID_int
}
Uponcompletion,player2issentawebsocketmessage:
{
function:joining_game,
gameID:gameID_string
}
Theajax.done()methodisusedtoredirectthefirstplayertothegamepage,whilethe
secondplayerwillredirectinthews.onmessagefunctionwiththeaboveformat.