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

Last change on this file since 253 was 241, checked in by alloc, 9 years ago

Scripts 92

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