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

Last change on this file since 302 was 302, checked in by alloc, 7 years ago

v107

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