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

Last change on this file since 327 was 308, checked in by alloc, 7 years ago

Scripts 109

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