Class: HGWeb

HGWeb

Creates a web interface for managing the Hungry Games. Expects ../hungryGames.js is loaded or will be loaded.

new HGWeb()

Source:

Members


<private, inner, constant> imageBuffer :object

Buffer storing all current image uploads and their associated meta-data.
Type:
  • object
Source:

<private, inner, constant> siblingSockets :object.<Socket>

Map of all sockets connected that are siblings.
Type:
  • object.<Socket>
Source:

<private, inner, constant> sockets :object.<Socket>

Map of all currently connected sockets.
Type:
  • object.<Socket>
Source:

Methods


createEvent(userData, socket, gId, type, message, nV, nA, oV, oA, kV, kA, wV, wA [, cb])

Create a game event.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
type string The type of event.
message string The message of the event.
nV string Number of victims.
nA string Number of attackers.
oV string Outcome of victims.
oA string Outcome of attackers.
kV string Do the victims kill.
kA string Do the attackers kill.
wV object <nullable>
The weapon information for this event.
wA object <nullable>
The weapon information for this event.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.createEvent

createGame(userData, socket, gId [, cb])

Create a Game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.createGame

createMajorEvent(userData, socket, gId, type, data, name [, cb])

Create a larger game event. Either Arena or Weapon at this point. If message or weapon name already exists, this will instead edit the event.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
type string The type of event.
data HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data.
name string <nullable>
The name of the weapon if this is a weapon event.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.addMajorEvent

createStatGroup(userData, socket, guildId, name [, cb])

Create a stat group.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId string The guild id to look at.
name string <nullable>
The name of the new group.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

deleteStatGroup(userData, socket, guildId, groupId [, cb])

Delete a stat group.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId string The guild id to look at.
groupId string The group id to delete.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

editMajorEvent(userData, socket, gId, type, search, data, name, newName [, cb])

Delete a larger game event. Either Arena or Weapon at this point.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
type string The type of event.
search HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data to find to edit.
data HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data to set the matched searches to.
name string <nullable>
The internal name of the weapon to find.
newName string <nullable>
The new internal name of the weapon.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.editMajorEvent

editTeam(userData, socket, gId, cmd, one, two [, cb])

Edit the teams.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cmd string The command to run.
one string The first argument.
two string The second argument.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.editTeam

endGame(userData, socket, gId [, cb])

End the game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.endGame

excludeMember(userData, socket, gId, mId [, cb])

Exclude a member from the Games.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
mId number | string The member id to exclude.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.excludeUsers

fetchChannel(userData, socket, gId, cId [, cb])

Fetch data about a channel of a guild.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cId number | string The channel's id to lookup.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchDay(userData, socket, gId [, cb])

Fetch the updated game's day information.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.getGame

fetchGames(userData, socket, gId [, cb])

Fetch all game data within a guild.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.getGame

fetchGuild(userData, socket, gId [, cb])

Fetch a single guild.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId string | number The ID of the guild that was requested.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchLeaderboard(userData, socket, guildId, groupId, opt [, cb])

Respond with leaderboard information.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId number | string The guild id to look at.
groupId string The ID of the group.
opt HGStatGroupUserSelectOptions Data select options.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchMember(userData, socket, gId, mId [, cb])

Fetch data about a member of a guild.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
mId number | string The member's id to lookup.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchNextDay(userData, socket, gId [, cb])

Fetch the game's next day information.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.getGame

fetchStatGroupList(userData, socket, gId [, cb])

Respond with list of stat groups for the requested guild.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchStatGroupMetadata(userData, socket, guildId, groupId [, cb])

Respond with metadata for the requested stat group.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId number | string The guild id to look at.
groupId string The ID of the group.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

fetchStats(userData, socket, guildId, groupId, userId [, cb])

Respond with stats for a specific user in a group.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId number | string The guild id to look at.
groupId string The ID of the group.
userId string The ID of the user.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

forcePlayerState(userData, socket, gId, list, state [, text] [, persists] [, cb])

Force a player in the game to end a day in a certain state.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo-Socket The socket connection to reply on.
gId number | string The guild id to run this command on.
list Array.<string> The list of user IDs of the players to effect.
state string The forced state.
text string <optional>
The message to show in the games as a result of this command.
persists boolean <optional>
Will this state be forced until the game ends.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete.
Source:
See:
  • HungryGames.forcePlayerState

getNumClients()

Returns the number of connected clients that are not siblings.
Source:
Returns:
Number of sockets.
Type
number

imageChunk(userData, socket, gId, iId, chunkId, chunk [, cb])

Handle receiving image data for avatar uploading.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
iId string The image ID that is being uploaded.
chunkId string Id of the chunk being received.
chunk Buffer <nullable>
Chunk of data received, or null if all data has been sent.
cb function <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

imageInfo(userData, socket, gId, meta [, cb])

Handle client requesting to begin image upload.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
meta object Metadata to associate with this upload.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed. If succeeded, an upload ID will be passed as the second parameter. Any error will be the first parameter.
Source:

includeMember(userData, socket, gId, mId [, cb])

Include a member in the Games.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
mId number | string The member id to include.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.includeUsers

initialize()

Source:

modifyInventory(userData, socket, gId, uId, weapon, count [, cb])

Give or take weapons from a player.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
uId string The ID of the user to give or take weapon from.
weapon string The ID of the weapon to give or take.
count number Number of weapons to give or take. Positive is give, negative is take.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

nextDay(userData, socket, gId, cId [, cb])

Start the next day.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cId number | string Channel to send the messages in.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.nextDay

pauseAutoplay(userData, socket, gId [, cb])

Disable autoplay.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.pauseAutoplay

pauseGame(userData, socket, gId [, cb])

Pause game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.pauseGame

removeEvent(userData, socket, gId, type, event [, cb])

Remove a game event.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
type string The type of event.
event HungryGames~Event The game event to remove.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.removeEvent

removeNPC(userData, socket, gId, npcId [, cb])

Remove an NPC from a game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo-Socket The socket connection to reply on.
gId number | string The guild id to run this command on.
npcId string The ID of the NPC to remove.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete.
Source:
See:
  • HungryGames.removeNPC

renameGame(userData, socket, gId, name [, cb])

Rename the guild's game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo-Socket The socket connection to reply on.
gId number | string The guild id to run this command on.
name string The name to change the game to.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete.
Source:
See:
  • HungryGames.renameGame

resetGame(userData, socket, gId, cmd [, cb])

Reset game data.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cmd string Command specifying what data to delete.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.resetGame

selectStatGroup(userData, socket, guildId, groupId [, cb])

Set the currently selected stat group.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
guildId string The guild id to look at.
groupId string <nullable>
The ID of the group to select, or null to set none.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

shutdown()

Causes a full shutdown of all servers.
Source:

startAutoplay(userData, socket, gId, cId [, cb])

Enable autoplay.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cId number | string Channel to send the messages in.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.startAutoplay

startGame(userData, socket, gId, cId [, cb])

Start the game.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
cId number | string Channel to start the game in.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.startGame

toggleEvent(userData, socket, gId, type, subCat, event, value [, cb])

Enable or disable an event without deleting it.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo-Socket The socket connection to reply on.
gId number | string The guild id to run this command on.
type string The type of event that we are toggling.
subCat string <nullable>
The subcategory if necessary.
event HungryGames~Event | HungryGames~ArenaEvent | HungryGames~WeaponEvent The event to toggle.
value boolean <nullable>
Set the enabled value instead of toggling.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete.
Source:
See:
  • HungryGames.toggleEvent

toggleOption(userData, socket, gId, option, value, extra [, cb])

Toggle an option in the Games.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
gId number | string The guild id to look at.
option string The option to change.
value string | number The value to set option to.
extra string The extra text if the option is in an object.
cb HGWeb~basicCB <optional>
Callback that fires once the requested action is complete, or has failed.
Source:
See:
  • HungryGames.setOption

<private, inner> beginImageUpload(uId)

Create an upload ID and buffer for a client to send to. Automatically cancelled after 60 seconds.
Parameters:
Name Type Description
uId string The user ID that started this upload.
Source:
Returns:
The metadata storing object.
Type
object

<private, inner> broadcastGame(hg, gId)

Handles broadcasting the game data to all relevant clients.
Parameters:
Name Type Description
hg HungryGames HG object firing event.
gId string The guild ID to data for.
Source:
Listens to Events:
  • HG#event:create
  • HG#event:refresh

<private, inner> cancelImageUpload(iId)

Cancel and clean up a current image upload.
Parameters:
Name Type Description
iId string Image upload ID to purge and abort.
Source:

<private, inner> checkChannelPerm(userData, gId, cId, cmd)

Check that the given user has permission to see and send messages in the given channel, as well as manage the games in the given guild.
Parameters:
Name Type Description
userData UserData The user to check.
gId string The guild id of the guild that contains the channel.
cId string The channel id to check against.
cmd string The command being attempted to check permisisons for.
Source:
Returns:
Whther the user has permission or not to manage the hungry games in the given guild and has permission to send messages in the given channel.
Type
boolean

<private, inner> checkMyGuild(gId)

Checks if the current shard is responsible for the requested guild.
Parameters:
Name Type Description
gId number | string The guild id to check.
Source:
Returns:
True if this shard has this guild.
Type
boolean

<private, inner> checkPerm(userData, gId, cId, cmd)

Check that the given user has permission to manage the games in the given guild.
Parameters:
Name Type Argument Description
userData UserData The user to check.
gId string The guild id to check against.
cId string <nullable>
The channel id to check against.
cmd string The command being attempted.
Source:
Returns:
Whther the user has permission or not to manage the hungry games in the given guild.
Type
boolean

<private, inner> clientSocketConnection(socket)

Handler for connecting as a client to the server.
Parameters:
Name Type Description
socket socketIo~Socket The socket.io socket that connected.
Source:

<private, inner> dayStateChange(hg, gId)

This gets fired whenever the day state of any game changes in the hungry games. This then notifies all clients that the state changed, if they care about the guild.
Parameters:
Name Type Description
hg HungryGames HG object firing the event.
gId string Guild id of the state change.
Source:
Listens to Events:
  • HG#event:dayStateChange

<private, inner> fetchGuilds(userData, socket [, cb])

Fetch all relevant data for all mutual guilds with the user and send it to the user.
Parameters:
Name Type Argument Description
userData object The current user's session data.
socket socketIo~Socket The socket connection to reply on.
cb function <optional>
Callback that fires once the requested action is complete, or has failed.
Source:

<private, inner> guildBroadcast(gId, event, args)

Broadcast a message to all relevant clients.
Parameters:
Name Type Argument Description
gId string Guild ID to broadcast message for.
event string The name of the event to broadcast.
args * <repeatable>
Data to send in broadcast.
Source:

<private, inner> handleOptionChange(hg, gId, opt1, opt2 [, opt3])

Handles an option being changed and broadcasting the update to clients.
Parameters:
Name Type Argument Description
hg HungryGames HG object firing the event.
gId string Guild ID of the option change.
opt1 string Option key.
opt2 string Option second key or value.
opt3 string <optional>
Option value if object option.
Source:
Listens to Events:
  • HG#event:toggleOption

<private, inner> handler(req, res)

Handler for all http requests. Should never be called.
Parameters:
Name Type Description
req http.IncomingMessage The client's request.
res http.ServerResponse Our response to the client.
Source:

<private, inner> hg()

Update the reference to HungryGames.
Source:
Returns:
Reference to the currently loaded HungryGames subModule.
Type
HG

<private, inner> makeMember(m)

Strips a Discord~GuildMember to only the necessary data that a client will need.
Parameters:
Name Type Description
m Discord~GuildMember The guild member to strip the data from.
Source:
Returns:
The minimal member.
Type
object

<private, inner> makeMessage(uId, gId, cId, msg)

Forms a Discord~Message similar object from given IDs.
Parameters:
Name Type Argument Description
uId string The id of the user who wrote this message.
gId string The id of the guild this message is in.
cId string <nullable>
The id of the channel this message was 'sent' in.
msg string <nullable>
The message content.
Source:
Returns:
The created message-like object.
Type
Object

<private, inner> replyNoPerm(socket, cmd)

Send a message to the given socket informing the client that the command they attempted failed due to insufficient permission.
Parameters:
Name Type Description
socket Socket The socket.io socket to reply on.
cmd string THe command the client attempted.
Source:

<private, inner> socketConnection(socket)

Handler for a new socket connecting.
Parameters:
Name Type Description
socket socketIo~Socket The socket.io socket that connected.
Source:

<private, inner> startClient()

Start a socketio client connection to the primary running server.
Source:

<private, inner> stripGuilds(guilds, userData)

Strip a Discord~Guild to the basic information the client will need.
Parameters:
Name Type Description
guilds Array.<Discord~Guild> The array of guilds to strip.
userData object The current user's session data.
Source:
Returns:
The stripped guilds.
Type
Array.<object>

<private, inner> unlinkHG()

Unregister all event handlers from `hg_`.
Source:

Type Definitions


basicCB(err, res)

Basic callback with single argument. The argument is null if there is no error, or a string if there was an error.
Parameters:
Name Type Argument Description
err string <nullable>
The error response.
res * Response data if no error.
Source:

SocketFunction(userData, socket, args [, cb])

Function calls handlers for requested commands.
Parameters:
Name Type Argument Description
userData WebUserData The user data of the user performing the request.
socket socketIo~Socket The socket connection firing the command. Not necessarily the socket that will reply to the end client.
args * <repeatable>
Additional function-specific arguments.
cb HGWeb~basicCB <optional>
Callback that fires once requested action is complete or has failed. Client may not pass a callback.
Source: