-
Notifications
You must be signed in to change notification settings - Fork 1
/
EmpyrionServerUpdateUtilityBeta.au3
9964 lines (9834 loc) · 546 KB
/
EmpyrionServerUpdateUtilityBeta.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Resources\phoenixtray.ico
#AutoIt3Wrapper_Outfile=Builds\EmpyrionServerUpdateUtility_v1.0.7.exe
#AutoIt3Wrapper_Res_Comment=By Phoenix125 based on Dateranoth's ConanServerUtility v3.3.0-Beta.3
#AutoIt3Wrapper_Res_Description=Empyrion Dedicated Server Update Utility
#AutoIt3Wrapper_Res_Fileversion=1.0.7
#AutoIt3Wrapper_Res_ProductName=EmpyrionServerUpdateUtility
#AutoIt3Wrapper_Res_ProductVersion=1.0.7
#AutoIt3Wrapper_Res_CompanyName=http://www.Phoenix125.com
#AutoIt3Wrapper_Res_LegalCopyright=http://www.Phoenix125.com
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_Icon_Add=Resources\phoenixfaded.ico
#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/mo
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <Array.au3>
#include <AutoItConstants.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiConstants.au3>
#include <IE.au3>
#include <Inet.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <Process.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <TabConstants.au3>
#include <TrayConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", $GUI_DOCKLEFT + $GUI_DOCKTOP)
; *** End added by AutoIt3Wrapper ***
$aUtilVerStable = "v1.0.7" ; (2023-07-14)
$aUtilVerBeta = "v1.0.7" ; (2023-07-14)
$aUtilVersion = $aUtilVerStable
Global $aUtilVerNumber = 2
; 0 = v1.0.0/1/2/3/4/5
; 1 = v1.0.6
; 2 = v1.0.7
;**** Directives created by AutoIt3Wrapper_GUI ****
;Originally written by Dateranoth for use and modified for Empyrion by Phoenix125.com
;by https://gamercide.com on their server
;Distributed Under GNU GENERAL PUBLIC LICENSE
; ----- CUSTOM VARIABLES ----
Global Const $aServerEXE = "EmpyrionLauncher.exe"
Global $aLaunchParams = "-startDedi -dedicated"
Global $aServerProcessName = "EmpyrionDedicated.exe"
Global Const $aSteamAppID = "530870"
Global $aGameName = "Empyrion"
Global $aGameCreators = "Eleon"
Global $aTelnetShutdown = "saveandexit 0"
Global $aTelnetKeepAliveCMD = "stats"
Global $aTelnetKeepAliveReponse = "GameName"
Global $aTelnetSayCMD = "say"
Global $aTelnetSayQuoteOrApostrophe = "apostrophe" ; "quote" or "apostrophe"
Global $aTelnetPlayersCMD = "plys"
Global $aTelnetWrongPasswordReponse = "Wrong password"
Global $aEAH_Name = "Empyrion Admin Helper"
Global $aEAH_PID = 0
Global $aEAH_Exe = "EmpAdminHelper.exe"
; ----- UNIVERSAL VARIABLES -----
Global $aServerName = $aGameName
Global Const $aUtilName = $aGameName & "ServerUpdateUtility"
Global Const $aServerShort = $aGameName
Global Const $aIniFile = @ScriptDir & "\" & $aUtilName & ".ini"
Global $aUtilityVer = $aUtilName & " " & $aUtilVersion
Global $aUtilUpdateFile = @ScriptDir & "\__UTIL_UPDATE_AVAILABLE___.txt"
Global $aIniFailFile = @ScriptDir & "\___INI_FAIL_VARIABLES___.txt"
Global $aFolderLog = @ScriptDir & "\_Log\"
Global $aLogFile = $aFolderLog & $aUtilName & "_Log_" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt"
Global $aLogDebugFile = $aFolderLog & $aUtilName & "_LogFull_" & @YEAR & "-" & @MON & "-" & @MDAY & ".txt"
Global $aFolderTemp = @ScriptDir & "\" & $aUtilName & "UtilFiles\"
DirCreate($aFolderTemp)
Global $aUtilCFGFile = $aFolderTemp & $aUtilName & "_cfg.ini"
Global $aDiscordSendWebhookEXE = $aFolderTemp & "DiscordSendWebhook.exe"
Global $aFilePlink = $aFolderTemp & "plink.exe"
Global $aServerBatchFile = @ScriptDir & "\_start_" & $aUtilName & ".bat"
Global $aBatchDIR = @ScriptDir & "\BatchFiles"
Global $aSteamUpdateCMDValY = $aBatchDIR & "\Update_" & $aGameName & "_Validate_YES.bat"
Global $aSteamUpdateCMDValN = $aBatchDIR & "\Update_" & $aGameName & "_Validate_NO.bat"
Global $aSteamUpdateCMDCustom = $aBatchDIR & "\Update_" & $aGameName & "_Custom.bat"
DirCreate($aBatchDIR)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\100px-Drill.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\99px-Oxygen_Bottle.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\alienchatclose.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\Canned_Vegetables.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\Drone.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\eah-logo.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\empylogo1.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\EmpyrionLogoPx.png", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\Large_Constructor.jpg", $aFolderTemp, 0)
FileInstall("K:\AutoIT\_MyProgs\EmpyrionServerUpdateUtility\Pics\Pumpkin_Sprout.jpg", $aFolderTemp, 0)
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Global Variables ****
If @Compiled = 0 Then
Global $aIconFile = @ScriptDir & "\" & $aUtilName & "_Icons.exe"
Else
Global $aIconFile = @ScriptFullPath
EndIf
Global $aTimeCheck0 = _NowCalc()
Global $aTimeCheck1 = _NowCalc()
Global $aTimeCheck2 = _NowCalc()
Global $aTimeCheck3 = _NowCalc()
Global $aTimeCheck4 = _NowCalc()
Global $aTimeCheck8 = _NowCalc()
Global $aPlinkPID = -1
Global $aTelnetBuffer = ""
Global $aBeginDelayedShutdown = 0
Global $aFirstBoot = 1
Global $aRebootMe = "no"
Global $aUseSteamCMD = "yes"
Global $aOnlinePlayerLast = ""
Global $aRCONError = False
Global $aServerReadyTF = False
Global $aServerReadyOnce = True
Global $aNoExistingPID = True
Global $hGUI = 0
Global $aGUIW = 275
Global $aGUIH = 250
Global $tUserCtTF = False
Global $iEdit = 0
Global $tUserCnt = 1
Global $aBusy = False
Global $aSteamUpdateNow = False
Global $aEAH_Close = False
;~ Global $aPlayerCountWindowTF = False
Global $tOnlinePlayerReady = False
Global $aPlayerCountShowTF = True
Global $aPlayersOnlineName = ""
Global $aPlayersOnlineSteamID = ""
Global $aPlayersJoined = ""
Global $aPlayersLeft = ""
Global $aPlayersName = ""
Global $xPlayerID[1]
Global $xPlayerName[1]
Local $aFirstStartDiscordAnnounce = True
Local $xLabels[15] = ["Raw", "Name", "Map", "Folder", "Game", "ID", "Players", "Max Players", "Bots", "Server Type", "Environment", "Visibility", "VAC", "Version", "Extra Data Field"]
Global $aServerQueryName = "[Not Read Yet]"
Global $aPlayersCount = 0
Global $aPlayersMax = 0
Global $gWatchdogServerStartTimeCheck = _NowCalc()
Global $aIniExist = False
Global $aRemoteRestartUse = "no"
;~ Global $aGameTime = "Day 1, 00:00"
Global $aNextHorde = 7
Global $tQueryLogReadDoneTF = False
;~ Global $aServerNamFromLog = "[Not Read Yet]"
Global $aServerNameToDisplay = ""
Global $tFailedCountQuery = 0
Global $tFailedCountTelnet = 0
Global $wGUIMainWindow = -1
Global $Config = -1
Global $wGUIMainWindow = -1
Global $hGUI_LoginLogo = -1
Global $W2_RestartServer = 9999999
Global $aRestartTime[1]
$aRestartTime[0] = 1
Global $aRestartMsg[1]
$aRestartMsg[0] = "Admin has requested a server reboot. Server is rebooting in 1 minute."
Global $aRestartCnt = 1
Global $sUseDiscordBotRestartServer = "no"
Global $sUseTwitchBotRestartServer = "no"
Global $aServerRebootReason = ""
Global $aRebootReason = ""
Global $aRebootConfigUpdate = "no"
Global $aAnnounceCount1 = 0
Global $aFPCount = 0
Global $aFPClock = _NowCalc()
Global $aMaxPlayers = 0
Global $aUpdateSource = "0" ; 0 = SteamCMD , 1 = SteamDB.com
Global $aServerPID = 0
Global $aServerPort = 0
Global $aTelnetPort = 0
Global $aTelnetPass = "Phoenix125bc123"
Global $aServerSaveGame = ""
$aServerUpdateLinkVerStable = "http://www.phoenix125.com/share/" & StringLower($aGameName) & "/" & StringLower($aGameName) & "latestver.txt"
$aServerUpdateLinkVerBeta = "http://www.phoenix125.com/share/" & StringLower($aGameName) & "/" & StringLower($aGameName) & "latestbeta.txt"
$aServerUpdateLinkDLStable = "http://www.phoenix125.com/share/" & StringLower($aGameName) & "/" & $aGameName & "ServerUpdateUtility.zip"
$aServerUpdateLinkDLBeta = "http://www.phoenix125.com/share/" & StringLower($aGameName) & "/" & $aGameName & "ServerUpdateUtilityBeta.zip"
Global $aShowUpdate = False
Global $aTelnetIP, $aTelnetPort, $aTelnetPass
Global $aPlayerCountErr = False
Global $aServerCrashMsgSentFailedTF = False
Global $aServerCrashMsgSentRestartTF = False
Global $aServerShuttingDownTF = False
#EndRegion ;**** Global Variables ****
Global Enum $WinHttpRequestOption_UserAgentString, _
$WinHttpRequestOption_URL, _
$WinHttpRequestOption_URLCodePage, _
$WinHttpRequestOption_EscapePercentInURL, _
$WinHttpRequestOption_SslErrorIgnoreFlags, _
$WinHttpRequestOption_SelectCertificate, _
$WinHttpRequestOption_EnableRedirects, _
$WinHttpRequestOption_UrlEscapeDisable, _
$WinHttpRequestOption_UrlEscapeDisableQuery, _
$WinHttpRequestOption_SecureProtocols, _
$WinHttpRequestOption_EnableTracing, _
$WinHttpRequestOption_RevertImpersonationOverSsl, _
$WinHttpRequestOption_EnableHttpsToHttpRedirects, _
$WinHttpRequestOption_EnablePassportAuthentication, _
$WinHttpRequestOption_MaxAutomaticRedirects, _
$WinHttpRequestOption_MaxResponseHeaderSize, _
$WinHttpRequestOption_MaxResponseDrainSize, _
$WinHttpRequestOption_EnableHttp1_1, _
$WinHttpRequestOption_EnableCertificateRevocationCheck
Global Const $WinHttpRequestOption_SslErrorIgnoreFlags_UnknownCA = 0x0100
Global Const $WinHttpRequestOption_SslErrorIgnoreFlags_CertWrongUsage = 0x0200
Global Const $WinHttpRequestOption_SslErrorIgnoreFlags_CertCNInvalid = 0x1000
Global Const $WinHttpRequestOption_SslErrorIgnoreFlags_CertDateInvalid = 0x2000
Global Const $WinHttpRequestOption_SslErrorIgnoreFlags_IgnoreAll = 0x3300 ;IGNORE ALL OF THE ABOVE
Global $oErrorFunc = ObjEvent("AutoIt.Error", "_ErrFunc")
Global $aObjErrFunc = "System"
_ShowLoginLogo()
If FileExists($aFolderTemp) = 0 Then DirCreate($aFolderTemp)
If FileExists($aFolderLog) = 0 Then DirCreate($aFolderLog)
If FileExists($aIniFile) Then _FileWriteToLine($aIniFile, 3, "Version : " & $aUtilityVer, True)
Global $aCFGLastVerNumber = IniRead($aUtilCFGFile, "CFG", "LastVerNumber", $aUtilVerNumber)
IniWrite($aUtilCFGFile, "CFG", "LastVerNumber", $aUtilVerNumber)
Local $tUpdateINI = False
If $aCFGLastVerNumber < 1 Then
Global $aServerDirLocal = IniRead($aIniFile, " --------------- GAME SERVER CONFIGURATION --------------- ", $aServerShort & " DIR ###", "Temp")
IniWrite($aIniFile, " --------------- " & StringUpper($aUtilName) & " MISC OPTIONS --------------- ", "EAH exe folder ###", $aServerDirLocal & "\DedicatedServer\EmpyrionAdminHelper")
IniWrite($aIniFile, " --------------- " & StringUpper($aUtilName) & " MISC OPTIONS --------------- ", "EAH exe filename ###", $aEAH_Exe)
$tUpdateINI = True
EndIf
If $aCFGLastVerNumber < 2 Then
Global $aEAH_Use = "Always"
IniWrite($aIniFile, " --------------- GAME SERVER CONFIGURATION --------------- ", "Start and stop EmpyrionAdminHelper (EAH) with Server? (Needed for some Steam updates) (Always/Updates/Never) ###", $aEAH_Use)
Global $aQueryYN = "yes"
IniWrite($aIniFile, " --------------- KEEP ALIVE WATCHDOG --------------- ", "Use Query Port to check if server is alive? (yes/no) ###", $aQueryYN)
IniWrite($aIniFile, " --------------- DISCORD MESSAGES --------------- ", "Announcement when server crash is first detected by Watchdog ###", ":warning: Server crash detected. Server will restart if no response in one minute.")
IniWrite($aIniFile, " --------------- DISCORD MESSAGES --------------- ", "Announcement when server crash is forcing a server roboot by Watchdog ###", ":exclamation::exclamation: Server crash detected. RESTARTING SERVER :exclamation::exclamation:")
IniWrite($aIniFile, " --------------- DISCORD INTEGRATION --------------- ", "Send Discord message when Watchdog first detects server crash? (yes/no) ###", "yes")
IniWrite($aIniFile, " --------------- DISCORD INTEGRATION --------------- ", "Send Discord message when Watchdog detects server crash and will restart server? (yes/no) ###", "yes")
Global $aWatchdogWaitServerUpdate = IniRead($aIniFile, " --------------- KEEP ALIVE WATCHDOG ---------------", "Pause watchdog for _ minutes after server updated to allow map generation (1-360) ###", "5")
IniWrite($aIniFile, " --------------- KEEP ALIVE WATCHDOG ---------------", "Pause watchdog for _ minutes after server updated to allow for update processes to complete (1-360) ###", $aWatchdogWaitServerUpdate)
$tUpdateINI = True
EndIf
If $tUpdateINI Then
ReadUini($aIniFile, $aLogFile)
FileDelete($aIniFile)
UpdateIni($aIniFile)
EndIf
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Startup Checks. Initial Log, Read INI, Check for Correct Paths, Check Remote Restart is bound to port. ****
OnAutoItExitRegister("Gamercide")
Global $aSplash = _Splash($aUtilName & " started.")
LogWrite(" ============================ " & $aUtilityVer & " Started ============================")
FileDelete($aUtilUpdateFile)
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Importing settings from " & $aIniFile & ".")
Global $aShowConfigSplash = True
ReadUini($aIniFile, $aLogFile)
$aShowConfigSplash = False
Global $aServerPID = PIDReadServer($aSplash)
If $aEAH_Use <> "Never" Then _CheckForExistingEAH($aSplash)
Global $gWatchdogServerStartTimeCheck = IniRead($aUtilCFGFile, "CFG", "Last Server Start", "no")
If $gWatchdogServerStartTimeCheck = "no" Then
$gWatchdogServerStartTimeCheck = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Start", $gWatchdogServerStartTimeCheck)
EndIf
If FileExists($aBackupOutputFolder) = 0 Then DirCreate($aBackupOutputFolder)
If $aTelnetIP = "" Then
$aTelnetIP = $aServerIP
EndIf
If $aUtilBetaYN = "1" Then
$aServerUpdateLinkVerUse = $aServerUpdateLinkVerBeta
$aServerUpdateLinkDLUse = $aServerUpdateLinkDLBeta
$aUtilVersion = $aUtilVerBeta
Else
$aServerUpdateLinkVerUse = $aServerUpdateLinkVerStable
$aServerUpdateLinkDLUse = $aServerUpdateLinkDLStable
$aUtilVersion = $aUtilVerStable
EndIf
$aUtilityVer = $aUtilName & " " & $aUtilVersion
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Updating config file.")
;~ AppendConfigSettings()
;GetfromServerConfig()
If $aUpdateUtil = "yes" Then
UtilUpdate($aServerUpdateLinkVerUse, $aServerUpdateLinkDLUse, $aUtilVersion, $aUtilName)
EndIf
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Creating temp config file.")
;Func GetfromServerConfig()
Global $sConfigPath = $aServerDirLocal & "\" & $aConfigFile
Local $sFileExists = FileExists($sConfigPath)
If $sFileExists = 0 Then
LogWrite(" [Config] !!! ERROR !!! Could not find " & $sConfigPath)
_SplashOff()
Local $xFileName = _PathSplitEx($sConfigPath)
Local $tFileName = $xFileName[3] & $xFileName[4]
$tMsg = MsgBox($MB_YESNO, $aConfigFile & " Not Found", "Could not find " & $aGameName & " Config: [" & $tFileName & "]" & @CRLF & @CRLF & $sConfigPath & @CRLF & @CRLF & _
"This is normal for New Install" & @CRLF & "Do you wish to continue with installation?" & @CRLF & "(YES) Continue with installation" & @CRLF & "(NO) Open Config Window", 60)
If $tMsg = 7 Then
LogWrite(" [Config] !!! ERROR !!! Could not find " & $sConfigPath & ". Config Window opened.")
GUI_Config(False, $aSplash)
Else
$aSplash = _Splash($aUtilName & " started.")
EndIf
EndIf
Global $aServerTelnetReboot = "no"
Local $tReturn = _ImportServerConfig()
If $tReturn Then _ImportServerConfig()
Local $x1Return = _GetEAHDefaultConfigFile()
If $x1Return[0] <> $aConfigFile Then LogWrite(" [Config] !!! NOTE !!! EAH is set to use config file [" & $x1Return[0] & "] & telnet port [" & $x1Return[2] & "]. ESUU is set to use config file [" & $aConfigFile & "] PLEASE UPDATE ESUU's CONFIG TO USE DESIRED YAML CONFIG. ")
#EndRegion ;**** Startup Checks. Initial Log, Read INI, Check for Correct Paths, Check Remote Restart is bound to port. ****
If $aUseSteamCMD = "yes" Then
Local $sFileExists = FileExists($aSteamCMDDir & "\steamcmd.exe")
If $sFileExists = 0 Then
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Downloading and installing SteamCMD.")
InetGet("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", @ScriptDir & "\steamcmd.zip", 0)
DirCreate($aSteamCMDDir) ; to extract to
_ExtractZip(@ScriptDir & "\steamcmd.zip", "", "steamcmd.exe", $aSteamCMDDir)
FileDelete(@ScriptDir & "\steamcmd.zip")
LogWrite(" [Update] Running SteamCMD. [steamcmd.exe +quit]")
RunWait("" & $aSteamCMDDir & "\steamcmd.exe +quit", @SW_MINIMIZE)
If Not FileExists($aSteamCMDDir & "\steamcmd.exe") Then
MsgBox(0x0, "SteamCMD Not Found", "Could not find steamcmd.exe at " & $aSteamCMDDir, 60)
;~ _ExitUtil()
EndIf
EndIf
Else
Local $cFileExists = FileExists($aServerDirLocal & "\" & $aServerEXE)
If $cFileExists = 0 Then
MsgBox(0x0, $aGameName & " Server Not Found", "Could not find " & $aServerEXE & " at " & $aServerDirLocal, 60)
;~ _ExitUtil()
EndIf
EndIf
_SteamCMDCommandlineRead()
If StringLen($aSteamUpdateCommandline) < 20 Then _SteamCMDCreate(True)
_SteamCMDBatchFilesCreate()
#Region ;**** Check for Update At Startup ****
If ($aCheckForUpdate = "yes") Then
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Checking for server updates.")
LogWrite(" [Update] Running initial update check . . ")
Local $bRestart = UpdateCheck(True, $aSplash, True)
If $bRestart Then
If ProcessExists($aServerPID) Then
$aBeginDelayedShutdown = 1
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Server outdated. Server update scheduled.")
Sleep(5000)
Else
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Server outdated. Server update process inititiated.")
SteamUpdate()
EndIf
EndIf
;~ SplashOff()
EndIf
#EndRegion ;**** Check for Update At Startup ****
ExternalScriptExist()
_StartRemoteRestart()
ControlSetText($aSplash, "", "Static1", $aUtilName & " " & $aUtilVersion & " started." & @CRLF & @CRLF & "Preparing icon tray.")
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1)
Global $iTrayQueryServerName = TrayCreateItem("PID(" & $aServerPID & ") " & $aServerQueryName)
TrayItemSetOnEvent(-1, "TrayShowPlayerCount")
Global $iTrayQueryPlayers = TrayCreateItem("Players Online: [Enable Query or Online Player Check]")
TrayItemSetOnEvent(-1, "TrayShowPlayerCount")
TrayCreateItem("") ; Create a separator line.
Local $iTrayExitCloseN = TrayCreateItem("Util CONFIG")
TrayItemSetOnEvent(-1, "TrayUtilConfig")
Local $iTrayExitCloseN = TrayCreateItem("Util LOG")
TrayItemSetOnEvent(-1, "TrayUtilLog")
Local $iTrayAbout = TrayCreateItem("About")
TrayItemSetOnEvent(-1, "TrayAbout")
Local $iTrayAbout = TrayCreateItem("Restart Util")
TrayItemSetOnEvent(-1, "TrayRestartUtil")
Local $iTrayUpdateUtilCheck = TrayCreateItem("Check for Util Update")
TrayItemSetOnEvent(-1, "TrayUpdateUtilCheck")
Local $iTrayUpdateUtilPause = TrayCreateItem("Pause Util")
TrayItemSetOnEvent(-1, "TrayUpdateUtilPause")
TrayCreateItem("") ; Create a separator line.
Local $iTrayBackupFocused = TrayCreateItem("Backup: Focused (Save & Config Files)")
TrayItemSetOnEvent(-1, "TrayBackupFocused")
Local $iTrayBackupFocused = TrayCreateItem("Backup: Full (Entire Server & Config)")
TrayItemSetOnEvent(-1, "TrayBackupFull")
TrayCreateItem("") ; Create a separator line.
Local $iTraySendMessage = TrayCreateItem("Send global chat message")
TrayItemSetOnEvent(-1, "TraySendMessage")
Local $iTraySendInGame = TrayCreateItem("Send telnet command")
TrayItemSetOnEvent(-1, "TraySendInGame")
TrayCreateItem("") ; Create a separator line.
Local $iTrayPlayerCount = TrayCreateItem("Show Online Players Window")
TrayItemSetOnEvent(-1, "TrayShowPlayerCount")
Local $iTrayPlayerCheckPause = TrayCreateItem("Disable Online Players Check/Log")
TrayItemSetOnEvent(-1, "TrayShowPlayerCheckPause")
Local $iTrayPlayerCheckUnPause = TrayCreateItem("Enable Online Players Check/Log")
TrayItemSetOnEvent(-1, "TrayShowPlayerCheckUnPause")
TrayCreateItem("") ; Create a separator line.
Local $iTrayUpdateServCheck = TrayCreateItem("Check for Server Update")
TrayItemSetOnEvent(-1, "TrayUpdateServCheck")
Local $iTrayUpdateServPause = TrayCreateItem("Disable Server Update Check")
TrayItemSetOnEvent(-1, "TrayUpdateServPause")
Local $iTrayUpdateServUnPause = TrayCreateItem("Enable Server Update Check")
TrayItemSetOnEvent(-1, "TrayUpdateServUnPause")
TrayCreateItem("") ; Create a separator line.
Local $iTrayRemoteRestart = TrayCreateItem("Initiate Remote Restart")
TrayItemSetOnEvent(-1, "TrayRemoteRestart")
Local $iTrayRestartNow = TrayCreateItem("Restart Server (with Options Window)")
TrayItemSetOnEvent(-1, "TrayRestartNow")
TrayCreateItem("") ; Create a separator line.
Local $iTrayExitCloseN = TrayCreateItem("Server CONFIG")
TrayItemSetOnEvent(-1, "TrayServerConfig")
Local $iTrayExitCloseN = TrayCreateItem("Server LOG")
TrayItemSetOnEvent(-1, "TrayServerLog")
TrayCreateItem("") ; Create a separator line.
Local $iTrayExitCloseN = TrayCreateItem("Exit: Do NOT Shut Down Servers")
TrayItemSetOnEvent(-1, "TrayExitCloseN")
Local $iTrayExitCloseY = TrayCreateItem("Exit: Shut Down Servers")
TrayItemSetOnEvent(-1, "TrayExitCloseY")
If $aCheckForUpdate = "yes" Then
TrayItemSetState($iTrayUpdateServPause, $TRAY_ENABLE)
TrayItemSetState($iTrayUpdateServUnPause, $TRAY_DISABLE)
Else
TrayItemSetState($iTrayUpdateServPause, $TRAY_DISABLE)
TrayItemSetState($iTrayUpdateServUnPause, $TRAY_ENABLE)
EndIf
If $aServerOnlinePlayerYN = "yes" Then
TrayItemSetState($iTrayPlayerCheckPause, $TRAY_ENABLE)
TrayItemSetState($iTrayPlayerCheckUnPause, $TRAY_DISABLE)
Else
TrayItemSetState($iTrayPlayerCheckPause, $TRAY_DISABLE)
TrayItemSetState($iTrayPlayerCheckUnPause, $TRAY_ENABLE)
EndIf
TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.
If WinExists($hGUI_LoginLogo) Then GUIDelete($hGUI_LoginLogo)
;~ ShowOnlineGUI(True)
_UpdateTray()
If $aUpdateUtil = "yes" Then AdlibRegister("RunUtilUpdate", 28800000)
Global $gTelnetTimeCheck0 = _NowCalc()
Global $gQueryTimeCheck0 = _DateAdd('h', -2, _NowCalc())
Global $gServerUpdatedTimeCheck0 = IniRead($aUtilCFGFile, "CFG", "Last Server Update", "no")
If $gServerUpdatedTimeCheck0 = "no" Then
$gServerUpdatedTimeCheck0 = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Update", $gServerUpdatedTimeCheck0)
EndIf
; -----------------------------------------------------------------------------------------------------------------------
$aServerCheck = TimerInit()
$aTelnetCheckTimer = TimerInit()
If ProcessExists($aServerPID) Then
$aTimeCheck8 = _DateAdd('h', -1, $aTimeCheck8)
$aServerCheck = _DateAdd('h', -1, $aServerCheck)
Else
$aServerCheck = _DateAdd('h', -1, $aServerCheck)
ControlSetText($aSplash, "", "Static1", "Preparing to start server...")
EndIf
$aPlayersOnlineName = IniRead($aUtilCFGFile, "CFG", "Players Name", "")
While True ;**** Loop Until Closed ****
#Region ;**** Listen for Remote Restart Request ****
If $aTelnetMonitorAllYN = "yes" Then
If TimerDiff($aTelnetCheckTimer) > ($aTelnetTrafficCheckSec * 1000) Then
_TelnetLookForAll(_PlinkRead())
If $aTelnetStayConnectedYN = "no" Then _PlinkDisconnect()
$aTelnetCheckTimer = TimerInit()
EndIf
EndIf
If TimerDiff($aServerCheck) > 10000 Then
TraySetToolTip("Server process check in progress...")
TraySetIcon(@ScriptName, 201)
If $aRemoteRestartUse = "yes" Then
Local $sRestart = _RemoteRestart($MainSocket, $aRemoteRestartCode, $aRemoteRestartKey, $sObfuscatePass, $aServerIP, $aGameName)
Switch @error
Case 0
If ProcessExists($aServerPID) And ($aBeginDelayedShutdown = 0) Then
Local $MEM = ProcessGetStats($aServerPID, 0)
LogWrite(" [Server] (PID: " & $aServerPID & ") [Work Memory:" & $MEM[0] & " | Peak Memory:" & $MEM[1] & "] " & $sRestart)
If ($sUseDiscordBotDaily = "yes") Or ($sUseDiscordBotUpdate = "yes") Or ($sUseTwitchBotDaily = "yes") Or ($sUseTwitchBotUpdate = "yes") Or ($sInGameAnnounce = "yes") Then
; Local $aMaintenanceMsg = """WARNING! " & $sAnnounceRemoteRestartMessage & " Restarting server in " & $aDelayShutdownTime & " minutes...""" & @CRLF
$aBeginDelayedShutdown = 1
$aRebootReason = "remoterestart"
$aTimeCheck0 = _NowCalc
Else
RunExternalRemoteRestart()
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
EndIf
EndIf
Case 1 To 4
LogWrite(" [Server] " & $sRestart & @CRLF)
EndSwitch
EndIf
#EndRegion ;**** Listen for Remote Restart Request ****
#Region ;**** Keep Server Alive Check. ****
If Not ProcessExists($aServerPID) Then
$tReturn = _CheckForExistingServer()
If $tReturn = 0 Then
$aBeginDelayedShutdown = 0
$aSplash = _Splash("Starting server.")
If $aExecuteExternalScript = "yes" Then
LogWrite(" [ Util ] Executing External Script " & $aExternalScriptDir & "\" & $aExternalScriptName)
If $aExternalScriptAnnounceWait = "no" Then
If $aExternalScriptHideYN = "yes" Then
Run($aExternalScriptFile, @SW_HIDE)
Else
Run($aExternalScriptFile)
EndIf
Else
If $aExternalScriptHideYN = "yes" Then
RunWait($aExternalScriptFile, @SW_HIDE)
Else
RunWait($aExternalScriptFile)
EndIf
EndIf
EndIf
;~ $LogTimeStamp = $aServerDirLocal & '\' & $aGameName & 'Data\output_log_dedi' & StringRegExpReplace(_NowCalc(), "[\\\/\: ]", "_") & ".txt"
;~ IniWrite($aUtilCFGFile, "CFG", "Last Log Time Stamp", $LogTimeStamp)
;~ Local $tRun = "" & $aServerDirLocal & "\" & $aServerEXE & ' -logfile "' & $LogTimeStamp & '" -quit -batchmode -nographics ' & $aServerExtraCMD & " -configfile=" & $aConfigFileTemp & " -dedicated"
If $aServerExtraCMD <> "" Then
Local $tExtraCMD = $aServerExtraCMD & " "
Else
Local $tExtraCMD = ""
EndIf
Local $tRun = '"' & $aServerDirLocal & "\" & $aServerEXE & '" ' & $aLaunchParams & ' ' & $tExtraCMD & $aConfigFile
PurgeLogFile()
;~ _ImportServerConfig()
Local $tPID = _CheckIfProcessRunning($aServerProcessName, $aServerDirLocal & "\DedicatedServer\")
If $tPID > 0 Then
$aServerPID = $tPID
LogWrite(" [Server] Server PID (" & $aServerPID & ") found via Auto Detect.")
_Splash("Running server found. PID:" & $aServerPID, 2500)
Else
$aServerPID = Run($tRun, $aServerDirLocal, @SW_HIDE)
LogWrite(" [Server] ******** Server Started ******** PID(" & $aServerPID & ")", " [Server] ******** Server Started ******** PID(" & $aServerPID & ") [" & $tRun & "]")
$gWatchdogServerStartTimeCheck = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Start", $gWatchdogServerStartTimeCheck)
ControlSetText($aSplash, "", "Static1", "Server launcher started." & @CRLF & @CRLF & "Waiting for server to start")
Sleep(2000)
Local $tPID = _CheckIfProcessRunning($aServerProcessName, $aServerDirLocal & "\DedicatedServer\")
If $tPID > 0 Then
$aServerPID = $tPID
LogWrite(" [Server] Server PID (" & $aServerPID & ") found via Auto Detect.")
ControlSetText($aSplash, "", "Static1", "Server launcher started." & @CRLF & @CRLF & "Server found. PID:" & $aServerPID)
Sleep(4000)
Else
$aServerPID = Run($tRun, $aServerDirLocal, @SW_HIDE)
LogWrite(" [Server] ******** Server Started ******** PID(" & $aServerPID & ")", " [Server] ******** Server Started ******** PID(" & $aServerPID & ") [" & $tRun & "]")
$gWatchdogServerStartTimeCheck = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Start", $gWatchdogServerStartTimeCheck)
ControlSetText($aSplash, "", "Static1", "Server not found. Launcher started again.")
Sleep(2000)
EndIf
$aServerCrashMsgSentFailedTF = False
$aServerCrashMsgSentRestartTF = False
_SplashOff()
EndIf
$gTelnetTimeCheck0 = _NowCalc()
$tQueryLogReadDoneTF = False
$aServerShuttingDownTF = False
;~ $aFPCount = $aFPCount + 1
;~ If ($aFPCount = 3) And ($aFPAutoUpdateYN = "yes") Then FPRun()
; **** Retrieve Server Version ****
;~ Sleep(3000)
;~ ControlSetText($aSplash, "", "Static1", "Server Started." & @CRLF & @CRLF & "Retrieving server version from log.")
;~ Local $sLogPath = $LogTimeStamp
;~ Local $sLogPathOpen = FileOpen($sLogPath, 0)
;~ Local $sLogRead = StringLeft(FileRead($sLogPathOpen), 2500)
;~ $aGameVer = _ArrayToString(_StringBetween($sLogRead, "INF Version: ", " Compatibility Version"))
;~ FileClose($sLogPath)
;~ If $aGameVer = "-1" Then
;~ Sleep(2000)
;~ Local $sLogPath = $LogTimeStamp
;~ Local $sLogPathOpen = FileOpen($sLogPath, 0)
;~ Local $sLogRead = StringLeft(FileRead($sLogPathOpen), 2500)
;~ $xGameVer = _StringBetween($sLogRead, "INF Version: ", " Compatibility Version")
;~ If @error Then
;~ ControlSetText($aSplash, "", "Static1", "Server Started." & @CRLF & @CRLF & "Unable to retrieve server version from log.")
;~ Sleep(5000)
;~ $aGameVer = "[Unable to retrieve]"
;~ Else
;~ $aGameVer = $xGameVer[0]
;~ EndIf
;~ $aGameVer = _ArrayToString(_StringBetween($sLogRead, "INF Version: ", " Compatibility Version"))
;~ FileClose($sLogPath)
;~ EndIf
;~ ControlSetText($aSplash, "", "Static1", "Server Started." & @CRLF & @CRLF & "Server Version: " & $aGameVer)
;~ LogWrite(" [Server] Server version: " & $aGameVer & ".", " [Server] Server version: " & $aGameVer & ". Version derived from """ & $LogTimeStamp & """.")
;~ IniWrite($aUtilCFGFile, "CFG", "Last Server Version", $aGameVer)
;~ Sleep(3000)
; **** END Retrieve Server Version ****
; **** Append Server Version to Server Name And/Or Change GameName to Server Version ****
Local $tRebootTF = False
;~ If $aAppendVerBegin = "yes" Or $aAppendVerEnd = "yes" Then
;~ ControlSetText($aSplash, "", "Static1", "Server Started." & @CRLF & @CRLF & "Waiting for Server Name to be written in log")
;~ $aServerNamFromLog = _GetServerNameFromLog($aSplash)
;~ Local $tConfigPathOpen = FileOpen($aConfigFileTempFull, 0)
;~ Local $tConfigRead2 = FileRead($tConfigPathOpen)
;~ FileClose($tConfigPathOpen)
;~ Local $tConfigRead1 = StringRegExpReplace($tConfigRead2, "</ServerSettings>", "")
;~ Local $sConfigFileTempExists = FileExists($aConfigFileTempFull)
;~ If $sConfigFileTempExists = 1 Then
;~ FileDelete($aConfigFileTempFull)
;~ EndIf
;~ FileWrite($aConfigFileTempFull, $tConfigRead1)
;~ ; **** Append Server Version to Server Name ****
;~ If ($aAppendVerBegin = "no") And ($aAppendVerEnd = "no") Then
;~ $aServerNameVer = $aServerName
;~ Else
;~ If $aGameVer = "[Unable to retrieve]" Then
;~ $aServerNameVer = $aServerName
;~ Else
;~ If $aAppendVerShort = "short" Then
;~ $aGameVerTemp1 = $aGameVer
;~ $aGameVerTemp1 = _StringBetween($aGameVerTemp1, "(", ")")
;~ $aGameVer = _ArrayToString($aGameVerTemp1)
;~ EndIf
;~ $aServerNameVer = $aServerName
;~ If $aAppendVerBegin = "yes" Then
;~ $aServerNameVer = $aGameVer & $aServerNameVer
;~ EndIf
;~ If $aAppendVerEnd = "yes" Then
;~ $aServerNameVer = $aServerNameVer & $aGameVer
;~ EndIf
;~ EndIf
;~ $aPropertyName = "ServerName"
;~ FileWriteLine($aConfigFileTempFull, "<property name=""" & $aPropertyName & """ value=""" & $aServerNameVer & """/>")
;~ IniWrite($aUtilCFGFile, "CFG", "Last Server Name", $aServerNameVer)
;~ EndIf
;~ If $aServerNamFromLog = $aServerNameVer Then
;~ LogWrite("", " [Server] Running server name contains correct server name. No restart necessary. [" & $aServerNameVer & "]")
;~ Else
;~ If $aServerNamFromLog = "[Unable to retrieve]" Then
;~ ControlSetText($aSplash, "", "Static1", "Server Started." & @CRLF & @CRLF & "Unable to retrieve server name from log.")
;~ Sleep(5000)
;~ Else
;~ $tRebootTF = True
;~ LogWrite("", " [Server] Changing Server Name to [" & $aServerNameVer & "]. Reboot necessary")
;~ EndIf
;~ EndIf
;~ EndIf
;~ If $aWipeServer = "no" Then
;~ $aGameName = "[no change]"
;~ Else
;~ Local $tGameName = IniRead($aUtilCFGFile, "CFG", "Last Game Name", $aFPGameName)
;~ $aPropertyName = "GameName"
;~ $aGameName = StringRegExpReplace($aGameVer, "[\(\)]", "")
;~ FileWriteLine($aConfigFileTempFull, "<property name=""" & $aPropertyName & """ value=""" & $aGameName & """/>")
;~ LogWrite("", " [Server] Changing GameName to """ & $aGameName & """ in " & $aConfigFileTempFull & ".")
;~ IniWrite($aUtilCFGFile, "CFG", "Last Game Name", $aGameName)
;~ If $tGameName = $aGameName Then
;~ LogWrite(" [Server] Running server Game Name = Appended server Game Name. No restart necessary.", " [Server] Running server Game Name = Appended server Game Name. No restart necessary. [" & $aGameName & "]")
;~ Else
;~ $tRebootTF = True
;~ EndIf
;~ EndIf
;~ If $aAppendVerBegin = "yes" Or $aAppendVerEnd = "yes" Or $aWipeServer = "yes" Then
;~ FileWriteLine($aConfigFileTempFull, "<property name=""TelnetEnabled"" value=""" & $aServerTelnetEnable & """/>")
;~ FileWriteLine($aConfigFileTempFull, "<property name=""TelnetPort"" value=""" & $aTelnetPort & """/>")
;~ FileWriteLine($aConfigFileTempFull, "<property name=""TelnetPassword"" value=""" & $aTelnetPass & """/>")
;~ FileWriteLine($aConfigFileTempFull, "</ServerSettings>")
;~ EndIf
;~ If $aQueryYN = "no" Then $aServerQueryName = $aServerNamFromLog
;~ If $tRebootTF Then
;~ ControlSetText($aSplash, "", "Static1", "Restarting server to apply config change(s)." & @CRLF & "Server name: " & $aServerNameVer & @CRLF & "Game Name: " & $aGameName)
;~ LogWrite(" [Server] ----- Restarting server to apply config change(s).")
;~ $aRebootConfigUpdate = "yes"
;~ $aRebootMe = "no"
;~ $aServerTelnetReboot = "no"
;~ CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
;~ EndIf
;~ SplashOff()
Else
LogWrite("", " [Server} Notice! Utility reported server PID(" & $aServerPID & ") not running, but searched and found a running server PID(" & $tReturn & "). New PID assigned.")
$aServerPID = $tReturn
_SplashOff()
EndIf
; **** Append Server Version to Server Name And/Or Change GameName to Server Version ****
If @error Or Not $aServerPID Then
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(262405, "Server Failed to Start", "The server tried to start, but it failed. Try again? This will automatically close in 60 seconds and try to start again.", 60)
Select
Case $iMsgBoxAnswer = 4 ;Retry
LogWrite(" [Server] (PID: " & $aServerPID & ") Server Failed to Start. User Initiated a Restart Attempt.")
Case $iMsgBoxAnswer = 2 ;Cancel
LogWrite(" [Server] (PID: " & $aServerPID & ") Server Failed to Start - " & $aUtilName & " Shutdown - Initiated by User")
_ExitUtil()
Case $iMsgBoxAnswer = -1 ;Timeout
LogWrite(" [Server] (PID: " & $aServerPID & ") Server Failed to Start. Script Initiated Restart Attempt after 60 seconds of no User Input.")
EndSelect
EndIf
IniWrite($aUtilCFGFile, "CFG", "PID", $aServerPID)
ElseIf ((_DateDiff('n', $aTimeCheck1, _NowCalc())) >= 5) Then
If $aExMemRestart = "yes" Then
Local $MEM = ProcessGetStats($aServerPID, 0)
If $MEM[0] > $aExMemAmt And $aExMemRestart = "yes" Then
LogWrite(" [Server] (PID: " & $aServerPID & ") Work Memory:" & $MEM[0] & " Peak Memory:" & $MEM[1] & " Excessive Memory Use - Restart requested by " & $aUtilName & " Script", " [Server] (PID: " & $aServerPID & ") Work Memory:" & $MEM[0] & " Peak Memory:" & $MEM[1])
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
EndIf
$aTimeCheck1 = _NowCalc()
EndIf
EndIf
If Not ProcessExists($aEAH_PID) Then
Local $tPID = _CheckIfProcessRunning($aEAH_Exe, $aEAH_Dir)
If $tPID > 0 Then
$aEAH_PID = $tPID
LogWrite(" [ EAH ] Existing " & $aEAH_Name & " process found. PID(" & $aEAH_PID & ")")
IniWrite($aUtilCFGFile, "CFG", "EAH_PID", $aEAH_PID)
Else
Local $tRun = '"' & $aEAH_Dir & '\' & $aEAH_Exe & '"'
$aEAH_PID = Run($tRun)
LogWrite(" [ EAH ] " & $aEAH_Name & " started. PID(" & $aEAH_PID & ")", " [ EAH ] " & $aEAH_Name & " started. PID(" & $aEAH_PID & ") " & $tRun)
IniWrite($aUtilCFGFile, "CFG", "EAH_PID", $aEAH_PID)
EndIf
EndIf
;~ If $aQueryYN = "no" And $tQueryLogReadDoneTF = False Then
If $aQueryYN = "no" Then
Local $tDiffStart = _DateDiff('n', $gWatchdogServerStartTimeCheck, _NowCalc())
If $tDiffStart < 1 Then
Else
;~ $aServerNamFromLog = _GetServerNameFromLog($aSplash)
$tQueryLogReadDoneTF = True
EndIf
EndIf
#EndRegion ;**** Keep Server Alive Check. ****
#Region ;**** Show Online Players ****
If $aServerOnlinePlayerYN = "yes" Then
If ((_DateDiff('s', $aTimeCheck8, _NowCalc())) >= $aServerOnlinePlayerSec) Then
_PlayersOnlineCheck()
$aTimeCheck8 = _NowCalc()
EndIf
EndIf
#EndRegion ;**** Show Online Players ****
#Region ;**** Restart Server Every X Days and X Hours & Min****
If (($aRestartDaily = "yes") And ((_DateDiff('n', $aTimeCheck2, _NowCalc())) >= 1) And (DailyRestartCheck($aRestartDays, $aRestartHours, $aRestartMin)) And ($aBeginDelayedShutdown = 0)) And $aServerShuttingDownTF = False Then
If ProcessExists($aServerPID) Then
Local $MEM = ProcessGetStats($aServerPID, 0)
LogWrite(" [Server] (PID: " & $aServerPID & ") Work Memory:" & $MEM[0] & " Peak Memory:" & $MEM[1] & " - Daily restart requested by " & $aUtilName & ".")
If $aDelayShutdownTime Not = 0 Then
$aBeginDelayedShutdown = 1
$aRebootReason = "daily"
$aTimeCheck0 = _NowCalc
$aAnnounceCount1 = $aAnnounceCount1 + 1
Else
RunExternalScriptDaily()
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
EndIf
EndIf
$aTimeCheck2 = _NowCalc()
EndIf
#EndRegion ;**** Restart Server Every X Days and X Hours & Min****
#Region ;**** Backup Every X Days and X Hours & Min****
If ($aBackupYN = "yes") And ((_DateDiff('n', $aTimeCheck4, _NowCalc())) >= 1) And (BackupCheck($aBackupDays, $aBackupHours, $aBackupMin)) Then
;~ SetStatusBusy("Server process check in progress...", "Check: Backup Game")
_BackupGame(True)
$aTimeCheck4 = _NowCalc()
EndIf
#EndRegion ;**** Backup Every X Days and X Hours & Min****
#Region ;**** KeepServerAlive Telnet Check ****
If ($aTelnetCheckYN = "yes") And (_DateDiff('s', $gTelnetTimeCheck0, _NowCalc()) >= $aTelnetCheckSec) And $aServerShuttingDownTF = False Then
Local $tSkipUpdateCheckTF = False
Local $tSkipStartCheckTF = False
Local $tDiffUpdate = _DateDiff('n', $gServerUpdatedTimeCheck0, _NowCalc())
Local $tDiffStart = _DateDiff('n', $gWatchdogServerStartTimeCheck, _NowCalc())
If $tDiffUpdate <= $aWatchdogWaitServerUpdate Then
$tSkipUpdateCheckTF = True
Local $tTxt = Int($aWatchdogWaitServerUpdate - $tDiffUpdate)
If $tTxt = 0 Then $tTxt = "<1"
LogWrite("", " [Telnet] KeepAlive check SKIPPED due to server update: " & $tTxt & " minute(s) remain.")
EndIf
If $tDiffStart <= $aWatchdogWaitServerStart Then
$tSkipStartCheckTF = True
Local $tTxt = Int($aWatchdogWaitServerStart - $tDiffStart)
If $tTxt = 0 Then $tTxt = "<1"
LogWrite("", " [Telnet] KeepAlive check SKIPPED due to server start: " & $tTxt & " minute(s) remain.")
EndIf
If $tSkipUpdateCheckTF = False And $tSkipStartCheckTF = False Then
For $i = 1 To 5
$aReply = _PlinkSend($aTelnetKeepAliveCMD)
If StringInStr($aReply, $aTelnetKeepAliveReponse) = 0 Then
LogWrite("", " [Telnet] KeepAlive check failed. Count:" & $i & " of 5")
Sleep(1000)
Else
$tFailedCountTelnet = 0
ExitLoop
EndIf
If $i = 5 Then
$tFailedCountTelnet += 1
If $tFailedCountTelnet = $aWatchdogAttemptsBeforeRestart Then
LogWrite(" [Telnet] KeepAlive check (series of 5) FAILED " & $aWatchdogAttemptsBeforeRestart & " attempt(s). RESTARTING SERVER.")
Local $x1Return = _GetEAHDefaultConfigFile()
If $x1Return[0] <> $aConfigFile Then LogWrite(" [Config] !!! NOTE !!! EAH is set to use config file [" & $x1Return[0] & "] & telnet port [" & $x1Return[2] & "]. ESUU is set to use config file [" & $aConfigFile & "] & telnet port [" & $aTelnetPort & "]. PLEASE UPDATE ESUU's CONFIG TO USE DESIRED YAML CONFIG. ")
If $aServerCrashMsgSentRestartTF = False And $sUseDiscordBotServerCrashMsgRestartYN <> "no" Then _SendDiscordCrash($sDiscordServerCrashMsgRestart)
$aServerCrashMsgSentRestartTF = True
$tFailedCountTelnet = 0
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
ExitLoop
Else
LogWrite(" [Telnet] KeepAlive check (series of 5) FAILED attempt " & $tFailedCountTelnet & " of " & $aWatchdogAttemptsBeforeRestart & ".")
Local $x1Return = _GetEAHDefaultConfigFile()
If $x1Return[0] <> $aConfigFile Then LogWrite(" [Config] !!! NOTE !!! EAH is set to use config file [" & $x1Return[0] & "] & telnet port [" & $x1Return[2] & "]. ESUU is set to use config file [" & $aConfigFile & "] & telnet port [" & $aTelnetPort & "]. PLEASE UPDATE ESUU's CONFIG TO USE DESIRED YAML CONFIG. ")
If $aServerCrashMsgSentFailedTF = False And $sUseDiscordBotServerCrashMsgFailedYN <> "no" Then _SendDiscordCrash($sDiscordServerCrashMsgFailed)
$aServerCrashMsgSentFailedTF = True
EndIf
EndIf
Next
If $i < 6 And $aServerShuttingDownTF = False Then LogWrite("", " [Telnet] KeepAlive check OK.")
EndIf
$gTelnetTimeCheck0 = _NowCalc()
EndIf
#EndRegion ;**** KeepServerAlive Telnet Check ****
#Region ;**** KeepServerAlive Query Port Check ****
If ($aQueryYN = "yes") And (_DateDiff('s', $gQueryTimeCheck0, _NowCalc()) >= $aQueryCheckSec) And $aServerShuttingDownTF = False Then
$tQueryResponseOK = _QueryCheck(True)
$gQueryTimeCheck0 = _NowCalc()
EndIf
#EndRegion ;**** KeepServerAlive Query Port Check ****
If $aPlayerCountErr = False Then
;~ If $aGameTime = "Day 1, 00:00" Then
;~ Else
If $aPlayersOnlineName <> IniRead($aUtilCFGFile, "CFG", "Players Name", "") Then
_SendDiscordPlayer()
IniWrite($aUtilCFGFile, "CFG", "Players Name", $aPlayersOnlineName)
IniWrite($aUtilCFGFile, "CFG", "Last Online Player Count", $aPlayersCount)
EndIf
EndIf
#Region ;**** Check for Update every X Minutes ****
If ($aCheckForUpdate = "yes") And ((_DateDiff('n', $aTimeCheck0, _NowCalc())) >= $aUpdateCheckInterval) And ($aBeginDelayedShutdown = 0) And $aServerShuttingDownTF = False Then
Local $bRestart = UpdateCheck(False)
If $bRestart And (($sUseDiscordBotDaily = "yes") Or ($sUseDiscordBotUpdate = "yes") Or ($sUseTwitchBotDaily = "yes") Or ($sUseTwitchBotUpdate = "yes") Or ($sInGameAnnounce = "yes")) Then
$aBeginDelayedShutdown = 1
$aRebootReason = "update"
ElseIf $bRestart Then
RunExternalScriptUpdate()
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
$gServerUpdatedTimeCheck0 = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Update", $gServerUpdatedTimeCheck0)
EndIf
$aTimeCheck0 = _NowCalc()
EndIf
#EndRegion ;**** Check for Update every X Minutes ****
#Region ;**** Announce to Twitch, In Game, Discord ****
If $aDelayShutdownTime Not = 0 Then
If $aBeginDelayedShutdown = 1 Then
RunExternalScriptAnnounce()
If $aRebootReason = "daily" Then
$aAnnounceCount0 = $aDailyCnt
$aAnnounceCount1 = $aAnnounceCount0 - 1
If $aAnnounceCount1 = 0 Then
; $aDelayShutdownTime = $aDailyTime[$aAnnounceCount0]
$aDelayShutdownTime = 0
$aBeginDelayedShutdown = 3
Else
$aDelayShutdownTime = $aDailyTime[$aAnnounceCount0] - $aDailyTime[$aAnnounceCount1]
EndIf
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aDailyMsgInGame[$aAnnounceCount0])
EndIf
If $sUseDiscordBotDaily = "yes" Then _SendDiscordStatus($aDailyMsgDiscord[$aAnnounceCount0])
If $sUseTwitchBotDaily = "yes" Then
TwitchMsgLog($aDailyMsgTwitch[$aAnnounceCount0])
EndIf
EndIf
If $aRebootReason = "remoterestart" Then
$aAnnounceCount0 = $aRemoteCnt
$aDelayShutdownTime = $aRemoteTime[$aAnnounceCount0] - $aRemoteTime[$aAnnounceCount1]
$aAnnounceCount1 = $aAnnounceCount0 - 1
If $aAnnounceCount1 = 0 Then
; $aDelayShutdownTime = $aRemoteTime[$aAnnounceCount0]
$aDelayShutdownTime = 0
$aBeginDelayedShutdown = 3
Else
$aDelayShutdownTime = $aRemoteTime[$aAnnounceCount0] - $aRemoteTime[$aAnnounceCount1]
EndIf
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aRemoteMsgInGame[$aAnnounceCount0])
EndIf
If $sUseDiscordBotRemoteRestart = "yes" Then _SendDiscordStatus($aRemoteMsgDiscord[$aAnnounceCount0])
If $sUseTwitchBotRemoteRestart = "yes" Then
TwitchMsgLog($aRemoteMsgTwitch[$aAnnounceCount0])
EndIf
EndIf
If $aRebootReason = "update" Then
$aAnnounceCount0 = $aUpdateCnt
$aDelayShutdownTime = $aUpdateTime[$aAnnounceCount0] - $aUpdateTime[$aAnnounceCount1]
$aAnnounceCount1 = $aAnnounceCount0 - 1
If $aAnnounceCount1 = 0 Then
$aDelayShutdownTime = 0
$aBeginDelayedShutdown = 3
Else
$aDelayShutdownTime = $aUpdateTime[$aAnnounceCount0] - $aUpdateTime[$aAnnounceCount1]
EndIf
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aUpdateMsgInGame[$aAnnounceCount0])
EndIf
If $sUseDiscordBotUpdate = "yes" Then _SendDiscordStatus($aUpdateMsgDiscord[$aAnnounceCount0])
If $sUseTwitchBotUpdate = "yes" Then
TwitchMsgLog($aUpdateMsgTwitch[$aAnnounceCount0])
EndIf
EndIf
If $aRebootReason = "restartserver" Then
$aAnnounceCount0 = $aRestartCnt
$aDelayShutdownTime = $aRestartTime[$aAnnounceCount0] - $aRestartTime[$aAnnounceCount1]
$aAnnounceCount1 = $aAnnounceCount0 - 1
If $aAnnounceCount1 = 0 Then
$aDelayShutdownTime = 0
$aBeginDelayedShutdown = 3
Else
$aDelayShutdownTime = $aRestartTime[$aAnnounceCount0] - $aRestartTime[$aAnnounceCount1]
EndIf
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aRestartMsg[$aAnnounceCount0])
If $sUseDiscordBotRestartServer = "yes" Then _SendDiscordStatus($aRestartMsg[$aAnnounceCount0])
If $sUseTwitchBotRestartServer = "yes" Then TwitchMsgLog($aRestartMsg[$aAnnounceCount0])
EndIf
$aBeginDelayedShutdown = 2
$aTimeCheck0 = _NowCalc()
ElseIf ($aBeginDelayedShutdown > 2 And ((_DateDiff('n', $aTimeCheck0, _NowCalc())) >= $aDelayShutdownTime)) Then ; **** REBOOT SERVER ****
$aBeginDelayedShutdown = 0
$aTimeCheck0 = _NowCalc()
If $aRebootReason = "daily" Then
$aSplash = _Splash("Daily server request. Restarting server . . .", 0, 350, 50)
RunExternalScriptDaily()
EndIf
If $aRebootReason = "update" Then
$aSplash = _Splash("New server update. Restarting server . . .", 0, 350, 50)
RunExternalScriptUpdate()
$gServerUpdatedTimeCheck0 = _NowCalc()
IniWrite($aUtilCFGFile, "CFG", "Last Server Update", $gServerUpdatedTimeCheck0)
EndIf
If $aRebootReason = "remoterestart" Then
$aSplash = _Splash("Remote Restart requested. Restarting server . . .", 0, 350, 50)
RunExternalRemoteRestart()
EndIf
If $aRebootReason = "restartserver" Then $aSplash = _Splash("Restart server requested. Restarting server . . .", 0, 350, 50)
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, "FINAL WARNING! Rebooting server in 10 seconds...")
Sleep(10000)
EndIf
CloseServer($aTelnetIP, $aTelnetPort, $aTelnetPass)
ElseIf ($aBeginDelayedShutdown = 2) And (_DateDiff('n', $aTimeCheck0, _NowCalc()) >= $aDelayShutdownTime) Then ; **** REPEAT ANNOUNCEMENTS UNTIL LAST COUNT ***
If $aRebootReason = "daily" Then
If $aAnnounceCount1 > 1 Then
$aDelayShutdownTime = $aDailyTime[$aAnnounceCount1] - $aDailyTime[($aAnnounceCount1 - 1)]
Else
$aDelayShutdownTime = $aDailyTime[$aAnnounceCount1]
EndIf
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aDailyMsgInGame[$aAnnounceCount1])
EndIf
If $sUseDiscordBotDaily = "yes" And ($sUseDiscordBotFirstAnnouncement = "no") Then _SendDiscordStatus($aDailyMsgDiscord[$aAnnounceCount1])
If $sUseTwitchBotDaily = "yes" And ($sUseTwitchFirstAnnouncement = "no") Then
TwitchMsgLog($aDailyMsgTwitch[$aAnnounceCount1])
EndIf
EndIf
If $aRebootReason = "remoterestart" Then
If $aAnnounceCount1 > 1 Then
$aDelayShutdownTime = $aRemoteTime[$aAnnounceCount1] - $aRemoteTime[($aAnnounceCount1 - 1)]
Else
$aDelayShutdownTime = $aRemoteTime[$aAnnounceCount1]
EndIf
If $sInGameAnnounce = "yes" Then
SendInGame($aTelnetIP, $aTelnetPort, $aTelnetPass, $aRemoteMsgInGame[$aAnnounceCount1])
EndIf
If ($sUseDiscordBotRemoteRestart = "yes") And ($sUseDiscordBotFirstAnnouncement = "no") Then _SendDiscordStatus($aRemoteMsgDiscord[$aAnnounceCount1])
If $sUseTwitchBotRemoteRestart = "yes" And ($sUseTwitchFirstAnnouncement = "no") Then
TwitchMsgLog($aRemoteMsgTwitch[$aAnnounceCount1])
EndIf
EndIf
If $aRebootReason = "update" Then
If $aAnnounceCount1 > 1 Then
$aDelayShutdownTime = $aUpdateTime[$aAnnounceCount1] - $aUpdateTime[($aAnnounceCount1 - 1)]
Else
$aDelayShutdownTime = $aUpdateTime[$aAnnounceCount1]