Server ~ GameCommInterface - UofM-COMP4350-4/NBGI GitHub Wiki
Interprets raw Socket.IO message data, sending the data to the Client in a standard generic game format (which can then be processed by the game block/GameInterface). APIs to communicate with the server, by passing generic game data.
##Socket.IO Emits Event name: "gameBoard"
Sends the current gameboard state; usually after a server has calculated a move request.
- Event data:
{
instanceID:0, // {Number} - Instance ID for match gameboard data
gameID:0, // {Number} - Type of game the game is
userToPlay:0, // {String} - User ID whose turn it is
players: { // {Object} - JSON of userID:userName pairs.
<userID>:"", // {String} - <userID> is the {String} value of the userID number
// and returns the displayable username
... // Repeating the userID:userName format for each player
},
currentBoard: { // {Object} - JSON of pieceID:piecePosition pairs.
<pieceID>: { // {Object} - <pieceID> is the {String} value of the pieceID
pos: { // {Object} - Position data for the piece
x:0, // {Number} - Board x-coordinate position number
y:0, // OPTIONAL {Number} - Board y-coordinate position number
z:0 // OPTIONAL {Number} - Board z-coordinate position number
}
},
... // Repeating the pieceID:piecePosition format for each piece on the board
},
status: undefined // {Object} - Any extra game-specific board data to pass; undefined if none
}
Event name: "moveFailure"
Sent when a move fails, indicating a problem in the client.
- Event data: {Object} - Data from the failed "move" event
Event name: "achievement"
Sent when the user gets an achievement in a game.
- Event data:
{
instanceID:0, // {Number} - Instance ID for match results
title:"", // {String} - Title of the achievement
caption:"", // {String} - Caption for the achievement
}
Event name: "matchResult"
Sent when a game match has ended.
- Event data:
{
instanceID:0, // {Number} - Instance ID for match results
winner:0, // {Number} - User ID of the match winner
score:0, // {Number} - Player's score for the match
gameBoard:undefined, // {Object} - Final game state in the form of "gameBoard" event data
moves:undefined // {Array} - List of all the user's moves (successful "move" event data objects)
}
##Socket.IO Receives Event name: "move"
Receives a move request from a client for a particular match.
- Event data:
{
instanceID:0, // {Number} - Instance ID for match the move request is for
reason:"", // {String} - Game-specific purpose of move
pieceID:0, // {Number} - Piece ID of the piece requesting to move
play:"", // {String} - Game-specific play information
pos1: { // {Object} - First position data for move request
x:0, // {Number} - Board x-coordinate position number
y:0, // OPTIONAL {Number} - Board y-coordinate position number
z:0 // OPTIONAL {Number} - Board z-coordinate position number
},
pos2: { // OPTIONAL {Object} - Second position data for move request
x:0, // OPTIONAL {Number} - Board x-coordinate position number
y:0, // OPTIONAL {Number} - Board y-coordinate position number
z:0 // OPTIONAL {Number} - Board z-coordinate position number
}
}
##Component API
validateMove(fn)
-
fn
{Function(moveData)} - A function that will evaluate a move request and check validity-
moveData
{Object} - Data from a "move" event to be evaluated - Function should return:
- {Boolean} - Whether or not the move is valid
-
sendGameBoard(data)
-
data
{Object} - Current gameboard state for a match
{
instanceID:0, // {Number} - Instance ID for match gameboard data
gameID:0, // {Number} - Type of game the game is
userToPlay:0, // {String} - User ID whose turn it is
players: { // {Object} - JSON of userID:userName pairs.
<userID>:"", // {String} - <userID> is the {String} value of the userID number
// and returns the displayable username
... // Repeating the userID:userName format for each player
},
currentBoard: { // {Object} - JSON of pieceID:piecePosition pairs.
<pieceID>: { // {Object} - <pieceID> is the {String} value of the pieceID
pos: { // {Object} - Position data for the piece
x:0, // {Number} - Board x-coordinate position number
y:0, // OPTIONAL {Number} - Board y-coordinate position number
z:0 // OPTIONAL {Number} - Board z-coordinate position number
}
},
... // Repeating the pieceID:piecePosition format for each piece on the board
},
status: undefined // {Object} - Any extra game-specific board data passed; undefined if none
}
sendAchievement(instance, title, caption)
-
instance
{Number} - Instance ID for match results -
title
{String} - Title of the achievement -
caption
{String} - Caption for the achievement
sendResults(data)
-
data
{Object} - Match results to send to the client
{
instanceID:0, // {Number} - Instance ID for match results
winner:0, // {Number} - User ID of the match winner
score:0, // {Number} - Player's score for the match
gameBoard:undefined, // {Object} - Final game state in the form of "gameBoard" event data
moves:undefined // {Array} - List of all the user's moves (successful "move" event data objects)
}