#!/bin/bash
#===============================================================================
#
#          FILE: webtool_log2db
#
#         USAGE: webtool_log2db
#
#   DESCRIPTION: Convert from log(-10 minutes) file to WebTool log_search
#
#       OPTIONS: 
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Mon Nov 28 02:01:08 EST 2011
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================
#set -o nounset                              # Treat unset variables as an error
#set -m                                      # Enable job control

source ~/.gamerc

PREV_TEN_MINUTES_DATE="$(date -d "-10 minutes" +"%Y/%m/%d %H:%M"|head -c 15)"

for MissionServerDir in ~/server*/MissionServer*;do

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

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

done

#for ZoneServerDir in ~/server*/ZoneServer*;do
#
#	# Item log and Trade(Gold) log
#	[ -d $ZoneServerDir ] && cd $ZoneServerDir || continue
#	export WORLDID=$(get_server_id $(get_set $(basename $PWD)) $(get_ch $(basename $PWD)) zone)
#	export SET=$(get_set $WORLDID)
#
#	grep -h "^[ 0-9]\+,$PREV_TEN_MINUTES_DATE" $(
#		ls -tr Item[0-9]* 2> /dev/null|tail -2
#	)|\
#	LC_ALL=C nice -19 egrep -A1 "$(cat $(dirname $0)/webtool_log2db_zonelog_filter|egrep -v "^$|^#"|tr '\n' '|'|sed 's/|$//g')"|\
#	sed "s/'/''/g" |\
#	nice -19 ~/bin/log2any.py log2db $SET $WORLDID 2>> ~/log2db_debug.log
#
#done
#
#
#for WorldServerDir in ~/server*/WorldServer*;do
#
#	# Character remove/add log
#	[ -d $WorldServerDir ] && cd $WorldServerDir || continue
#	export WORLDID=$(get_server_id $(get_set $(basename $PWD)) $(get_ch $(basename $PWD)) world)
#	export SET=$(get_set $WORLDID)
#
#	grep -h "^[ 0-9]\+,$PREV_TEN_MINUTES_DATE" $(
#		ls -tr Character*log* 2> /dev/null|tail -2
#	)|sed "s/'/''/g" |\
#	nice -19 ~/bin/log2any.py log2db $SET $WORLDID 2>> ~/log2db_debug.log
#
#done
#
#for MissionServerDir in ~/server*/MissionServer*;do
#
#        # Auction log
#        [ -d $MissionServerDir ] && cd $MissionServerDir || continue
#        export SET=$(get_set $(awk -F/ '{print $NF}' <<< $MissionServerDir))
#
#        grep -h "^[ 0-9]\+,$PREV_TEN_MINUTES_DATE" $(
#                ls -tr Auction.log.* 2> /dev/null|tail -2
#        )|sed "s/'/''/g" |\
#	nice -19 ~/bin/log2any.py log2db $SET $WORLDID 2>> ~/log2db_debug.log
#
#done
#
#if [ "$GAME_TYPE" == "FF" ] || [ "$GAME_TYPE" == "AR" ] ; then
#    for WorldServerDir in ~/server*/WorldServer*;do
#        # Two Password log
#        [ -d $WorldServerDir ] && cd $WorldServerDir || continue
#        export WORLDID=$(get_server_id $(get_set $(basename $PWD)) $(get_ch $(basename $PWD)) world)
#        export SET=$(get_set $WORLDID)
#
#        grep -h "^[ 0-9]\+,$PREV_TEN_MINUTES_DATE" $(
#                ls -tr Password*log* 2> /dev/null|tail -2
#        )|sed "s/'/''/g" |\
#        nice -19 ~/bin/log2any.py pwdlog $SET $WORLDID 2>> ~/pwd2db_debug.log
#    done
#fi
#
