Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Latest commit

 

History

History
232 lines (158 loc) · 4.32 KB

README.md

File metadata and controls

232 lines (158 loc) · 4.32 KB

trashbot server

API

HTTP

Ping

Send GET /ping to check if the server is online. The server will return 200 and "pong" if working.

Socket.io

If the server encountered a problem while evaluating your message it will send an error to me/error. These messages will be of the form:

{ event: string, errorCode: number }

where event is the name of the event that you sent the server and errorCodeis an integer indicating what went wrong. Codes 0 - 9 are reserved for universal errors, while codes 10 and up are related to the specific message you sent.

UNIVERSAL ERROR CODES:

  • 0 = Room does not exist
  • 1 = Player does not exist
  • 2 = Player does not have permission for this action
  • 3 = Player does not have access to the room
  • 4 = The message was missing some important property
  • 5 = Item does not exist

Host

A player may open a new room on the server by sending it their name. The server will create a room with the player as its host. It will then send back the id of this room as well as the player's unique id. This id will be used to authenticate the player in future exchanges.

Client -> Server server/host

{ playerName: string }

OK: Server -> Client me/host

{ playerId: number, roomId: number }

ERRORS:

  • 10 = Bad player name

Join

A player may join an existing room. For this they need to have a name and the id of the room they want to join. The server will attempt to add the player to the given room. If successful it will send back the unique id of the joined player.

Client -> Server server/join

{ playerName: string, roomId: number }

OK: Server -> Client me/join

{ playerId: number }

ERRORS:

  • 10 = Bad name
  • 11 = Duplicate name

Lobby changed

Sent to the client if the lobby changes.

Server -> Client lobby/changed

{ playerId: number, action: "JOINED" | "LEFT" }

Players in lobby

Send this to the server to get all the players which are currently in the lobby.

Client -> Server lobby/players

{ playerId: number, roomId: number }

Server -> Client lobby/players

{ players: { id: number, name: string }[] }

Lobby ready

Sent from host to server to indicate that all players have joined and the room is now ready to choose a rule-set. The server will send a message to all players in the room, notifying them of this event, so that they can transition to the game. It will also send them the duration of the game in minutes.

Client -> Server lobby/ready

{ playerId: number; roomId: number, location: {lat: number, lng: number} }

Server -> Client game/start

{ minutes: number, gameCenter: {lat: number, lng: number} }

Send player location

Send the player's location to the server, so it can store it. The server will respond with all items the player is in range to pick-up

Client -> Server game/location

{ playerId: number, roomId: number, location: {lat: number, lng: number}}

Server -> Client me/items-in-range

{
    id: number,
    type: number
    stats: Object
}[]

Pick up item

Send the id of an item to the server to pick it up.

Client -> Server game/pick-up-item

{ playerId: number, roomId: number, itemId: number }

If successful the server will not answer.

ERRORS

  • 10 = You are not in range to pick up this item

Get actors

Get all actors around the player. Server responds with array of players and items.

Client -> Server game/get-actors

{
    playerId: number, 
    roomId: number
}

Server -> Client me/actors

{
    players: [
        {
            id: number,
            location: {lat: number, lng: number}
        }
    ],
    items: [
        {
            id: number,
            location: {lat: number, lng: number}
        }
    ]
}

Get specific robot info

Get the current robot for a player.

Client -> Server game/robot

{ playerId: number, roomId: number }

Server -> Client me/robot

Get all robots info

Get the info of all robots.

Client -> Server game/robots

{ roomId: number }

Server -> Client game/robots

{ robot: Object }

Game end

The server keeps track of the game time. Once it is over, it will send this message to all players to indicate to move to the results page.

Server -> Clients game/done

{}