source: scripts/usr/local/lib/7dtd/serverconfig.sh@ 204

Last change on this file since 204 was 204, checked in by alloc, 10 years ago

Scripts 63

File size: 20.1 KB
RevLine 
[19]1#!/bin/bash
2
3# Provides functions to query and validate values for serverconfig.xml
4
[23]5#################################
6## Definition of options
7
[19]8serverconfig_ServerPort_QueryName() {
9 echo "Base Port"
10}
11serverconfig_ServerPort_Type() {
12 echo "number"
13}
14serverconfig_ServerPort_Default() {
15 echo "25000"
16}
17serverconfig_ServerPort_Range() {
18 echo "1024-65533"
19}
20serverconfig_ServerPort_Validate() {
21 local I=${INSTANCE:-!}
22 if [ $(checkGamePortUsed "$1" "$I") -eq 0 ]; then
23 echo "1"
24 else
25 echo "0"
26 fi
27}
28serverconfig_ServerPort_ErrorMessage() {
29 echo "Illegal port number or port already in use by another instance."
30}
31
32
33
34serverconfig_ServerIsPublic_QueryName() {
35 echo "Public server"
36}
37serverconfig_ServerIsPublic_Type() {
38 echo "boolean"
39}
40serverconfig_ServerIsPublic_Default() {
41 echo "true"
42}
43serverconfig_ServerIsPublic_ErrorMessage() {
44 echo "Not a valid boolean given (true/false or yes/no or y/n)."
45}
46
47
48
49serverconfig_ServerName_QueryName() {
50 echo "Server name"
51}
52serverconfig_ServerName_Type() {
53 echo "string"
54}
55serverconfig_ServerName_Validate() {
56 if [ ! -z "$1" ]; then
57 echo "1"
58 else
59 echo "0"
60 fi
61}
62serverconfig_ServerName_ErrorMessage() {
63 echo "Server name cannot be empty."
64}
65
66
67
[204]68serverconfig_ServerDescription_QueryName() {
69 echo "Server description"
70}
71serverconfig_ServerDescription_Type() {
72 echo "string"
73}
74
75
76
77serverconfig_ServerWebsiteURL_QueryName() {
78 echo "Server website URL"
79}
80serverconfig_ServerWebsiteURL_Type() {
81 echo "string"
82}
83
84
85
[19]86serverconfig_ServerPassword_QueryName() {
87 echo "Server password"
88}
89serverconfig_ServerPassword_Type() {
90 echo "string"
91}
92
93
94
95serverconfig_ServerMaxPlayerCount_QueryName() {
96 echo "Max players"
97}
98serverconfig_ServerMaxPlayerCount_Type() {
99 echo "number"
100}
101serverconfig_ServerMaxPlayerCount_Default() {
102 echo "4"
103}
104serverconfig_ServerMaxPlayerCount_Range() {
105 echo "1-64"
106}
107
108
109
110serverconfig_GameWorld_QueryName() {
111 echo "World name"
112}
113serverconfig_GameWorld_Type() {
114 echo "enum"
115}
116serverconfig_GameWorld_Default() {
117 echo "1"
118}
119serverconfig_GameWorld_Values() {
[119]120 config_allowed_values=("Random Gen" "Navezgane" "MP Wasteland Horde" "MP Wasteland Skirmish" "MP Wasteland War")
[19]121}
122
123
124
125serverconfig_GameName_QueryName() {
[204]126 echo "Random gen seed"
[19]127}
128serverconfig_GameName_Type() {
129 echo "string"
130}
131serverconfig_GameName_Validate() {
132 if [ ! -z "$1" ]; then
133 echo "1"
134 else
135 echo "0"
136 fi
137}
138serverconfig_GameName_ErrorMessage() {
[204]139 echo "Seed cannot be empty."
[19]140}
141
142
143
144serverconfig_GameDifficulty_QueryName() {
[204]145 echo "Difficulty (+ damage given / received)"
[19]146}
147serverconfig_GameDifficulty_Type() {
148 echo "number"
149}
150serverconfig_GameDifficulty_Default() {
151 echo "2"
152}
153serverconfig_GameDifficulty_Range() {
[204]154 echo "0-5"
[19]155}
156serverconfig_GameDifficulty_Values() {
[204]157 config_allowed_values=("Scavenger (200% / 50%)" "Adventurer (150% / 75%)" "Nomad (100% / 100%)" "Warrior (75% / 150%)" "Survivalist (50% / 200%)" "Insane (25% / 250%)")
[19]158}
159
160
161
162serverconfig_GameMode_QueryName() {
163 echo "Game mode"
164}
165serverconfig_GameMode_Type() {
166 echo "enum"
167}
168serverconfig_GameMode_Default() {
169 echo "1"
170}
171serverconfig_GameMode_Values() {
172 config_allowed_values=("GameModeSurvivalMP" "GameModeSurvivalSP")
173}
174
175
176
177serverconfig_ZombiesRun_QueryName() {
178 echo "Zombies run"
179}
180serverconfig_ZombiesRun_Type() {
181 echo "number"
182}
183serverconfig_ZombiesRun_Default() {
184 echo "0"
185}
186serverconfig_ZombiesRun_Range() {
187 echo "0-2"
188}
189serverconfig_ZombiesRun_Values() {
190 config_allowed_values=("Default day/night walk/run" "Never run" "Always run")
191}
192
193
194
195serverconfig_BuildCreate_QueryName() {
196 echo "Item spawn menu"
197}
198serverconfig_BuildCreate_Type() {
199 echo "boolean"
200}
201serverconfig_BuildCreate_Default() {
[204]202 echo "false"
[19]203}
204serverconfig_BuildCreate_ErrorMessage() {
205 echo "Not a valid boolean given (true/false or yes/no or y/n)."
206}
207
208
209
210serverconfig_DayNightLength_QueryName() {
211 echo "Length of one day"
212}
213serverconfig_DayNightLength_Type() {
214 echo "number"
215}
216serverconfig_DayNightLength_Default() {
[204]217 echo "40"
[19]218}
219
220
221
222serverconfig_FriendlyFire_QueryName() {
223 echo "Friendly fire"
224}
225serverconfig_FriendlyFire_Type() {
226 echo "boolean"
227}
228serverconfig_FriendlyFire_Default() {
229 echo "false"
230}
231serverconfig_FriendlyFire_ErrorMessage() {
232 echo "Not a valid boolean given (true/false or yes/no or y/n)."
233}
234
235
236
237serverconfig_ControlPanelEnabled_QueryName() {
238 echo "Enable control panel"
239}
240serverconfig_ControlPanelEnabled_Type() {
241 echo "boolean"
242}
243serverconfig_ControlPanelEnabled_Default() {
244 echo "false"
245}
246serverconfig_ControlPanelEnabled_ErrorMessage() {
247 echo "Not a valid boolean given (true/false or yes/no or y/n)."
248}
249
250
251
252serverconfig_ControlPanelPort_QueryName() {
253 echo "Control panel port"
254}
255serverconfig_ControlPanelPort_Type() {
256 echo "number"
257}
258serverconfig_ControlPanelPort_Default() {
259 echo "8080"
260}
261serverconfig_ControlPanelPort_Range() {
262 echo "1024-65535"
263}
264serverconfig_ControlPanelPort_Validate() {
265 local I=${INSTANCE:-!}
266 if [ $(checkTCPPortUsed "$1" "$I") -eq 0 ]; then
267 echo "1"
268 else
269 echo "0"
270 fi
271}
272serverconfig_ControlPanelPort_ErrorMessage() {
273 echo "Illegal port number or port already in use by another instance."
274}
275
276
277
278serverconfig_ControlPanelPassword_QueryName() {
279 echo "Control panel password"
280}
281serverconfig_ControlPanelPassword_Type() {
282 echo "string"
283}
284
285
286
287serverconfig_TelnetPort_QueryName() {
288 echo "Telnet port"
289}
290serverconfig_TelnetPort_Type() {
291 echo "number"
292}
293serverconfig_TelnetPort_Default() {
294 echo "8081"
295}
296serverconfig_TelnetPort_Range() {
297 echo "1024-65535"
298}
299serverconfig_TelnetPort_Validate() {
300 local I=${INSTANCE:-!}
301 if [ $(checkTCPPortUsed "$1" "$I") -eq 0 ]; then
302 echo "1"
303 else
304 echo "0"
305 fi
306}
307serverconfig_TelnetPort_ErrorMessage() {
308 echo "Illegal port number or port already in use by another instance."
309}
310
311
312
313serverconfig_TelnetPassword_QueryName() {
314 echo "Telnet password"
315}
316serverconfig_TelnetPassword_Type() {
317 echo "string"
318}
319
320
321
322serverconfig_DisableNAT_QueryName() {
323 echo "Disable NAT"
324}
325serverconfig_DisableNAT_Type() {
326 echo "boolean"
327}
328serverconfig_DisableNAT_Default() {
329 echo "true"
330}
331serverconfig_DisableNAT_ErrorMessage() {
332 echo "Not a valid boolean given (true/false or yes/no or y/n)."
333}
334
335
336
337
338serverconfig_DropOnDeath_QueryName() {
339 echo "Drop on Death"
340}
341serverconfig_DropOnDeath_Type() {
342 echo "number"
343}
344serverconfig_DropOnDeath_Default() {
345 echo "0"
346}
347serverconfig_DropOnDeath_Range() {
348 echo "0-3"
349}
350serverconfig_DropOnDeath_Values() {
351 config_allowed_values=("Everything" "Toolbelt only" "Backpack only" "Delete all")
352}
353
354
355serverconfig_DropOnQuit_QueryName() {
356 echo "Drop on Quit"
357}
358serverconfig_DropOnQuit_Type() {
359 echo "number"
360}
361serverconfig_DropOnQuit_Default() {
[204]362 echo "1"
[19]363}
364serverconfig_DropOnQuit_Range() {
365 echo "0-3"
366}
367serverconfig_DropOnQuit_Values() {
368 config_allowed_values=("Nothing" "Everything" "Toolbelt only" "Backpack only")
369}
370
371
372
373
374serverconfig_CraftTimer_QueryName() {
375 echo "Craft speed"
376}
377serverconfig_CraftTimer_Type() {
378 echo "number"
379}
380serverconfig_CraftTimer_Default() {
381 echo "1"
382}
383serverconfig_CraftTimer_Range() {
384 echo "0-2"
385}
386serverconfig_CraftTimer_Values() {
387 config_allowed_values=("Instant" "Normal" "Double")
388}
389
390
391serverconfig_LootTimer_QueryName() {
392 echo "Loot open speed"
393}
394serverconfig_LootTimer_Type() {
395 echo "number"
396}
397serverconfig_LootTimer_Default() {
398 echo "1"
399}
400serverconfig_LootTimer_Range() {
401 echo "0-2"
402}
403serverconfig_LootTimer_Values() {
404 config_allowed_values=("Instant" "Normal" "Double")
405}
406
407
408
409
410serverconfig_EnemySenseMemory_QueryName() {
411 echo "Sense memory (seconds)"
412}
413serverconfig_EnemySenseMemory_Type() {
414 echo "number"
415}
416serverconfig_EnemySenseMemory_Default() {
417 echo "60"
418}
419
420
421serverconfig_EnemySpawnMode_QueryName() {
422 echo "Spawn mode"
423}
424serverconfig_EnemySpawnMode_Type() {
425 echo "number"
426}
427serverconfig_EnemySpawnMode_Default() {
428 echo "3"
429}
430serverconfig_EnemySpawnMode_Range() {
431 echo "0-5"
432}
433serverconfig_EnemySpawnMode_Values() {
434 config_allowed_values=("Disabled" "50%" "75%" "100%" "125%" "150%")
435}
436
437
438serverconfig_EnemyDifficulty_QueryName() {
439 echo "Enemy difficulty"
440}
441serverconfig_EnemyDifficulty_Type() {
442 echo "number"
443}
444serverconfig_EnemyDifficulty_Default() {
445 echo "0"
446}
447serverconfig_EnemyDifficulty_Range() {
448 echo "0-1"
449}
450serverconfig_EnemyDifficulty_Values() {
451 config_allowed_values=("Normal" "Feral")
452}
453
454
455
456
457serverconfig_NightPercentage_QueryName() {
458 echo "Night percentage"
459}
460serverconfig_NightPercentage_Type() {
461 echo "number"
462}
463serverconfig_NightPercentage_Default() {
464 echo "35"
465}
466serverconfig_NightPercentage_Range() {
467 echo "10-90"
468}
469
470
471
472serverconfig_BlockDurabilityModifier_QueryName() {
473 echo "Block durability (%)"
474}
475serverconfig_BlockDurabilityModifier_Type() {
476 echo "number"
477}
478serverconfig_BlockDurabilityModifier_Default() {
479 echo "100"
480}
481
482
483
484
485serverconfig_LootAbundance_QueryName() {
486 echo "Loot abundance (%)"
487}
488serverconfig_LootAbundance_Type() {
489 echo "number"
490}
491serverconfig_LootAbundance_Default() {
492 echo "100"
493}
494
495
496serverconfig_LootRespawnDays_QueryName() {
497 echo "Loot respawn delay (days)"
498}
499serverconfig_LootRespawnDays_Type() {
500 echo "number"
501}
502serverconfig_LootRespawnDays_Default() {
503 echo "7"
504}
505
506
507
508
509serverconfig_LandClaimSize_QueryName() {
510 echo "Land claim size"
511}
512serverconfig_LandClaimSize_Type() {
513 echo "number"
514}
515serverconfig_LandClaimSize_Default() {
516 echo "7"
517}
518
519
520serverconfig_LandClaimDeadZone_QueryName() {
521 echo "Minimum keystone distance"
522}
523serverconfig_LandClaimDeadZone_Type() {
524 echo "number"
525}
526serverconfig_LandClaimDeadZone_Default() {
527 echo "30"
528}
529
530
531serverconfig_LandClaimExpiryTime_QueryName() {
532 echo "Claim expiry time (days)"
533}
534serverconfig_LandClaimExpiryTime_Type() {
535 echo "number"
536}
537serverconfig_LandClaimExpiryTime_Default() {
538 echo "3"
539}
540
541
542serverconfig_LandClaimDecayMode_QueryName() {
543 echo "Claim decay mode"
544}
545serverconfig_LandClaimDecayMode_Type() {
546 echo "number"
547}
548serverconfig_LandClaimDecayMode_Default() {
549 echo "0"
550}
551serverconfig_LandClaimDecayMode_Range() {
552 echo "0-2"
553}
554serverconfig_LandClaimDecayMode_Values() {
555 config_allowed_values=("Linear" "Exponential" "Full protection")
556}
557
558
559serverconfig_LandClaimOnlineDurabilityModifier_QueryName() {
560 echo "Claim durability modifier - online"
561}
562serverconfig_LandClaimOnlineDurabilityModifier_Type() {
563 echo "number"
564}
565serverconfig_LandClaimOnlineDurabilityModifier_Default() {
566 echo "4"
567}
568
569
570serverconfig_LandClaimOfflineDurabilityModifier_QueryName() {
571 echo "Claim durability modifier - offline"
572}
573serverconfig_LandClaimOfflineDurabilityModifier_Type() {
574 echo "number"
575}
576serverconfig_LandClaimOfflineDurabilityModifier_Default() {
577 echo "4"
578}
579
580
581
582
583serverconfig_AirDropFrequency_QueryName() {
584 echo "Airdrop delay (hours)"
585}
586serverconfig_AirDropFrequency_Type() {
587 echo "number"
588}
589serverconfig_AirDropFrequency_Default() {
[204]590 echo "72"
[19]591}
592
593
[67]594serverconfig_MaxSpawnedZombies_QueryName() {
595 echo "Maximum number of concurrent zombies"
596}
597serverconfig_MaxSpawnedZombies_Type() {
598 echo "number"
599}
600serverconfig_MaxSpawnedZombies_Default() {
601 echo "60"
602}
[19]603
604
[204]605serverconfig_EACEnabled_QueryName() {
606 echo "Enable EasyAntiCheat"
[67]607}
[204]608serverconfig_EACEnabled_Type() {
[67]609 echo "boolean"
610}
[204]611serverconfig_EACEnabled_Default() {
[67]612 echo "true"
613}
[204]614serverconfig_EACEnabled_ErrorMessage() {
[67]615 echo "Not a valid boolean given (true/false or yes/no or y/n)."
616}
617
618
619
620
[23]621#################################
622## Edit option functions
623
624configEditServer() {
625 local CV
626
627 echo "Server"
628 echo "--------------------------------"
629 for CV in \
[204]630 ServerName ServerPassword ServerIsPublic ServerPort ServerMaxPlayerCount ServerDescription ServerWebsiteURL \
631 DisableNAT EACEnabled MaxSpawnedZombies \
[23]632 ; do
[24]633 $1 $CV
[23]634 done
635 echo
636}
637
638configEditRemoteControl() {
639 local CV
640
641 echo "Remote control"
642 echo "--------------------------------"
643 for CV in \
644 ControlPanelEnabled ControlPanelPort ControlPanelPassword \
645 TelnetPort TelnetPassword \
646 ; do
647 if [ "$CV" = "TelnetPort" ]; then
648 echo
649 echo "NOTE: Telnet will always be enabled for management purposes!"
[88]650 echo "Make sure you block external access to this port or set no password"
651 echo "so the server will only listen on the loopback interface!"
[23]652 echo
653 fi
[24]654 $1 $CV
[23]655 done
656 echo
657}
658
659configEditGameType() {
660 local CV
661
662 echo "Game type"
663 echo "--------------------------------"
664 for CV in \
665 GameName GameWorld GameMode \
666 ; do
[24]667 $1 $CV
[23]668 done
669 echo
670}
671
672configEditGeneric() {
673 local CV
674
675 echo "Generic options"
676 echo "--------------------------------"
677 for CV in \
[204]678 FriendlyFire BuildCreate \
[23]679 BlockDurabilityModifier \
680 ; do
[24]681 $1 $CV
[23]682 done
683 echo
684}
685
686configEditDropLoot() {
687 local CV
688
689 echo "Drop and Loot"
690 echo "--------------------------------"
691 for CV in \
692 DropOnDeath DropOnQuit \
693 LootAbundance LootRespawnDays AirDropFrequency \
694 ; do
[24]695 $1 $CV
[23]696 done
697 echo
698}
699
700configEditTimes() {
701 local CV
702
703 echo "Times / Durations"
704 echo "--------------------------------"
705 for CV in \
706 CraftTimer LootTimer \
707 DayNightLength NightPercentage \
708 ; do
[24]709 $1 $CV
[23]710 done
711 echo
712}
713
714configEditDifficulty() {
715 local CV
716
717 echo "Difficulty"
718 echo "--------------------------------"
719 for CV in \
720 GameDifficulty ZombiesRun \
[204]721 EnemySenseMemory EnemySpawnMode EnemyDifficulty \
[23]722 ; do
[24]723 $1 $CV
[23]724 done
725 echo
726}
727
728configEditLandClaim() {
729 local CV
730
731 echo "Land claim options"
732 echo "--------------------------------"
733 for CV in \
734 LandClaimSize LandClaimDeadZone LandClaimExpiryTime LandClaimDecayMode \
735 LandClaimOnlineDurabilityModifier LandClaimOfflineDurabilityModifier \
736 ; do
[24]737 $1 $CV
[23]738 done
739 echo
740}
741
742configEditAll() {
[24]743 configEditServer "$1"
744 configEditRemoteControl "$1"
745 configEditGameType "$1"
746 configEditGeneric "$1"
747 configEditDropLoot "$1"
748 configEditTimes "$1"
749 configEditDifficulty "$1"
750 configEditLandClaim "$1"
[23]751}
752
753
754
755
756
757#################################
758## Generic worker functions
759
760
761# List all defined config editing parts
762# Returns:
763# List of config funcs
764listConfigEditFuncs() {
765 local CV
766 for CV in $(declare -F | cut -d\ -f3 | grep "^configEdit.*$"); do
767 CV=${CV#configEdit}
768 printf "%s " "$CV"
769 done
770}
771
772
773# List all defined config options
774# Returns:
775# List of defined config options
[19]776listConfigValues() {
777 local CV
778 for CV in $(declare -F | cut -d\ -f3 | grep "^serverconfig_.*_Type$"); do
779 CV=${CV#serverconfig_}
780 CV=${CV%_Type}
781 printf "%s " "$CV"
782 done
783}
784
785
[23]786# Validate the given value for the given option
787# Params:
788# 1: Option name
789# 2: Value
790# Returns:
791# 0/1: invalid/valid
[19]792isValidOptionValue() {
793 local TYPE=$(serverconfig_$1_Type)
794 local RANGE=""
795
796 if [ "$TYPE" = "enum" ]; then
797 TYPE="number"
798 serverconfig_$1_Values
799 RANGE=1-${#config_allowed_values[@]}
800 else
801 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
802 RANGE=$(serverconfig_$1_Range)
803 fi
804 fi
805
806 case "$TYPE" in
807 number)
808 if [ $(isANumber "$2") -eq 0 ]; then
809 echo "0"
810 return
811 fi
812 if [ ! -z "$RANGE" ]; then
813 local MIN=$(cut -d- -f1 <<< "$RANGE")
814 local MAX=$(cut -d- -f2 <<< "$RANGE")
815 if [ $2 -lt $MIN -o $2 -gt $MAX ]; then
816 echo "0"
817 return
818 fi
819 fi
820 ;;
821 boolean)
822 if [ $(isABool "$2") -eq 0 ]; then
823 echo "0"
824 return
825 fi
826 ;;
827 string)
828 ;;
829 esac
830
831
832 if [ "$(type -t serverconfig_$1_Validate)" = "function" ]; then
833 if [ $(serverconfig_$1_Validate "$2") -eq 0 ]; then
834 echo "0"
835 return
836 fi
837 fi
838
839 echo "1"
840}
841
[23]842# Query for the value of a single config option
843# Will be stored in $configCurrent_$1
844# Params:
845# 1: Option name
[19]846configQueryValue() {
847 local TYPE=$(serverconfig_$1_Type)
848 local NAME=""
849 local RANGE=""
850 local DEFAULT=""
851 local currentValName=configCurrent_$1
852
853 if [ "$(type -t serverconfig_$1_Values)" = "function" ]; then
854 echo "$(serverconfig_$1_QueryName), options:"
855 serverconfig_$1_Values
856 NAME="Select option"
857 if [ "$TYPE" = "enum" ]; then
858 local OPTOFFSET=1
859 else
860 local OPTOFFSET=0
861 fi
862 for (( i=$OPTOFFSET; i < ${#config_allowed_values[@]}+$OPTOFFSET; i++ )); do
863 printf " %2d: %s\n" $i "${config_allowed_values[$i-$OPTOFFSET]}"
864 done
865 else
866 NAME=$(serverconfig_$1_QueryName)
867 fi
868
869 if [ "$TYPE" = "enum" ]; then
870 RANGE=1-${#config_allowed_values[@]}
871 if [ ! -z "${!currentValName}" ]; then
872 for (( i=1; i < ${#config_allowed_values[@]}+1; i++ )); do
873 if [ "${!currentValName}" = "${config_allowed_values[$i-1]}" ]; then
874 DEFAULT=$i
875 fi
876 done
877 export $currentValName=
878 fi
879 else
880 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
881 RANGE=$(serverconfig_$1_Range)
882 fi
883 fi
884
885 if [ -z "$DEFAULT" ]; then
886 if [ ! -z "${!currentValName}" ]; then
887 DEFAULT=${!currentValName}
888 else
889 if [ "$(type -t serverconfig_$1_Default)" = "function" ]; then
890 DEFAULT=$(serverconfig_$1_Default)
891 fi
892 fi
893 fi
894
895 local prompt=$(printf "%s" "$NAME")
896 if [ ! -z "$RANGE" ]; then
897 prompt=$(printf "%s (%s)" "$prompt" "$RANGE")
898 fi
899 if [ ! -z "$DEFAULT" ]; then
900 prompt=$(printf "%s [%s]" "$prompt" "$DEFAULT")
901 fi
902 prompt=$(printf "%s:" "$prompt")
[24]903 prompt=$(printf "%-*s " 40 "$prompt")
[19]904
905 while : ; do
906 read -p "$prompt" $currentValName
907 export $currentValName="${!currentValName:-$DEFAULT}"
908 if [ $(isValidOptionValue "$1" "${!currentValName}") -eq 0 ]; then
909 if [ "$(type -t serverconfig_$1_ErrorMessage)" = "function" ]; then
910 serverconfig_$1_ErrorMessage "${!currentValName}"
911 fi
912 fi
913 [ $(isValidOptionValue "$1" "${!currentValName}") -eq 1 ] && break
914 done
915
[45]916 if [ "$TYPE" = "boolean" ]; then
917 if [ $(getBool ${!currentValName}) -eq 1 ]; then
918 export $currentValName="true"
919 else
920 export $currentValName="false"
921 fi
922 fi
[19]923 if [ "$TYPE" = "enum" ]; then
924 export $currentValName="${config_allowed_values[$currentValName-1]}"
925 fi
[24]926 echo
[19]927}
928
[23]929# Set parameters for current instance that have forced values:
930# - TelnetEnabled must be set so that management scripts can work
931# - AdminFileName is made to point to the local instance admins.xml
932# - SaveGameFolder is made to point to the instance folder
933# Params:
[19]934# 1: Instance name
935configSetAutoParameters() {
936 configCurrent_TelnetEnabled=true
937 configCurrent_AdminFileName=admins.xml
[35]938 configCurrent_SaveGameFolder="$(getInstancePath "$1")"
[19]939}
940
941
[24]942# Print defined config value
943# Params:
944# 1: Config option
945printConfigValue() {
946 local currentValName=configCurrent_$1
947 printf "%-25s = %s\n" "$(serverconfig_$1_QueryName)" "${!currentValName}"
[19]948}
949
[23]950# Query for an instance name (will be saved in $INSTANCE)
[19]951readInstanceName() {
952 until [ $(isValidInstanceName "$INSTANCE") -eq 1 ]; do
953 read -p "Instance name: " INSTANCE
954 if [ $(isValidInstanceName "$INSTANCE") -eq 0 ]; then
955 echo "Invalid instance name, may only contain:"
956 echo " - letters (A-Z / a-z)"
957 echo " - digits (0-9)"
958 echo " - underscores (_)"
959 echo " - hyphens (-)"
960 fi
961 done
962}
963
[23]964# Undefine the current config values
[19]965unsetAllConfigValues() {
966 local CV
967 for CV in $(listConfigValues); do
968 local currentValName=configCurrent_$CV
969 export $currentValName=
970 done
971}
972
[23]973# Load all config values from the config.xml of the given instance
974# Params:
[19]975# 1: Instance name
976loadCurrentConfigValues() {
977 local CV
978 for CV in $(listConfigValues); do
979 local currentValName=configCurrent_$CV
980 local cfile=$(getInstancePath "$1")/config.xml
981 local XPATH="/ServerSettings/property[@name='$CV']/@value"
982 local VAL=$($XMLSTARLET sel -t -v "$XPATH" $cfile)
983 if [ ! -z "$VAL" ]; then
984 export $currentValName="$VAL"
985 fi
986 done
987}
988
[23]989# Save all config values to the config.xml of the given instance
990# Params:
[19]991# 1: Instance name
992saveCurrentConfigValues() {
993 local CV
994 for CV in $(listConfigValues) TelnetEnabled AdminFileName SaveGameFolder; do
995 local currentValName=configCurrent_$CV
996 local val="${!currentValName}"
997 local cfile=$(getInstancePath "$1")/config.xml
998
999 XPATHBASE="/ServerSettings/property[@name='$CV']"
1000
1001 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@name" $cfile) ]; then
1002 $XMLSTARLET ed -L \
1003 -s "/ServerSettings" -t elem -n "property" -v "" \
1004 -i "/ServerSettings/property[not(@name)]" -t attr -n "name" -v "$CV" \
1005 -i "$XPATHBASE" -t attr -n "value" -v "$val" \
1006 $cfile
1007 else
1008 $XMLSTARLET ed -L \
1009 -u "$XPATHBASE/@value" -v "$val" \
1010 $cfile
1011 fi
1012 done
1013}
1014
[23]1015# Check if the config template exists
1016# Returns:
1017# 0/1: no/yes
[19]1018configTemplateExists() {
1019 if [ -f $SDTD_BASE/templates/config.xml ]; then
1020 echo 1
1021 else
1022 echo 0
1023 fi
1024}
1025
1026# Get a single value from a serverconfig
1027# Params:
1028# 1: Instance name
1029# 2: Property name
1030# Returns:
1031# Property value
1032getConfigValue() {
1033 local CONF=$(getInstancePath $1)/config.xml
1034 $XMLSTARLET sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
1035}
1036
1037# Update a single value in a serverconfig
1038# Params:
1039# 1: Instance name
1040# 2: Property name
1041# 3: New value
1042setConfigValue() {
1043 local CONF=$(getInstancePath $1)/config.xml
1044 $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
1045}
1046
Note: See TracBrowser for help on using the repository browser.