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

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

v.44: Update for alpha 9

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