#!/bin/bash

source ~/.gamerc

PREV_SIX_HOURS_DATE="$(date -d "-6 hours" +"%Y/%m/%d %H:%M"|head -c 14)"

###### BEGIN: Section for Checking MissionServer Blew Date ######
if [ "$GAME_TYPE" == "FF" ] || [ "$GAME_TYPE" == "AK" ] || [ "$GAME_TYPE" == "M11" ] || [ "$GAME_TYPE" == "M12" ] || [ "$GAME_TYPE" == "G1" ] ; then
        for MissionServerDir in ~/server*/MissionServer*;do

                # MissionServer Rank log ( Blew Date )
                [ -d $MissionServerDir ] && cd $MissionServerDir || continue
                export SET=$(get_set $(awk -F/ '{print $NF}' <<< $MissionServerDir))

                grep -h "^[ 0-9]\+,$PREV_SIX_HOURS_DATE" $(
                        ls -tr Rank*.log.* 2> /dev/null|tail -5
                )|grep ',RankUpdate'|sed "s/'/''/g" |\
                nice -19 ~/bin/log2any.py ms_blew_date $SET 2>> ~/log2db_debug.log

        done
elif [ "$GAME_TYPE" == "AR" ] || [ "$GAME_TYPE" == "LA" ] ; then
        for MissionServerDir in ~/server*/MissionServer*;do

                # MissionServer Family log ( Blew Date )
                [ -d $MissionServerDir ] && cd $MissionServerDir || continue
                export SET=$(get_set $(awk -F/ '{print $NF}' <<< $MissionServerDir))

                grep -h "^[ 0-9]\+,$PREV_SIX_HOURS_DATE" $(
                        ls -tr Family*.log.* 2> /dev/null|tail -5
                )|grep ',FamilyUpdate'|sed "s/'/''/g" |\
                nice -19 ~/bin/log2any.py ms_blew_date $SET 2>> ~/log2db_debug.log

        done
fi
###### END: Section for Checking MissionServer Blew Date ######
