UNPKG

gameguard

Version:

GameGuard is a NodeJS game server that can be used to manage the players connecting to your game, manage rooms and the players in them, and more.

114 lines (71 loc) 4.13 kB
# **Room** At it's core, GameGuard works around watching for clients trying to connect to the server and turning those clients into players. Once connected, players can be interacted with in forms of messaging, kicking, banning, or placing in rooms. ## **Table of Contents** - [Signals](#signals) - [Properties](#properties) - [API](#api) ## **Signals** ### **roomCreated** The `roomCreated` signal is dispatched from the base GameGuard object when a room is created. This signal includes the Room object of the room that was created. ```js gameguard.roomCreated.add(room => console.log(`Room ${room.name} created.`)); ``` ### **roomDestroyed** The `roomDestroyed` signal is dispatched from the GameGuard object when a room is destroyed. This signal includes the Room object of the room that was destroyed. ```js gameguard.roomDestroyed.add(room => console.log(`Room ${room.name} destroyed.`)); ``` ## **Properties** ### **name** The name of the room. ### **capacity** The number of players that can be in the room at any point. ### **players** A list of the players currently in the room. ### **playerCount** The number of players currently in the room. ## **API** ### **capacity** Sets a new capacity for the room. If the new capacity is lower than the current number of players in the room, the capacity will not be changed. | param | type | description | default | |---------- |-------- |------------------------------------------------------------------------------ |--------- | | newCapacity | number | The new capacity for the room. | | ```js const waitingRoom = gameguard.createRoom('Waiting Room', 5); waitingRoom.capacity = 10; ``` ### **addPlayer** Adds a player to the room if the room is not at full capacity. If the room is at full capacity then a warning will be logged and the player will not be added. | param | type | description | default | |-------- |-------- |---------------------------------------------------------------------------------------------------------------------------------------------------- |--------- | | player | Player | The Player to add to the room. | | ```js const waitingRoom = gameguard.createRoom('Waiting Room'); gameguard.playerConnected.add(player => waitingRoom.addPlayer(player)); ``` ### **removePlayer** Removes a player from the room. | param | type | description | default | |-------- |-------- |---------------------------------------------------------------------------------------------------------------------------------------------------- |--------- | | player | Player | The Player to remove from the room. | | ```js const waitingRoom = gameguard.createRoom('Waiting Room'); gameguard.playerConnected.add(player => waitingRoom.addPlayer(player)); gameguard.playerDisconnected.add(player => waitingRoom.removePlayer(player)); ``` ### **clear** Removes all players from the room. ```js const waitingRoom = gameguard.createRoom('Waiting Room'); waitingRoom.clear(); ``` ### **broadcast** Sends a message to all of the players in the room. | param | type | description | default | |--------- |-------- |------------------------------------------------------------------------------ |--------- | | type | string | The type of message this is. This helps you decipher messages on the client. | | | contents | string | The contents of the message to send to the players. | | ```js const waitingRoom = gameguard.createRoom('Waiting Room'); waitingRoom.broadcast('alert', 'the game is starting soon'); ```