Add server variable to the event handlers.
This commit is contained in:
parent
c5e1621366
commit
c0e9efcc9f
16 changed files with 44 additions and 44 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const ChancellorNomination = (socket: Socket, data: ChancellorNomination) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const ChancellorNomination = (io: Server, socket: Socket, data: ChancellorNomination) => {
|
||||
console.log(`ChancellorNomination event`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const ChancellorPolicy = (socket: Socket, data: ChancellorPolicy) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const ChancellorPolicy = (io: Server, socket: Socket, data: ChancellorPolicy) => {
|
||||
console.log(`Chancellor policy`);
|
||||
};
|
||||
|
|
@ -4,11 +4,11 @@ Get's the current player list for a game.
|
|||
Emissions:
|
||||
PlayerListResponse->sender - Sends the list of players to the client
|
||||
*/
|
||||
import { Socket } from 'socket.io';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { Game } from '../utils/Game';
|
||||
import { active_games } from '../main';
|
||||
|
||||
export const GetPlayerList = (socket: Socket, data: GetPlayerList) => {
|
||||
export const GetPlayerList = (io: Server, socket: Socket, data: GetPlayerList) => {
|
||||
try {
|
||||
if (!Object.keys(active_games).includes(data.game_code)) {
|
||||
socket.emit(`PlayerListResponse`, {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ Client Side: After the host receives the `HostInformation` event, the Query
|
|||
String parameters should be updated with the Websocket URI and the game code so
|
||||
that the host is able to just send that to the other players
|
||||
*/
|
||||
import { Socket } from 'socket.io';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { Game } from '../utils/Game';
|
||||
import { active_games, log } from '../main';
|
||||
import { generate_game_code } from '../utils/gamecode';
|
||||
|
||||
export const HostGame = (socket: Socket, data: HostGame) => {
|
||||
export const HostGame = (io: Server, socket: Socket, data: HostGame) => {
|
||||
try {
|
||||
|
||||
// Get a game code that is not in use to prevent join conflicts
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ Emissions:
|
|||
GameJoined->sender - Sent to the client to tell them the current list of
|
||||
players and that they were added to the game either successfully or not
|
||||
*/
|
||||
import { Socket } from 'socket.io';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { active_games, log } from '../main';
|
||||
export const JoinGame = (socket: Socket, data: JoinGame) => {
|
||||
export const JoinGame = (io: Server, socket: Socket, data: JoinGame) => {
|
||||
try {
|
||||
// Check if it's an active game
|
||||
if (!Object.keys(active_games).includes(data.game_code)) {
|
||||
|
|
@ -57,7 +57,7 @@ export const JoinGame = (socket: Socket, data: JoinGame) => {
|
|||
})
|
||||
|
||||
// Alert existing players about new player
|
||||
socket.broadcast.emit(`NewPlayer`, {
|
||||
socket.to(game.code).emit(`NewPlayer`, {
|
||||
game_code: data.game_code,
|
||||
player: data.username,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ Emissions:
|
|||
name to be itself, it kicks the player back to he main page. Otherwise
|
||||
it just removes the player from the display list.
|
||||
*/
|
||||
import { Socket } from 'socket.io';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { active_games, log } from '../main';
|
||||
export const KickPlayer = (socket: Socket, data: KickPlayer) => {
|
||||
export const KickPlayer = (io: Server, socket: Socket, data: KickPlayer) => {
|
||||
try {
|
||||
// Check if it's an active game
|
||||
if (!Object.keys(active_games).includes(data.game_code)) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Emissions:
|
|||
ChancellorChoice - This emits to everyone, but only the active chancellor's
|
||||
client should do anything.
|
||||
*/
|
||||
import { Socket } from 'socket.io';
|
||||
export const PresidentPolicies = (socket: Socket, data: PresidentPolicies) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const PresidentPolicies = (io: Server, socket: Socket, data: PresidentPolicies) => {
|
||||
console.log(`Received Presidential policies`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const StartGame = (socket: Socket, data: StartGame) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const StartGame = (io: Server, socket: Socket, data: StartGame) => {
|
||||
console.log(`Game starting`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const VetoConfirm = (socket: Socket, data: VetoConfirm) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const VetoConfirm = (io: Server, socket: Socket, data: VetoConfirm) => {
|
||||
console.log(`President's veto confirmation`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const VetoRequest = (socket: Socket, data: VetoRequest) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const VetoRequest = (io: Server, socket: Socket, data: VetoRequest) => {
|
||||
console.log(`Chancellor requesting veto`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const Vote = (socket: Socket, data: Vote) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const Vote = (io: Server, socket: Socket, data: Vote) => {
|
||||
console.log(`Vote received`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const ExecutePlayer = (socket: Socket, data: ExecutePlayer) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const ExecutePlayer = (io: Server, socket: Socket, data: ExecutePlayer) => {
|
||||
console.log(`Killing a player`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const ExecutiveConfirmation = (socket: Socket, data: ExecutiveConfirmation) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const ExecutiveConfirmation = (io: Server, socket: Socket, data: ExecutiveConfirmation) => {
|
||||
console.log(`Just a plain ole confirmation`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const InvestigateAffiliation = (socket: Socket, data: InvestigateAffiliation) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const InvestigateAffiliation = (io: Server, socket: Socket, data: InvestigateAffiliation) => {
|
||||
console.log(`Investigating a player`);
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { Socket } from 'socket.io';
|
||||
export const NextPresident = (socket: Socket, data: NextPresident) => {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
export const NextPresident = (io: Server, socket: Socket, data: NextPresident) => {
|
||||
console.log(`Choosing the Next President`);
|
||||
};
|
||||
26
src/main.ts
26
src/main.ts
|
|
@ -55,32 +55,32 @@ io.on(`connection`, (socket: sio.Socket) => {
|
|||
log.silly(`Client connected with id ${socket.id}`);
|
||||
|
||||
// Game Management
|
||||
socket.on(`HostGame`, (data: HostGame) => HostGame(socket, data));
|
||||
socket.on(`JoinGame`, (data: JoinGame) => JoinGame(socket, data));
|
||||
socket.on(`HostGame`, (data: HostGame) => HostGame(io, socket, data));
|
||||
socket.on(`JoinGame`, (data: JoinGame) => JoinGame(io, socket, data));
|
||||
|
||||
|
||||
// Join a game
|
||||
socket.on(`StartGame`, (data: any) => StartGame(socket, data));
|
||||
socket.on(`StartGame`, (data: any) => StartGame(io, socket, data));
|
||||
|
||||
// Chancellor Nominations
|
||||
socket.on(`ChancellorNomination`, (data: any) => ChancellorNomination(socket, data));
|
||||
socket.on(`ChancellorNomination`, (data: any) => ChancellorNomination(io, socket, data));
|
||||
socket.on(`Vote`, Vote);
|
||||
|
||||
// Policy Receiving
|
||||
socket.on(`PresidentPolicies`, (data: any) => PresidentPolicies(socket, data));
|
||||
socket.on(`ChancellorPolicy`, (data: any) => ChancellorPolicy(socket, data));
|
||||
socket.on(`VetoRequest`, (data: any) => VetoRequest(socket, data));
|
||||
socket.on(`VetoConfirm`, (data: any) => VetoConfirm(socket, data));
|
||||
socket.on(`PresidentPolicies`, (data: any) => PresidentPolicies(io, socket, data));
|
||||
socket.on(`ChancellorPolicy`, (data: any) => ChancellorPolicy(io, socket, data));
|
||||
socket.on(`VetoRequest`, (data: any) => VetoRequest(io, socket, data));
|
||||
socket.on(`VetoConfirm`, (data: any) => VetoConfirm(io, socket, data));
|
||||
|
||||
// Special Actions
|
||||
socket.on(`ExecutePlayer`, (data: any) => ExecutePlayer(socket, data));
|
||||
socket.on(`NextPresident`, (data: any) => NextPresident(socket, data));
|
||||
socket.on(`ExecutiveConfirmation`, (data: any) => ExecutiveConfirmation(socket, data));
|
||||
socket.on(`InvestigateAffiliation`, (data: any) => InvestigateAffiliation(socket, data));
|
||||
socket.on(`ExecutePlayer`, (data: any) => ExecutePlayer(io, socket, data));
|
||||
socket.on(`NextPresident`, (data: any) => NextPresident(io, socket, data));
|
||||
socket.on(`ExecutiveConfirmation`, (data: any) => ExecutiveConfirmation(io, socket, data));
|
||||
socket.on(`InvestigateAffiliation`, (data: any) => InvestigateAffiliation(io, socket, data));
|
||||
|
||||
|
||||
// Utility Events
|
||||
socket.on(`GetPlayerList`, (data: GetPlayerList) => GetPlayerList(socket, data));
|
||||
socket.on(`GetPlayerList`, (data: GetPlayerList) => GetPlayerList(io, socket, data));
|
||||
});
|
||||
|
||||
io.on(`reconnect_attempt`, (socket: sio.Socket) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue