11import EventEmitter from "events"
22import { Events , Messages , Socket } from "./Socket.js"
33import { Console } from "./Console.js"
4+ import { Game } from "./Game.js"
45import { Players } from "./Players.js"
56
67/**
@@ -11,7 +12,6 @@ import { Players } from "./Players.js"
1112 * @property {object } socket - An instance of the `Socket` class used for interacting with the WebSocket. Will be null if not yet connected.
1213 * @property {object } console - Instance of the `Console` object for this server.
1314 * @property {object } players - Instance of the `Players` object for this server.
14- *
1515 * @property {string } currentMap - Name of the current map. Keep in mind that this is a generic response from the engine and not the game itself.
1616 * @property {bool } isDedicated - Whether the server is a dedicated server or not.
1717 * @property {sring } authID - The SteamID of the server.
@@ -35,6 +35,7 @@ export class Server extends EventEmitter {
3535 this . socket = null
3636 this . console = new Console ( this )
3737 this . players = new Players ( this )
38+ this . game = null
3839
3940 this . currentMap = ""
4041 this . nextMap = ""
@@ -55,14 +56,8 @@ export class Server extends EventEmitter {
5556 */
5657 async connect ( ) {
5758 await new Socket ( this , this . host )
58- . then ( ( socket ) => {
59+ . then ( async ( socket ) => {
5960 this . socket = socket
60- /**
61- * Fired when the connection to the server has been established.
62- *
63- * @event Server#ready
64- */
65- this . emit ( "ready" , true )
6661
6762 this . socket . on ( Events . ServerUpdate , ( data ) => {
6863 var msg = data . message
@@ -85,6 +80,27 @@ export class Server extends EventEmitter {
8580 data . message . value
8681 )
8782 } )
83+
84+ await this . fetch ( )
85+
86+ switch ( this . gameDescription ) {
87+ case "Team Fortress" :
88+ await import ( "../games/TeamFortress2.js" ) . then ( module => {
89+ this . game = new module . TeamFortress2 ( )
90+ this . game . serverModifier ( this )
91+ } )
92+ break
93+ default :
94+ this . game = new Game ( )
95+ this . game . serverModifier ( this )
96+ }
97+
98+ /**
99+ * Fired when the connection to the server has been established.
100+ *
101+ * @event Server#ready
102+ */
103+ this . emit ( "ready" , true )
88104 } )
89105 . catch ( err => { throw err } )
90106 }
0 commit comments