-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.sh
executable file
·2751 lines (2317 loc) · 87.4 KB
/
server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Project Zomboid Linux Server Manager.
#
# Copyright (c) 2023 Pavel Korotkiy (outdead).
# Use of this source code is governed by the MIT license.
#
# DO NOT EDIT THIS FILE!
#
# To change config go to config/pzlsm.cfg file.
# This file will never be updated automatically.
# VERSION of Project Zomboid Linux Server Manager.
# Follows semantic versioning, SEE: http://semver.org/.
VERSION="0.25.1"
YEAR="2024"
AUTHOR="Pavel Korotkiy (outdead)"
# Color variables. Used when displaying messages in stdout.
GREEN='\033[0;32m'; RED='\033[0;31m'; YELLOW='\033[0;33m'; BLUE='\033[0;36m'; NC='\033[0m'
# Message types. Used when displaying messages in stdout.
OK=$(echo -e "[ ${GREEN} OK ${NC} ]"); ER=$(echo -e "[ ${RED} ER ${NC} ]"); WARN=$(echo -e "[ ${YELLOW} YELLOW ${NC} ]"); INFO=$(echo -e "[ ${BLUE}INFO${NC} ]")
# Project Zomboid App ID and Dedicated Server App ID in Steam.
APP_ID=108600
APP_DEDICATED_ID=380870
BASEDIR=$(dirname "$(readlink -f "${BASH_SOURCE[@]}")")
SCRIPT_LOCATION=${BASEDIR}
# MEMORY_AVAILABLE is the amount of memory available on the server in MB.
MEMORY_AVAILABLE=$(free | awk 'NR==2 { printf("%.0f", $2/1024); }')
# MEMORY_USED is the amount of memory used on the server in MM.
MEMORY_USED=$(free | awk 'NR==2 { printf("%.0f", $3/1024); }')
# CPU_CORE_COUNT is the number of processors cores on the server.
CPU_CORE_COUNT=$(nproc)
# NOW is the current date and time in default format Y%m%d_%H%M%S.
# You can change format in config file.
NOW=$(date "+%Y%m%d_%H%M%S")
# TIMESTAMP is current timestamp.
TIMESTAMP=$(date "+%s")
ENV_FILE="${BASEDIR}/.env"
# Import env file if exists.
# shellcheck source=.env
test -f "${ENV_FILE}" && . "${ENV_FILE}"
# OLD INIT VARIABLES WAS HERE. See function `init_variables`.
fn_exists() { declare -F "$1" > /dev/null; }
# echoerr prints red error message to stderr and FILE_PZLSM_LOG file.
function echoerr() {
echo "${ER} $1"
if [ "${WRITE_PZLSM_LOGS}" == "true" ]; then
mkdir -p "${DIR_LOGS}"
echo "[$(date "+%Y-%m-%d %H:%M:%S")] $0 - $1" >> "${FILE_PZLSM_LOG}"
fi
}
# echowarn prints yellow error message to stderr and FILE_PZLSM_LOG file.
function echowarn() {
echo "${WARN} $1"
if [ "${WRITE_PZLSM_LOGS}" == "true" ]; then
mkdir -p "${DIR_LOGS}"
echo "[$(date "+%Y-%m-%d %H:%M:%S")] $0 - $1" >> "${FILE_PZLSM_LOG}"
fi
}
# get_screen_pid prints server's pid.
function get_screen_pid() {
ps aux | grep -v grep | grep -i "screen -U -mdS ${SCREEN_ZOMBOID} " | awk '{print $2}'
}
# get_server_pid prints server's pid.
function get_server_pid() {
pgrep -af ProjectZomboid64 | grep "servername ${SERVER_NAME}" | grep -o -e "^[0-9]*"
}
# is_server_running prints true if server is running, or false if is not.
# TODO: Check state file.
function is_server_running() {
[ -n "$(get_screen_pid)" ] && echo "true" || echo "false"
}
# is_admin_exists prints true if admin username exists in PZ database.
function is_admin_exists() {
[ "$(sqlite3 "${ZOMBOID_FILE_DB}" "SELECT count(*) FROM whitelist WHERE username='admin'" 2> /dev/null)" == "1" ] && echo "true" || echo "false"
}
# is_dir_exist returns true if directory is exist.
function is_dir_exist() {
[ -d "$1" ] && echo "true" || echo "false"
}
# is_file_exist returns true if file is exist.
function is_file_exist() {
[ -f "$1" ] && echo "true" || echo "false"
}
# is_symlink returns true if file is symlink.
function is_symlink() {
[ -L "$1" ] && echo "true" || echo "false"
}
# init_variables creates pzlsm variables.
function init_variables() {
# Linux Server Manager directories definitions.
DIR_BACKUPS="${BASEDIR}/backups"
DIR_UTILS="${BASEDIR}/utils"
DIR_PZLSD="${BASEDIR}/utils/pzlsd"
DIR_PLUGINS="${BASEDIR}/utils/plugins"
DIR_LOGS="${BASEDIR}/logs"
DIR_CONFIG="${BASEDIR}/config"
DIR_PUBLIC="${BASEDIR}/public"
DIR_STATE="${BASEDIR}/state"
DIR_BACKUPS_DOWN="${DIR_BACKUPS}/down"
DIR_BACKUPS_ZOMBOID="${DIR_BACKUPS}/zomboid"
DIR_BACKUPS_PZLSD="${DIR_BACKUPS}/pzlsd"
DIR_BACKUPS_COPY="${DIR_BACKUPS}/copy"
DIR_BACKUPS_PLAYERS="${DIR_BACKUPS}/players"
DIR_BACKUPS_TIME_MACHINE="${DIR_BACKUPS}/timemachine"
# Linux Server Manager files definitions.
FILE_PZLSM_LOG="${DIR_LOGS}/pzlsm.log"
FILE_PZLSM_CONFIG="${DIR_CONFIG}/pzlsm.cfg"
# FILE_PZLSM_STATE="${DIR_STATE}/pzlsm.json"
# Import config file if exists.
# shellcheck source=config/pzlsm.cfg
test -f "${FILE_PZLSM_CONFIG}" && . "${FILE_PZLSM_CONFIG}"
# BASENAME=$(basename "${BASEDIR}")
## Check config variables and set default values if not defined.
[ -z "${CLEAR_MAP_DAY}" ] && CLEAR_MAP_DAY=0
[ -z "${CLEAR_LOGS_DAY}" ] && CLEAR_LOGS_DAY=0
[ -z "${CLEAR_STACK_TRACE_DAY}" ] && CLEAR_STACK_TRACE_DAY=0
[ -z "${CLEAR_BACKUPS_DAY}" ] && CLEAR_BACKUPS_DAY=7
[ -z "${CLEAR_TIME_MACHINE_DAY}" ] && CLEAR_TIME_MACHINE_DAY=5
[ -z "${UTIL_RANGE_VERSION}" ] && UTIL_RANGE_VERSION="1.0.1"
[ -z "${UTIL_RCON_VERSION}" ] && UTIL_RCON_VERSION="0.10.2"
[ -z "${SERVER_MEMORY_LIMIT}" ] && SERVER_MEMORY_LIMIT=2048
[ -z "${SERVER_NAME}" ] && SERVER_NAME="servertest"
[ -z "${ZOMBOID_HOME_DIR}" ] && ZOMBOID_HOME_DIR=".\/"
[ -z "${SCREEN_ZOMBOID}" ] && SCREEN_ZOMBOID="${SERVER_NAME}"
[ -z "${SERVER_LANG}" ] && SERVER_LANG="en"
[ -z "${SERVER_DIR}" ] && SERVER_DIR="${BASEDIR}/projectzomboid"
[ -z "${ZOMBOID_DIR}" ] && ZOMBOID_DIR="${BASEDIR}/Zomboid"
[ -z "${FIRST_RUN_ADMIN_PASSWORD}" ] && FIRST_RUN_ADMIN_PASSWORD="changeme"
[ -z "${BACKUP_ON_STOP}" ] && BACKUP_ON_STOP="false"
[ -z "${AUTO_RESTORE}" ] && AUTO_RESTORE="false"
[ -z "${STEAMCMD_USERNAME}" ] && STEAMCMD_USERNAME="anonymous"
[ -z "${STEAMCMD_BETA}" ] && STEAMCMD_BETA="-beta none"
[ -z "${PZLSM_SOURCE_LINK}" ] && PZLSM_SOURCE_LINK="https://raw.githubusercontent.com/openzomboid/pzlsm/master"
[ -z "${WRITE_PZLSM_LOGS}" ] && WRITE_PZLSM_LOGS="false"
## Utils
# Numeric range regular expression builder written in bash.
# https://github.com/outdead/regex-range-builder.
UTIL_RANGE_LINK="https://github.com/outdead/regex-range-builder/archive/v${UTIL_RANGE_VERSION}.tar.gz"
UTIL_RANGE_DIR="${DIR_UTILS}/regex-range-builder-${UTIL_RANGE_VERSION}"
UTIL_RANGE_FILE="${UTIL_RANGE_DIR}/range.sh"
# Rcon client for executing queries on game server.
# https://github.com/gorcon/rcon-cli.
UTIL_RCON_LINK="https://github.com/gorcon/rcon-cli/releases/download/v${UTIL_RCON_VERSION}/rcon-${UTIL_RCON_VERSION}-amd64_linux.tar.gz"
UTIL_RCON_DIR="${DIR_UTILS}/rcon-${UTIL_RCON_VERSION}-amd64_linux"
UTIL_RCON_FILE="${UTIL_RCON_DIR}/rcon"
## Directories in Zomboid folder.
ZOMBOID_DIR_SAVES="${ZOMBOID_DIR}/Saves"
ZOMBOID_DIR_LOGS="${ZOMBOID_DIR}/Logs"
ZOMBOID_DIR_SERVER="${ZOMBOID_DIR}/Server"
ZOMBOID_DIR_DB="${ZOMBOID_DIR}/db"
ZOMBOID_DIR_MAP="${ZOMBOID_DIR_SAVES}/Multiplayer/${SERVER_NAME}"
ZOMBOID_FILE_CONFIG_INI="${ZOMBOID_DIR_SERVER}/${SERVER_NAME}.ini"
ZOMBOID_FILE_CONFIG_SANDBOX="${ZOMBOID_DIR_SERVER}/${SERVER_NAME}_SandboxVars.lua"
ZOMBOID_FILE_CONFIG_SPAWNPOINTS="${ZOMBOID_DIR_SERVER}/${SERVER_NAME}_spawnpoints.lua"
ZOMBOID_FILE_CONFIG_SPAWNREGIONS="${ZOMBOID_DIR_SERVER}/${SERVER_NAME}_spawnregions.lua"
ZOMBOID_FILE_DB="${ZOMBOID_DIR_DB}/${SERVER_NAME}.db"
ZOMBOID_FILE_VEHICLES_DB="${ZOMBOID_DIR_MAP}/vehicles.db"
ZOMBOID_FILE_PLAYERS_DB="${ZOMBOID_DIR_MAP}/players.db"
# ZOMBOID_MANIFEST="${SERVER_DIR}/steamapps/appmanifest_${APP_DEDICATED_ID}.acf"
ZOMBOID_MODS_MANIFEST="${SERVER_DIR}/steamapps/workshop/appworkshop_${APP_ID}.acf"
if [ -f "${ZOMBOID_DIR}/server-console.txt" ]; then
PZ_VERSION=$(grep -roE "Startup version [0-9]+.[0-9]+.[0-9]+" "${ZOMBOID_DIR}/server-console.txt" | grep -Eo "[0-9]+.[0-9]+.[0-9]+")
fi
[ -z "${PZ_VERSION}" ] && PZ_VERSION="$(echo -e "${RED}undefined${NC}")"
}
# print_variables prints pzlsm variables.
# TODO: Add all variables.
function print_variables() {
check_dir() {
[ ! -d "$1" ] && echo -e "${RED} (not exists)${NC}"
}
check_file() {
[ ! -f "$1" ] && echo -e "${RED} (not exists)${NC}"
}
echo "${INFO} MEMORY_AVAILABLE: ${MEMORY_AVAILABLE}"
echo "${INFO} MEMORY_USED: ${MEMORY_USED}"
echo "${INFO} CPU_CORE_COUNT: ${CPU_CORE_COUNT}"
echo "${INFO} APP_ID: ${APP_ID}"
echo "${INFO} APP_DEDICATED_ID: ${APP_DEDICATED_ID}"
echo "${INFO} SCREEN_ZOMBOID: ${SCREEN_ZOMBOID}"
echo "${INFO} NOW: ${NOW}"
echo "${INFO} TIMESTAMP: ${TIMESTAMP}"
echo "${INFO} BASEDIR: ${BASEDIR}"
echo "${INFO}"
echo "${INFO} FILE_PZLSM_LOG: ${FILE_PZLSM_LOG}$(check_file "${FILE_PZLSM_LOG}")"
echo "${INFO} FILE_PZLSM_CONFIG: ${FILE_PZLSM_CONFIG}$(check_file "${FILE_PZLSM_CONFIG}")"
echo "${INFO} UTIL_RANGE_FILE: ${UTIL_RANGE_FILE}$(check_file "${UTIL_RANGE_FILE}")"
echo "${INFO} UTIL_RCON_FILE: ${UTIL_RCON_FILE}$(check_file "${UTIL_RCON_FILE}")"
echo "${INFO}"
echo "${INFO} SERVER_DIR: ${SERVER_DIR}$(check_dir "${SERVER_DIR}")"
echo "${INFO} ZOMBOID_DIR: ${ZOMBOID_DIR}$(check_dir "${ZOMBOID_DIR}")"
echo "${INFO} ZOMBOID_DIR_SAVES: ${ZOMBOID_DIR_SAVES}$(check_dir "${ZOMBOID_DIR_SAVES}")"
echo "${INFO} ZOMBOID_DIR_LOGS: ${ZOMBOID_DIR_LOGS}$(check_dir "${ZOMBOID_DIR_LOGS}")"
echo "${INFO} ZOMBOID_DIR_SERVER: ${ZOMBOID_DIR_SERVER}$(check_dir "${ZOMBOID_DIR_SERVER}")"
echo "${INFO} ZOMBOID_DIR_DB: ${ZOMBOID_DIR_DB}$(check_dir "${ZOMBOID_DIR_DB}")"
echo "${INFO} ZOMBOID_DIR_MAP: ${ZOMBOID_DIR_MAP}$(check_dir "${ZOMBOID_DIR_MAP}")"
echo "${INFO}"
echo "${INFO} ZOMBOID_FILE_CONFIG_INI: ${ZOMBOID_FILE_CONFIG_INI}$(check_file "${ZOMBOID_FILE_CONFIG_INI}")"
echo "${INFO} ZOMBOID_FILE_CONFIG_SANDBOX: ${ZOMBOID_FILE_CONFIG_SANDBOX}$(check_file "${ZOMBOID_FILE_CONFIG_SANDBOX}")"
echo "${INFO} ZOMBOID_FILE_DB: ${ZOMBOID_FILE_DB}$(check_file "${ZOMBOID_FILE_DB}")"
echo "${INFO}"
echo "${INFO} DIR_BACKUPS: ${DIR_BACKUPS}$(check_dir "${DIR_BACKUPS}")"
echo "${INFO} DIR_UTILS: ${DIR_UTILS}$(check_dir "${DIR_UTILS}")"
echo "${INFO} DIR_PZLSD: ${DIR_PZLSD}$(check_dir "${DIR_PZLSD}")"
echo "${INFO} DIR_PLUGINS: ${DIR_PLUGINS}$(check_dir "${DIR_PLUGINS}")"
echo "${INFO} DIR_LOGS: ${DIR_LOGS}$(check_dir "${DIR_LOGS}")"
echo "${INFO} DIR_CONFIG: ${DIR_CONFIG}$(check_dir "${DIR_CONFIG}")"
echo "${INFO} DIR_PUBLIC: ${DIR_PUBLIC}$(check_dir "${DIR_PUBLIC}")"
echo "${INFO} DIR_STATE: ${DIR_STATE}$(check_dir "${DIR_STATE}")"
}
# save_config_example saves pzlsm config example.
function save_config_example() {
bash -c "cat <<'EOF' > ${DIR_CONFIG}/pzlsm.example.cfg
#!/usr/bin/env bash
# SERVER_MEMORY_LIMIT contains memory Limit for JVM in MB.
SERVER_MEMORY_LIMIT=${SERVER_MEMORY_LIMIT}
# SERVER_NAME contains name of Project Zomboid server.
SERVER_NAME=\"${SERVER_NAME}\"
# CLEAR_MAP_DAY contains the number of days after which map chunks will
# be deleted if no one has visited them. Set to 0 to turn off.
CLEAR_MAP_DAY=${CLEAR_MAP_DAY}
# CLEAR_LOGS_DAY contains the number of days after which old game logs will
# be deleted. Set to 0 to turn off.
CLEAR_LOGS_DAY=${CLEAR_LOGS_DAY}
# CLEAR_STACK_TRACE_DAY contains the number of days after which old game
# hs_err_pid (java stack traces) files will be deleted. Set to 0 to turn off.
CLEAR_STACK_TRACE_DAY=${CLEAR_STACK_TRACE_DAY}
# CLEAR_BACKUPS_DAY contains the number of days after which old backups
# will be deleted. Set to 0 to turn off.
CLEAR_BACKUPS_DAY=${CLEAR_BACKUPS_DAY}
# CLEAR_TIME_MACHINE_DAY contains the number of days after which old
# time machine backups will be deleted. Set to 0 to turn off.
CLEAR_TIME_MACHINE_DAY=${CLEAR_TIME_MACHINE_DAY}
# BACKUP_ON_STOP contains switcher to make backup on every server stop.
BACKUP_ON_STOP=\"${BACKUP_ON_STOP}\"
# FIRST_RUN_ADMIN_PASSWORD contains password for user admin which be created
# on first server run.
FIRST_RUN_ADMIN_PASSWORD=\"${FIRST_RUN_ADMIN_PASSWORD}\"
# AUTO_RESTORE contains switcher to restart server if it was down.
AUTO_RESTORE=\"${AUTO_RESTORE}\"
# GITHUB_CONFIG_REPO contains link to github repo with pz config files.
# Leave it blank if you don't plan to use this.
GITHUB_CONFIG_REPO=\"${GITHUB_CONFIG_REPO}\"
# GITHUB_ACCESS_TOKEN contains access token for download server configs from GitHub.
# Leave it blank if you don't plan to use this.
GITHUB_ACCESS_TOKEN=\"${GITHUB_ACCESS_TOKEN}\"
# WRITE_PZLSM_LOGS turns on pzlsm logging.
WRITE_PZLSM_LOGS=\"${WRITE_PZLSM_LOGS}\"
DIR_PLUGINS=\"${DIR_PLUGINS}\"
EOF"
}
# print_version prints versions.
# TODO: Check installations.
function print_version() {
echo "${INFO} Project Zomboid build ${PZ_VERSION}"
echo "${INFO} pzlsm version ${VERSION}"
echo "${INFO} gorcon version ${UTIL_RCON_VERSION}"
echo "${INFO} range version ${UTIL_RANGE_VERSION}"
}
# strclear removes all spaces, quotation marks and tabs from a string.
function strclear() {
local str=${1//\"/}; str=${str// /}; str=${str//$'\t'/}
echo "${str}"
}
# replace_logs_path_to_symlink moves Zomboid/Logs folder to logs/Logs and
# replaces original folder to symlink.
function replace_logs_path_to_symlink() {
if [ "$(is_symlink "${ZOMBOID_DIR_LOGS}")" == "true" ]; then
echo "${ER} ZOMBOID_DIR_LOGS is already symlink to $(realpath "${ZOMBOID_DIR_LOGS}")"; return 0
fi
if [ "$(is_server_running)" == "true" ]; then
echo "${ER} cannot replace logs to symlink on started server"; return 0
fi
if [ "$(is_dir_exist "${DIR_LOGS}/Logs")" == "true" ]; then
echo "${ER} ${DIR_LOGS}/Logs already exists"; return 0
fi
mv "${ZOMBOID_DIR_LOGS}" "${DIR_LOGS}"
if [ ! $? -eq 0 ]; then
echo "${ER} can't move logs folder to new path ${DIR_LOGS}"; return 0
fi
ln -s "${DIR_LOGS}/Logs" "${ZOMBOID_DIR}/Logs"
ZOMBOID_DIR_LOGS="${DIR_LOGS}/Logs"
echo "${INFO} replace logs path form symlink completed"
}
# rollback_logs_path_from_symlink removes Zomboid/Logs symlink and restores
# original logs folder from logs/Logs.
function rollback_logs_path_from_symlink() {
if [ "$(is_symlink "${ZOMBOID_DIR_LOGS}")" != "true" ]; then
echo "${ER} ZOMBOID_DIR_LOGS is not a symlink"; return 0
fi
if [ "$(is_server_running)" == "true" ]; then
echo "${ER} cannot rollback logs path form symlink on started server"; return 0
fi
local symlink_server_logs; symlink_server_logs="$(realpath "${ZOMBOID_DIR_LOGS}")"
rm -f "${ZOMBOID_DIR_LOGS}"
mv "${symlink_server_logs}" "${ZOMBOID_DIR}"
ZOMBOID_DIR_LOGS="${ZOMBOID_DIR}/Logs"
echo "${INFO} rollback logs path form symlink completed"
}
# install_dependencies installs the necessary dependencies to the server.
# You must have sudo privileges to call function install_dependencies.
# This is the only function in this script that needs root privileges.
# You can install dependencies yourself before running this script and do
# not call this function.
function install_dependencies() {
sudo apt-get update
# If a 64-bit version of the system is used, then 32-bit libraries must
# be installed for SteamCMD.
if [ "$(arch)" == "x86_64" ]; then
sudo apt-get install -y lib32gcc-s1
fi
# Update the C libraries for system calls.
sudo apt-get install -y libc6 libc6-dev libc6-dbg linux-libc-dev gcc
# Install Java-SDK. It is required to run the Project Zomboid game server.
sudo apt-get install -y openjdk-17-jdk
# Install screen to run Project Zomboid in the background.
sudo apt-get install -y screen
# To access the game database, you will need the sqlite3 library.
sudo apt-get install -y sqlite3
# Install basic calculator.
sudo apt-get install -y bc
# Install jq for json config parsing.
sudo apt-get install -y jq
sudo apt-get install -y net-tools nmap
echo "${OK} dependencies installed"
}
# create_folders creates folders for pzlsm script.
function create_folders() {
mkdir -p "${DIR_BACKUPS}"
mkdir -p "${DIR_LOGS}"
mkdir -p "${DIR_CONFIG}"
mkdir -p "${DIR_PUBLIC}"
mkdir -p "${DIR_UTILS}"
mkdir -p "${DIR_PZLSD}"
mkdir -p "${DIR_PLUGINS}" # TODO: Spit into two variables.
mkdir -p "${DIR_STATE}"
# Config.
save_config_example
# Backups.
mkdir -p "${DIR_BACKUPS_DOWN}"
mkdir -p "${DIR_BACKUPS_ZOMBOID}"
mkdir -p "${DIR_BACKUPS_PZLSD}"
mkdir -p "${DIR_BACKUPS_COPY}"
mkdir -p "${DIR_BACKUPS_PLAYERS}"
mkdir -p "${DIR_BACKUPS_TIME_MACHINE}"
# Logs
mkdir -p "${DIR_LOGS}/gc"
# Public.
mkdir -p "${DIR_PUBLIC}/saves"
mkdir -p "${DIR_PUBLIC}/logs"
rm -f "${DIR_PUBLIC}/backups"
rm -f "${DIR_PUBLIC}/logs/server"
rm -f "${DIR_PUBLIC}/logs/gc"
ln -s "${DIR_BACKUPS}" "${DIR_PUBLIC}/backups"
ln -s "${ZOMBOID_DIR_LOGS}" "${DIR_PUBLIC}/logs/server"
ln -s "${DIR_LOGS}/gc" "${DIR_PUBLIC}/logs/gc"
ln -sf "${ZOMBOID_DIR_MAP}/WorldDictionary.bin" "${DIR_PUBLIC}/saves/WorldDictionary.bin"
ln -sf "${ZOMBOID_DIR_MAP}/WorldDictionaryLog.lua" "${DIR_PUBLIC}/saves/WorldDictionaryLog.lua"
ln -sf "${ZOMBOID_DIR_MAP}/WorldDictionaryReadable.lua" "${DIR_PUBLIC}/saves/WorldDictionaryReadable.lua"
ln -sf "${ZOMBOID_DIR_MAP}/erosion.ini" "${DIR_PUBLIC}/saves/erosion.ini"
ln -sf "${ZOMBOID_DIR_MAP}/global_mod_data.bin" "${DIR_PUBLIC}/saves/global_mod_data.bin"
ln -sf "${ZOMBOID_DIR_MAP}/gos_campfire.bin" "${DIR_PUBLIC}/saves/gos_campfire.bin"
ln -sf "${ZOMBOID_DIR_MAP}/gos_farming.bin" "${DIR_PUBLIC}/saves/gos_farming.bin"
ln -sf "${ZOMBOID_DIR_MAP}/gos_metaldrum.bin" "${DIR_PUBLIC}/saves/gos_metaldrum.bin"
ln -sf "${ZOMBOID_DIR_MAP}/gos_rainbarrel.bin" "${DIR_PUBLIC}/saves/gos_rainbarrel.bin"
ln -sf "${ZOMBOID_DIR_MAP}/gos_trap.bin" "${DIR_PUBLIC}/saves/gos_trap.bin"
ln -sf "${ZOMBOID_DIR_MAP}/map_meta.bin" "${DIR_PUBLIC}/saves/map_meta.bin"
ln -sf "${ZOMBOID_DIR_MAP}/map_t.bin" "${DIR_PUBLIC}/saves/map_t.bin"
ln -sf "${ZOMBOID_DIR_MAP}/map_zone.bin" "${DIR_PUBLIC}/saves/map_zone.bin"
ln -sf "${ZOMBOID_DIR_MAP}/players.db" "${DIR_PUBLIC}/saves/players.db"
ln -sf "${ZOMBOID_DIR_MAP}/reanimated.bin" "${DIR_PUBLIC}/saves/reanimated.bin"
ln -sf "${ZOMBOID_DIR_MAP}/recorded_media.bin" "${DIR_PUBLIC}/saves/recorded_media.bin"
ln -sf "${ZOMBOID_DIR_MAP}/vehicles.db" "${DIR_PUBLIC}/saves/vehicles.db"
ln -sf "${ZOMBOID_DIR_MAP}/z_outfits.bin" "${DIR_PUBLIC}/saves/z_outfits.bin"
ln -sf "${ZOMBOID_DIR_MAP}/zpop_virtual.bin" "${DIR_PUBLIC}/saves/zpop_virtual.bin"
ln -sf "${ZOMBOID_FILE_DB}" "${DIR_PUBLIC}/saves/${SERVER_NAME}.db"
echo "${OK} folders created"
}
# install_range_builder downloads the regex-range-builder script and puts it
# in the utils directory.
function install_range_builder() {
test -d "${UTIL_RANGE_DIR}" && echo "${UTIL_RANGE_DIR}" && return
wget -P "${DIR_UTILS}" "${UTIL_RANGE_LINK}"
tar -zxvf "${DIR_UTILS}/v${UTIL_RANGE_VERSION}.tar.gz" -C "${DIR_UTILS}"
rm "${DIR_UTILS}/v${UTIL_RANGE_VERSION}.tar.gz"
}
# install_rcon downloads the rcon client and puts it in the utils directory.
function install_rcon() {
test -d "${UTIL_RCON_DIR}" && echo "${UTIL_RCON_DIR}" && return
wget -P "${DIR_UTILS}" "${UTIL_RCON_LINK}"
tar -zxvf "${DIR_UTILS}/rcon-${UTIL_RCON_VERSION}-amd64_linux.tar.gz" -C "${DIR_UTILS}"
rm "${DIR_UTILS}/rcon-${UTIL_RCON_VERSION}-amd64_linux.tar.gz"
}
# install_server installs Project Zomboid dedicated server.
# As arguments, you can pass validate and beta parameters in any order.
# If validate, the integrity and relevance of the current files will be checked.
# The beta parameter will download and install the game from the experimental
# IWBUMS branch. Only the latest stable and IWBUMS branches are supported.
function install_server() {
if [ "$(is_server_running)" == "true" ]; then
echo "${ER} cannot install on started server"; return 0
fi
local beta="${STEAMCMD_BETA}"
case $1 in
none)
beta="-beta none";;
unstable)
beta="-beta unstable";;
iwbums)
beta="-beta iwillbackupmysave -betapassword iaccepttheconsequences";;
*)
if [ -n "$1" ]; then
beta="-beta $1"
fi
esac
# Create a directory for steamcmd and go to it. If the directory
# already exists, no errors occur.
mkdir -p "${HOME}/steamcmd" && cd "${HOME}/steamcmd" || return
# Download steamcmd if it is not in the specified directory.
if [ ! -f "steamcmd.sh" ]; then
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz && tar -xvzf steamcmd_linux.tar.gz
rm steamcmd_linux.tar.gz
fi
# Install Project Zomboid Server.
./steamcmd.sh +login "${STEAMCMD_USERNAME}" +force_install_dir "${SERVER_DIR}" +app_update ${APP_DEDICATED_ID} ${beta} validate +exit
# Return to the script directory.
cd "${BASEDIR}" || return
echo "${OK} server installed"
}
# update_server updates Project Zomboid dedicated server.
function update_server() {
if [ "$(is_server_running)" == "true" ]; then
echo "${ER} cannot update on started server"; return 0
fi
cd "${HOME}/steamcmd" || return
# Update Project Zomboid Server.
./steamcmd.sh +login "${STEAMCMD_USERNAME}" +force_install_dir "${SERVER_DIR}" +app_update ${APP_DEDICATED_ID} validate +exit
# Return to the script directory.
cd "${BASEDIR}" || return
echo "${OK} server updated"
}
# fix_options changes game language to EN.
function fix_options() {
sed -i -r "s/language=.*/language=EN/g" "${ZOMBOID_DIR}/options.ini"
echo "${OK} options fixed"
}
# fix_args sets the home directory for the game, utf8 encoding, server name,
# game language, changes GC option.
function fix_args() {
local arg_home=""
arg_home=$(grep "Duser.home" "${SERVER_DIR}/ProjectZomboid64.json")
[ "${arg_home}" ] && return 0
# Set memory limit for JVM.
sed -i -r "s/Xmx8g/Xmx${SERVER_MEMORY_LIMIT}m/g" "${SERVER_DIR}/ProjectZomboid64.json"
# Change GC type.
sed -i -r "s/UseZGC/UseG1GC/g" "${SERVER_DIR}/ProjectZomboid64.json"
local set_home="\"-Duser.home=${ZOMBOID_HOME_DIR}\""
local set_encoding='"-Dfile.encoding=UTF-8"'
local set_servername="\"-Dservername=${SERVER_NAME}\""
local set_serverlang="\"-Duser.language=${SERVER_LANG}\""
local set_gclog="\"-Xlog:gc*,gc+heap=debug,age*=debug:file=${DIR_LOGS}/gc/gc.out:time,uptime,level,tags:filesize=0:filecount=0\""
local indent="\r\n\t\t"
local _search='"-Dzomboid.steam=1",'
local _replace="${_search}${indent}${set_home},${indent}${set_encoding},${indent}${set_servername},${indent}${set_serverlang},${indent}${set_gclog},"
sed -i -r "s|${_search}|${_replace}|g" "${SERVER_DIR}/ProjectZomboid64.json"
echo "${OK} args fixed"
}
# start starts the server in a screen window.
# An error message will be displayed if server has been started earlier.
# TODO: Add wait arg.
function start() {
echo "${INFO} starting the server..."
local no_screen="$1"
local wait="$2"
if [ "$(is_server_running)" == "true" ]; then
echo "${INFO} server already started"; return 0
fi
rm -f "${DIR_STATE}/started"
screen -wipe > /dev/null 2>&1; sleep 1s
if [ "$no_screen" == "true" ]; then
if ! "${SERVER_DIR}/start-server.sh" -servername "${SERVER_NAME}"; then
echoerr "start: failed to start the server"; return 1
fi
else
if ! env LANG=ru_RU.utf8 screen -U -mdS "${SCREEN_ZOMBOID}" "${SERVER_DIR}/start-server.sh" -servername "${SERVER_NAME}"; then
echoerr "start: failed to start the server"; return 1
fi
fi
sleep 1s
if [ "$(is_server_running)" == "false" ]; then
echoerr "start: failed to start the server"; return 1
fi
if [ "$(is_admin_exists)" == "false" ] && [ -n "${FIRST_RUN_ADMIN_PASSWORD}" ]; then
sleep 1s && screencmd "${FIRST_RUN_ADMIN_PASSWORD}" # Create password.
sleep 1s && screencmd "${FIRST_RUN_ADMIN_PASSWORD}" # Confirm password.
fi
mkdir -p "${DIR_STATE}" && echo "${NOW}" > "${DIR_STATE}/started"
if [ "$wait" == "true" ]; then
while [ "$wait" == "true" ]; do
sleep 10s
local started=""; started=$(clog_search "SERVER STARTED" "DebugLog-server" | wc -l)
if [ "$started" == "1" ]; then
wait="false"
echo "${OK} SERVER STARTED"
fi
done
fi
}
# stop stops the server.
function stop() {
echo "${INFO} stopping the server..."
rm -f "${DIR_STATE}/started"
if [ "$(is_server_running)" == "false" ]; then
echo "${INFO} server already stopped"; return 0
fi
# kickusers is used for fix a game bug.
# When `quit` game command is executed, there is no log record the fact
# that the players was exit the game. If you make a forced kick from the
# server, then the log entry appears correctly.
kickusers
sleep 1s
if ! screencmd 'quit'; then
echoerr "stop: server is not stopped correctly"
fi
# If after a regular shutdown server remains running, we must forcibly stop it.
sleep 20s
local pid_screen
pid_screen=$(get_screen_pid)
if [ -n "${pid_screen}" ]; then
echo "${INFO} kill screen process ${pid_screen}"
kill "${pid_screen}" > /dev/null 2>&1; sleep 1s
fi
echo "${OK} server is stopped"
if [ "$1" == "fix" ] || [ "$2" == "fix" ]; then
delete_mods_manifest
fi
if [ "${NO_TASKS_ON_STOP}" == "true" ]; then
echo "${INFO} no tasks enabled"; return 0
fi
if [ "$1" == "now" ] || [ "$1" == "kill" ]; then
return 0
fi
# After a stopping the server invokes the function of cleaning garbage that
# the game generates during its operation.
delete_old_chunks "${CLEAR_MAP_DAY}"
delete_old_logs "${CLEAR_LOGS_DAY}"
delete_old_java_stack_traces "${CLEAR_STACK_TRACE_DAY}"
# Backups.
if [ "${BACKUP_ON_STOP}" == "true" ]; then
backup "world"
backup "pzlsd"
fi
}
# restart stops the server and starts it after 10 seconds.
function restart() {
echo "${INFO} restarting the server..."
stop "$1" "$2"
sleep 10s
start "false" "$3"
}
# autorestart restarts server if it stuck.
function autorestart() {
if [ "${AUTO_RESTORE}" != "true" ]; then
return 0
fi
local pid_zomboid=""
pid_zomboid=$(get_server_pid)
if [ -z "${pid_zomboid}" ] && [ -f "${DIR_STATE}/started" ]; then
NOW=$(date "+%Y%m%d_%H%M%S")
local down="${DIR_BACKUPS_DOWN}/${NOW}"
mkdir "${down}"
find "${ZOMBOID_DIR_LOGS}" -maxdepth 1 -name \*.txt -exec cp {} "${down}" \;
cp "${ZOMBOID_DIR}/server-console.txt" "${down}"
cp "${DIR_LOGS}/gc/gc.out" "${down}"
start
return 0
fi
local result
result=$(rconcmd players 5s 2>&1 >/dev/null | grep ': i/o timeout')
if [ -n "${result}" ]; then
NOW=$(date "+%Y%m%d_%H%M%S")
local down="${DIR_BACKUPS_DOWN}/${NOW}"
mkdir "${down}"
find "${ZOMBOID_DIR_LOGS}" -maxdepth 1 -name \*.txt -exec cp {} "${down}" \;
cp "${ZOMBOID_DIR}/server-console.txt" "${down}"
cp "${DIR_LOGS}/gc/gc.out" "${down}"
restart kill
fi
}
# stats displays information on the peak processor consumption and
# current RAM consumption.
function stats() {
local pid_zomboid=""
pid_zomboid=$(get_server_pid)
if [ -z "${pid_zomboid}" ]; then
echoerr "stats: server is not running"; return 1
fi
local pid_zomboid_count; pid_zomboid_count="$(echo "${pid_zomboid}" | wc -l)"
if [ "${pid_zomboid_count}" -gt "1" ]; then
pid_zomboid="${pid_zomboid//$'\n'/ }"
echoerr "stats: multiple server processes are running with pids: ${pid_zomboid}"
return 1
fi
local cpu; cpu=$(strclear "$(ps S -p "${pid_zomboid}" -o pcpu=)")
local mem1; mem1=$(ps S -p "${pid_zomboid}" -o pmem=)
local mem2; mem2=$(ps -ylp "${pid_zomboid}" | awk '{x += $8} END {print "" x/1024;}')
local jvmres; jvmres=$(jstat -gc "${pid_zomboid}")
local jvm1; jvm1=$(echo "${jvmres}" | awk 'NR>1 { printf("%.1f", $8/$7*100); }')
local jvm2; jvm2=$(echo "${jvmres}" | awk 'NR>1 { printf("%.2f", $8/1024); }')
local jvm3; jvm3=$(echo "${jvmres}" | awk 'NR>1 { printf("%.2f", $7/1024); }')
#local mem_used_percent=$((100*"${MEMORY_USED}"/"${MEMORY_AVAILABLE}"))
local mem_used_percent=$(bc <<< "scale=1; (100*${MEMORY_USED}/${MEMORY_AVAILABLE})")
local uptime; uptime=$(ps -p "${pid_zomboid}" -o etime | grep -v "ELAPSED" | xargs)
[ "${#cpu}" == "3" ] && cpu=" ${cpu}"
echo "${INFO} cpu srv: ${cpu}%"
echo "${INFO} mem host: ${mem_used_percent}% (${MEMORY_USED} MB from ${MEMORY_AVAILABLE})"
echo "${INFO} mem srv: ${mem1}% (${mem2} MB)"
echo "${INFO} mem jvm: ${jvm1}% (${jvm2} MB from ${jvm3} MB)"
echo "${INFO} uptime: ${uptime}"
}
# stats_top prints list of top $1 processes with memory usage.
function stats_top() {
local number="$1"
[ -z "${number}" ] && number=10
ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n ${number} | sort -rn | awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}'
}
# shutdown_wrapper triggers informational messages for players to alert them of
# impending server shutdown. After 5 minutes, it calls the stop or restart
# function.
function shutdown_wrapper() {
if [ "$(is_server_running)" == "false" ]; then
echo "${INFO} server already stopped"
return 0
fi
ticker() {
local msg=$1
if [ "$2" != "now" ] && [ "$2" != "kill" ]; then
echo "${INFO} ${msg} 5 minutes"
screencmd "servermsg \"${msg} 5 minutes\""
sleep 240s
echo "${INFO} ${msg} 1 minute";
screencmd "servermsg \"${msg} 1 minute\""
sleep 50s
fi
if [ "$2" != "kill" ]; then
echo "${INFO} ${msg} 10 seconds";
screencmd "servermsg \"${msg} 10 seconds\""
sleep 5s
t=5
while [ ${t} -gt 0 ]; do
screencmd "servermsg \"${msg} ${t} seconds\""
sleep 1s
((t=t-1))
done
fi
}
case "$1" in
stop)
ticker "Stopping the server in" "$2"
stop "$2" "$3"
;;
restart)
ticker "Restarting the server in" "$2"
restart "$2" "$3" "$4"
;;
*)
echoerr "shutdown_wrapper: wrong shutdown command: $1"
return 1
;;
esac
}
# console connects to screen session.
function console() {
if [ "$(is_server_running)" == "false" ]; then
echo "${INFO} server is not running"
return 0
fi
screen -r "${SERVER_NAME}"
}
# screencmd calls the $1 command to the game using screen util.
# The screencmd function is faster than rconcmd, but you cannot get a response
# to the request. Therefore, it should be used when the answer is not needed.
function screencmd() {
if [ "$(is_server_running)" == "false" ]; then
echo "${INFO} server is not running"
return 0
fi
local command="$1"
[ -z "${command}" ] && { echoerr "screencmd: command is not set"; return 1; }
screen -S "${SCREEN_ZOMBOID}" -X stuff "${command}\r"
}
# rconcmd calls the $1 command to the game using Source RCON Protocol.
# The port and authorization parameters takes from the Project Zomboid config.
function rconcmd() {
if [ "$(is_server_running)" == "false" ]; then
echo "${INFO} server is not running"
return 0
fi
local command="$1"
[ -z "${command}" ] && { echoerr "rconcmd: command is not set"; return 1; }
local timeout="$2"
[ -z "${timeout}" ] && timeout=3s
local host='127.0.0.1'
local port=""
local password=""
port=$(grep "RCONPort=" "${ZOMBOID_FILE_CONFIG_INI}"); port=${port//RCONPort=/}; port=${port// /}
password=$(grep "RCONPassword=" "${ZOMBOID_FILE_CONFIG_INI}"); password=${password//RCONPassword=/}; password=${password// /}
${UTIL_RCON_FILE} -a "${host}:${port}" -p "${password}" -T "${timeout}" "${command}"
}
# kickusers kicks all players from the server.
function kickusers() {
local players=""
if ! players=$(rconcmd "players"); then
echoerr "kickusers: cannot get users"; return 0;
fi
local i=0
players=$(echo "${players}" | grep ^"-")
if [ "${players}" ]; then
IFS=$'\n'
declare -a a
a=("${players}")
for line in "${a[@]}"; do
((i=i+1))
local username="${line:1}"
screencmd "kickuser \"${username}\""
done
fi
echo "${OK} kicked ${i} users"
}
# delete_mods_manifest deletes appworkshop_108600.acf file. It need to
# update mods correctly.
function delete_mods_manifest() {
[ ! -f "${ZOMBOID_MODS_MANIFEST}" ] && return 0
echo "${INFO} remove appworkshop_${APP_ID}.acf"
rm "${ZOMBOID_MODS_MANIFEST}"
}
# delete_old_java_stack_traces deletes hs_err_pid*.log files that are older
# than $1 days from server root directory.
# If you do not pass the number of days $1, or pass the value 0 then the
# default value will be taken from the variable CLEAR_STACK_TRACE_DAY.
function delete_old_java_stack_traces() {
local days="$1"
[ -z "${days}" ] && days=${CLEAR_STACK_TRACE_DAY}
# Do nothing if turned off in the settings.
[ "${days}" -eq "0" ] && return
# Remove java stack traces.
local count
(( days-- ))
count=$(find "${SERVER_DIR}" -name "hs_err_pid*.log" -mtime +${days} | wc -l)
find "${SERVER_DIR}" -name "hs_err_pid*.log" -mtime +${days} -delete
(( days++ ))
echo "${INFO} remove hs_err_pid*.log files older than ${days} days... ${count} files"
}
# delete_old_logs deletes log files that are older than $1 days from
# Zomboid/Logs directory.
# If you do not pass the number of days $1, or pass the value 0 then the
# default value will be taken from the variable CLEAR_LOGS_DAY.
function delete_old_logs() {
local days="$1"
[ -z "${days}" ] && days=${CLEAR_LOGS_DAY}
# Do nothing if turned off in the settings.
[ "${days}" -eq "0" ] && return 0
# Remove old logs folders.
local count
(( days-- ))
count=$(find "${ZOMBOID_DIR_LOGS}" -name "*.txt" -mtime +${days} | wc -l)
find "${ZOMBOID_DIR_LOGS}" -name "*.txt" -mtime +${days} -delete
(( days++ ))
echo "${INFO} remove logs files older than ${days} days... ${count} files"
# Remove empty logs folders.
find "${ZOMBOID_DIR_LOGS}" -empty -type d -delete
}
# delete_zombies deletes all zpop_*_*.bin files from Zomboid/Saves directory.
# These files are responsible for placing zombies on the world.
# It is recommended to use with a turned off server. When used on a running
# server, it can create more problems than it solves.
# But it can help the game restart the threads responsible for the zombies,
# if they freeze.
# TODO: Find a way to real zombies delete.
function delete_zombies() {
local count
count=$(find "${ZOMBOID_DIR_MAP}" -name "zpop_*_*.bin" | wc -l)
echo "${INFO} remove zpop_*_*.bin files... ${count} files"
rm -rf "${ZOMBOID_DIR_MAP}/zpop_*_*.bin"
}
# delete_gos_files deletes gos_*.bin files from Zomboid/Saves directory.
function delete_gos_files() {
local count
count=$(find "${ZOMBOID_DIR_MAP}" -name "gos_*.bin" | wc -l)
echo "${INFO} remove gos_*.bin files... ${count} files"
rm -rf "${ZOMBOID_DIR_MAP}/gos_*.bin"
}
# delete_isoregiondata deletes isoregiondata folder from Zomboid/Saves directory.
function delete_isoregiondata() {