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

Last change on this file since 32 was 24, checked in by alloc, 11 years ago

Version 7: Added 'instances print_config <instance>'

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