#!/bin/bash
#===============================================================================
#
#          FILE: webtool_log2db
#
#         USAGE: webtool_log2db
#
#   DESCRIPTION: Convert from log(in running server directory only) 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


for ZoneServerDir in ~/server*/ZoneServer*;do
        [ -d $ZoneServerDir ] && cd $ZoneServerDir || continue
        export WORLDID=$(get_server_id $(get_set $(basename $PWD)) $(get_ch $(basename $PWD)) zone)
        export SET=$(get_set $WORLDID)

        cat Item[0-9]* 2> /dev/null|\
        LC_ALL=C nice -19 egrep "$(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
        [ -d $WorldServerDir ] && cd $WorldServerDir || continue
        export WORLDID=$(get_server_id $(get_set $(basename $PWD)) $(get_ch $(basename $PWD)) world)
        export SET=$(get_set $WORLDID 2> /dev/null)

        cat Character.log* 2> /dev/null |sed "s/'/''/g" |\
	nice -19 ~/bin/log2any.py log2db $SET $WORLDID 2>> ~/log2db_debug.log
done


for MissionServerDir in ~/server*/MissionServer*;do
        [ -d $MissionServerDir ] && cd $MissionServerDir || continue
        export SET=$(get_set $(awk -F/ '{print $NF}' <<< $MissionServerDir))

        cat Auction.log* 2> /dev/null |\
	sed "s/'/''/g" |\
        nice -19 ~/bin/log2any.py log2db $SET $WORLDID 2>> ~/log2db_debug.log
done
