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

Last change on this file since 300 was 296, checked in by alloc, 8 years ago

Fixes 105

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