-
Notifications
You must be signed in to change notification settings - Fork 0
/
7dtdServerUtility_v1.7.au3
1552 lines (1454 loc) · 76.7 KB
/
7dtdServerUtility_v1.7.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\phoenix_5Vq_icon.ico
#AutoIt3Wrapper_Outfile=Builds\7dtdServerUtility_v1.7.exe
#AutoIt3Wrapper_Outfile_x64=Builds\7dtdServerUtility_x64_v1.7.exe
#AutoIt3Wrapper_Res_Comment=By Phoenix125 based on Dateranoth's 7dServerUtility v3.3.0-Beta.3
#AutoIt3Wrapper_Res_Description=7 Days To Die Dedicated Server Utility
#AutoIt3Wrapper_Res_Fileversion=1.7.0.0
#AutoIt3Wrapper_Res_ProductName=7dtdServerUtility
#AutoIt3Wrapper_Res_ProductVersion=1.7.0
#AutoIt3Wrapper_Res_CompanyName=http://www.Phoenix125.com
#AutoIt3Wrapper_Res_LegalCopyright=http://www.Phoenix125.com
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Version:1.7 (2018-12-29)
;**** Directives created by AutoIt3Wrapper_GUI ****
;Originally written by Dateranoth for use and modified for 7DTD by Phoenix125.com
;by https://gamercide.com on their server
;Distributed Under GNU GENERAL PUBLIC LICENSE
;RCON notifications will download external application mcrcon if enabled.
;Tiiffi/mcrcon is licensed under the zlib License
;https://github.com/Tiiffi/mcrcon/blob/master/LICENSE
;https://github.com/Tiiffi/mcrcon
#include <Date.au3>
#include <Process.au3>
#include <StringConstants.au3>
#include <String.au3>
#include <IE.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Global Variables ****
Global $g_sTimeCheck0 = _NowCalc()
Global $g_sTimeCheck1 = _NowCalc()
Global $g_sTimeCheck2 = _NowCalc()
Global $g_sTimeCheck3 = _NowCalc()
Global $g_sTimeCheck4 = _NowCalc()
Global Const $g_c_sUtilityVer = "7dtdServerUtility"
Global Const $g_c_sServerEXE = "7DaysToDieServer.exe"
Global Const $g_c_sPIDFile = @ScriptDir & "\7dtdServerUtility_lastpid.tmp"
Global Const $g_c_sLogFile = @ScriptDir & "\7dtdServerUtility.log"
Global Const $g_c_sIniFile = @ScriptDir & "\7dtdServerUtility.ini"
Global $g_iBeginDelayedShutdown = 0
Global $aFirstBoot = 1
If FileExists($g_c_sPIDFile) Then
Global $g_s7dtdPID = FileRead($g_c_sPIDFile)
Else
Global $g_s7dtdPID = "0"
EndIf
#EndRegion ;**** Global Variables ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ; **** Gamercide Shutdown Protocol ****
Func Gamercide()
If @exitMethod <> 1 Then
$Shutdown = MsgBox(4100, "Shut Down?", "Do you wish to shutdown Server " & $aServerName & "? (PID: " & $g_s7dtdPID & ")", 60)
If $Shutdown = 6 Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Server Shutdown - Intiated by User when closing " & $g_c_sUtilityVer & " Script")
CloseServer()
EndIf
MsgBox(4096, "Thanks for using our Application", "Please visit http://www.Phoenix125.com and https://gamercide.com", 15)
FileWriteLine($g_c_sLogFile, _NowCalc() & " " & $g_c_sUtilityVer & " Stopped by User")
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " " & $g_c_sUtilityVer & " Stopped")
EndIf
If $UseRemoteRestart = "yes" Then
TCPShutdown()
EndIf
SplashOff()
Exit
EndFunc ;==>Gamercide
#EndRegion ; **** Gamercide Shutdown Protocol ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Close Server ****
Func CloseServer()
Local $sFileExists = FileExists(@ScriptDir & "\puttytel.exe")
If $sFileExists = 0 Then
InetGet("https://the.earth.li/~sgtatham/putty/latest/w32/puttytel.exe", @ScriptDir & "\puttytel.exe", 0)
If Not FileExists(@ScriptDir & "\puttytel.exe") Then
MsgBox(0x0, "puttytel.exe Not Found", "Could not find puttytel.exe at " & @ScriptDir)
Exit
EndIf
EndIf
If FileExists(@ScriptDir & "\puttytel.exe") Then
Run(@ScriptDir & "\puttytel.exe -P " & $aServerTelnetPort & " " & $g_IP)
WinWait($g_IP & " - PuTTYtel", "")
Local $CrashCheck = WinWait("PuTTYtel Fatal Error", "", 5)
If $CrashCheck = 0 Then
ControlSend($g_IP & " - PuTTYtel", "", "", "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", $aServerTelnetPass & "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", "shutdown{enter}")
WinWait("PuTTYtel Fatal Error", "", 10)
If ProcessExists("puttytel.exe") Then
ProcessClose("puttytel.exe")
EndIf
Else
If ProcessExists("puttytel.exe") Then
ProcessClose("puttytel.exe")
EndIf
If ProcessExists($g_s7dtdPID) Then
ProcessClose($g_s7dtdPID)
EndIf
EndIf
Else
If ProcessExists($g_s7dtdPID) Then
ProcessClose($g_s7dtdPID)
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Server Did not Shut Down Properly. Killing Process")
EndIf
EndIf
EndFunc ;==>CloseServer
#EndRegion ;**** Close Server ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Log File Maintenance Scripts ****
Func LogWrite($sString)
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] " & $sString)
EndFunc ;==>LogWrite
Func RotateFile($sFile, $sBackupQty, $bDelOrig = True) ;Pass File to Rotate and Quantity of Files to Keep for backup. Optionally Keep Original.
Local $hCreateTime = @YEAR & @MON & @MDAY
For $i = $sBackupQty To 1 Step -1
If FileExists($sFile & $i) Then
$hCreateTime = FileGetTime($sFile & $i, 1)
FileMove($sFile & $i, $sFile & ($i + 1), 1)
FileSetTime($sFile & ($i + 1), $hCreateTime, 1)
EndIf
Next
If FileExists($sFile & ($sBackupQty + 1)) Then
FileDelete($sFile & ($sBackupQty + 1))
EndIf
If FileExists($sFile) Then
If $bDelOrig = True Then
$hCreateTime = FileGetTime($sFile, 1)
FileMove($sFile, $sFile & "1", 1)
FileWriteLine($sFile, _NowCalc() & $sFile & " Rotated")
FileSetTime($sFile & "1", $hCreateTime, 1)
FileSetTime($sFile, @YEAR & @MON & @MDAY, 1)
Else
FileCopy($sFile, $sFile & "1", 1)
EndIf
EndIf
EndFunc ;==>RotateFile
#EndRegion ;**** Log File Maintenance Scripts ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Function to Send Message In Game ****
Func SendInGame($g_sInGameMessage)
Local $sFileExists = FileExists(@ScriptDir & "\puttytel.exe")
If $sFileExists = 0 Then
InetGet("https://the.earth.li/~sgtatham/putty/latest/w32/puttytel.exe", @ScriptDir & "\puttytel.exe", 0)
If Not FileExists(@ScriptDir & "\puttytel.exe") Then
MsgBox(0x0, "puttytel.exe Not Found", "Could not find puttytel.exe at " & @ScriptDir)
Exit
EndIf
EndIf
If FileExists(@ScriptDir & "\puttytel.exe") Then
Run(@ScriptDir & "\puttytel.exe -P " & $aServerTelnetPort & " " & $g_IP)
WinWait($g_IP & " - PuTTYtel", "")
Local $CrashCheck = WinWait("PuTTYtel Fatal Error", "", 5)
If $CrashCheck = 0 Then
ControlSend($g_IP & " - PuTTYtel", "", "", "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", $aServerTelnetPass & "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", "{enter}")
ControlSend($g_IP & " - PuTTYtel", "", "", "Say " & $g_sInGameMessage)
WinWait("PuTTYtel Fatal Error", "", 10)
If ProcessExists("puttytel.exe") Then
ProcessClose("puttytel.exe")
EndIf
Else
If ProcessExists("puttytel.exe") Then
ProcessClose("puttytel.exe")
EndIf
EndIf
EndIf
EndFunc
#EndRegion ;**** END Function to Send Message In Game ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Function to Send Message to Discord ****
Func _Discord_ErrFunc($oError)
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Error: 0x" & Hex($oError.number) & " While Sending Discord Bot Message.")
EndFunc ;==>_Discord_ErrFunc
Func SendDiscordMsg($sHookURLs, $sBotMessage, $sBotName = "", $sBotTTS = False, $sBotAvatar = "")
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_Discord_ErrFunc")
Local $sJsonMessage = '{"content" : "' & $sBotMessage & '", "username" : "' & $sBotName & '", "tts" : "' & $sBotTTS & '", "avatar_url" : "' & $sBotAvatar & '"}'
Local $oHTTPOST = ObjCreate("WinHttp.WinHttpRequest.5.1")
Local $aHookURLs = StringSplit($sHookURLs, ",")
For $i = 1 To $aHookURLs[0]
$oHTTPOST.Open("POST", StringStripWS($aHookURLs[$i], 2) & "?wait=true", False)
$oHTTPOST.SetRequestHeader("Content-Type", "application/json")
$oHTTPOST.Send($sJsonMessage)
Local $oStatusCode = $oHTTPOST.Status
Local $sResponseText = ""
If Not $g_bDebug Then
$sResponseText = "Enable Debugging to See Full Response Message"
Else
$sResponseText = "Message Response: " & $oHTTPOST.ResponseText
EndIf
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Discord Bot] Message Status Code {" & $oStatusCode & "} " & $sResponseText)
Next
EndFunc ;==>SendDiscordMsg
#EndRegion ;**** Function to Send Message to Discord ****
#Region ;**** Post to Twitch Chat Function ****
Opt("TCPTimeout", 500)
Func SendTwitchMsg($sT_Nick, $sT_OAuth, $sT_Channels, $sT_Message)
Local $aTwitchReturn[4] = [False, False, "", False]
Local $sTwitchIRC = TCPConnect(TCPNameToIP("irc.chat.twitch.tv"), 6667)
If @error Then
TCPCloseSocket($sTwitchIRC)
Return $aTwitchReturn
Else
$aTwitchReturn[0] = True ;Successfully Connected to irc
TCPSend($sTwitchIRC, "PASS " & StringLower($sT_OAuth) & @CRLF)
TCPSend($sTwitchIRC, "NICK " & StringLower($sT_Nick) & @CRLF)
Local $sTwitchReceive = ""
Local $iTimer1 = TimerInit()
While TimerDiff($iTimer1) < 1000
$sTwitchReceive &= TCPRecv($sTwitchIRC, 1)
If @error Then ExitLoop
WEnd
Local $aTwitchReceiveLines = StringSplit($sTwitchReceive, @CRLF, 1)
$aTwitchReturn[2] = $aTwitchReceiveLines[1] ;Status Line. Accepted or Not
If StringRegExp($aTwitchReceiveLines[$aTwitchReceiveLines[0] - 1], "(?i):tmi.twitch.tv 376 " & $sT_Nick & " :>") Then
$aTwitchReturn[1] = True ;Username and OAuth was accepted. Ready for PRIVMSG
Local $aTwitchChannels = StringSplit($sT_Channels, ",")
For $i = 1 To $aTwitchChannels[0]
TCPSend($sTwitchIRC, "PRIVMSG #" & StringLower($aTwitchChannels[$i]) & " :" & $sT_Message & @CRLF)
If @error Then
TCPCloseSocket($sTwitchIRC)
$aTwitchReturn[3] = False ;Check that all channels succeeded or none
Return $aTwitchReturn
ExitLoop
Else
$aTwitchReturn[3] = True ;Check that all channels succeeded or none
If $aTwitchChannels[0] > 17 Then ;This is to make sure we don't break the rate limit
Sleep(1600)
Else
Sleep(100)
EndIf
EndIf
Next
TCPSend($sTwitchIRC, "QUIT")
TCPCloseSocket($sTwitchIRC)
Else
Return $aTwitchReturn
EndIf
EndIf
Return $aTwitchReturn
EndFunc ;==>SendTwitchMsg
Func TwitchMsgLog($sT_Msg)
Local $aTwitchIRC = SendTwitchMsg($sTwitchNick, $sChatOAuth, $sTwitchChannels, $sT_Msg)
If $aTwitchIRC[0] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] Successfully Connected to Twitch IRC")
If $aTwitchIRC[1] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] Username and OAuth Accepted. [" & $aTwitchIRC[2] & "]")
If $aTwitchIRC[3] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] Successfully sent ( " & $sT_Msg & " ) to all Channels")
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] ERROR | Failed sending message ( " & $sT_Msg & " ) to one or more channels")
EndIf
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] ERROR | Username and OAuth Denied [" & $aTwitchIRC[2] & "]")
EndIf
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] [Twitch Bot] ERROR | Could not connect to Twitch IRC. Is this URL or port blocked? [irc.chat.twitch.tv:6667]")
EndIf
EndFunc ;==>TwitchMsgLog
#EndRegion ;**** Post to Twitch Chat Function ****
#Region ;*** MCRCON Commands
Func MCRCONcmd($l_sPath, $l_sIP, $l_sPort, $l_sPass, $l_sCommand, $l_sMessage = "")
If $l_sCommand = "broadcast" Then
RunWait($l_sPath & '\mcrcon.exe -c -s -H ' & $l_sIP & ' -P ' & $l_sPort & ' -p ' & $l_sPass & ' "broadcast ' & $l_sMessage & '"', $l_sPath, @SW_HIDE)
EndIf
EndFunc ;==>MCRCONcmd
#EndRegion ;*** MCRCON Commands
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Restart Server Scheduling Scrips ****
Func DailyRestartCheck($sWDays, $sHours, $sMin)
Local $iDay = -1
Local $iHour = -1
Local $aDays = StringSplit($sWDays, ",")
Local $aHours = StringSplit($sHours, ",")
For $d = 1 To $aDays[0]
$iDay = StringStripWS($aDays[$d], 8)
If Int($iDay) = Int(@WDAY) Or Int($iDay) = 0 Then
For $h = 1 To $aHours[0]
$iHour = StringStripWS($aHours[$h], 8)
If Int($iHour) = Int(@HOUR) And Int($sMin) = Int(@MIN) Then
Return True
EndIf
Next
EndIf
Next
Return False
EndFunc ;==>DailyRestartCheck
#EndRegion ;**** Restart Server Scheduling Scrips ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** Functions to Check for Update ****
Func GetLatestVersion($sCmdDir)
Local $aReturn[2] = [False, ""]
$sAppInfoTemp = "app_info_" & StringRegExpReplace(_NowCalc(), "[\\\/\: ]", "_") & ".tmp"
RunWait('"' & @ComSpec & '" /c "' & $sCmdDir & '\steamcmd.exe" +login anonymous +app_info_update 1 +app_info_print 294420 +app_info_print 294420 +exit > ' & $sAppInfoTemp & '', $sCmdDir, @SW_HIDE)
Local Const $sFilePath = $sCmdDir & "\" & $sAppInfoTemp
Local $hFileOpen = FileOpen($sFilePath, 0)
Local $hFileRead = FileRead($hFileOpen)
If $hFileOpen = -1 Then
$aReturn[0] = False
Else
If $ServerVer = 0 Then
Local $hString1 = _StringBetween($hFileRead, "branches", "timeupdated")
Else
Local $hString1 = _StringBetween($hFileRead, "latest_experimental", "timeupdated")
EndIf
Local $hString2 = StringSplit($hString1[0], '"', 2)
$hString3 = _ArrayToString($hString2)
Local $hString4 = StringRegExpReplace($hString3, "\t", "")
Local $hString5 = StringRegExpReplace($hString4, @CR & @LF, ".")
Local $hString6 = StringRegExpReplace($hString5, "{", "")
Local $hBuildIDArray = _StringBetween($hString6, "buildid||", "|.")
Local $hBuildID = _ArrayToString($hBuildIDArray)
If $ServerVer = 0 Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Update Check via 7DTD Stable Branch")
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Update Check via 7DTD Experimental Branch")
EndIf
FileClose($hFileOpen)
If FileExists($sFilePath) Then
FileDelete($sFilePath)
EndIf
EndIf
$aReturn[0] = True
$aReturn[1] = $hBuildID
Return $aReturn
EndFunc ;==>GetLatestVersion
Func GetInstalledVersion($sGameDir)
Local $aReturn[2] = [False, ""]
Local Const $sFilePath = $sGameDir & "\steamapps\appmanifest_294420.acf"
Local $hFileOpen = FileOpen($sFilePath, 0)
If $hFileOpen = -1 Then
$aReturn[0] = False
Else
Local $sFileRead = FileRead($hFileOpen)
Local $aAppInfo = StringSplit($sFileRead, '"buildid"', 1)
If UBound($aAppInfo) >= 3 Then
$aAppInfo = StringSplit($aAppInfo[2], '"buildid"', 1)
EndIf
If UBound($aAppInfo) >= 2 Then
$aAppInfo = StringSplit($aAppInfo[1], '"LastOwner"', 1)
EndIf
If UBound($aAppInfo) >= 2 Then
$aAppInfo = StringSplit($aAppInfo[1], '"', 1)
EndIf
If UBound($aAppInfo) >= 2 Then
$aReturn[0] = True
$aReturn[1] = $aAppInfo[2]
EndIf
If FileExists($sFilePath) Then
FileClose($hFileOpen)
EndIf
EndIf
Return $aReturn
EndFunc ;==>GetInstalledVersion
Func UpdateCheck()
Local $bUpdateRequired = False
Local $aLatestVersion = GetLatestVersion($steamcmddir)
Local $aInstalledVersion = GetInstalledVersion($serverdir)
SplashOff()
If ($aLatestVersion[0] And $aInstalledVersion[0]) Then
If StringCompare($aLatestVersion[1], $aInstalledVersion[1]) = 0 Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Server is Up to Date. Version: " & $aInstalledVersion[1])
Else
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Server is Out of Date! Installed Version: " & $aInstalledVersion[1] & " Latest Version: " & $aLatestVersion[1])
Global $aRebootMe = 0
Global $aBotMsg = $sAnnounceUpdateMessage
$TimeStamp = StringRegExpReplace(_NowCalc(), "[\\\/\: ]", "_")
Local $sManifestExists = FileExists($steamcmddir & "\steamapps\appmanifest_294420.acf")
If $sManifestExists = 1 Then
FileMove($steamcmddir & "\steamapps\appmanifest_294420.acf", $steamcmddir & "\steamapps\appmanifest_294420_" & $TimeStamp & ".acf", 1)
If $g_bDebug Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " Notice: """ & $serverdir & "\steamapps\appmanifest_294420.acf"" renamed to ""appmanifest_294420_" & $TimeStamp & ".acf""")
EndIf
EndIf
Local $sManifestExists = FileExists($serverdir & "\steamapps\appmanifest_294420.acf")
If $sManifestExists = 1 Then
FileMove($serverdir & "\steamapps\appmanifest_294420.acf", $serverdir & "\steamapps\appmanifest_294420_" & $TimeStamp & ".acf", 1)
If $g_bDebug Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " Notice: """ & $serverdir & "\steamapps\appmanifest_294420.acf"" renamed to ""appmanifest_294420_" & $TimeStamp & ".acf""")
EndIf
EndIf
$bUpdateRequired = True
EndIf
ElseIf Not $aLatestVersion[0] And Not $aInstalledVersion[0] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Something went wrong retrieving Latest Version")
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Something went wrong retrieving Installed Version")
ElseIf Not $aInstalledVersion[0] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Something went wrong retrieving Installed Version")
ElseIf Not $aLatestVersion[0] Then
FileWriteLine($g_c_sLogFile, _NowCalc() & " [" & $aServerName & " (PID: " & $g_s7dtdPID & ")] Something went wrong retrieving Latest Version")
EndIf
Return $bUpdateRequired
EndFunc ;==>UpdateCheck
#EndRegion ;**** Functions to Check for Update ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** UnZip Function by trancexx ****
; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
; $sFolderStructure - 'path' to the file/folder to extract inside ZIP file
; $sFile - file/folder to extract
; $sDestinationFolder - folder to extract to. Must exist.
; Return values .: Success - Returns 1
; - Sets @error to 0
; Failure - Returns 0 sets @error:
; |1 - Shell Object creation failure
; |2 - Destination folder is unavailable
; |3 - Structure within ZIP file is wrong
; |4 - Specified file/folder to extract not existing
; Author ........: trancexx
; https://www.autoitscript.com/forum/topic/101529-sunzippings-zipping/#comment-721866
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction
Local $oShell = ObjCreate("Shell.Application")
If Not IsObj($oShell) Then
Return SetError(1, 0, 0) ; highly unlikely but could happen
EndIf
Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then
Return SetError(2, 0, 0) ; unavailable destionation location
EndIf
Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then
Return SetError(3, 0, 0) ; unavailable location
EndIf
Local $oOriginFile = $oOriginFolder.ParseName($sFile)
If Not IsObj($oOriginFile) Then
Return SetError(4, 0, 0) ; no such file in ZIP file
EndIf
; copy content of origin to destination
$oDestinationFolder.CopyHere($oOriginFile, 4) ; 4 means "do not display a progress dialog box", but apparently doesn't work
DirRemove($sTempZipFolder, 1) ; clean temp dir
Return 1 ; All OK!
EndFunc ;==>_ExtractZip
#EndRegion ;**** UnZip Function by trancexx ****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** _RemoteRestart ****
;===============================================================================
;
; Name...........: _RemoteRestart
; Description ...: Receives TCP string from GET request and checks against list of known passwords.
; Expects GET /?restart=user_pass HTTP/x.x
; Syntax.........: RemoteRestart($vMSocket, $sCodes, [$sKey = "restart", $sHideCodes = "no", [$sServIP = "0.0.0.0", [$sName = "Server", [$bDebug = False]]]]])
; Parameters ....: $vMSocket - Main Socket to Accept TCP Requests on. Should already be open from TCPListen
; $sCodes - Comma Seperated list of user1_password1,user2_password2,password3
; Allowed Characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@$%^&*()+=-{}[]\|:;./?
; $sKey - Key to match before matching password. http://IP:Pass?KEY=user_pass
; $sHideCodes - Obfuscate codes or not, (yes/no) string
; $sServIP - IP to send back in Header Response.
; $sName - Server Name to use in HTML Response.
; $sDebug - True to return Full TCP Request when Request is invalid
; Return values .: Success - Returns String
; - Sets @error to 0
; No Connection - Sets @ error to -1
; Failure - Returns Descriptive String sets @error:
; |1 - Password doesn't match
; |2 - Invalid Request
; |3 - CheckHTTPReq Failed - Returns error in string
; |4 - TCPRecv Failed - Returns error in string
; Author ........: Dateranoth
;
;==========================================================================================
#Region ;**** PassCheck - Checks if received password matches any of the known passwords ****
Func PassCheck($sPass, $sPassString)
Local $aPassReturn[3] = [False, "", ""]
Local $aPasswords = StringSplit($sPassString, ",")
For $i = 1 To $aPasswords[0]
If (StringCompare($sPass, $aPasswords[$i], 1) = 0) Then
Local $aUserPass = StringSplit($aPasswords[$i], "_")
If $aUserPass[0] > 1 Then
$aPassReturn[0] = True
$aPassReturn[1] = $aUserPass[1]
$aPassReturn[2] = $aUserPass[2]
Else
$aPassReturn[0] = True
$aPassReturn[1] = "Anonymous"
$aPassReturn[2] = $aUserPass[1]
EndIf
ExitLoop
EndIf
Next
Return $aPassReturn
EndFunc ;==>PassCheck
#EndRegion ;**** PassCheck - Checks if received password matches any of the known passwords ****
#Region ;**** ObfPass - Obfuscates password string for logging
Func ObfPass($sObfPassString)
Local $sObfPass = ""
For $i = 1 To (StringLen($sObfPassString) - 3)
If $i <> 4 Then
$sObfPass = $sObfPass & "*"
Else
$sObfPass = $sObfPass & StringMid($sObfPassString, 4, 4)
EndIf
Next
Return $sObfPass
EndFunc ;==>ObfPass
#EndRegion ;**** ObfPass - Obfuscates password string for logging
#Region ;**** Function to get IP from Restart Client ****
Func _TCP_Server_ClientIP($hSocket)
Local $pSocketAddress, $aReturn
$pSocketAddress = DllStructCreate("short;ushort;uint;char[8]")
$aReturn = DllCall("ws2_32.dll", "int", "getpeername", "int", $hSocket, "ptr", DllStructGetPtr($pSocketAddress), "int*", DllStructGetSize($pSocketAddress))
If @error Or $aReturn[0] <> 0 Then Return $hSocket
$aReturn = DllCall("ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($pSocketAddress, 3))
If @error Then Return $hSocket
$pSocketAddress = 0
Return $aReturn[0]
EndFunc ;==>_TCP_Server_ClientIP
#EndRegion ;**** Function to get IP from Restart Client ****
#Region ;**** Function to Check Request from Browser and return restart string if request is valid****
Func CheckHTTPReq($sRequest, $sKey = "restart")
If IsString($sRequest) Then
Local $aRequest = StringRegExp($sRequest, '^GET[[:blank:]]\/\?(?i)' & $sKey & '(?-i)=(\S+)[[:blank:]]HTTP\/\d.\d\R', 2)
If Not @error Then
Return SetError(0, 0, $aRequest[1])
ElseIf @error = 1 Then
Return SetError(1, @extended, "Invalid Request")
ElseIf @error = 2 Then
Return SetError(2, @extended, "Bad pattern, array is invalid. @extended = offset of error in pattern.")
EndIf
Else
Return SetError(3, 0, "Not A String")
EndIf
EndFunc ;==>CheckHTTPReq
#EndRegion ;**** Function to Check Request from Browser and return restart string if request is valid****
#Region ;**** Function to Check for Multiple Password Failures****
Local $aPassFailure[1][3] = [[0, 0, 0]]
Func MultipleAttempts($sRemoteIP, $bFailure = False, $bSuccess = False)
For $i = 1 To UBound($aPassFailure, 1) - 1
If StringCompare($aPassFailure[$i][0], $sRemoteIP) = 0 Then
If (_DateDiff('n', $aPassFailure[$i][2], _NowCalc()) >= 10) Or $bSuccess Then
$aPassFailure[$i][1] = 0
$aPassFailure[$i][2] = _NowCalc()
Return SetError(0, 0, "Maximum Attempts Reset")
ElseIf $bFailure Then
$aPassFailure[$i][1] += 1
$aPassFailure[$i][2] = _NowCalc()
EndIf
If $aPassFailure[$i][1] >= 15 Then
Return SetError(1, $aPassFailure[$i][1], "Maximum Number of Attempts Exceeded. Wait 10 minutes before trying again.")
Else
Return SetError(0, $aPassFailure[$i][1], $aPassFailure[$i][1] & " attempts out of 15 used.")
EndIf
ExitLoop
EndIf
Next
ReDim $aPassFailure[(UBound($aPassFailure, 1) + 1)][3]
$aPassFailure[(UBound($aPassFailure, 1) - 1)][0] = $sRemoteIP
$aPassFailure[(UBound($aPassFailure, 1) - 1)][1] = 0
$aPassFailure[(UBound($aPassFailure, 1) - 1)][2] = _NowCalc
Return SetError(0, 0, "IP Added to List")
EndFunc ;==>MultipleAttempts
#EndRegion ;**** Function to Check for Multiple Password Failures****
#Region ;**** Uses other Functions to check connection, verify request is valid, verify restart code is correct, gather IP, and send proper message back to User depending on request received****
Func _RemoteRestart($vMSocket, $sCodes, $sKey = "restart", $sHideCodes = "no", $sServIP = "0.0.0.0", $sName = "Server", $bDebug = False)
Local $vConnectedSocket = TCPAccept($vMSocket)
If $vConnectedSocket >= 0 Then
Local $sRecvIP = _TCP_Server_ClientIP($vConnectedSocket)
Local $sRECV = TCPRecv($vConnectedSocket, 512)
Local $iError = 0
Local $iExtended = 0
If @error = 0 Then
Local $sRecvPass = CheckHTTPReq($sRECV, $sKey)
If @error = 0 Then
Local $sCheckMaxAttempts = MultipleAttempts($sRecvIP)
If @error = 1 Then
TCPSend($vConnectedSocket, "HTTP/1.1 429 Too Many Requests" & @CRLF & "Retry-After: 600" & @CRLF & "Connection: close" & @CRLF & "Content-Type: text/html; charset=iso-8859-1" & @CRLF & "Cache-Control: no-cache" & @CRLF & "Server: " & $sServIP & @CRLF & @CRLF)
TCPSend($vConnectedSocket, "<!DOCTYPE HTML><html><head><link rel='icon' href='data:;base64,iVBORw0KGgo='><title>" & $sName & " Remote Restart</title></head><body><h1>429 Too Many Requests</h1><p>You tried to Restart " & $sName & " 15 times in a row.<BR>" & $sCheckMaxAttempts & "</body></html>")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
Return SetError(1, 0, "Restart ATTEMPT by Remote Host: " & $sRecvIP & " | Wrong Code was entered 15 times. User must wait 10 minutes before trying again.")
EndIf
Local $aPassCompare = PassCheck($sRecvPass, $sCodes)
If $sHideCodes = "yes" Then
$aPassCompare[2] = ObfPass($aPassCompare[2])
EndIf
If $aPassCompare[0] Then
TCPSend($vConnectedSocket, "HTTP/1.1 200 OK" & @CRLF & "Connection: close" & @CRLF & "Content-Type: text/html; charset=iso-8859-1" & @CRLF & "Cache-Control: no-cache" & @CRLF & "Server: " & $sServIP & @CRLF & @CRLF)
TCPSend($vConnectedSocket, "<!DOCTYPE HTML><html><head><link rel='icon' href='data:;base64,iVBORw0KGgo='><title>" & $sName & " Remote Restart</title></head><body><h1>Authentication Accepted. " & $sName & " Restarting.</h1></body></html>")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
$sCheckMaxAttempts = MultipleAttempts($sRecvIP, False, True)
Return SetError(0, 0, "Restart Requested by Remote Host: " & $sRecvIP & " | User: " & $aPassCompare[1] & " | Pass: " & $aPassCompare[2])
Else
TCPSend($vConnectedSocket, "HTTP/1.1 403 Forbidden" & @CRLF & "Connection: close" & @CRLF & "Content-Type: text/html; charset=iso-8859-1" & @CRLF & "Cache-Control: no-cache" & @CRLF & "Server: " & $sServIP & @CRLF & @CRLF)
TCPSend($vConnectedSocket, "<!DOCTYPE HTML><html><head><link rel='icon' href='data:;base64,iVBORw0KGgo='><title>" & $sName & " Remote Restart</title></head><body><h1>403 Forbidden</h1><p>You are not allowed to restart " & $sName & ".<BR> Attempt from <b>" & $sRecvIP & "</b> has been logged.</body></html>")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
$sCheckMaxAttempts = MultipleAttempts($sRecvIP, True, False)
Return SetError(1, 0, "Restart ATTEMPT by Remote Host: " & $sRecvIP & " | Unknown Restart Code: " & $sRecvPass)
EndIf
Else
$iError = @error
$iExtended = @extended
TCPSend($vConnectedSocket, "HTTP/1.1 404 Not Found" & @CRLF & "Connection: close" & @CRLF & "Content-Type: text/html; charset=iso-8859-1" & @CRLF & "Cache-Control: no-cache" & @CRLF & "Server: " & $sServIP & @CRLF & @CRLF)
TCPSend($vConnectedSocket, "<!DOCTYPE HTML><html><head><link rel='icon' href='data:;base64,iVBORw0KGgo='><title>404 Not Found</title></head><body><h1>404 Not Found.</h1></body></html>")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
If $iError = 1 Then
If Not $bDebug Then
$sRECV = "Enable Debug to Log Full TCP Request"
Else
$sRECV = "Full TCP Request: " & @CRLF & $sRECV
EndIf
Return SetError(2, 0, "Invalid Restart Request by: " & $sRecvIP & ". Should be in the format of GET /?" & $sKey & "=user_pass HTTP/x.x | " & $sRECV)
Else
;This Shouldn't Happen
Return SetError(3, 0, "CheckHTTPReq Failed with Error: " & $iError & " Extended: " & $iExtended & " [" & $sRecvPass & "]")
EndIf
EndIf
Else
$iError = @error
$iExtended = @extended
TCPSend($vConnectedSocket, "HTTP/1.1 400 Bad Request" & @CRLF & "Connection: close" & @CRLF & "Content-Type: text/html; charset=iso-8859-1" & @CRLF & "Cache-Control: no-cache" & @CRLF & "Server: " & $sServIP & @CRLF & @CRLF)
TCPSend($vConnectedSocket, "<!DOCTYPE HTML><html><head><link rel='icon' href='data:;base64,iVBORw0KGgo='><title>400 Bad Request</title></head><body><h1>400 Bad Request.</h1></body></html>")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
Return SetError(4, 0, "TCPRecv Failed to Complete with Error: " & $iError & " Extended: " & $iExtended)
EndIf
EndIf
Return SetError(-1, 0, "No Connection")
If $vConnectedSocket <> -1 Then TCPCloseSocket($vConnectedSocket)
EndFunc ;==>_RemoteRestart
#EndRegion ;**** Uses other Functions to check connection, verify request is valid, verify restart code is correct, gather IP, and send proper message back to User depending on request received****
; -----------------------------------------------------------------------------------------------------------------------
#Region ;**** INI Settings - User Variables ****
Func ReadUini($sIniFile, $sLogFile)
Local $iIniFail = 0
Local $iniCheck = ""
Local $aChar[3]
For $i = 1 To 13
$aChar[0] = Chr(Random(97, 122, 1)) ;a-z
$aChar[1] = Chr(Random(48, 57, 1)) ;0-9
$iniCheck &= $aChar[Random(0, 1, 1)]
Next
Global $serverdir = IniRead($sIniFile, "Server Directory. NO TRAILING SLASH", "serverdir", $iniCheck)
Global $steamcmddir = IniRead($sIniFile, "SteamCMD Directory. NO TRAILING SLASH", "steamcmddir", $iniCheck)
Global $ServerVer = IniRead($sIniFile, "Version: 0-Stable/1-Latest Experimental", "ServerVer", $iniCheck)
Global $ConfigFile = IniRead($sIniFile, "Server Config File (New install: leave as ServerConfig.xml... after files downloaded, CHANGE name... SteamCMD WILL overwrite it)", "ConfigFile", $iniCheck)
Global $WipeServer = IniRead($sIniFile, "Use Version Name (ex. Alpha 17 (b238)) for Game Name (Folder used within SaveGameFolder)? (yes/no) (Leaves previous world saved but creates a new game)", "WipeServer", $iniCheck)
Global $AppendVerBegin = IniRead($sIniFile, "Append Server Version (ex. Alpha 16.4 (b8)) at Beginning/End of Server Name? (yes/no)", "AppendVerBegin", $iniCheck)
Global $AppendVerEnd = IniRead($sIniFile, "Append Server Version (ex. Alpha 16.4 (b8)) at Beginning/End of Server Name? (yes/no)", "AppendVerEnd", $iniCheck)
Global $AppendVerShort = IniRead($sIniFile, "If Append Server Version, then Use SHORT Name (ex B240) or LONG (ex. Aplha (B240))? (short/long)", "AppendVerShort", $iniCheck)
Global $g_IP = IniRead($sIniFile, "Game Server IP", "ListenIP", $iniCheck)
Global $UseSteamCMD = IniRead($sIniFile, "Use SteamCMD To Update Server? (yes/no)", "UseSteamCMD", $iniCheck)
Global $validategame = IniRead($sIniFile, "Validate Files Every Time SteamCMD Runs? (yes/no)", "validategame", $iniCheck)
Global $UseRemoteRestart = IniRead($sIniFile, "Use Remote Restart? (yes/no)", "UseRemoteRestart", $iniCheck)
Global $g_Port = IniRead($sIniFile, "Remote Restart Port", "ListenPort", $iniCheck)
Global $g_sRKey = IniRead($sIniFile, "Remote Restart Request Key http://IP:Port?KEY=user_pass", "RestartKey", $iniCheck)
Global $RestartCode = IniRead($sIniFile, "Remote Restart Password", "RestartCode", $iniCheck)
Global $sObfuscatePass = IniRead($sIniFile, "Hide Passwords in Log? (yes/no)", "ObfuscatePass", $iniCheck)
Global $CheckForUpdate = IniRead($sIniFile, "Check for Update Every X Minutes? (yes/no)", "CheckForUpdate", $iniCheck)
Global $UpdateInterval = IniRead($sIniFile, "Update Check Interval in Minutes 05-59", "UpdateInterval", $iniCheck)
Global $g_sRestartDaily = IniRead($sIniFile, "Restart Server Daily? (yes/no)", "RestartDaily", $iniCheck)
Global $g_sRestartDays = IniRead($sIniFile, "Daily Restart Hours Comma Seperated 0=Everyday Sunday=1 Saturday=7 0-7. ex: 2,4,6", "RestartDays", $iniCheck)
Global $g_sRestartHours = IniRead($sIniFile, "Daily Restart Hours Comma Seperated 00-23", "RestartHours", $iniCheck)
Global $g_sRestartMin = IniRead($sIniFile, "Daily Restart Minute 00-59", "RestartMinute", $iniCheck)
Global $ExMem = IniRead($sIniFile, "Excessive Memory Amount?", "ExMem", $iniCheck)
Global $ExMemRestart = IniRead($sIniFile, "Restart On Excessive Memory Use? (yes/no)", "ExMemRestart", $iniCheck)
Global $logRotate = IniRead($sIniFile, "Rotate X Number of Logs every X Hours? (yes/no)", "logRotate", $iniCheck)
Global $logQuantity = IniRead($sIniFile, "Rotate X Number of Logs every X Hours? (yes/no)", "logQuantity", $iniCheck)
Global $logHoursBetweenRotate = IniRead($sIniFile, "Rotate X Number of Logs every X Hours? (yes/no)", "logHoursBetweenRotate", $iniCheck)
Global $sAnnounceScheduled = IniRead($sIniFile, "Use Enabled Discord/MCRCON/Twitch Bot to Announce Server SCHEDULED Restarts? (yes/no)", "AnnounceScheduled", $iniCheck)
Global $sAnnounceScheduledMessage = IniRead($sIniFile, "Use Enabled Discord/MCRCON/Twitch Bot to Announce Server SCHEDULED Restarts? (yes/no)", "AnnounceScheduledMessage", $iniCheck)
Global $sAnnounceUpdate = IniRead($sIniFile, "Use Enabled Discord/MCRCON/Twitch Bot to Announce Server UPDATE Restarts? (yes/no)", "AnnounceUpdate", $iniCheck)
Global $sAnnounceUpdateMessage = IniRead($sIniFile, "Use Enabled Discord/MCRCON/Twitch Bot to Announce Server UPDATE Restarts? (yes/no)", "AnnounceUpdateMessage", $iniCheck)
Global $sInGameAnnounce = IniRead($sIniFile, "Send In Game Message to Announce Restart? (yes/no)", "InGameAnnounce", $iniCheck)
Global $sUseDiscordBot = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "UseDiscordBot", $iniCheck)
Global $sDiscordWebHookURLs = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "DiscordWebHookURL", $iniCheck)
Global $sDiscordBotName = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "DiscordBotName", $iniCheck)
Global $bDiscordBotUseTTS = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "DiscordBotUseTTS", $iniCheck)
Global $sDiscordBotAvatar = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "DiscordBotAvatarLink", $iniCheck)
Global $iDiscordBotNotifyTime = IniRead($sIniFile, "Use Discord Bot to Announce Restart? (yes/no)", "DiscordBotTimeBeforeRestart", $iniCheck)
Global $g_sUseMCRCON = IniRead($sIniFile, "Use MCRCON to Announce Restart? (yes/no)", "use_mcrcon", $iniCheck)
Global $g_sMCrconPath = IniRead($sIniFile, "Use MCRCON to Announce Restart? (yes/no)", "mcrconPath", $iniCheck)
Global $g_iMCrconNotifyTime = IniRead($sIniFile, "Use MCRCON to Announce Restart? (yes/no)", "mcrconTimeBeforeRestart", $iniCheck)
Global $sUseTwitchBot = IniRead($sIniFile, "Use Twitch Bot to Announce Restart? (yes/no)", "UseTwitchBot", $iniCheck)
Global $sTwitchNick = IniRead($sIniFile, "Use Twitch Bot to Announce Restart? (yes/no)", "TwitchNick", $iniCheck)
Global $sChatOAuth = IniRead($sIniFile, "Use Twitch Bot to Announce Restart? (yes/no)", "ChatOAuth", $iniCheck)
Global $sTwitchChannels = IniRead($sIniFile, "Use Twitch Bot to Announce Restart? (yes/no)", "TwitchChannels", $iniCheck)
Global $iTwitchBotNotifyTime = IniRead($sIniFile, "Use Twitch Bot to Announce Restart? (yes/no)", "TwitchBotTimeBeforeRestart", $iniCheck)
Global $g_sExecuteExternalScript = IniRead($sIniFile, "Execute External Script Before Server Start? (yes/no)", "ExecuteExternalScript", $iniCheck)
Global $g_sExternalScriptDir = IniRead($sIniFile, "External Script Directory", "ExternalScriptDir", $iniCheck)
Global $g_sExternalScriptName = IniRead($sIniFile, "External Script Filename", "ExternalScriptName", $iniCheck)
Global $g_sEnableDebug = IniRead($sIniFile, "Enable Debug to Output More Log Detail? (yes/no)", "EnableDebug", $iniCheck)
Global $ConfigFileTemp = $ConfigFile
If $iniCheck = $serverdir Then
$serverdir = "D:\Game Servers\SteamCMD\steamapps\common\7 Days to Die Dedicated Server"
$iIniFail += 1
EndIf
If $iniCheck = $steamcmddir Then
$steamcmddir = "D:\Game Servers\SteamCMD"
$iIniFail += 1
EndIf
If $iniCheck = $ServerVer Then
$ServerVer = "0"
$iIniFail += 1
EndIf
If $iniCheck = $ConfigFile Then
$ConfigFile = "serverconfig.xml"
$iIniFail += 1
EndIf
If $iniCheck = $WipeServer Then
$WipeServer = "no"
$iIniFail += 1
EndIf
If $iniCheck = $AppendVerBegin Then
$AppendVerBegin = "no"
$iIniFail += 1
EndIf
If $iniCheck = $AppendVerEnd Then
$AppendVerEnd = "no"
$iIniFail += 1
EndIf
If $iniCheck = $AppendVerShort Then
$AppendVerShort = "long"
$iIniFail += 1
EndIf
If $iniCheck = $g_IP Then
$g_IP = "127.0.0.1"
$iIniFail += 1
EndIf
If $iniCheck = $UseSteamCMD Then
$UseSteamCMD = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $validategame Then
$validategame = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $UseRemoteRestart Then
$UseRemoteRestart = "no"
$iIniFail += 1
EndIf
If $iniCheck = $g_Port Then
$g_Port = "57520"
$iIniFail += 1
EndIf
If $iniCheck = $g_sRKey Then
$g_sRKey = "restart"
$iIniFail += 1
EndIf
If $iniCheck = $RestartCode Then
$RestartCode = "-AllowedCharacters=1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&*()+=-{}[]\|:;./?"
$iIniFail += 1
EndIf
If $iniCheck = $sObfuscatePass Then
$sObfuscatePass = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $CheckForUpdate Then
$CheckForUpdate = "yes"
$iIniFail += 1
ElseIf $CheckForUpdate = "yes" And $UseSteamCMD <> "yes" Then
$CheckForUpdate = "no"
FileWriteLine($sLogFile, _NowCalc() & " SteamCMD disabled. Disabling CheckForUpdate. Update will not work without SteamCMD to update it!")
EndIf
If $iniCheck = $UpdateInterval Then
$UpdateInterval = "15"
$iIniFail += 1
ElseIf $UpdateInterval < 5 Then
$UpdateInterval = 5
EndIf
If $iniCheck = $g_sRestartDaily Then
$g_sRestartDaily = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $g_sRestartDays Then
$g_sRestartDays = "0"
$iIniFail += 1
EndIf
If $iniCheck = $g_sRestartHours Then
$g_sRestartHours = "04,16"
$iIniFail += 1
EndIf
If $iniCheck = $g_sRestartMin Then
$g_sRestartMin = "00"
$iIniFail += 1
EndIf
If $iniCheck = $ExMem Then
$ExMem = "6000000000"
$iIniFail += 1
EndIf
If $iniCheck = $ExMemRestart Then
$ExMemRestart = "no"
$iIniFail += 1
EndIf
If $iniCheck = $logRotate Then
$logRotate = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $logQuantity Then
$logQuantity = "10"
$iIniFail += 1
EndIf
If $iniCheck = $logHoursBetweenRotate Then
$logHoursBetweenRotate = "24"
$iIniFail += 1
ElseIf $logHoursBetweenRotate < 1 Then
$logHoursBetweenRotate = 1
EndIf
If $iniCheck = $g_sUseMCRCON Then
$g_sUseMCRCON = "no"
$iIniFail += 1
ElseIf $g_sUseMCRCON = "yes" And $g_sRconEnabled <> "yes" Then
$g_sUseMCRCON = "no"
FileWriteLine($sLogFile, _NowCalc() & " Server RCON is Disabled. Disabling MCRCON Notifications. Cannot send RCON message without RCON enabled!")
EndIf
If $iniCheck = $g_sMCrconPath Then
$g_sMCrconPath = "D:\Game Servers\mcrcon"
$iIniFail += 1
EndIf
If $iniCheck = $g_iMCrconNotifyTime Then
$g_iMCrconNotifyTime = "5"
$iIniFail += 1
EndIf
If $iniCheck = $sAnnounceScheduled Then
$sAnnounceScheduled = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $sAnnounceScheduledMessage Then
$sAnnounceScheduledMessage = "Scheduled Server Restart."
$iIniFail += 1
EndIf
If $iniCheck = $sAnnounceUpdate Then
$sAnnounceUpdate = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $sAnnounceUpdateMessage Then
$sAnnounceUpdateMessage = "New server update."
$iIniFail += 1
EndIf
If $iniCheck = $sInGameAnnounce Then
$sInGameAnnounce = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $sUseDiscordBot Then
$sUseDiscordBot = "no"
$iIniFail += 1
EndIf
If $iniCheck = $sDiscordWebHookURLs Then
$sDiscordWebHookURLs = "https://discordapp.com/api/webhooks/XXXXXX/XXXX<-NO TRAILING SLASH AND USE FULL URL FROM WEBHOOK URL ON DISCORD"
$iIniFail += 1
EndIf
If $iniCheck = $sDiscordBotName Then
$sDiscordBotName = "7 Days To Die Bot"
$iIniFail += 1
EndIf
If $iniCheck = $bDiscordBotUseTTS Then
$bDiscordBotUseTTS = "yes"
$iIniFail += 1
EndIf
If $iniCheck = $sDiscordBotAvatar Then
$sDiscordBotAvatar = ""
$iIniFail += 1
EndIf
If $iniCheck = $iDiscordBotNotifyTime Then
$iDiscordBotNotifyTime = "5"
$iIniFail += 1
ElseIf $iDiscordBotNotifyTime < 1 Then
$iDiscordBotNotifyTime = 1
EndIf
If $iniCheck = $sUseTwitchBot Then
$sUseTwitchBot = "no"
$iIniFail += 1
EndIf
If $iniCheck = $sTwitchNick Then
$sTwitchNick = "twitchbotusername"
$iIniFail += 1
EndIf
If $iniCheck = $sChatOAuth Then
$sChatOAuth = "oauth:1234(Generate OAuth Token Here: https://twitchapps.com/tmi)"
$iIniFail += 1
EndIf
If $iniCheck = $sTwitchChannels Then
$sTwitchChannels = "channel1,channel2,channel3"
$iIniFail += 1
EndIf
If $iniCheck = $iTwitchBotNotifyTime Then
$iTwitchBotNotifyTime = "5"
$iIniFail += 1
ElseIf $iTwitchBotNotifyTime < 1 Then
$iTwitchBotNotifyTime = 1
EndIf
If $iniCheck = $g_sExecuteExternalScript Then
$g_sExecuteExternalScript = "no"
$iIniFail += 1
EndIf
If $iniCheck = $g_sExternalScriptDir Then
$g_sExternalScriptDir = "D:\Game Servers\SQL_Scripts"
$iIniFail += 1
EndIf
If $iniCheck = $g_sExternalScriptName Then
$g_sExternalScriptName = "CleanDB.bat"
$iIniFail += 1
EndIf
If $iniCheck = $g_sEnableDebug Then
$g_sEnableDebug = "no"
$iIniFail += 1
EndIf
If $iIniFail > 0 Then
iniFileCheck($sIniFile, $iIniFail)
EndIf
If $bDiscordBotUseTTS = "yes" Then
$bDiscordBotUseTTS = True
Else
$bDiscordBotUseTTS = False
EndIf
Global $g_iDelayShutdownTime = 0
If ($sUseDiscordBot = "yes") Or ($sUseTwitchBot = "yes") Or ($g_sUseMCRCON = "yes") Then
If ($sUseDiscordBot = "yes") And ($iDiscordBotNotifyTime > $g_iDelayShutdownTime) Then
$g_iDelayShutdownTime = $iDiscordBotNotifyTime
EndIf
If ($sUseTwitchBot = "yes") And ($iTwitchBotNotifyTime > $g_iDelayShutdownTime) Then
$g_iDelayShutdownTime = $iTwitchBotNotifyTime
EndIf
If ($g_sUseMCRCON = "yes") And ($g_iMCrconNotifyTime > $g_iDelayShutdownTime) Then
$g_iDelayShutdownTime = $g_iMCrconNotifyTime
EndIf
Else
$g_iDelayShutdownTime = $g_iMCrconNotifyTime
EndIf
If $g_sEnableDebug = "yes" Then
Global $g_bDebug = True ; This enables Debugging. Outputs more information to log file.
Else
Global $g_bDebug = False
EndIf