Add code to handle socket connections and listen for events
This commit is contained in:
parent
44782f3e85
commit
6b1e95e800
1 changed files with 58 additions and 0 deletions
58
src/main.ts
58
src/main.ts
|
|
@ -0,0 +1,58 @@
|
||||||
|
import * as sio from "socket.io";
|
||||||
|
import { Vote } from "./events/Vote";
|
||||||
|
import { JoinGame } from "./events/JoinGame";
|
||||||
|
import { HostGame } from "./events/HostGame";
|
||||||
|
import { StartGame } from "./events/StartGame";
|
||||||
|
import { VetoConfirm } from "./events/VetoConfirm";
|
||||||
|
import { VetoRequest } from "./events/VetoRequest";
|
||||||
|
import { ChancellorPolicy } from "./events/ChancellorPolicy";
|
||||||
|
import { PresidentPolicies } from "./events/PresidentPolicies";
|
||||||
|
import { ChancellorNomination } from "./events/ChancellorNomination";
|
||||||
|
import { ExecutePlayer } from "./events/special/Execution/ExecutePlayer";
|
||||||
|
import { NextPresident } from "./events/special/SpecialElection/NextPresident";
|
||||||
|
import { ExecutiveConfirmation } from "./events/special/ExecutiveConfirmation";
|
||||||
|
import { InvestigateAffiliation } from "./events/special/InvestigateLoyalty/InvestigateAffiliation";
|
||||||
|
import { GetPlayerList } from "./events/GetPlayerList";
|
||||||
|
|
||||||
|
|
||||||
|
const io = sio.listen(3000);
|
||||||
|
|
||||||
|
io.on(`connection`, (socket: sio.Socket) => {
|
||||||
|
console.log(`Client connected`);
|
||||||
|
|
||||||
|
// Game Management
|
||||||
|
socket.on(`HostGame`, (data: HostGame) => HostGame(socket, data));
|
||||||
|
socket.on(`JoinGame`, (data: JoinGame) => JoinGame(socket, data));
|
||||||
|
|
||||||
|
|
||||||
|
// Join a game
|
||||||
|
socket.on(`StartGame`, (data: any) => StartGame(socket, data));
|
||||||
|
|
||||||
|
// Chancellor Nominations
|
||||||
|
socket.on(`ChancellorNomination`, (data: any) => ChancellorNomination(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));
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
|
||||||
|
// Utility Events
|
||||||
|
socket.on(`GetPlayerList`, (data: GetPlayerList) => GetPlayerList(socket, data));
|
||||||
|
});
|
||||||
|
|
||||||
|
io.on(`reconnect_attempt`, (socket: sio.Socket) => {
|
||||||
|
console.log(`Client attempting to reconnect`)
|
||||||
|
});
|
||||||
|
|
||||||
|
io.on(`disconnect`, (socket: sio.Socket) => {
|
||||||
|
console.log(`Client disconnected`)
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue