DayZ-Stat-Server/config/statserver_json.sh

142 lines
4.2 KiB
Bash
Raw Normal View History

2021-01-31 13:30:33 +01:00
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/dayz/database:/home/dayz/Dayz:/root/bin
#
# Script Bash json to sql for Dayz Server Stat
# Version : 0.1
##remise a zero ID :
# ALTER TABLE StatServer AUTO_INCREMENT=0
# DELETE FROM `StatServer`;
# TRUNCATE TABLE StatServer
#
2021-01-31 15:23:05 +01:00
# need to create the directory if dosen't exist an error will appear.
2021-02-02 14:23:37 +01:00
pathd="/home/dayz/git-DayZ-server-stat"
2021-01-31 15:23:05 +01:00
# create directory
varMod="server1"
2021-01-31 13:30:33 +01:00
# Game Port IP mod
2021-02-02 14:23:37 +01:00
IpGame="103.58.149.102"
2021-02-02 17:05:03 +01:00
PortGame="2302"
QueryGame="27016"
2021-01-31 13:30:33 +01:00
2021-02-02 17:05:03 +01:00
TABLE="StatServer_1"
2021-02-02 17:25:40 +01:00
DB_USER=""
DB_PASSWD=""
DB_NAME=""
DB_SERV=""
2021-02-02 17:05:03 +01:00
CHECKstatserver="/tmp/CHECKstatserver_${varMod}.json"
2021-01-31 15:42:37 +01:00
statserver="${pathd}/${varMod}/statserver.json"
gameqjson="${pathd}/${varMod}/gameqjson.json"
2021-01-31 15:23:05 +01:00
####### don't touch below #####
2021-01-31 13:30:33 +01:00
# (will change in future update)
2021-01-31 15:23:05 +01:00
# pathBin="/dayz/bin"
pathDBe="${pathd}/${varMod}"
2021-01-31 13:30:33 +01:00
2021-02-02 17:05:03 +01:00
# NEED to SET date
2021-01-31 13:30:33 +01:00
# SQL
2021-01-31 15:23:05 +01:00
datesql=$(date +'%F %T')
date=$(date +'%F %T')
2021-01-31 13:30:33 +01:00
#DEBUG:
# ls ${statserver}
########################
2021-01-31 15:23:05 +01:00
if [ -d ${pathd}/${varMod} ]
2021-01-31 13:30:33 +01:00
then
2021-02-02 14:23:37 +01:00
echo " ✅ Directory ${pathd}/${varMod} ok"
2021-01-31 13:30:33 +01:00
else
2021-01-31 15:23:05 +01:00
mkdir -p ${pathd}/${varMod}
echo " ✅ Directory ${pathd}/${varMod} CREATED ✅"
2021-01-31 13:30:33 +01:00
fi
2021-02-02 14:23:37 +01:00
2021-01-31 15:27:43 +01:00
if [ ! -r "$statserver" ]; then
echo " ⛔Error:"${statserver}" doesn't exits"
2021-02-02 17:05:03 +01:00
# exit 1
2021-01-31 15:27:43 +01:00
fi
2021-01-31 13:30:33 +01:00
2021-02-02 14:23:37 +01:00
nmapGame=`/usr/local/bin/gamedig --type dayz $IpGame:$QueryGame > ${CHECKstatserver}`
catCHECKstatserver=`cat ${CHECKstatserver}`
if [[ "$catCHECKstatserver" == *error* ]]
then
echo -e " ✅ Game is Down | port $PortGame closed! ⛔ "
insert_mysql_down && echo -e " ✅ Mysql Updated " || echo -e "\n !!!!!!!!!!!!! Huston , MYSQL issue ⛔"
# echo -e "\n Mysql updated"
2021-01-31 15:23:05 +01:00
exit 1
2021-02-02 14:23:37 +01:00
else
echo -e " ✅ Game is UP | port $PortGame OPEN ✅ !\n"
cp ${CHECKstatserver} ${statserver}
2021-01-31 15:23:05 +01:00
2021-01-31 15:27:43 +01:00
########################## not use
2021-01-31 15:23:05 +01:00
2021-01-31 13:30:33 +01:00
insert_mysql_down() {
numplayers="0"
players="0"
ping="0"
2021-02-02 17:05:03 +01:00
mysql --host=$DB_SERV --user=$DB_USER --password=$DB_PASSWD --database=$DB_NAME << EOF
2021-01-31 13:30:33 +01:00
SET NAMES utf8;
2021-01-31 15:42:37 +01:00
insert into $TABLE (\`date\`,\`name\`,\`game\`,\`map\`,\`version\`,\`requiredVersion\`,\`numplayers\`,\`players\`,\`maxplayers\`,\`ping\`,\`timeserver\`,\`hive\`,\`battleye\`,\`connect\`,\`secure\`) VALUES ("$datesql","OFFLINE","$game","$map","$version","$requiredVersion","$numplayers","$players","$maxplayers","$ping","$timeserver","$hive","$battleye","$connect","$secure");
2021-01-31 13:30:33 +01:00
EOF
}
varcat=$(cat $statserver)
name=$(echo $varcat | jq -r '.name')
map=$(echo $varcat | jq -r '.map')
password=$(echo $varcat | jq -r '.password')
game=$(echo $varcat | jq -r '.raw.game')
numplayers=$(echo $varcat | jq -r '.raw.numplayers')
version=$(echo $varcat | jq -r '.raw.version')
maxplayers=$(echo $varcat | jq -r '.maxplayers')
ping=$(echo $varcat | jq -r '.ping')
connect=$(echo $varcat | jq -r '.connect')
secure=$(echo $varcat | jq -r '.raw.secure')
requiredVersion=$(echo $varcat | jq -r '.raw.rules.requiredVersion')
island=$(echo $varcat | jq -r '.raw.rules.island')
#players=$(echo $varcat | jq -r '.players[]')
#players="on"
#gq_players=$(echo `cat ${gameqjson}` | jq -r 'gq_players')
mod=$(echo $varcat | jq -r '.raw.tags[63:66]')
hive=$(echo $varcat | jq -r '.raw.tags[18:26]')
battleye=$(echo $varcat | jq -r '.raw.tags[:8]')
2021-02-02 17:05:03 +01:00
timeserver=$(echo $varcat | jq -r '.raw.tags[68:]')
2021-01-31 13:30:33 +01:00
speedtime=$(echo $varcat | jq -r '.raw.tags[41:42]')
speedtimenight=$(echo $varcat | jq -r '.raw.tags[54:55]')
timeLeft=$(echo $varcat | jq -r '.raw.rules.timeLeft')
secure=$(echo $varcat | jq -r '.raw.secure')
serverstatus="UP"
#timeserver="00:00"
###############
# check
echo " [✔] Server UP =>> update mysql"
echo " Debug: $numplayers"
insert_mysql() {
2021-02-02 17:05:03 +01:00
mysql --host=$DB_SERV --user=$DB_USER --password=$DB_PASSWD --database=$DB_NAME << EOF
2021-01-31 13:30:33 +01:00
SET NAMES utf8;
2021-01-31 15:42:37 +01:00
insert into $TABLE (\`date\`,\`name\`,\`game\`,\`map\`,\`version\`,\`requiredVersion\`,\`numplayers\`,\`players\`,\`maxplayers\`,\`ping\`,\`timeserver\`,\`hive\`,\`battleye\`,\`connect\`,\`secure\`) VALUES ("$datesql","$name","$game","$map","$version","$requiredVersion","$numplayers","$players","$maxplayers","$ping","$timeserver","$hive","$battleye","$connect","$secure");
2021-01-31 13:30:33 +01:00
EOF
}
insert_mysql && echo -e "\n ✅ Updated Mysql " || echo -e "\n Huston ,up MYSQL issue"
fi
2021-02-02 17:05:03 +01:00
echo -e "\nCheck Date SQL format:"
echo $date
2021-01-31 13:30:33 +01:00
exit 1