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

Last change on this file since 280 was 262, checked in by alloc, 9 years ago

v98

File size: 19.8 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_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() {
135 config_allowed_values=("Random Gen" "Navezgane" "MP Wasteland Horde" "MP Wasteland Skirmish" "MP Wasteland War")
136}
137
138
139
140serverconfig_GameName_QueryName() {
141 echo "Random gen seed"
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() {
154 echo "Seed cannot be empty."
155}
156
157
158
159serverconfig_GameDifficulty_QueryName() {
160 echo "Difficulty (+ damage given / received)"
161}
162serverconfig_GameDifficulty_Type() {
163 echo "number"
164}
165serverconfig_GameDifficulty_Default() {
166 echo "2"
167}
168serverconfig_GameDifficulty_Range() {
169 echo "0-5"
170}
171serverconfig_GameDifficulty_Values() {
172 config_allowed_values=("Scavenger (200% / 50%)" "Adventurer (150% / 75%)" "Nomad (100% / 100%)" "Warrior (75% / 150%)" "Survivalist (50% / 200%)" "Insane (25% / 250%)")
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() {
217 echo "false"
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() {
232 echo "40"
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() {
361 echo "1"
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_EnemySenseMemory_QueryName() {
374 echo "Sense memory (seconds)"
375}
376serverconfig_EnemySenseMemory_Type() {
377 echo "number"
378}
379serverconfig_EnemySenseMemory_Default() {
380 echo "60"
381}
382
383
384serverconfig_EnemySpawnMode_QueryName() {
385 echo "Spawn mode"
386}
387serverconfig_EnemySpawnMode_Type() {
388 echo "number"
389}
390serverconfig_EnemySpawnMode_Default() {
391 echo "3"
392}
393serverconfig_EnemySpawnMode_Range() {
394 echo "0-5"
395}
396serverconfig_EnemySpawnMode_Values() {
397 config_allowed_values=("Disabled" "50%" "75%" "100%" "125%" "150%")
398}
399
400
401serverconfig_EnemyDifficulty_QueryName() {
402 echo "Enemy difficulty"
403}
404serverconfig_EnemyDifficulty_Type() {
405 echo "number"
406}
407serverconfig_EnemyDifficulty_Default() {
408 echo "0"
409}
410serverconfig_EnemyDifficulty_Range() {
411 echo "0-1"
412}
413serverconfig_EnemyDifficulty_Values() {
414 config_allowed_values=("Normal" "Feral")
415}
416
417
418
419
420serverconfig_DayLightLength_QueryName() {
421 echo "Day length"
422}
423serverconfig_DayLightLength_Type() {
424 echo "number"
425}
426serverconfig_DayLightLength_Default() {
427 echo "18"
428}
429serverconfig_DayLightLength_Range() {
430 echo "0-24"
431}
432
433
434
435serverconfig_BlockDurabilityModifier_QueryName() {
436 echo "Block durability (%)"
437}
438serverconfig_BlockDurabilityModifier_Type() {
439 echo "number"
440}
441serverconfig_BlockDurabilityModifier_Default() {
442 echo "100"
443}
444
445
446
447
448serverconfig_LootAbundance_QueryName() {
449 echo "Loot abundance (%)"
450}
451serverconfig_LootAbundance_Type() {
452 echo "number"
453}
454serverconfig_LootAbundance_Default() {
455 echo "100"
456}
457
458
459serverconfig_LootRespawnDays_QueryName() {
460 echo "Loot respawn delay (days)"
461}
462serverconfig_LootRespawnDays_Type() {
463 echo "number"
464}
465serverconfig_LootRespawnDays_Default() {
466 echo "7"
467}
468
469
470
471
472serverconfig_LandClaimSize_QueryName() {
473 echo "Land claim size"
474}
475serverconfig_LandClaimSize_Type() {
476 echo "number"
477}
478serverconfig_LandClaimSize_Default() {
479 echo "7"
480}
481
482
483serverconfig_LandClaimDeadZone_QueryName() {
484 echo "Minimum keystone distance"
485}
486serverconfig_LandClaimDeadZone_Type() {
487 echo "number"
488}
489serverconfig_LandClaimDeadZone_Default() {
490 echo "30"
491}
492
493
494serverconfig_LandClaimExpiryTime_QueryName() {
495 echo "Claim expiry time (days)"
496}
497serverconfig_LandClaimExpiryTime_Type() {
498 echo "number"
499}
500serverconfig_LandClaimExpiryTime_Default() {
501 echo "3"
502}
503
504
505serverconfig_LandClaimDecayMode_QueryName() {
506 echo "Claim decay mode"
507}
508serverconfig_LandClaimDecayMode_Type() {
509 echo "number"
510}
511serverconfig_LandClaimDecayMode_Default() {
512 echo "0"
513}
514serverconfig_LandClaimDecayMode_Range() {
515 echo "0-2"
516}
517serverconfig_LandClaimDecayMode_Values() {
518 config_allowed_values=("Linear" "Exponential" "Full protection")
519}
520
521
522serverconfig_LandClaimOnlineDurabilityModifier_QueryName() {
523 echo "Claim durability modifier - online"
524}
525serverconfig_LandClaimOnlineDurabilityModifier_Type() {
526 echo "number"
527}
528serverconfig_LandClaimOnlineDurabilityModifier_Default() {
529 echo "4"
530}
531
532
533serverconfig_LandClaimOfflineDurabilityModifier_QueryName() {
534 echo "Claim durability modifier - offline"
535}
536serverconfig_LandClaimOfflineDurabilityModifier_Type() {
537 echo "number"
538}
539serverconfig_LandClaimOfflineDurabilityModifier_Default() {
540 echo "4"
541}
542
543
544
545
546serverconfig_AirDropFrequency_QueryName() {
547 echo "Airdrop delay (hours)"
548}
549serverconfig_AirDropFrequency_Type() {
550 echo "number"
551}
552serverconfig_AirDropFrequency_Default() {
553 echo "72"
554}
555
556
557serverconfig_MaxSpawnedZombies_QueryName() {
558 echo "Maximum number of concurrent zombies"
559}
560serverconfig_MaxSpawnedZombies_Type() {
561 echo "number"
562}
563serverconfig_MaxSpawnedZombies_Default() {
564 echo "60"
565}
566
567
568serverconfig_EACEnabled_QueryName() {
569 echo "Enable EasyAntiCheat"
570}
571serverconfig_EACEnabled_Type() {
572 echo "boolean"
573}
574serverconfig_EACEnabled_Default() {
575 echo "true"
576}
577serverconfig_EACEnabled_ErrorMessage() {
578 echo "Not a valid boolean given (true/false or yes/no or y/n)."
579}
580
581
582
583
584#################################
585## Edit option functions
586
587configEditServer() {
588 local CV
589
590 echo "Server"
591 echo "--------------------------------"
592 for CV in \
593 ServerName ServerPassword ServerIsPublic ServerPort ServerMaxPlayerCount ServerDescription ServerWebsiteURL \
594 EACEnabled MaxSpawnedZombies \
595 ; do
596 $1 $CV
597 done
598 echo
599}
600
601configEditRemoteControl() {
602 local CV
603
604 echo "Remote control"
605 echo "--------------------------------"
606 for CV in \
607 ControlPanelEnabled ControlPanelPort ControlPanelPassword \
608 TelnetPort TelnetPassword \
609 ; do
610 if [ "$CV" = "TelnetPort" ]; then
611 echo
612 echo "NOTE: Telnet will always be enabled for management purposes!"
613 echo "Make sure you block external access to this port or set no password"
614 echo "so the server will only listen on the loopback interface!"
615 echo
616 fi
617 $1 $CV
618 done
619 echo
620}
621
622configEditGameType() {
623 local CV
624
625 echo "Game type"
626 echo "--------------------------------"
627 for CV in \
628 GameName GameWorld GameMode \
629 ; do
630 $1 $CV
631 done
632 echo
633}
634
635configEditGeneric() {
636 local CV
637
638 echo "Generic options"
639 echo "--------------------------------"
640 for CV in \
641 FriendlyFire BuildCreate \
642 BlockDurabilityModifier \
643 ; do
644 $1 $CV
645 done
646 echo
647}
648
649configEditDropLoot() {
650 local CV
651
652 echo "Drop and Loot"
653 echo "--------------------------------"
654 for CV in \
655 DropOnDeath DropOnQuit \
656 LootAbundance LootRespawnDays AirDropFrequency \
657 ; do
658 $1 $CV
659 done
660 echo
661}
662
663configEditTimes() {
664 local CV
665
666 echo "Times / Durations"
667 echo "--------------------------------"
668 for CV in \
669 DayNightLength DayLightLength \
670 ; do
671 $1 $CV
672 done
673 echo
674}
675
676configEditDifficulty() {
677 local CV
678
679 echo "Difficulty"
680 echo "--------------------------------"
681 for CV in \
682 GameDifficulty ZombiesRun \
683 EnemySenseMemory EnemySpawnMode EnemyDifficulty \
684 ; do
685 $1 $CV
686 done
687 echo
688}
689
690configEditLandClaim() {
691 local CV
692
693 echo "Land claim options"
694 echo "--------------------------------"
695 for CV in \
696 LandClaimSize LandClaimDeadZone LandClaimExpiryTime LandClaimDecayMode \
697 LandClaimOnlineDurabilityModifier LandClaimOfflineDurabilityModifier \
698 ; do
699 $1 $CV
700 done
701 echo
702}
703
704configEditAll() {
705 configEditServer "$1"
706 configEditRemoteControl "$1"
707 configEditGameType "$1"
708 configEditGeneric "$1"
709 configEditDropLoot "$1"
710 configEditTimes "$1"
711 configEditDifficulty "$1"
712 configEditLandClaim "$1"
713}
714
715
716
717
718
719#################################
720## Generic worker functions
721
722
723# List all defined config editing parts
724# Returns:
725# List of config funcs
726listConfigEditFuncs() {
727 local CV
728 for CV in $(declare -F | cut -d\ -f3 | grep "^configEdit.*$"); do
729 CV=${CV#configEdit}
730 printf "%s " "$CV"
731 done
732}
733
734
735# List all defined config options
736# Returns:
737# List of defined config options
738listConfigValues() {
739 local CV
740 for CV in $(declare -F | cut -d\ -f3 | grep "^serverconfig_.*_Type$"); do
741 CV=${CV#serverconfig_}
742 CV=${CV%_Type}
743 printf "%s " "$CV"
744 done
745}
746
747
748# Validate the given value for the given option
749# Params:
750# 1: Option name
751# 2: Value
752# Returns:
753# 0/1: invalid/valid
754isValidOptionValue() {
755 local TYPE=$(serverconfig_$1_Type)
756 local RANGE=""
757
758 if [ "$TYPE" = "enum" ]; then
759 TYPE="number"
760 serverconfig_$1_Values
761 RANGE=1-${#config_allowed_values[@]}
762 else
763 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
764 RANGE=$(serverconfig_$1_Range)
765 fi
766 fi
767
768 case "$TYPE" in
769 number)
770 if [ $(isANumber "$2") -eq 0 ]; then
771 echo "0"
772 return
773 fi
774 if [ ! -z "$RANGE" ]; then
775 local MIN=$(cut -d- -f1 <<< "$RANGE")
776 local MAX=$(cut -d- -f2 <<< "$RANGE")
777 if [ $2 -lt $MIN -o $2 -gt $MAX ]; then
778 echo "0"
779 return
780 fi
781 fi
782 ;;
783 boolean)
784 if [ $(isABool "$2") -eq 0 ]; then
785 echo "0"
786 return
787 fi
788 ;;
789 string)
790 ;;
791 esac
792
793
794 if [ "$(type -t serverconfig_$1_Validate)" = "function" ]; then
795 if [ $(serverconfig_$1_Validate "$2") -eq 0 ]; then
796 echo "0"
797 return
798 fi
799 fi
800
801 echo "1"
802}
803
804# Query for the value of a single config option
805# Will be stored in $configCurrent_$1
806# Params:
807# 1: Option name
808configQueryValue() {
809 local TYPE=$(serverconfig_$1_Type)
810 local NAME=""
811 local RANGE=""
812 local DEFAULT=""
813 local currentValName=configCurrent_$1
814
815 if [ "$(type -t serverconfig_$1_Values)" = "function" ]; then
816 echo "$(serverconfig_$1_QueryName), options:"
817 serverconfig_$1_Values
818 NAME="Select option"
819 if [ "$TYPE" = "enum" ]; then
820 local OPTOFFSET=1
821 else
822 local OPTOFFSET=0
823 fi
824 for (( i=$OPTOFFSET; i < ${#config_allowed_values[@]}+$OPTOFFSET; i++ )); do
825 printf " %2d: %s\n" $i "${config_allowed_values[$i-$OPTOFFSET]}"
826 done
827 else
828 NAME=$(serverconfig_$1_QueryName)
829 fi
830
831 if [ "$TYPE" = "enum" ]; then
832 RANGE=1-${#config_allowed_values[@]}
833 if [ ! -z "${!currentValName}" ]; then
834 for (( i=1; i < ${#config_allowed_values[@]}+1; i++ )); do
835 if [ "${!currentValName}" = "${config_allowed_values[$i-1]}" ]; then
836 DEFAULT=$i
837 fi
838 done
839 export $currentValName=
840 fi
841 else
842 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
843 RANGE=$(serverconfig_$1_Range)
844 fi
845 fi
846
847 if [ -z "$DEFAULT" ]; then
848 if [ ! -z "${!currentValName}" ]; then
849 DEFAULT=${!currentValName}
850 else
851 if [ "$(type -t serverconfig_$1_Default)" = "function" ]; then
852 DEFAULT=$(serverconfig_$1_Default)
853 fi
854 fi
855 fi
856
857 local prompt=$(printf "%s" "$NAME")
858 if [ ! -z "$RANGE" ]; then
859 prompt=$(printf "%s (%s)" "$prompt" "$RANGE")
860 fi
861 if [ ! -z "$DEFAULT" ]; then
862 prompt=$(printf "%s [%s]" "$prompt" "$DEFAULT")
863 fi
864 prompt=$(printf "%s:" "$prompt")
865 prompt=$(printf "%-*s " 40 "$prompt")
866
867 while : ; do
868 read -p "$prompt" $currentValName
869 export $currentValName="${!currentValName:-$DEFAULT}"
870 if [ $(isValidOptionValue "$1" "${!currentValName}") -eq 0 ]; then
871 if [ "$(type -t serverconfig_$1_ErrorMessage)" = "function" ]; then
872 serverconfig_$1_ErrorMessage "${!currentValName}"
873 fi
874 fi
875 [ $(isValidOptionValue "$1" "${!currentValName}") -eq 1 ] && break
876 done
877
878 if [ "$TYPE" = "boolean" ]; then
879 if [ $(getBool ${!currentValName}) -eq 1 ]; then
880 export $currentValName="true"
881 else
882 export $currentValName="false"
883 fi
884 fi
885 if [ "$TYPE" = "enum" ]; then
886 export $currentValName="${config_allowed_values[$currentValName-1]}"
887 fi
888 echo
889}
890
891# Set parameters for current instance that have forced values:
892# - TelnetEnabled must be set so that management scripts can work
893# - AdminFileName is made to point to the local instance admins.xml
894# - SaveGameFolder is made to point to the instance folder
895# Params:
896# 1: Instance name
897configSetAutoParameters() {
898 configCurrent_TelnetEnabled=true
899 configCurrent_AdminFileName=admins.xml
900 configCurrent_SaveGameFolder="$(getInstancePath "$1")"
901}
902
903
904# Print defined config value
905# Params:
906# 1: Config option
907printConfigValue() {
908 local currentValName=configCurrent_$1
909 printf "%-25s = %s\n" "$(serverconfig_$1_QueryName)" "${!currentValName}"
910}
911
912# Query for an instance name (will be saved in $INSTANCE)
913readInstanceName() {
914 until [ $(isValidInstanceName "$INSTANCE") -eq 1 ]; do
915 read -p "Instance name: " INSTANCE
916 if [ $(isValidInstanceName "$INSTANCE") -eq 0 ]; then
917 echo "Invalid instance name, may only contain:"
918 echo " - letters (A-Z / a-z)"
919 echo " - digits (0-9)"
920 echo " - underscores (_)"
921 echo " - hyphens (-)"
922 fi
923 done
924}
925
926# Undefine the current config values
927unsetAllConfigValues() {
928 local CV
929 for CV in $(listConfigValues); do
930 local currentValName=configCurrent_$CV
931 export $currentValName=
932 done
933}
934
935# Load all config values from the config.xml of the given instance
936# Params:
937# 1: Instance name
938loadCurrentConfigValues() {
939 local CV
940 for CV in $(listConfigValues); do
941 local currentValName=configCurrent_$CV
942 local cfile=$(getInstancePath "$1")/config.xml
943 local XPATH="/ServerSettings/property[@name='$CV']/@value"
944 local VAL=$($XMLSTARLET sel -t -v "$XPATH" $cfile)
945 if [ ! -z "$VAL" ]; then
946 export $currentValName="$VAL"
947 fi
948 done
949}
950
951# Save all config values to the config.xml of the given instance
952# Params:
953# 1: Instance name
954saveCurrentConfigValues() {
955 local CV
956 for CV in $(listConfigValues) TelnetEnabled AdminFileName SaveGameFolder; do
957 local currentValName=configCurrent_$CV
958 local val="${!currentValName}"
959 local cfile=$(getInstancePath "$1")/config.xml
960
961 XPATHBASE="/ServerSettings/property[@name='$CV']"
962
963 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@name" $cfile) ]; then
964 $XMLSTARLET ed -L \
965 -s "/ServerSettings" -t elem -n "property" -v "" \
966 -i "/ServerSettings/property[not(@name)]" -t attr -n "name" -v "$CV" \
967 -i "$XPATHBASE" -t attr -n "value" -v "$val" \
968 $cfile
969 else
970 $XMLSTARLET ed -L \
971 -u "$XPATHBASE/@value" -v "$val" \
972 $cfile
973 fi
974 done
975}
976
977# Check if the config template exists
978# Returns:
979# 0/1: no/yes
980configTemplateExists() {
981 if [ -f $SDTD_BASE/templates/config.xml ]; then
982 echo 1
983 else
984 echo 0
985 fi
986}
987
988# Get a single value from a serverconfig
989# Params:
990# 1: Instance name
991# 2: Property name
992# Returns:
993# Property value
994getConfigValue() {
995 local CONF=$(getInstancePath $1)/config.xml
996 $XMLSTARLET sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
997}
998
999# Update a single value in a serverconfig
1000# Params:
1001# 1: Instance name
1002# 2: Property name
1003# 3: New value
1004setConfigValue() {
1005 local CONF=$(getInstancePath $1)/config.xml
1006 $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
1007}
1008
Note: See TracBrowser for help on using the repository browser.