-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFactorioServerTool.bat
1970 lines (1749 loc) · 73.5 KB
/
FactorioServerTool.bat
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
@echo off
setlocal
:: Factorio Server Tool v0.1.38
:: 23/July/2016
:: http://cr4zyb4st4rd.co.uk
:: https://github.com/Cr4zyy/FactorioServerTool
::Skip this stuff only called when needed
goto skip
::Functions and calls
:ascii
echo _______________________________________________________________________________
echo -------------------------------------------------------------------------------
echo 888888 db dP""b8 888888 dP"Yb 88""Yb 88 dP"Yb
echo ________ 88__ dPYb dP `" 88 dP Yb 88__dP 88 dP Yb ________
echo """""""" 88"" dP__Yb Yb 88 Yb dP 88"Yb 88 Yb dP """"""""
echo 88 dP""""Yb YboodP 88 YbodP 88 Yb 88 YbodP
echo.
echo .dP"Y8 888888 88""Yb Yb dP 888888 88""Yb 888888 dP"Yb dP"Yb 88
echo `Ybo." 88__ 88__dP Yb dP 88__ 88__dP 88 dP Yb dP Yb 88
echo o.`Y8b 88"" 88"Yb YbdP 88"" 88"Yb 88 Yb dP Yb dP 88 .o
echo 8bodP' 888888 88 Yb YP 888888 88 Yb 88 YbodP YbodP 88ood8
echo -------------------------------------------------------------------------------
echo _______________________________________________________________________________
echo.
goto:eof
:getDateTime
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set dateTime=%%I
set dateTime=%dateTime:~0,8%-%dateTime:~8,6%
goto:eof
:: %2 > or eq to %1 < or eq to %3
:GEOLE
call :clearEL
set GEOLEvalue=0
set GEOLEerror=0
set evalue=0
::make sure we're working with numbers here!
set /a "num1=%1"
IF ERRORLEVEL== 1 set GEOLEerror=1&& goto:eof
set /a "num2=%2"
set /a "num3=%3"
IF %1 NEQ %num1% set GEOLEerror=1&& goto:eof
IF %2 NEQ %num2% set GEOLEerror=1&& goto:eof
IF %3 NEQ %num3% set GEOLEerror=1&& goto:eof
IF %num1% GEQ %num2% set /a "evalue+=1"
IF %num1% LEQ %num3% set /a "evalue+=1"
IF %evalue% EQU 2 set GEOLEvalue=1
goto:eof
::Write values to ini config
:iniWrite
call :clearEL
type %3 | find /v "%1=" > "%writeTemp%"
copy /y %writeTemp% %3
IF ERRORLEVEL 1 set failed=Could not write file Make sure you have permission, you may need to run this tool as an admin ^(right-click run as admin^) Attempted to write files to: %3&& call :errorEnd 0
echo %1=%2 >> %3
del %writeTemp%
goto:eof
::Read the values from the ini config
:: iniRead "STRING to READ" "VAR to SET" "DIR for FILE" "FILENAME"
:iniRead
pushd "%3"
set readOutput=
FOR /f "delims== tokens=2" %%i in ('findstr "%1=" "%4"') do set readOutput=%%i
popd
::batch is atrocious so we're writing many values with spaces on the end unavoidably, this is to remove those...
IF "%readOutput%"=="" set %2=%readOutput%&& goto:eof
set %2=%readOutput: =%
goto:eof
::sets errorlevel to 0 properly
:clearEL
exit /b 0
::updates modified date/time
:touch
if "%2"=="" goto:eof
pushd "%1"
copy /b "%2" +,, > NUL
echo Updated time stamp.
popd
exit /b 0
::checks for running process
:procfind
call :clearEL
tasklist /FI "IMAGENAME eq %1" 2>NUL | find /I /N "%1">NUL
if "%ERRORLEVEL%"=="0" set %2=1
call :clearEL
goto:eof
:skip
call :clearEL
set vnumber=0.1.38
::scale cmd to fit nicely
mode con: cols=80 lines=60
::prettyness
color 30
title Factorio Server Tool %vnumber%
::grab and store ip because it echos annoying stuff
for /f "skip=4 usebackq tokens=2" %%a in (`nslookup myip.opendns.com resolver1.opendns.com`) do set CurrIP=%%a
cls
::variables
set BatchDir=%~dp0
set FSTbat=%~f0
set ProcBool=0
::FactorioServerTool files
set FST_Config=%appdata%\Factorio\FST_Config.ini
set FST_ConfigFile=FST_Config.ini
set FST_ConfigDir=%appdata%\Factorio
set FacAppdata=%appdata%\Factorio
::If a user wants they can store the config.ini in the same place as the batchfile this is a check for that.
IF EXIST "%BatchDir%\FST_Config.ini" (
set FST_Config=%BatchDir%\FST_Config.ini
set FST_ConfigDir=%BatchDir%
)
::Try to create temp files in %temp%, if that fails try %appdata%, if that fails error
IF NOT EXIST "%temp%\Factorio" (
mkdir "%temp%\Factorio"
IF ERRORLEVEL== 1 (
IF NOT EXIST "%appdata%\Factorio" (
mkdir "%appdata%\Factorio"
IF ERRORLEVEL== 1 (
set failed=The tool could not create a temporary folder in either your temp or appdata folders, please try running the tool as an administrator to gain permissions.
goto errorEnd
) else (
set FacTemp=%appdata%\Factorio
set TempConfig=%appdata%\Factorio\config-temp.tmp
set TempFile=%appdata%\Factorio\temp.tmp
set writeTemp=%appdata%\Factorio\writeTemp.tmp
set TempLib=%appdata%\Factorio\TempLib.tmp
)
)
) else (
set FacTemp=%temp%\Factorio
set TempConfig=%temp%\Factorio\config-temp.tmp
set TempFile=%temp%\Factorio\temp.tmp
set writeTemp=%temp%\Factorio\writeTemp.tmp
set TempLib=%temp%\Factorio\TempLib.tmp
)
) else (
set FacTemp=%temp%\Factorio
set TempConfig=%temp%\Factorio\config-temp.tmp
set TempFile=%temp%\Factorio\temp.tmp
set writeTemp=%temp%\Factorio\writeTemp.tmp
set TempLib=%temp%\Factorio\TempLib.tmp
)
:: Default FST settings/options
:: Used incase of resets etc
set Latency=100
set AutoSaveTimer=5
set AutoSaveSlots=3
set NewServerPort=34190
set InstallDir=0
set OptionDelay=10
set CreateSave=0
set FastStart=0
set SaveSelection=0
set SetupComplete=0
set WinOS=0
set ExtraParams=0
::string vars
set errorString1=The tool has attempted to fix the error that occured, please re-launch the tool. If these errors continue please delete the config located: %FST_Config%
set enterRecommended= Enter/Return will input the default 'Recommended' value listed
:: Check if batch has been run before and a config exists
IF NOT EXIST "%FST_Config%" goto setupBatch
call :iniRead version cfgvnumber "%FST_ConfigDir%" "%FST_ConfigFile%"
set /a cfgvnumber=cfgvnumber
set intvnumber=%vnumber:.=%
::if cfg older than 0.1.31 write new values if they DONT exist!
IF %cfgvnumber% LEQ 0131 (
echo ------------------------------------------------------------------------------
echo NOTE! If you were using an older version due to changes in making this tool
echo work across other Windows locale installs the tool could quit without error
echo.
echo If that is the case you may have to delete the config file for the tool which
echo is located at: %FST_Config%
echo.
echo ------------------------------------------------------------------------------
pause
)
:: read ini "Search STRG" "VAR to set" "Folder containing file" "File to search"
:: have to specify folder seperately because findstr cant handle spaces in dir names....
call :iniRead SetupComplete SetupValue "%FST_ConfigDir%" "%FST_ConfigFile%"
IF [%SetupValue%]==[1] (
goto checkBatch
) else (
goto setupBatch
)
:checkBatch
call :ascii
echo ------------------------------------------------------------------------------
echo Reading config options from file:
echo %FST_Config%
echo ------------------------------------------------------------------------------
echo.
call :iniRead version cfgvnumber "%FST_ConfigDir%" "%FST_ConfigFile%"
set intvnumber=%vnumber:.=%
::update cfg if higher version number
IF %intvnumber% GTR %cfgvnumber% (
echo Updating config version number
call :iniWrite version %intvnumber% "%FST_Config%"
)
::if cfg older than 0.1.31 write new values if they DONT exist!
IF %cfgvnumber% LEQ 0131 (
echo ------------------------------------------------------------------------------
echo Detected an older config file version, writing new entries as required.
echo ------------------------------------------------------------------------------
find "ExtraParams=" "%FST_Config%" > NUL
IF ERRORLEVEL== 1 ( call :iniWrite ExtraParams %ExtraParams% "%FST_Config%" )
call :clearEL
find "FastStart=" "%FST_Config%" > NUL
IF ERRORLEVEL== 1 ( call :iniWrite FastStart %FastStart% "%FST_Config%" )
call :clearEL
find "version=" "%FST_Config%" > NUL
IF ERRORLEVEL== 1 ( call :iniWrite version %intvnumber% "%FST_Config%" )
echo ------------------------------------------------------------------------------
)
:: read ini "Search STRG" "VAR to set" "File to search"
call :iniRead SetupComplete SetupValue "%FST_ConfigDir%" "%FST_ConfigFile%"
IF [%SetupValue%]==[] set failed=%errorString1%&& call :errorFix SetupComplete 1
call :GEOLE %SetupValue% 0 1
::Check SetupComplete
IF %GEOLEvalue%== 1 echo SetupComplete = OK
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix SetupComplete 1
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix SetupComplete 1
::Check Install Directory
call :iniRead InstallDir SavedDir "%FST_ConfigDir%" "%FST_ConfigFile%"
:: sets the dir in a usable fashion with spaces
set FactorioDir=%SavedDir:?= %
:: sets dir with no spaces
set InstallDir=%SavedDir%
IF EXIST "%FactorioDir%\bin" echo InstallDir = OK
IF NOT EXIST "%FactorioDir%\bin" set failed=%errorString1%&& call :errorFix InstallDir 0 SetupComplete 0
::get FacData for var
call :iniRead FacData FacData "%FST_ConfigDir%" "%FST_ConfigFile%"
set FacData=%FacData:?= %
call :iniRead FacConfig FactorioConfig "%FST_ConfigDir%" "%FST_ConfigFile%"
set FacCfg=%FactorioConfig:?= %
::set the server data vars
::faccfg
set DefaultConfig=%FacCfg%\config.ini
set ServerConfig=%FacCfg%\config-server.ini
set ServerConfigFile=config-server.ini
::facdata
set ServerSaveFolder=%FacData%\server\saves
set ServerModFolder=%FacData%\server\mods
set StandardSaveFolder=%FacData%\saves
set StandardModFolder=%FacData%\mods
set ServerFolder=%FacData%\server
::Check for 32/64 bit Install
call :iniRead WinOS WinOS "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%WinOS%"=="" set failed=%errorString1%&& call :errorFix WinOS 0
IF EXIST "%FactorioDir%\bin\%WinOS%\Factorio.exe" echo Executable = OK
IF NOT EXIST "%FactorioDir%\bin\%WinOS%\Factorio.exe" set failed=%errorString1%&& call :errorFix WinOS 0
::Check AutoSave Timer
call :iniRead AutoSaveTimer AutoSaveTimer "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%AutoSaveTimer%"=="" set failed=%errorString1%&& call :errorFix AutoSaveTimer 5
call :GEOLE %AutoSaveTimer% 1 500
IF %GEOLEvalue%== 1 echo AutoSaveTimer = OK
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix AutoSaveTimer 5
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix AutoSaveTimer 5
::Check AutoSave Slots
call :iniRead AutoSaveSlots AutoSaveSlots "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%AutoSaveSlots%"=="" set failed=%errorString1%&& call :errorFix AutoSaveSlots 3
call :GEOLE %AutoSaveSlots% 1 500
IF %GEOLEvalue%== 1 echo AutoSaveSlots = OK
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix AutoSaveSlots 3
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix AutoSaveSlots 3
::Check Latency
call :iniRead Latency Latency "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%Latency%"=="" set failed=%errorString1%&& call :errorFix Latency 100
call :GEOLE %Latency% 1 5000
IF %GEOLEvalue%== 1 echo Latency = OK
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix Latency 100
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix Latency 100
::Check Save Selection
call :iniRead SaveSelection SaveSelection "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%SaveSelection%"=="" set failed=%errorString1%&& call :errorFix SaveSelection 0
call :GEOLE %SaveSelection% 0 1
IF %GEOLEvalue%== 1 echo SaveSelection = OK
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix SaveSelection 0
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix SaveSelection 0
::Check Fast Start
::this value is not set by the batch but can be added as explained in the "About"
call :iniRead FastStart FastStart "%FST_ConfigDir%" "%FST_ConfigFile%"
IF "%FastStart%"=="" set failed=%errorString1%&& call :errorFix FastStart 0
call :GEOLE %FastStart% 0 1
IF %GEOLEvalue%== 1 IF %FastStart%== 1 ( echo FastStart = OK ) else ( echo FastStart = NO )
IF %GEOLEvalue%== 0 set failed=%errorString1%&& call :errorFix FastStart 0
IF %GEOLEerror%== 1 set failed=%errorString1%&& call :errorFix FastStart 0
::Check for config-server.ini
IF NOT EXIST %ServerConfig% set failed=%errorString1%&& call :errorFix SetupComplete 0
::Check ExtraParams
::this value is not set by the batch but can be added as explained in the "About"
find "ExtraParams=" "%FST_Config%" > NUL
IF %ERRORLEVEL%== 0 (
for /f "tokens=*" %%p in (%FST_Config%) do call :processParam %%p
goto pbreak1
:processParam
set line=%*
echo %line: =?% >> "%TempFile%"
goto :eof
:pbreak1
find "ExtraParams=" "%TempFile%" | find "=" > "%TempConfig%"
for /f "tokens=2 delims==" %%d in (%TempConfig%) do set ExtraParams=%%d
::anything with 0/?/null is not an arg, so ignore
set ExtraParams=%ExtraParams: =%
IF "%ExtraParams%"=="0" set ExtraParams=&& del %TempFile%&& del %TempConfig%&& echo ExtraParams = NONE&& goto ParamsChecked
IF "%ExtraParams%"=="" set ExtraParams=&& del %TempFile%&& del %TempConfig%&& echo ExtraParams = NONE&& goto ParamsChecked
::remove the ? we used to let us read all the values
del %TempFile%
del %TempConfig%
set ExtraParams=%ExtraParams:?= %
echo ExtraParams = OK
goto ParamsChecked
)
echo ExtraParams = NONE
:ParamsChecked
call :iniRead write-data CheckWriteData "%FacCfg%" "%ServerConfigFile%"
IF "%CheckWriteData%"=="\server" del "%ServerConfig%"&& set failed=Failed to write correct data to config-server.ini this could be due to a permissions error or your config files are stored in %PROGRAMFILES% and writing files there isn't possible&& goto errorEnd
echo Server Data = OK
echo.
::do Fast Start bypass
IF %FastStart%== 1 goto latestSave
:: Check SaveSelection and goto appropriate choice
IF %SaveSelection%== 1 (
goto enterSave
) else (
goto latestSave
)
:setupBatch
call :clearEL
:: Begin server setup enter install dir
::look for factorio first
title Factorio Server Tool [ Setup Wizard ]
cls
call :ascii
echo ------------------------------------------------------------------------------
echo Welcome to the Factorio Server Tool
echo ------------------------------------------------------------------------------
echo.
echo Please make sure you have launched the Factorio game previously!
echo If you haven't played the game it will not create necessary files
echo Without files created by launching the game the tool can not set up a server
echo.
echo ------------------------------------------------------------------------------
::If a config file already exists, dont select a location for a new one.
IF EXIST "%FST_Config%" goto findSteam
echo.
echo Select where to save the config file for FST. 'FST_Config.ini'
echo Either the Appdata folder or the same directory as the FactorioServerTool.bat
echo.
echo Appdata:
echo %FacAppdata%
echo.
echo or Same Directory:
echo %BatchDir%
echo.
echo You can move the ini file between the appdata folder and the batch directory
echo.
echo However if a ini exists in the batch file directory it will be the file used
echo.
echo ------------------------------------------------------------------------------
echo.
choice /c:NAS /n /m ">Use [A]ppdata folder or the [S]ame directory as FactorioServerTool.bat"
IF %ERRORLEVEL%== 1 goto setupBatch
IF %ERRORLEVEL%== 2 set FST_Config=%appdata%\Factorio\FST_Config.ini&& set FST_ConfigDir=%appdata%\Factorio
IF %ERRORLEVEL%== 3 set FST_Config=%BatchDir%FST_Config.ini&& set FST_ConfigDir=%BatchDir%
call :clearEL
IF NOT EXIST "%FST_ConfigDir%" (
mkdir "%FST_ConfigDir%"
IF ERRORLEVEL== 1 (
echo.
echo ERROR!
echo.
echo The tool could not create the directory in the location you have selected
echo Please either choose the other directory option, run the tool as an admin
echo ^(right-click run as admin^) or change the location you are running the
echo FactorioServerTool.bat from.
echo.
pause
goto setupBatch
)
)
IF NOT EXIST "%FST_Config%" (
copy NUL "%FST_Config%"
IF ERRORLEVEL== 1 (
echo.
echo ERROR!
echo.
echo The tool could not create the 'FST_Config.ini' in the location you have
echo selected, this is probably due to permission issues, either select the
echo other location provided, run the tool as an admin ^(right-click run as admin^)
echo or change the location you are running the FactorioServerTool.bat from.
echo.
pause
goto setupBatch
)
::delete it after empty file inteferes with some checks
del %FST_Config%
)
:findSteam
cls
call :ascii
echo ------------------------------------------------------------------------------
echo Now attempting to find your Steam directory
echo If you don't use Steam you will be prompted to input your Install dir after.
echo ------------------------------------------------------------------------------
echo Locating Steam Directory...
FOR /f "tokens=1,2*" %%E in ('reg query HKEY_CURRENT_USER\Software\Valve\Steam\') do if %%E==SteamPath set SteamDir=%%G
:: if nothing then go to input
IF ["%SteamDir%"]==[] echo No Steam Install found && goto inputLocation
set SteamDir=%SteamDir:/=\%
IF EXIST "%SteamDir%\steamapps\appmanifest_427520.acf" (
goto checkInstallDir
) else (
goto notInMainDir
)
:checkInstallDir
echo Found Factorio appmanifest checking for Factorio install location
IF EXIST "%SteamDir%\steamapps\common\Factorio\bin\win32" set WinOS=win32&&goto checkExecutable
IF EXIST "%SteamDir%\steamapps\common\Factorio\bin\x64" set WinOS=x64&&goto checkExecutable
echo No Factorio folder located, please make sure Factorio is installed.
goto inputLocation
:checkExecutable
echo Found Factorio install folder as '%WinOS%' checking for Factorio.exe
IF EXIST "%SteamDir%\steamapps\common\Factorio\bin\%WinOS%\Factorio.exe" set InstallDir=%SteamDir%\steamapps\common\Factorio&&goto foundInstallDir
echo No Factorio.exe located, please make sure Factorio is installed.
goto inputLocation
:notInMainDir
:: if factorio is not in the main steam dir it could be in an alternative steam library location so we find it here
IF EXIST %SteamDir%\steamapps\libraryfolders.vdf (
echo Searching for other Steam Library folder locations...
set FactorioLib=0
set LibraryFile=%SteamDir%\steamapps\libraryfolders.vdf
type "%LibraryFile%" > %TempLib%
for /f "tokens=*" %%a in (%TempLib%) do call :processLine %%a
del %TempLib%
goto break2
:processline
set line=%*
echo %line: =?%>> %TempFile%
goto :eof
:break2
::library dir only have \\ in them this way we can ignore other lines in the file
::also findstr sucks and hates spaces in directories so pushd
pushd "%FacTemp%"
for /f "tokens=2" %%d in ('findstr "\\" "Temp.tmp"') do call :processDir %%d
del Temp.tmp
popd
goto break3
:processDir
set LibraryEntry=%*
::remove delimiting \
set LibraryEntry=%LibraryEntry:\\=\%
::remove quotes ""
set LibraryEntry=%LibraryEntry:"=%
::finally remove the ? we added earlier so we can have a working dir path
set LibraryEntry=%LibraryEntry:?= %
echo %LibraryEntry%>> %TempFile%
goto :eof
:break3
for /f "tokens=*" %%L in (%TempFile%) do call :searchLib %%L
del %TempFile%
goto break4
:searchLib
set SteamLibDir=%*
:: make sure we check the version
IF EXIST "%SteamLibDir%\steamapps\common\Factorio\bin\win32" set WinOS=win32
IF EXIST "%SteamLibDir%\steamapps\common\Factorio\bin\x64" set WinOS=x64
:: if we find the exe set installdir
IF EXIST "%SteamLibDir%\SteamApps\common\Factorio\bin\%WinOS%\Factorio.exe" set InstallDir=%SteamLibDir%\SteamApps\common\Factorio&&set FactorioLib=1
goto :eof
) else (
echo Could not locate Factorio automatically.
)
:break4
IF %FactorioLib%== 1 (
goto foundInstallDir
) else (
echo ------------------------------------------------------------------------------
echo No Factorio.exe located, if Factorio is installed
goto inputLocation
)
:foundInstallDir
echo ------------------------------------------------------------------------------
echo.
echo Found Factorio.exe installed in
echo %InstallDir%
echo.
echo ------------------------------------------------------------------------------
choice /c:YN /n /m ">Is this location correct? [Y/N]"
IF %ERRORLEVEL%== 1 goto makeConfig
IF %ERRORLEVEL%== 2 goto inputLocation
:inputLocation
cls
call :ascii
:inputLocationCLS
echo ------------------------------------------------------------------------------
echo Please enter the main Factorio Install Directory
echo.
echo This is the top level Factorio directory, it contains all the sub folders
echo.
echo e.g. %PROGRAMFILES%\Factorio
echo ------------------------------------------------------------------------------
echo.
set /p InstallDir=
::NUL WinOS incase it found a steam install but user wants another directory
set WinOS=
::do a check for the supplied location
IF EXIST "%InstallDir%\bin\win32" set WinOS=win32
IF EXIST "%InstallDir%\bin\x64" set WinOS=x64
IF NOT EXIST "%InstallDir%\bin\%WinOS%\Factorio.exe" echo No Factorio.exe located, please make sure Factorio is installed.&& goto inputLocationCLS
choice /c:YN /n /m ">Is the directory - '%InstallDir%' correct? [Y/N]"
IF %ERRORLEVEL%== 1 goto makeConfig
IF %ERRORLEVEL%== 2 goto inputLocation
:makeConfig
cls
call :ascii
echo ------------------------------------------------------------------------------
echo Welcome to the Setup Wizard!
echo This tool will help you through the configuration of your server options
echo ------------------------------------------------------------------------------
set FactorioDir=%InstallDir%
goto findSaveLoc
:findSaveLoc
::game can be installed without steam so we need to check for where the default config is stored and from that we can get the folder location for saves, mods, etc
echo ------------------------------------------------------------------------------
echo Locating default location for config, mod and save folders
echo ------------------------------------------------------------------------------
set ConfigPathFile=config-path.cfg
IF EXIST "%InstallDir%\%ConfigPathFile%" (
pushd "%InstallDir%"
::config location
FOR /f "delims=__ tokens=3" %%i in ('findstr "config-path=" "%ConfigPathFile%"') do set ConfigDefault=%%i
FOR /f "delims=__ tokens=4" %%j in ('findstr "config-path=" "%ConfigPathFile%"') do set FacCfgPath=%%j
::data location
FOR /f "delims== tokens=2" %%i in ('findstr "use-system-read-write-data-directories=" "%ConfigPathFile%"') do set DataDefault=%%i
popd
)
set FacCfgPath=%FacCfgPath:/=\%
set FacCfgPath=%FacCfgPath:~1%
::The last part of the config path refers to the config folder so add it to the directory location
IF [%ConfigDefault%]==[system-write-data] set FacCfg=%appdata%\Factorio\%FacCfgPath%
::While the default folder would be the %InstallDir% as it's configurable check for the dir anyway
IF [%ConfigDefault%]==[executable] set FacCfg=%InstallDir%\bin\%WinOS%\%FacCfgPath%
::Check where data is stored by default
IF [%DataDefault%]==[true] set FacData=%appdata%\Factorio
::if not using the system data dir use the config dir and go up a level to find the data location
IF [%DataDefault%]==[false] set FacData=%FacCfg%\..
::Now that we know the actual data locations we can set the vars (for this run, we store and set again on next run)
:: Factorio variables
set DefaultConfig=%FacCfg%\config.ini
set ServerConfig=%FacCfg%\config-server.ini
set ServerConfigFile=config-server.ini
set ServerSaveFolder=%FacData%\server\saves
set ServerModFolder=%FacData%\server\mods
set StandardSaveFolder=%FacData%\saves
set StandardModFolder=%FacData%\mods
set ServerFolder=%FacData%\server
::save facdata to ini for next runs
::tell the user where the files are
echo Default locations at:
echo %DefaultConfig%
echo %ServerConfig%
echo %ServerSaveFolder%
echo %ServerModFolder%
echo %StandardSaveFolder%
echo %StandardModFolder%
echo ------------------------------------------------------------------------------
IF EXIST "%FacData%" (
goto saveData
) else (
goto noAppData
)
:noAppData
echo ------------------------------------------------------------------------------
echo Could not locate Factorio data folders.
echo ------------------------------------------------------------------------------
set failed=No Factorio data folder was found, you need to launch the game to create these files.
call :errorEnd 0
:saveData
IF NOT EXIST "%DefaultConfig%" goto creatingConfigFail
IF EXIST "%ServerSaveFolder%\*.zip" (
IF EXIST "%ServerConfig%" (
set ChangeSaveInterval=0
goto setSaveTimer
) else (
goto checkConfig
)
) else (
goto noServerSave
)
:noServerSave
echo ------------------------------------------------------------------------------
echo You have no server data files, you will need to create them.
echo ------------------------------------------------------------------------------
echo.
choice /c:YN /n /m ">Would you like to create the server files and folders? [Y/N]"
IF %ERRORLEVEL%== 1 goto createServerDir
IF %ERRORLEVEL%== 2 set failed=You opted to not create server files! Without them this tool can not operate&& call :errorEnd 0
:createServerDir
::make the directories before we do anything with them to avoid all kinds of wonderful errors
IF NOT EXIST "%ServerFolder%" mkdir "%ServerFolder%"
IF NOT EXIST "%ServerSaveFolder%" mkdir "%ServerSaveFolder%"
IF NOT EXIST "%ServerModFolder%" mkdir "%ServerModFolder%"
IF NOT EXIST "%StandardSaveFolder%" mkdir "%StandardSaveFolder%"
IF NOT EXIST "%StandardModFolder%" mkdir "%StandardModFolder%"
cls
call :ascii
echo -------------------------------------------------------------------------------
echo Server Mods and Save file setup
echo -------------------------------------------------------------------------------
echo.
choice /c:YN /n /m ">Copy your Single Player mods folder? [Y/N]"
IF %ERRORLEVEL%== 1 set SPMods=1&& goto spFolder
IF %ERRORLEVEL%== 2 set SPMods=0&& goto spFolder
:spFolder
echo ------------------------------------------------------------------------------
echo.
echo Selecting [N]o will still allow you to create a new save file
echo.
choice /c:YN /n /m ">Copy your Single Player saves folder? [Y/N]"
IF %ERRORLEVEL%== 1 set SPSaves=1&& goto createSave
IF %ERRORLEVEL%== 2 set SPSaves=0&& goto createSave
IF %SPSaves%== 0 (call :createSave) else goto copyContent
:createSave
echo ------------------------------------------------------------------------------
echo.
echo If you do not have any save files you will need to create one!
echo.
choice /c:YN /n /m ">Create a new save file? [Y/N]"
IF %ERRORLEVEL%== 1 set CreateSave=1&& goto saveCreateDone
IF %ERRORLEVEL%== 2 set CreateSave=2&& goto saveCreateDone
:saveCreateDone
call :clearEL
IF %SPSaves%== 0 (
IF %CreateSave%== 2 (
set failed=You chose to not copy current SP saves or to create a new one. Without a save file the server can not start.
call :errorEnd 0
)
)
::create a new save file using --create
call :getDateTime
set CreateSaveName=FST_%dateTime%.zip
call :procfind factorio.exe ProcBool
call :clearEL
IF %ProcBool%== 1 (
echo ------------------------------------------------------------------------------
echo Warning: Detected Factorio.exe is running!
echo please close any instances of Factorio and continue.
echo If Factorio is running you won't be able to create a new save file.
echo ------------------------------------------------------------------------------
choice /c:C /n /m ">If you have closed Factorio.exe please [C]ontinue"
)
pushd %StandardSaveFolder%
echo %cd%
pause
IF %CreateSave%== 1 "%FactorioDir%\bin\%WinOS%\Factorio.exe" --create %CreateSaveName%&& set SPSaves=2
popd
IF NOT EXIST "%StandardSaveFolder%\%CreateSaveName%" (
echo ------------------------------------------------------------------------------
echo FST could not locate the created save file, you can [R]etry or [Q]uit
echo ------------------------------------------------------------------------------
choice /c:RQ /n /m ">Retry or Quit? [R/Q]"
IF %ERRORLEVEL%== 1 goto saveCreateDone
IF %ERRORLEVEL%== 2 set failed=The tool failed to create a new save file and you chose to quit you can retry or create a single player save file first and use that&& goto errorEnd
)
cls
call :ascii
echo -------------------------------------------------------------------------------
echo.
echo Created a new save file: %CreateSaveName%
echo.
echo -------------------------------------------------------------------------------
echo.
:copyContent
echo -------------------------------------------------------------------------------
echo.
echo Copying files to server directory
echo.
echo -------------------------------------------------------------------------------
echo.
IF %SPMods%== 1 xcopy /s /e /y "%StandardModFolder%" "%ServerModFolder%"
IF %SPSaves%== 1 xcopy /s /e /y "%StandardSaveFolder%" "%ServerSaveFolder%"
IF %SPSaves%== 2 move /y "%StandardSaveFolder%\%CreateSaveName%" "%ServerSaveFolder%"
timeout 2
cls
set failed=Failed to create the server files^(s^) and^/or folder^(s^) This tool may need to be run as an administrator ^(right-click^) it to do so
IF EXIST "%ServerSaveFolder%" (
call :ascii
goto configSetup
) else (
call :errorEnd 0
)
:checkConfig
echo -------------------------------------------------------------------------------
echo While this tool found server save files
echo It could not locate a config-server.ini file
echo In the following location:
echo %FacCfg%
echo.
echo Answering ^(N^)o will allow you to choose another config if you have one
echo -------------------------------------------------------------------------------
echo.
choice /c:YN /n /m ">Create a new config-server.ini? [Y/N]"
IF %ERRORLEVEL%== 1 goto configSetup
IF %ERRORLEVEL%== 2 goto useAnotherConfig
:useAnotherConfig
echo -------------------------------------------------------------------------------
echo If you are using another name for your config-server.ini
echo or have it stored in another location
echo enter the full filename below and it will be copied
echo.
echo You can still [C]reate a new config, just input anything to get the choice
echo -------------------------------------------------------------------------------
echo.
set /p AlternateConfig=
IF NOT EXIST "%AlternateConfig%" (
echo No file located you can [R]etry or [C]reate a new one
choice /c:RC /n /m "[R/C]"
IF %ERRORLEVEL%== 1 goto useAnotherConfig
IF %ERRORLEVEL%== 2 goto configSetup&& set AlternateConfig=
)
choice /c:YNC /n /m ">Is the location - %AlternateConfig%, correct? [Y/N/C]"
IF %ERRORLEVEL%== 1 goto copyConfig
IF %ERRORLEVEL%== 2 goto useAnotherConfig
IF %ERRORLEVEL%== 3 goto configSetup&& set AlternateConfig=
:copyConfig
echo -------------------------------------------------------------------------------
echo Copying your config file into config-server.ini
echo Located in %FacCfg%
echo -------------------------------------------------------------------------------
copy "%AlternateConfig%" "%ServerConfig%"
set ChangeSaveInterval=0
goto setSaveTimer
:configSetup
::setup server config
echo -------------------------------------------------------------------------------
echo Server Config Setup
echo Sets up server write data location
echo Lets you pick the server port
echo -------------------------------------------------------------------------------
echo.
choice /c:YN /n /m ">Setup Server config file? [Y/N]"
IF %ERRORLEVEL%== 1 goto configServerData
IF %ERRORLEVEL%== 2 goto useAnotherConfig
:configServerData
::save configs and make new ones and a backup
IF EXIST "%DefaultConfig%" goto creatingConfig
IF NOT EXIST "%DefaultConfig%" goto creatingConfigFail
:creatingConfig
call :getDateTime
call :clearEL
echo -------------------------------------------------------------------------------
echo Creating config.ini backup
copy /y "%DefaultConfig%" "%FacCfg%\config-backup_%dateTime%.ini"
echo Creating config-server.ini
copy "%DefaultConfig%" "%ServerConfig%"
echo -------------------------------------------------------------------------------
IF ERRORLEVEL 1 set failed=Could not write config-backup.ini/config-server.ini Make sure you have permission, you may need to run this tool as an admin ^(right-click run as admin^) Attempted to write files to: %FacCfg%&& call :errorEnd 0
goto writeServerConfig
:creatingConfigFail
set failed=Could not locate a config.ini you need to start the game to create this file! If you have started the game, the file couldn't be found in: %FacCfg%
call :errorEnd 0
:writeServerConfig
::modify save locations for server
call :iniRead read-data CurReadData "%FacCfg%" "%ServerConfigFile%"
call :iniRead write-data CurWriteData "%FacCfg%" "%ServerConfigFile%"
IF "%CurReadData%"=="" set failed=Could not set the variable 'CurWriteData' because when reading the file '%ServerConfigFile%' the string requested 'read-data' returned NUL&& goto errorEnd
IF "%CurWriteData%"=="" set failed=Could not set the variable 'CurWriteData' because when reading the file '%ServerConfigFile%' the string requested 'write-data' returned NUL&& goto errorEnd
type "%ServerConfig%" | find /v "[path]" > "%TempConfig%"
type "%TempConfig%" | find /v "read-data=" > "%ServerConfig%"
type "%ServerConfig%" | find /v "write-data=" > "%TempConfig%"
echo [path]>> "%TempFile%"
echo read-data=%CurReadData%>> "%TempFile%"
echo write-data=%CurWriteData%\server>> "%TempFile%"
type "%TempFile%" "%TempConfig%" > "%ServerConfig%"
del "%TempConfig%"
del "%TempFile%"
:checkServerConfig
::for some reason this has been failing to write correct config files for some people, so lets create an error if that occurs
::and delete the created broken file
call :iniRead write-data NewWriteData "%FacCfg%" "%ServerConfigFile%"
IF "%NewWriteData%"=="\server" del "%FacCfg%\config-backup_%dateTime%.ini"&& del "%ServerConfig%"&& set failed=Failed to write correct data to config-server.ini this could be due to a permissions error or your config files are stored in %PROGRAMFILES% and writing files there isn't possible&& goto errorEnd
set ChangePortNumber=0
:pickPort
title Factorio Server Tool [ Setup Port ]
cls
call :ascii
:pickPortcls
IF EXIST "%ServerConfig%" (
call :iniRead port CurServPort "%FacCfg%" "%ServerConfigFile%"
) else (
set CurServPort=-NOT SET OR FOUND-
)
::Get current default config port and add + 1 for recommended port this way it cant conflict with gameclient
call :iniRead port NewServerPort "%FacCfg%" "config.ini"
set /a "NewServerPort+=1"
echo -------------------------------------------------------------------------------
echo %enterRecommended%
echo -------------------------------------------------------------------------------
echo Set your SERVER port number ^(Recommended: %NewServerPort%^)
echo This port needs to be forwarded as UDP ^(Accepted Values: 1024-65535^)
echo Current port number: %CurServPort%
echo -------------------------------------------------------------------------------
echo.
set /p NewServerPort=
::dont allow ports outside range
call :GEOLE %NewServerPort% 1024 65535
if %GEOLEvalue%== 1 (call :confirmPort) else goto portFail
:portFail
cls
call :ascii
echo -------------------------------------------------------------------------------
echo %enterRecommended%
echo -------------------------------------------------------------------------------
echo The port %NewServerPort% has not been accepted
echo It is outside the range of 1024-65535
echo Please use a port within the defined range
echo -------------------------------------------------------------------------------
goto pickPortcls
:confirmPort
choice /c:YN /n /m ">Is the port - %NewServerPort%, correct? [Y/N]"
IF %ERRORLEVEL%== 1 goto addPort
IF %ERRORLEVEL%== 2 goto pickPort
:addPort
call :iniWrite port %NewServerPort% "%ServerConfig%"
echo.
echo -------------------------------------------------------------------------------
echo Forward port %NewServerPort% on your router/firewall, UDP only
echo -------------------------------------------------------------------------------
echo Your friends will be able to connect on:
echo %CurrIP%:%NewServerPort%
echo -------------------------------------------------------------------------------
echo YOU will be able to connect with:
echo localhost:%NewServerPort%
echo -------------------------------------------------------------------------------
set ChangeSaveInterval=0
IF %ChangePortNumber%== 0 goto setSaveTimer
IF %ChangePortNumber%== 1 goto startServer
:setSaveTimer
title Factorio Server Tool [ Setup Autosave ]
cls
call :ascii
:setSaveTimercls
::get current value if available
IF EXIST "%FST_Config%" (
call :iniRead AutoSaveTimer CurSaveInt "%FST_ConfigDir%" "%FST_ConfigFile%"
) else (
set CurSaveInt=-NOT SET OR FOUND-
)
echo -------------------------------------------------------------------------------
echo %enterRecommended%
echo -------------------------------------------------------------------------------
echo Set the auto save timer for the server ^(Recommended: 5^)
echo Value is in minutes ^(Accepted values: 1-500^)
echo Current save interval: %CurSaveInt% mins
echo -------------------------------------------------------------------------------
echo.
set /p AutoSaveTimer=
call :GEOLE %AutoSaveTimer% 1 500
if %GEOLEvalue%== 1 (call :confirmTimer) else goto timerFail
:timerFail
cls
call :ascii
echo -------------------------------------------------------------------------------
echo The value %AutoSaveTimer% has not been accepted
echo It is outside the range of 1-500
echo Please use a value within the defined range
echo -------------------------------------------------------------------------------
goto setSaveTimercls
:confirmTimer
choice /c:YN /n /m ">Is this time value - %AutoSaveTimer% mins, correct? [Y/N]"
IF %ChangeSaveInterval%== 0 (