@@ -37,11 +37,14 @@ class RconInterface {
3737 */
3838 private checkIntervals : Map < string , NodeJS . Timeout > = new Map ( ) ;
3939
40+ public serverConnected : ( server : FactorioServer ) => void ;
41+
4042 constructor ( servers : FactorioServer [ ] ) {
4143 this . servers = servers ;
4244 this . rconConnections = [ ] ;
4345
4446 this . servers . map ( ( _ , i ) => this . initServer ( i ) ) ;
47+ this . serverConnected = ( ) => { } ;
4548 }
4649
4750 private async initServer ( serverIndex : number ) {
@@ -63,32 +66,33 @@ class RconInterface {
6366 server : server ,
6467 hasScenario : hasScenario ,
6568 } ) ;
69+ this . serverConnected ( server ) ;
6670
6771 // reconnection mechanism
6872 rcon . on ( "end" , ( ) => {
6973 this . reconnectRcon ( rcon , server ) ; // start the reconnection mechanism
70- if ( ! server . dev ) {
71- this . client . sendToErrorChannel (
72- `Server <#${
73- server . discordid
74- } > has dropped connection to RCON at <t:${ Math . floor (
75- Date . now ( ) / 1000
76- ) } >`
77- ) ;
78- }
74+ if ( ! server . dev ) {
75+ this . client . sendToErrorChannel (
76+ `Server <#${
77+ server . discordid
78+ } > has dropped connection to RCON at <t:${ Math . floor (
79+ Date . now ( ) / 1000
80+ ) } >`
81+ ) ;
82+ }
7983 } ) ;
8084 } catch ( error ) {
8185 // mechanism to reconnect to RCON after some time
8286 this . reconnectRcon ( rcon , server ) ; // start the reconnection mechanism
8387 if ( ! server . dev ) {
84- this . client . sendToErrorChannel (
85- `Server <#${
86- server . discordid
87- } > has failed to initially connect to RCON at <t:${ Math . floor (
88- Date . now ( ) / 1000
89- ) } >`
90- ) ;
91- }
88+ this . client . sendToErrorChannel (
89+ `Server <#${
90+ server . discordid
91+ } > has failed to initially connect to RCON at <t:${ Math . floor (
92+ Date . now ( ) / 1000
93+ ) } >`
94+ ) ;
95+ }
9296 }
9397 }
9498
@@ -121,6 +125,7 @@ class RconInterface {
121125 Date . now ( ) / 1000
122126 ) } >, after ${ dayjs ( startedAt ) . fromNow ( true ) } . Synchronizing banlist`
123127 ) ;
128+ this . serverConnected ( server ) ;
124129 return ;
125130 } catch {
126131 connectionAttempts ++ ;
@@ -129,14 +134,14 @@ class RconInterface {
129134 // dayjs is used to get the relative time since the start of the reconnection attempts
130135 if ( attempts . includes ( connectionAttempts ) ) {
131136 if ( ! server . dev ) {
132- this . client . sendToErrorChannel (
133- `Server <#${
134- server . discordid
135- } > has dropped connection to RCON at <t:${ Math . floor (
136- Date . now ( ) / 1000
137- ) } >`
138- ) ;
139- }
137+ this . client . sendToErrorChannel (
138+ `Server <#${
139+ server . discordid
140+ } > has dropped connection to RCON at <t:${ Math . floor (
141+ Date . now ( ) / 1000
142+ ) } >`
143+ ) ;
144+ }
140145 }
141146 }
142147 } ;
@@ -159,19 +164,19 @@ class RconInterface {
159164 s . server . name === serverIdentifier ||
160165 s . server . discordid === serverIdentifier
161166 ) ;
162- // if (serverIdentifier == "724696348871622818")
163- // console.log(server)
167+ // if (serverIdentifier == "724696348871622818")
168+ // console.log(server)
164169 if ( ! server )
165170 return {
166171 resp : false ,
167- identifier : serverIdentifier ,
172+ identifier : serverIdentifier ,
168173 } ;
169174 // eslint-disable-next-line @typescript-eslint/no-empty-function
170175 const response = await server . rcon . send ( command ) . catch ( ( ) => { } ) ;
171176 if ( ! response )
172177 return {
173178 resp : false ,
174- identifier : serverIdentifier ,
179+ identifier : serverIdentifier ,
175180 } ;
176181 return {
177182 resp : response ,
0 commit comments