Server ~ DatabaseInterface - UofM-COMP4350-4/NBGI GitHub Wiki

Draft 1

Interface to easily store user/game/friend/chat data formats into a database, with support for the relational database and the flat file data format.

##Component API

Games-Table Storage

listGames(fn)

  • fn {Function(games)} - A callback function for when online status is retrieved

    • games {Array} - List of game information objects, each in the form of:
{
    <gameID>:"" // {String} - Where <gameID> is the game ID and the value is the game name
}

Users-Table Storage

addUser(userID, userName, isOnline, avatarURL, fn)

  • userID {Number} - User ID to add
  • userName {String} - Displayable username
  • isOnline {Boolean} - Whether or not the user is online
  • avatarURL {String} - URL for the user's personal avatar
  • fn {Function} - A callback function for when action is complete

removeUser(userID, fn)

  • userID {Number} - User ID to remove
  • fn {Function} - A callback function for when action is complete

setUserOnlineStatus(userID, isOnline, fn)

  • userID {Number} - User ID to set status for
  • isOnline {Boolean} - Whether or not the user is online
  • fn {Function} - A callback function for when action is complete

isUserOnline(userID)

  • userID {Number} - User ID to set status for

  • fn {Function(isOnline)} - A callback function for when online status is retrieved

    • isOnline {Boolean} - Whether or not the user is online

setUserAvatarURL(userID, url, fn)

  • userID {Number} - User ID to set status for
  • url {String} - Full URL of the user's personal avatar
  • fn {Function} - A callback function for when action is complete

getUserAvatarURL(userID)

  • userID {Number} - User ID to get the personal avatar URL for

  • fn {Function(url)} - A callback function for when online status is retrieved

    • url {String} - Full URL of the user's personal avatar

Friends-Table Storage

addFriend(userID, friendID, fn)

  • userID {Number} - User ID to add a friend to
  • friendID {Number} - User ID of the friend to add
  • fn {Function} - A callback function for when action is complete

listFriends(userID, fn)

  • userID {Number} - User ID to look for friends

  • fn {Function(friendsList)} - A callback function for when friends list is retrieved

    • friendsList {Array} - Array of friend user IDs (each as simple {Numbers} entries)

removeFriend(userID, friendID, fn)

  • userID {Number} - User ID to remove a friend from
  • friendID {Number} - User ID of the friend to remove
  • fn {Function} - A callback function for when action is complete

Matches-Table Storage

addToMatch(userID, game, instance, fn)

Adds a user to a match, starting a new one if needed, and updating the game state flat-file in the process.

  • userID {Number} - User ID to add to a match

  • game {Number} - Game ID of the game this match is/will be

  • instance OPTIONAL {Number} - Instance number of match to join; if undefined it will create a new instance

  • fn {Function(isOnline)} - A callback function for when online status is retrieved

    • isOnline {Boolean} - Whether or not the user is online

listActiveMatches(userID, fn)

  • userID {Number} - User ID to search for active matches

  • fn {Function(instances)} - A callback function for when active matches are retrieved

    • instances {Array} - List of instance IDs of active matches for the user, each in the form of a {Number}

removeFromMatch(userID, instance, fn)

Removes a user from a match, updating game state flat-file in the process.

  • userID {Number} - User ID to remove from a match
  • instance {Number} - Specific match instance ID to remove the user from
  • fn {Function} - A callback function for when action is complete

Flat-File Storage

saveGameState(instance, gameBoard, fn)

  • instance {Number} - Instance ID of the match chatroom
  • gameBoard {Object} - Current gameboard state, in the format:
{
    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
}
  • fn {Function} - A callback function for when action is complete

loadGameState(instance, fn)

  • instance {Number} - Instance ID of the match chatroom

  • fn {Function(gameBoard)} - A callback function that is called once the gameboard state cache is retrieved

    • gameBoard {Object} - Cached gameboard state (see above)

saveChatLog(instance, chatData)

  • instance {Number} - Instance ID of the match chatroom
  • chatData {Array} - List of received message objects, in order, each in the format:
{
    userID:0, // {Number} - User ID who sent the message
    userName:"", // {String} - Displayable username for who is sent the message
    text:"", // {String} - Chat message text
    timestample:0 // {Number} - Numeric timestamp of the message
}

loadChatLogCache(instance, fn)

  • instance {Number} - Instance ID of the match chatroom

  • fn {Function(chatData)} - A callback function that is called once the chat log cache is retrieved

    • chatData {Array} - List of received message objects, in order (see above)

uploadAvatar(userID, avatarData, fn)

Removes any existing avatar file, and uploads the new one.

  • userID {Number} - User ID that owns the avatar

  • avatarData {Object} - Node.js file data object, parsed from HTTP request body

  • fn {Function(avatarURL)} - A callback function that is called once the chat log cache is retrieved

    • avatarURL {String} - The avatar URL for the user
⚠️ **GitHub.com Fallback** ⚠️