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

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

v25: Fixes #22, #23. Also adds new serverconfig options

File size: 21.8 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
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
[67]686serverconfig_MaxSpawnedZombies_QueryName() {
687 echo "Maximum number of concurrent zombies"
688}
689serverconfig_MaxSpawnedZombies_Type() {
690 echo "number"
691}
692serverconfig_MaxSpawnedZombies_Default() {
693 echo "60"
694}
[19]695
696
[67]697serverconfig_VACEnabled_QueryName() {
698 echo "Enable Valve Anti Cheat"
699}
700serverconfig_VACEnabled_Type() {
701 echo "boolean"
702}
703serverconfig_VACEnabled_Default() {
704 echo "true"
705}
706serverconfig_VACEnabled_ErrorMessage() {
707 echo "Not a valid boolean given (true/false or yes/no or y/n)."
708}
709
710
711
712
[23]713#################################
714## Edit option functions
715
716configEditServer() {
717 local CV
718
719 echo "Server"
720 echo "--------------------------------"
721 for CV in \
722 ServerName ServerPassword ServerIsPublic ServerPort ServerMaxPlayerCount \
[67]723 DisableNAT VACEnabled MaxSpawnedZombies \
[23]724 ; do
[24]725 $1 $CV
[23]726 done
727 echo
728}
729
730configEditRemoteControl() {
731 local CV
732
733 echo "Remote control"
734 echo "--------------------------------"
735 for CV in \
736 ControlPanelEnabled ControlPanelPort ControlPanelPassword \
737 TelnetPort TelnetPassword \
738 ; do
739 if [ "$CV" = "TelnetPort" ]; then
740 echo
741 echo "NOTE: Telnet will always be enabled for management purposes!"
742 echo "Make sure you block external access to this port!"
743 echo
744 fi
[24]745 $1 $CV
[23]746 done
747 echo
748}
749
750configEditGameType() {
751 local CV
752
753 echo "Game type"
754 echo "--------------------------------"
755 for CV in \
756 GameName GameWorld GameMode \
757 ; do
[24]758 $1 $CV
[23]759 done
760 echo
761}
762
763configEditGameTypeSpecific() {
764 local CV
765
766 echo "Options for specific game types"
767 echo "--------------------------------"
768 for CV in \
769 DayCount FragLimit MatchLength RebuildMap \
770 ; do
[24]771 $1 $CV
[23]772 done
773 echo
774}
775
776configEditGeneric() {
777 local CV
778
779 echo "Generic options"
780 echo "--------------------------------"
781 for CV in \
782 ShowAllPlayersOnMap FriendlyFire BuildCreate \
783 BlockDurabilityModifier \
784 ; do
[24]785 $1 $CV
[23]786 done
787 echo
788}
789
790configEditDropLoot() {
791 local CV
792
793 echo "Drop and Loot"
794 echo "--------------------------------"
795 for CV in \
796 DropOnDeath DropOnQuit \
797 LootAbundance LootRespawnDays AirDropFrequency \
798 ; do
[24]799 $1 $CV
[23]800 done
801 echo
802}
803
804configEditTimes() {
805 local CV
806
807 echo "Times / Durations"
808 echo "--------------------------------"
809 for CV in \
810 CraftTimer LootTimer \
811 DayNightLength NightPercentage \
812 ; do
[24]813 $1 $CV
[23]814 done
815 echo
816}
817
818configEditDifficulty() {
819 local CV
820
821 echo "Difficulty"
822 echo "--------------------------------"
823 for CV in \
824 GameDifficulty ZombiesRun \
825 PlayerDamageGiven PlayerDamageRecieved EnemySenseMemory EnemySpawnMode EnemyDifficulty \
826 ; do
[24]827 $1 $CV
[23]828 done
829 echo
830}
831
832configEditLandClaim() {
833 local CV
834
835 echo "Land claim options"
836 echo "--------------------------------"
837 for CV in \
838 LandClaimSize LandClaimDeadZone LandClaimExpiryTime LandClaimDecayMode \
839 LandClaimOnlineDurabilityModifier LandClaimOfflineDurabilityModifier \
840 ; do
[24]841 $1 $CV
[23]842 done
843 echo
844}
845
846configEditAll() {
[24]847 configEditServer "$1"
848 configEditRemoteControl "$1"
849 configEditGameType "$1"
850 configEditGameTypeSpecific "$1"
851 configEditGeneric "$1"
852 configEditDropLoot "$1"
853 configEditTimes "$1"
854 configEditDifficulty "$1"
855 configEditLandClaim "$1"
[23]856}
857
858
859
860
861
862#################################
863## Generic worker functions
864
865
866# List all defined config editing parts
867# Returns:
868# List of config funcs
869listConfigEditFuncs() {
870 local CV
871 for CV in $(declare -F | cut -d\ -f3 | grep "^configEdit.*$"); do
872 CV=${CV#configEdit}
873 printf "%s " "$CV"
874 done
875}
876
877
878# List all defined config options
879# Returns:
880# List of defined config options
[19]881listConfigValues() {
882 local CV
883 for CV in $(declare -F | cut -d\ -f3 | grep "^serverconfig_.*_Type$"); do
884 CV=${CV#serverconfig_}
885 CV=${CV%_Type}
886 printf "%s " "$CV"
887 done
888}
889
890
[23]891# Validate the given value for the given option
892# Params:
893# 1: Option name
894# 2: Value
895# Returns:
896# 0/1: invalid/valid
[19]897isValidOptionValue() {
898 local TYPE=$(serverconfig_$1_Type)
899 local RANGE=""
900
901 if [ "$TYPE" = "enum" ]; then
902 TYPE="number"
903 serverconfig_$1_Values
904 RANGE=1-${#config_allowed_values[@]}
905 else
906 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
907 RANGE=$(serverconfig_$1_Range)
908 fi
909 fi
910
911 case "$TYPE" in
912 number)
913 if [ $(isANumber "$2") -eq 0 ]; then
914 echo "0"
915 return
916 fi
917 if [ ! -z "$RANGE" ]; then
918 local MIN=$(cut -d- -f1 <<< "$RANGE")
919 local MAX=$(cut -d- -f2 <<< "$RANGE")
920 if [ $2 -lt $MIN -o $2 -gt $MAX ]; then
921 echo "0"
922 return
923 fi
924 fi
925 ;;
926 boolean)
927 if [ $(isABool "$2") -eq 0 ]; then
928 echo "0"
929 return
930 fi
931 ;;
932 string)
933 ;;
934 esac
935
936
937 if [ "$(type -t serverconfig_$1_Validate)" = "function" ]; then
938 if [ $(serverconfig_$1_Validate "$2") -eq 0 ]; then
939 echo "0"
940 return
941 fi
942 fi
943
944 echo "1"
945}
946
[23]947# Query for the value of a single config option
948# Will be stored in $configCurrent_$1
949# Params:
950# 1: Option name
[19]951configQueryValue() {
952 local TYPE=$(serverconfig_$1_Type)
953 local NAME=""
954 local RANGE=""
955 local DEFAULT=""
956 local currentValName=configCurrent_$1
957
958 if [ "$(type -t serverconfig_$1_Values)" = "function" ]; then
959 echo "$(serverconfig_$1_QueryName), options:"
960 serverconfig_$1_Values
961 NAME="Select option"
962 if [ "$TYPE" = "enum" ]; then
963 local OPTOFFSET=1
964 else
965 local OPTOFFSET=0
966 fi
967 for (( i=$OPTOFFSET; i < ${#config_allowed_values[@]}+$OPTOFFSET; i++ )); do
968 printf " %2d: %s\n" $i "${config_allowed_values[$i-$OPTOFFSET]}"
969 done
970 else
971 NAME=$(serverconfig_$1_QueryName)
972 fi
973
974 if [ "$TYPE" = "enum" ]; then
975 RANGE=1-${#config_allowed_values[@]}
976 if [ ! -z "${!currentValName}" ]; then
977 for (( i=1; i < ${#config_allowed_values[@]}+1; i++ )); do
978 if [ "${!currentValName}" = "${config_allowed_values[$i-1]}" ]; then
979 DEFAULT=$i
980 fi
981 done
982 export $currentValName=
983 fi
984 else
985 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
986 RANGE=$(serverconfig_$1_Range)
987 fi
988 fi
989
990 if [ -z "$DEFAULT" ]; then
991 if [ ! -z "${!currentValName}" ]; then
992 DEFAULT=${!currentValName}
993 else
994 if [ "$(type -t serverconfig_$1_Default)" = "function" ]; then
995 DEFAULT=$(serverconfig_$1_Default)
996 fi
997 fi
998 fi
999
1000 local prompt=$(printf "%s" "$NAME")
1001 if [ ! -z "$RANGE" ]; then
1002 prompt=$(printf "%s (%s)" "$prompt" "$RANGE")
1003 fi
1004 if [ ! -z "$DEFAULT" ]; then
1005 prompt=$(printf "%s [%s]" "$prompt" "$DEFAULT")
1006 fi
1007 prompt=$(printf "%s:" "$prompt")
[24]1008 prompt=$(printf "%-*s " 40 "$prompt")
[19]1009
1010 while : ; do
1011 read -p "$prompt" $currentValName
1012 export $currentValName="${!currentValName:-$DEFAULT}"
1013 if [ $(isValidOptionValue "$1" "${!currentValName}") -eq 0 ]; then
1014 if [ "$(type -t serverconfig_$1_ErrorMessage)" = "function" ]; then
1015 serverconfig_$1_ErrorMessage "${!currentValName}"
1016 fi
1017 fi
1018 [ $(isValidOptionValue "$1" "${!currentValName}") -eq 1 ] && break
1019 done
1020
[45]1021 if [ "$TYPE" = "boolean" ]; then
1022 if [ $(getBool ${!currentValName}) -eq 1 ]; then
1023 export $currentValName="true"
1024 else
1025 export $currentValName="false"
1026 fi
1027 fi
[19]1028 if [ "$TYPE" = "enum" ]; then
1029 export $currentValName="${config_allowed_values[$currentValName-1]}"
1030 fi
[24]1031 echo
[19]1032}
1033
[23]1034# Set parameters for current instance that have forced values:
1035# - TelnetEnabled must be set so that management scripts can work
1036# - AdminFileName is made to point to the local instance admins.xml
1037# - SaveGameFolder is made to point to the instance folder
1038# Params:
[19]1039# 1: Instance name
1040configSetAutoParameters() {
1041 configCurrent_TelnetEnabled=true
1042 configCurrent_AdminFileName=admins.xml
[35]1043 configCurrent_SaveGameFolder="$(getInstancePath "$1")"
[19]1044}
1045
1046
[24]1047# Print defined config value
1048# Params:
1049# 1: Config option
1050printConfigValue() {
1051 local currentValName=configCurrent_$1
1052 printf "%-25s = %s\n" "$(serverconfig_$1_QueryName)" "${!currentValName}"
[19]1053}
1054
[23]1055# Query for an instance name (will be saved in $INSTANCE)
[19]1056readInstanceName() {
1057 until [ $(isValidInstanceName "$INSTANCE") -eq 1 ]; do
1058 read -p "Instance name: " INSTANCE
1059 if [ $(isValidInstanceName "$INSTANCE") -eq 0 ]; then
1060 echo "Invalid instance name, may only contain:"
1061 echo " - letters (A-Z / a-z)"
1062 echo " - digits (0-9)"
1063 echo " - underscores (_)"
1064 echo " - hyphens (-)"
1065 fi
1066 done
1067}
1068
[23]1069# Undefine the current config values
[19]1070unsetAllConfigValues() {
1071 local CV
1072 for CV in $(listConfigValues); do
1073 local currentValName=configCurrent_$CV
1074 export $currentValName=
1075 done
1076}
1077
[23]1078# Load all config values from the config.xml of the given instance
1079# Params:
[19]1080# 1: Instance name
1081loadCurrentConfigValues() {
1082 local CV
1083 for CV in $(listConfigValues); do
1084 local currentValName=configCurrent_$CV
1085 local cfile=$(getInstancePath "$1")/config.xml
1086 local XPATH="/ServerSettings/property[@name='$CV']/@value"
1087 local VAL=$($XMLSTARLET sel -t -v "$XPATH" $cfile)
1088 if [ ! -z "$VAL" ]; then
1089 export $currentValName="$VAL"
1090 fi
1091 done
1092}
1093
[23]1094# Save all config values to the config.xml of the given instance
1095# Params:
[19]1096# 1: Instance name
1097saveCurrentConfigValues() {
1098 local CV
1099 for CV in $(listConfigValues) TelnetEnabled AdminFileName SaveGameFolder; do
1100 local currentValName=configCurrent_$CV
1101 local val="${!currentValName}"
1102 local cfile=$(getInstancePath "$1")/config.xml
1103
1104 XPATHBASE="/ServerSettings/property[@name='$CV']"
1105
1106 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@name" $cfile) ]; then
1107 $XMLSTARLET ed -L \
1108 -s "/ServerSettings" -t elem -n "property" -v "" \
1109 -i "/ServerSettings/property[not(@name)]" -t attr -n "name" -v "$CV" \
1110 -i "$XPATHBASE" -t attr -n "value" -v "$val" \
1111 $cfile
1112 else
1113 $XMLSTARLET ed -L \
1114 -u "$XPATHBASE/@value" -v "$val" \
1115 $cfile
1116 fi
1117 done
1118}
1119
[23]1120# Check if the config template exists
1121# Returns:
1122# 0/1: no/yes
[19]1123configTemplateExists() {
1124 if [ -f $SDTD_BASE/templates/config.xml ]; then
1125 echo 1
1126 else
1127 echo 0
1128 fi
1129}
1130
1131# Get a single value from a serverconfig
1132# Params:
1133# 1: Instance name
1134# 2: Property name
1135# Returns:
1136# Property value
1137getConfigValue() {
1138 local CONF=$(getInstancePath $1)/config.xml
1139 $XMLSTARLET sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
1140}
1141
1142# Update a single value in a serverconfig
1143# Params:
1144# 1: Instance name
1145# 2: Property name
1146# 3: New value
1147setConfigValue() {
1148 local CONF=$(getInstancePath $1)/config.xml
1149 $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
1150}
1151
Note: See TracBrowser for help on using the repository browser.