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

Last change on this file since 261 was 258, checked in by alloc, 9 years ago

Scripts: License

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