game runner - Paaspop/Paaspop-Server GitHub Wiki

Game runner

The game runner is a component that launches all games and communicates with the other components of the system through WebSockets.

General rules of using the game runner

  • Your game will have to contain its own player list and send the results itself
  • Your game will start immediately when your game file is loaded. Usually, a join screen or wait screen will occur before the actual game starts, to give players some time to join. You will have to indicate the actual start of the game by calling the next round function (specified below). This will make sure everything behaves correctly.
  • You will not have to write any socket connections yourself. If there is something missing in the game runner please contact the game runner's developers for advice.

API Routes

There are several functions games can call to communicate with other parts of the system, ie the admin panel or the mobile client.

Name Route Description
Next Round nextRound(buttons) Start the next round with the buttons that round uses
Send user buttons sendUserButtons(buttons, userNickname) Send buttons to a specific user nickname
Send Answer sendAnswer(answer) Sends the correct answer to the mobile client
Set Live Header setLiveHeader(header, [userNickname]) Send a live header to all, or to a certain user if specified
Set screen setScreen(screen) Set the current screen for all clients connected
Set status setStatus(status, userNickname = null) Set the status for everyone, or optional for a specific user
Clear Live Header clearLiveHeader([userNickname]) Clears the live header from all, or from a certain user if specified
Set Live Footer setLiveFooter(footer, [userNickname]) Send a live footer to all, or to a certain user if specified
Clear Live Footer clearLiveFooter([userNickname]) Clears the live footer from all, or from a certain user if specified
Set Action setAction(action) Set the action a clients receives after pressing a button. Refer to 'clientapp'
Stop Game stopGame() Indicate ending of game
Switch Screen switchScreen(screen) Switch client screen. Refer to 'clientapp'
Load In Transition loadInTransition() Load the closing transition
Load Out Transition loadOutTransition() Unload the closing transition
Enable Footer enableFooter() Enable game runner footer
Disable Footer disableFooter() Disable game runner footer
Send points sendPoints(points) Send user won points in array (Points = array with JSON data [{'user_id':id, 'points':points}])

Events

There are also several functions the game runner can call, that games will have to listen to. These functions usually contain information sent from the admin panel or the mobile client.

Your game will have to specify these functions in its own code, for the game runner to call. Will throw an exception if not specified.

Name Route Description
user Joined gameUserJoined(user, userId) User has joined a game
User Input gameUserInput(user, userId, data) User has pressed a button and joins the game
Force Stop gameForceStop() Game was forced to stop

Extra functions for debug

There are several functions that will help you integrate your game into the game runner.

Name Route Description
Load Game loadGame(game) Force load a game into the game runner
Unload Game unloadGame() Force unload game from the game runner
WS Connect connect() Manually reconnect the game runner to WebSocket
WS Close closeConnection() Manually disconnect the game runner from WebSocket
WS Send data wsSendData() Send custom data to WebSocket. Make sure it is a JSON object. Only use it if you know what you're doing!