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

Last change on this file since 22 was 20, checked in by alloc, 11 years ago

Version 5. Fixes #9, #11

File size: 18.3 KB
Line 
1#!/bin/bash
2# Version 5
3
4# Provides functions to query and validate values for serverconfig.xml
5
6serverconfig_ServerPort_QueryName() {
7 echo "Base Port"
8}
9serverconfig_ServerPort_Type() {
10 echo "number"
11}
12serverconfig_ServerPort_Default() {
13 echo "25000"
14}
15serverconfig_ServerPort_Range() {
16 echo "1024-65533"
17}
18serverconfig_ServerPort_Validate() {
19 local I=${INSTANCE:-!}
20 if [ $(checkGamePortUsed "$1" "$I") -eq 0 ]; then
21 echo "1"
22 else
23 echo "0"
24 fi
25}
26serverconfig_ServerPort_ErrorMessage() {
27 echo "Illegal port number or port already in use by another instance."
28}
29
30
31
32serverconfig_ServerIsPublic_QueryName() {
33 echo "Public server"
34}
35serverconfig_ServerIsPublic_Type() {
36 echo "boolean"
37}
38serverconfig_ServerIsPublic_Default() {
39 echo "true"
40}
41serverconfig_ServerIsPublic_ErrorMessage() {
42 echo "Not a valid boolean given (true/false or yes/no or y/n)."
43}
44
45
46
47serverconfig_ServerName_QueryName() {
48 echo "Server name"
49}
50serverconfig_ServerName_Type() {
51 echo "string"
52}
53serverconfig_ServerName_Validate() {
54 if [ ! -z "$1" ]; then
55 echo "1"
56 else
57 echo "0"
58 fi
59}
60serverconfig_ServerName_ErrorMessage() {
61 echo "Server name cannot be empty."
62}
63
64
65
66serverconfig_ServerPassword_QueryName() {
67 echo "Server password"
68}
69serverconfig_ServerPassword_Type() {
70 echo "string"
71}
72
73
74
75serverconfig_ServerMaxPlayerCount_QueryName() {
76 echo "Max players"
77}
78serverconfig_ServerMaxPlayerCount_Type() {
79 echo "number"
80}
81serverconfig_ServerMaxPlayerCount_Default() {
82 echo "4"
83}
84serverconfig_ServerMaxPlayerCount_Range() {
85 echo "1-64"
86}
87
88
89
90serverconfig_GameWorld_QueryName() {
91 echo "World name"
92}
93serverconfig_GameWorld_Type() {
94 echo "enum"
95}
96serverconfig_GameWorld_Default() {
97 echo "1"
98}
99serverconfig_GameWorld_Values() {
100 config_allowed_values=("Navezgane" "MP Wasteland Horde" "MP Wasteland Skirmish" "MP Wasteland War")
101}
102
103
104
105serverconfig_GameName_QueryName() {
106 echo "Game name"
107}
108serverconfig_GameName_Type() {
109 echo "string"
110}
111serverconfig_GameName_Validate() {
112 if [ ! -z "$1" ]; then
113 echo "1"
114 else
115 echo "0"
116 fi
117}
118serverconfig_GameName_ErrorMessage() {
119 echo "Game name cannot be empty."
120}
121
122
123
124serverconfig_GameDifficulty_QueryName() {
125 echo "Difficulty"
126}
127serverconfig_GameDifficulty_Type() {
128 echo "number"
129}
130serverconfig_GameDifficulty_Default() {
131 echo "2"
132}
133serverconfig_GameDifficulty_Range() {
134 echo "0-4"
135}
136serverconfig_GameDifficulty_Values() {
137 config_allowed_values=("Very easy" "Easy" "Medium" "Hard" "Very hard")
138}
139
140
141
142serverconfig_GameMode_QueryName() {
143 echo "Game mode"
144}
145serverconfig_GameMode_Type() {
146 echo "enum"
147}
148serverconfig_GameMode_Default() {
149 echo "1"
150}
151serverconfig_GameMode_Values() {
152 config_allowed_values=("GameModeSurvivalMP" "GameModeSurvivalSP")
153}
154
155
156
157serverconfig_ZombiesRun_QueryName() {
158 echo "Zombies run"
159}
160serverconfig_ZombiesRun_Type() {
161 echo "number"
162}
163serverconfig_ZombiesRun_Default() {
164 echo "0"
165}
166serverconfig_ZombiesRun_Range() {
167 echo "0-2"
168}
169serverconfig_ZombiesRun_Values() {
170 config_allowed_values=("Default day/night walk/run" "Never run" "Always run")
171}
172
173
174
175serverconfig_ShowAllPlayersOnMap_QueryName() {
176 echo "Show all players on map"
177}
178serverconfig_ShowAllPlayersOnMap_Type() {
179 echo "boolean"
180}
181serverconfig_ShowAllPlayersOnMap_Default() {
182 echo "true"
183}
184serverconfig_ShowAllPlayersOnMap_ErrorMessage() {
185 echo "Not a valid boolean given (true/false or yes/no or y/n)."
186}
187
188
189
190serverconfig_BuildCreate_QueryName() {
191 echo "Item spawn menu"
192}
193serverconfig_BuildCreate_Type() {
194 echo "boolean"
195}
196serverconfig_BuildCreate_Default() {
197 echo "true"
198}
199serverconfig_BuildCreate_ErrorMessage() {
200 echo "Not a valid boolean given (true/false or yes/no or y/n)."
201}
202
203
204
205serverconfig_DayNightLength_QueryName() {
206 echo "Length of one day"
207}
208serverconfig_DayNightLength_Type() {
209 echo "number"
210}
211serverconfig_DayNightLength_Default() {
212 echo "45"
213}
214
215
216
217serverconfig_FriendlyFire_QueryName() {
218 echo "Friendly fire"
219}
220serverconfig_FriendlyFire_Type() {
221 echo "boolean"
222}
223serverconfig_FriendlyFire_Default() {
224 echo "false"
225}
226serverconfig_FriendlyFire_ErrorMessage() {
227 echo "Not a valid boolean given (true/false or yes/no or y/n)."
228}
229
230
231
232serverconfig_DayCount_QueryName() {
233 echo "Day Count (Horde)"
234}
235serverconfig_DayCount_Type() {
236 echo "number"
237}
238serverconfig_DayCount_Default() {
239 echo "3"
240}
241
242
243
244serverconfig_FragLimit_QueryName() {
245 echo "Frag limit (DM)"
246}
247serverconfig_FragLimit_Type() {
248 echo "number"
249}
250serverconfig_FragLimit_Default() {
251 echo "5"
252}
253
254
255
256serverconfig_MatchLength_QueryName() {
257 echo "Match length (DM)"
258}
259serverconfig_MatchLength_Type() {
260 echo "number"
261}
262serverconfig_MatchLength_Default() {
263 echo "15"
264}
265
266
267
268serverconfig_RebuildMap_QueryName() {
269 echo "Rebuild map on round restart"
270}
271serverconfig_RebuildMap_Type() {
272 echo "boolean"
273}
274serverconfig_RebuildMap_Default() {
275 echo "false"
276}
277serverconfig_RebuildMap_ErrorMessage() {
278 echo "Not a valid boolean given (true/false or yes/no or y/n)."
279}
280
281
282
283serverconfig_ControlPanelEnabled_QueryName() {
284 echo "Enable control panel"
285}
286serverconfig_ControlPanelEnabled_Type() {
287 echo "boolean"
288}
289serverconfig_ControlPanelEnabled_Default() {
290 echo "false"
291}
292serverconfig_ControlPanelEnabled_ErrorMessage() {
293 echo "Not a valid boolean given (true/false or yes/no or y/n)."
294}
295
296
297
298serverconfig_ControlPanelPort_QueryName() {
299 echo "Control panel port"
300}
301serverconfig_ControlPanelPort_Type() {
302 echo "number"
303}
304serverconfig_ControlPanelPort_Default() {
305 echo "8080"
306}
307serverconfig_ControlPanelPort_Range() {
308 echo "1024-65535"
309}
310serverconfig_ControlPanelPort_Validate() {
311 local I=${INSTANCE:-!}
312 if [ $(checkTCPPortUsed "$1" "$I") -eq 0 ]; then
313 echo "1"
314 else
315 echo "0"
316 fi
317}
318serverconfig_ControlPanelPort_ErrorMessage() {
319 echo "Illegal port number or port already in use by another instance."
320}
321
322
323
324serverconfig_ControlPanelPassword_QueryName() {
325 echo "Control panel password"
326}
327serverconfig_ControlPanelPassword_Type() {
328 echo "string"
329}
330
331
332
333serverconfig_TelnetPort_QueryName() {
334 echo "Telnet port"
335}
336serverconfig_TelnetPort_Type() {
337 echo "number"
338}
339serverconfig_TelnetPort_Default() {
340 echo "8081"
341}
342serverconfig_TelnetPort_Range() {
343 echo "1024-65535"
344}
345serverconfig_TelnetPort_Validate() {
346 local I=${INSTANCE:-!}
347 if [ $(checkTCPPortUsed "$1" "$I") -eq 0 ]; then
348 echo "1"
349 else
350 echo "0"
351 fi
352}
353serverconfig_TelnetPort_ErrorMessage() {
354 echo "Illegal port number or port already in use by another instance."
355}
356
357
358
359serverconfig_TelnetPassword_QueryName() {
360 echo "Telnet password"
361}
362serverconfig_TelnetPassword_Type() {
363 echo "string"
364}
365serverconfig_TelnetPassword_Validate() {
366 if [ -z $1 ]; then
367 echo "0"
368 else
369 echo "1"
370 fi
371}
372serverconfig_TelnetPassword_ErrorMessage() {
373 echo "Telnet must have a password set to function."
374}
375
376
377
378serverconfig_DisableNAT_QueryName() {
379 echo "Disable NAT"
380}
381serverconfig_DisableNAT_Type() {
382 echo "boolean"
383}
384serverconfig_DisableNAT_Default() {
385 echo "true"
386}
387serverconfig_DisableNAT_ErrorMessage() {
388 echo "Not a valid boolean given (true/false or yes/no or y/n)."
389}
390
391
392
393
394serverconfig_DropOnDeath_QueryName() {
395 echo "Drop on Death"
396}
397serverconfig_DropOnDeath_Type() {
398 echo "number"
399}
400serverconfig_DropOnDeath_Default() {
401 echo "0"
402}
403serverconfig_DropOnDeath_Range() {
404 echo "0-3"
405}
406serverconfig_DropOnDeath_Values() {
407 config_allowed_values=("Everything" "Toolbelt only" "Backpack only" "Delete all")
408}
409
410
411serverconfig_DropOnQuit_QueryName() {
412 echo "Drop on Quit"
413}
414serverconfig_DropOnQuit_Type() {
415 echo "number"
416}
417serverconfig_DropOnQuit_Default() {
418 echo "0"
419}
420serverconfig_DropOnQuit_Range() {
421 echo "0-3"
422}
423serverconfig_DropOnQuit_Values() {
424 config_allowed_values=("Nothing" "Everything" "Toolbelt only" "Backpack only")
425}
426
427
428
429
430serverconfig_CraftTimer_QueryName() {
431 echo "Craft speed"
432}
433serverconfig_CraftTimer_Type() {
434 echo "number"
435}
436serverconfig_CraftTimer_Default() {
437 echo "1"
438}
439serverconfig_CraftTimer_Range() {
440 echo "0-2"
441}
442serverconfig_CraftTimer_Values() {
443 config_allowed_values=("Instant" "Normal" "Double")
444}
445
446
447serverconfig_LootTimer_QueryName() {
448 echo "Loot open speed"
449}
450serverconfig_LootTimer_Type() {
451 echo "number"
452}
453serverconfig_LootTimer_Default() {
454 echo "1"
455}
456serverconfig_LootTimer_Range() {
457 echo "0-2"
458}
459serverconfig_LootTimer_Values() {
460 config_allowed_values=("Instant" "Normal" "Double")
461}
462
463
464
465
466serverconfig_PlayerDamageGiven_QueryName() {
467 echo "Damage Player->Zombies"
468}
469serverconfig_PlayerDamageGiven_Type() {
470 echo "number"
471}
472serverconfig_PlayerDamageGiven_Default() {
473 echo "2"
474}
475serverconfig_PlayerDamageGiven_Range() {
476 echo "0-4"
477}
478serverconfig_PlayerDamageGiven_Values() {
479 config_allowed_values=("50%" "75%" "100%" "150%" "200%")
480}
481
482
483serverconfig_PlayerDamageRecieved_QueryName() {
484 echo "Damage Zombies->Player"
485}
486serverconfig_PlayerDamageRecieved_Type() {
487 echo "number"
488}
489serverconfig_PlayerDamageRecieved_Default() {
490 echo "2"
491}
492serverconfig_PlayerDamageRecieved_Range() {
493 echo "0-4"
494}
495serverconfig_PlayerDamageRecieved_Values() {
496 config_allowed_values=("50%" "75%" "100%" "150%" "200%")
497}
498
499
500serverconfig_EnemySenseMemory_QueryName() {
501 echo "Sense memory (seconds)"
502}
503serverconfig_EnemySenseMemory_Type() {
504 echo "number"
505}
506serverconfig_EnemySenseMemory_Default() {
507 echo "60"
508}
509
510
511serverconfig_EnemySpawnMode_QueryName() {
512 echo "Spawn mode"
513}
514serverconfig_EnemySpawnMode_Type() {
515 echo "number"
516}
517serverconfig_EnemySpawnMode_Default() {
518 echo "3"
519}
520serverconfig_EnemySpawnMode_Range() {
521 echo "0-5"
522}
523serverconfig_EnemySpawnMode_Values() {
524 config_allowed_values=("Disabled" "50%" "75%" "100%" "125%" "150%")
525}
526
527
528serverconfig_EnemyDifficulty_QueryName() {
529 echo "Enemy difficulty"
530}
531serverconfig_EnemyDifficulty_Type() {
532 echo "number"
533}
534serverconfig_EnemyDifficulty_Default() {
535 echo "0"
536}
537serverconfig_EnemyDifficulty_Range() {
538 echo "0-1"
539}
540serverconfig_EnemyDifficulty_Values() {
541 config_allowed_values=("Normal" "Feral")
542}
543
544
545
546
547serverconfig_NightPercentage_QueryName() {
548 echo "Night percentage"
549}
550serverconfig_NightPercentage_Type() {
551 echo "number"
552}
553serverconfig_NightPercentage_Default() {
554 echo "35"
555}
556serverconfig_NightPercentage_Range() {
557 echo "10-90"
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
596
597
598
599serverconfig_LandClaimSize_QueryName() {
600 echo "Land claim size"
601}
602serverconfig_LandClaimSize_Type() {
603 echo "number"
604}
605serverconfig_LandClaimSize_Default() {
606 echo "7"
607}
608
609
610serverconfig_LandClaimDeadZone_QueryName() {
611 echo "Minimum keystone distance"
612}
613serverconfig_LandClaimDeadZone_Type() {
614 echo "number"
615}
616serverconfig_LandClaimDeadZone_Default() {
617 echo "30"
618}
619
620
621serverconfig_LandClaimExpiryTime_QueryName() {
622 echo "Claim expiry time (days)"
623}
624serverconfig_LandClaimExpiryTime_Type() {
625 echo "number"
626}
627serverconfig_LandClaimExpiryTime_Default() {
628 echo "3"
629}
630
631
632serverconfig_LandClaimDecayMode_QueryName() {
633 echo "Claim decay mode"
634}
635serverconfig_LandClaimDecayMode_Type() {
636 echo "number"
637}
638serverconfig_LandClaimDecayMode_Default() {
639 echo "0"
640}
641serverconfig_LandClaimDecayMode_Range() {
642 echo "0-2"
643}
644serverconfig_LandClaimDecayMode_Values() {
645 config_allowed_values=("Linear" "Exponential" "Full protection")
646}
647
648
649serverconfig_LandClaimOnlineDurabilityModifier_QueryName() {
650 echo "Claim durability modifier - online"
651}
652serverconfig_LandClaimOnlineDurabilityModifier_Type() {
653 echo "number"
654}
655serverconfig_LandClaimOnlineDurabilityModifier_Default() {
656 echo "4"
657}
658
659
660serverconfig_LandClaimOfflineDurabilityModifier_QueryName() {
661 echo "Claim durability modifier - offline"
662}
663serverconfig_LandClaimOfflineDurabilityModifier_Type() {
664 echo "number"
665}
666serverconfig_LandClaimOfflineDurabilityModifier_Default() {
667 echo "4"
668}
669
670
671
672
673serverconfig_AirDropFrequency_QueryName() {
674 echo "Airdrop delay (hours)"
675}
676serverconfig_AirDropFrequency_Type() {
677 echo "number"
678}
679serverconfig_AirDropFrequency_Default() {
680 echo "24"
681}
682
683
684
685
686############
687listConfigValues() {
688 local CV
689 for CV in $(declare -F | cut -d\ -f3 | grep "^serverconfig_.*_Type$"); do
690 CV=${CV#serverconfig_}
691 CV=${CV%_Type}
692 printf "%s " "$CV"
693 done
694}
695
696
697# 1: Option name
698# 2: Value
699isValidOptionValue() {
700 local TYPE=$(serverconfig_$1_Type)
701 local RANGE=""
702
703 if [ "$TYPE" = "enum" ]; then
704 TYPE="number"
705 serverconfig_$1_Values
706 RANGE=1-${#config_allowed_values[@]}
707 else
708 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
709 RANGE=$(serverconfig_$1_Range)
710 fi
711 fi
712
713 case "$TYPE" in
714 number)
715 if [ $(isANumber "$2") -eq 0 ]; then
716 echo "0"
717 return
718 fi
719 if [ ! -z "$RANGE" ]; then
720 local MIN=$(cut -d- -f1 <<< "$RANGE")
721 local MAX=$(cut -d- -f2 <<< "$RANGE")
722 if [ $2 -lt $MIN -o $2 -gt $MAX ]; then
723 echo "0"
724 return
725 fi
726 fi
727 ;;
728 boolean)
729 if [ $(isABool "$2") -eq 0 ]; then
730 echo "0"
731 return
732 fi
733 ;;
734 string)
735 ;;
736 esac
737
738
739 if [ "$(type -t serverconfig_$1_Validate)" = "function" ]; then
740 if [ $(serverconfig_$1_Validate "$2") -eq 0 ]; then
741 echo "0"
742 return
743 fi
744 fi
745
746 echo "1"
747}
748
749# 1: Option name
750# 2: Target variable
751configQueryValue() {
752 local TYPE=$(serverconfig_$1_Type)
753 local NAME=""
754 local RANGE=""
755 local DEFAULT=""
756 local currentValName=configCurrent_$1
757
758 if [ "$(type -t serverconfig_$1_Values)" = "function" ]; then
759 echo "$(serverconfig_$1_QueryName), options:"
760 serverconfig_$1_Values
761 NAME="Select option"
762 if [ "$TYPE" = "enum" ]; then
763 local OPTOFFSET=1
764 else
765 local OPTOFFSET=0
766 fi
767 for (( i=$OPTOFFSET; i < ${#config_allowed_values[@]}+$OPTOFFSET; i++ )); do
768 printf " %2d: %s\n" $i "${config_allowed_values[$i-$OPTOFFSET]}"
769 done
770 else
771 NAME=$(serverconfig_$1_QueryName)
772 fi
773
774 if [ "$TYPE" = "enum" ]; then
775 RANGE=1-${#config_allowed_values[@]}
776 if [ ! -z "${!currentValName}" ]; then
777 for (( i=1; i < ${#config_allowed_values[@]}+1; i++ )); do
778 if [ "${!currentValName}" = "${config_allowed_values[$i-1]}" ]; then
779 DEFAULT=$i
780 fi
781 done
782 export $currentValName=
783 fi
784 else
785 if [ "$(type -t serverconfig_$1_Range)" = "function" ]; then
786 RANGE=$(serverconfig_$1_Range)
787 fi
788 fi
789
790 if [ -z "$DEFAULT" ]; then
791 if [ ! -z "${!currentValName}" ]; then
792 DEFAULT=${!currentValName}
793 else
794 if [ "$(type -t serverconfig_$1_Default)" = "function" ]; then
795 DEFAULT=$(serverconfig_$1_Default)
796 fi
797 fi
798 fi
799
800 local prompt=$(printf "%s" "$NAME")
801 if [ ! -z "$RANGE" ]; then
802 prompt=$(printf "%s (%s)" "$prompt" "$RANGE")
803 fi
804 if [ ! -z "$DEFAULT" ]; then
805 prompt=$(printf "%s [%s]" "$prompt" "$DEFAULT")
806 fi
807 prompt=$(printf "%s:" "$prompt")
808 prompt=$(printf "%-*s " 35 "$prompt")
809
810 while : ; do
811 read -p "$prompt" $currentValName
812 export $currentValName="${!currentValName:-$DEFAULT}"
813 if [ $(isValidOptionValue "$1" "${!currentValName}") -eq 0 ]; then
814 if [ "$(type -t serverconfig_$1_ErrorMessage)" = "function" ]; then
815 serverconfig_$1_ErrorMessage "${!currentValName}"
816 fi
817 fi
818 [ $(isValidOptionValue "$1" "${!currentValName}") -eq 1 ] && break
819 done
820
821 if [ "$TYPE" = "enum" ]; then
822 export $currentValName="${config_allowed_values[$currentValName-1]}"
823 fi
824}
825
826# 1: Instance name
827configSetAutoParameters() {
828 configCurrent_TelnetEnabled=true
829 configCurrent_AdminFileName=admins.xml
830 configCurrent_SaveGameFolder="$(winepath -w $(getInstancePath "$1") 2>/dev/null | grep instances)"
831}
832
833configEditAll() {
834 local CV
835 for CV in \
836 ServerName ServerPort ServerIsPublic ServerPassword ServerMaxPlayerCount \
837 DisableNAT \
838 ControlPanelEnabled ControlPanelPort ControlPanelPassword \
839 TelnetPort TelnetPassword \
840 GameWorld GameName GameMode \
841 ShowAllPlayersOnMap FriendlyFire BuildCreate \
842 DayCount FragLimit MatchLength RebuildMap \
843 DropOnDeath DropOnQuit \
844 LootAbundance LootRespawnDays AirDropFrequency \
845 CraftTimer LootTimer \
846 DayNightLength NightPercentage \
847 GameDifficulty ZombiesRun \
848 PlayerDamageGiven PlayerDamageRecieved EnemySenseMemory EnemySpawnMode EnemyDifficulty \
849 BlockDurabilityModifier \
850 LandClaimSize LandClaimDeadZone LandClaimExpiryTime LandClaimDecayMode \
851 LandClaimOnlineDurabilityModifier LandClaimOfflineDurabilityModifier \
852 ; do
853 configQueryValue $CV
854 echo
855 done
856}
857
858printCurrentConfig() {
859 local CV
860 for CV in $(listConfigValues); do
861 local currentValName=configCurrent_$CV
862 printf "%-20s = %s\n" "$CV" "${!currentValName}"
863 done
864}
865
866readInstanceName() {
867 until [ $(isValidInstanceName "$INSTANCE") -eq 1 ]; do
868 read -p "Instance name: " INSTANCE
869 if [ $(isValidInstanceName "$INSTANCE") -eq 0 ]; then
870 echo "Invalid instance name, may only contain:"
871 echo " - letters (A-Z / a-z)"
872 echo " - digits (0-9)"
873 echo " - underscores (_)"
874 echo " - hyphens (-)"
875 fi
876 done
877}
878
879unsetAllConfigValues() {
880 local CV
881 for CV in $(listConfigValues); do
882 local currentValName=configCurrent_$CV
883 export $currentValName=
884 done
885}
886
887# 1: Instance name
888loadCurrentConfigValues() {
889 local CV
890 for CV in $(listConfigValues); do
891 local currentValName=configCurrent_$CV
892 local cfile=$(getInstancePath "$1")/config.xml
893 local XPATH="/ServerSettings/property[@name='$CV']/@value"
894 local VAL=$($XMLSTARLET sel -t -v "$XPATH" $cfile)
895 if [ ! -z "$VAL" ]; then
896 export $currentValName="$VAL"
897 fi
898 done
899}
900
901# 1: Instance name
902saveCurrentConfigValues() {
903 local CV
904 for CV in $(listConfigValues) TelnetEnabled AdminFileName SaveGameFolder; do
905 local currentValName=configCurrent_$CV
906 local val="${!currentValName}"
907 local cfile=$(getInstancePath "$1")/config.xml
908
909 XPATHBASE="/ServerSettings/property[@name='$CV']"
910
911 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@name" $cfile) ]; then
912 $XMLSTARLET ed -L \
913 -s "/ServerSettings" -t elem -n "property" -v "" \
914 -i "/ServerSettings/property[not(@name)]" -t attr -n "name" -v "$CV" \
915 -i "$XPATHBASE" -t attr -n "value" -v "$val" \
916 $cfile
917 else
918 $XMLSTARLET ed -L \
919 -u "$XPATHBASE/@value" -v "$val" \
920 $cfile
921 fi
922 done
923}
924
925configTemplateExists() {
926 if [ -f $SDTD_BASE/templates/config.xml ]; then
927 echo 1
928 else
929 echo 0
930 fi
931}
932
933# Get a single value from a serverconfig
934# Params:
935# 1: Instance name
936# 2: Property name
937# Returns:
938# Property value
939getConfigValue() {
940 local CONF=$(getInstancePath $1)/config.xml
941 $XMLSTARLET sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
942}
943
944# Update a single value in a serverconfig
945# Params:
946# 1: Instance name
947# 2: Property name
948# 3: New value
949setConfigValue() {
950 local CONF=$(getInstancePath $1)/config.xml
951 $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
952}
953
Note: See TracBrowser for help on using the repository browser.