#!/bin/bash
#===============================================================================
#
#          FILE: searchplayer
#
#         USAGE: searchplayer <Account Name|Character name|Character ID|Client IP>
#
#   DESCRIPTION: Search players from table currentuser
#
#       OPTIONS: <Account Name|Character name|Character ID|Client IP>
#
#  REQUIREMENTS:
#
#         NOTES:
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Mon May 23 02:35:52 EDT 2011
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================

#set -o nounset                              # Treat unset variables as an error
set -m                                       # Enable job control 
source ~/.gamerc

[ "$1" == "" ] && exec echo "Usage: $0 <Account Name|Character name|Character ID|Client IP>"

NUM="$(echo $1|tr -d '[[:space:][:punct:][:cntrl:]A-Za-z]')"
[ "$NUM" == "" ] && NUM=0

if [ "$2" == "" ] ;then
	echo "select * from currentuser where strcharid like '$1' or mid like '$1' or char_id::text like '$NUM' or clientip like '$1';" \
	| PGPASSWORD="$LIVE_SERVER_DB_PASSWORD" psql -h "accountdb" $MEMBER_DB_NAME # | grep "$1" --color
else
	echo "select * from currentuser where strcharid like '$1' or mid like '$1' or char_id::text like '$NUM' or clientip like '$1';" \
	| PGPASSWORD="$LIVE_SERVER_DB_PASSWORD" psql -h "$2" $MEMBER_DB_NAME # | grep "$1" --color
fi

