My NWN helper script (Bash, OS X)

Moderator: Event DM

Post Reply
User avatar
Pat Briams
Scholar of Fools
Posts: 348
Joined: Mon Oct 19, 2009 10:04 am
Timezone: +8
Location: Shanghai, China

My NWN helper script (Bash, OS X)

Post by Pat Briams » Wed Jun 29, 2011 4:31 am

I've been having all sorts of problems connecting to Gamespy since last week. So I expanded my log rotator shell script to do direct connecting as well. Not sure if anyone will find it useful, but by all means modify it to your hearts content~

Linux users: replace lines 8 and 10 with your NWN executable path, and lines 92-104 with your NWN logs directory path.

Code: Select all

#!/bin/bash
# CoPaP direct connector and log rotator for Mac OS X
# Usage: invoke filename without parameters

connect () {
	if [ -z "$1" ]
	then
		/Applications/Neverwinter\ Nights/Neverwinter\ Nights.app/Contents/MacOS/Neverwinter\ Nights
	else
		/Applications/Neverwinter\ Nights/Neverwinter\ Nights.app/Contents/MacOS/Neverwinter\ Nights +connect "$1"
	fi
	wait
}

echo "Choose an option (case insensitive):"
echo -e "\t\033[1mN\033[0muvar"
echo -e "\tI\033[1mr\033[0mon"
echo -e "\t\033[1mT\033[0moloira"
echo -e "\t\033[1mD\033[0meglos"
echo -e "\t\033[1mE\033[0mlysia"
echo -e "\t\033[1mF\033[0merrell"
echo -e "\t\033[1mL\033[0me'Or"
echo -e "\t\033[1mM\033[0m'Chek"
echo -e "\tM\033[1mi\033[0mkona"
echo -e "\t\033[1mU\033[0mnderdark"
echo -e "\t\033[1mV\033[0misimontium"
echo -e "\t\033[1mW\033[0milderness"
echo -e "\t\033[1mH\033[0mala"
echo -e "\tT\033[1ma\033[0miris'nàdur"
echo -e "\t\033[1mY\033[0msgard"
echo -e "\tConnect to \033[1mG\033[0mamespy"

echo -n ">"
read option

case "$option" in
	"N" | "n" )			#Nuvar
	connect server.arkaz.com:5121
	;;
	"r" | "R" )			#Iron
	connect server.arkaz.com:5122
	;;
	"T" | "t" )			#Toloira
	connect server.arkaz.com:5123
	;;
	"i" | "I" )			#Mikona
	connect world.avlis.org:5121
	;;
	"W" | "w" )			#Wilderness
	connect world.avlis.org:5122
	;;
	"E" | "e" )			#Elysia
	connect world.avlis.org:5123
	;;
	"L" | "l" )			#Le'Or
	connect world.avlis.org:5124
	;;
	"D" | "d" )			#Deglos
	connect world.avlis.org:5125
	;;
	"F" | "f" )			#Ferrell
	connect world.avlis.org:5126
	;;
	"V" | "v" )			#Visimontium
	connect world.avlis.org:5129
	;;
	"U" | "u" )			#Underdark
	connect world.avlis.org:5130
	;;
	"M" | "m" )			#M'Chek
	connect world.avlis.org:5131
	;;
	"H" | "h" )			#Hala
	connect nwn.ysgard.org:5123
	;;
	"Y" | "y" )			#Ysgard
	connect nwn.ysgard.org:5124
	;;
	"a" | "A" )			#Tairis'nàdur
	connect nwn.tairisnadur.com:5121
	;;
	"G" | "g" ) 		#Gamespy
	connect
	;;
	* )			#Default
	echo "* Unknown option"
	exit 1
	;;
esac

# Consolidates current session logs into one file
if [ -s /Applications/Neverwinter\ Nights/Logs/nwclientLog1.txt ]; then
	cat /Applications/Neverwinter\ Nights/Logs/nwclientLog1.txt >> ~/Desktop/nwclientLog1.txt
	echo "---" >> ~/Desktop/nwclientLog1.txt 
fi

if [ -e /Applications/Neverwinter\ Nights/Logs/nwclientLog2.txt ]; then
	cat /Applications/Neverwinter\ Nights/Logs/nwclientLog2.txt >> ~/Desktop/nwclientLog1.txt
	mv /Applications/Neverwinter\ Nights/Logs/nwclientLog2.txt ~/.Trash/
fi

if [ -e /Applications/Neverwinter\ Nights/Logs/nwclientLog3.txt ]; then
        cat /Applications/Neverwinter\ Nights/Logs/nwclientLog3.txt >> ~/Desktop/nwclientLog1.txt
        mv /Applications/Neverwinter\ Nights/Logs/nwclientLog3.txt ~/.Trash/
fi

Patrick Briams
Greater Ivory rookie
User avatar
maxinion
Team Member; Retired with Honors
Posts: 2778
Joined: Mon Mar 17, 2003 7:44 pm
DM Avatar: Andrinor
Location: Bay Area, CA
Contact:

Re: My NWN helper script (Bash, OS X)

Post by maxinion » Wed Jun 29, 2011 4:43 am

Friggen nice man. I may make some modifications to the log rotator part now that someone's given me a skeleton to work with. Thanks!
User avatar
PlasmaJohn
CCC / Release Admin
CCC / Release Admin
Posts: 9010
Joined: Fri Dec 26, 2003 10:37 pm
Timezone: US/Eastern
Location: Negaria
Contact:

Re: My NWN helper script (Bash, OS X)

Post by PlasmaJohn » Wed Jun 29, 2011 12:53 pm

Neither +connect nor -connect work under Linux. Regardless, I've populated my Favorites tab with the Avlis server instead of depending on GameSpy or history.
Calvin: This is so cool!
Hobbes: This is so stupid.
User avatar
S_N
Team Member; Retired with Honors
Posts: 452
Joined: Tue Feb 09, 2010 3:21 pm
Timezone: UTC+1
DM Avatar: Ingoren
Location: Scandinavia

Re: My NWN helper script (Bash, OS X)

Post by S_N » Wed Oct 12, 2011 1:43 pm

Here's some extra log processing snipplets to save logs and rename them into ISO 8601 date format for easy sorting. Maybe you find some of it useful too?

Prior running neverwinter, start with clean empty logs.

Code: Select all

rm logs/nwclientLog*
touch logs/nwclientLog{1,2,3,4}.txt
then I'd add a '&' after nwmain so the script does not block until nwn finished running. (Skipping lots of LD_PRELOAD hacks for brevity)

Code: Select all

./nwmain $@ &
sleep 2  #give nwmain 2 second to have it's pid registered
tail --pid=$(pidof nwmain) -f -q logs/nwclientLog{1,2,3,4}.txt | python logparse.py >> logs/$(date +%Y-%m-%d).log&
Quick and dirty log processor in python that cuts down timestamps to once each minute and removes the stuff in brackets ([] [CLIENT_CHAT_BLAH]) preceding every line.

Code: Select all

import sys
import re

ts_interval = 0
lastlog_time = 1
def parsetime(timestr):
    global lastlog_time
    newtime=timestr[12:17]
    if lastlog_time != newtime:
        lastlog_time=newtime
        print timestr

a = 0
for line in sys.stdin:
    line = line.strip()
    a=a+1
    if line=='' or len(line) < 41:
        continue
    m = re.search('^(\[.+?\])?\ +(\[.*?\])?\ +(.+)$',line)
    parsetime(line[19:40])
    if m == None:
        print "STRANGE: " + line
    else:
        #print "Norm: " + m.group(3)
        if m.group(3).count(" : ") >= 2:
            if m.group(3).endswith(")"):  #This handle most combat rolls
                continue        #just throw away for now.
        print m.group(3)
My python script does not flush actively, so if you are looking at the log file while playing you will notice it lags behind until python decide to flush it's output buffers. But there is no risk of losing it will flush when "tail -f" exits.
Sample logfile processor wrote:Beck Dattian: I am a bit thirsty, Care for some more wine?
June Osammy: I've some too, shouldnt it be my treat this time?
Lost Item: Sweet Tirith I'Ni Wine
[Wed Oct 12 02:29:07]
Kassha Firehart: [Tell] what are you up too?
Beck Dattian: No no, it is my duty to share wine with all. It is also my pleasure
Beck Dattian: *smiles*
Acquired Item: Vervain Wine
Beck Dattian: Well here's to you Ms. Osammy
Beck Dattian uses item's special power.
* drinks *
June Osammy: [Tell] Too?
[Wed Oct 12 02:30:06]
Kassha Firehart: [Tell] to? maybe
June Osammy uses item's special power.
* drinks *
Lost Item: Vervain Wine
Beck Dattian: *nods head* Very fine
Beck Dattian: Well shall we take care of the rest?
June Osammy: [Tell] :-) We're in the mikona crypt.
Kassha Firehart: [Tell] still skeletons?
June Osammy: [Tell] Drinking wines
[Wed Oct 12 02:31:07]
Acquired Item: Sweet Tirith I'Ni Wine
Success: 8 (24), Remaining PSPs: 510
Remaining Psionic Strength Points: 538
You manifest Psionic Residue
Zombie Warrior damages Beck Dattian: 3 (3 Physical)
Beck Dattian damages Ghast: 10 (6 Physical 2 Cold 2 Fire)
Zombie Warrior damages Beck Dattian: 1 (1 Physical)
Beck Dattian damages Ghast: 10 (6 Physical 2 Cold 2 Fire)
Beck Dattian damages Ghast: 14 (10 Physical 2 Cold 2 Fire)
Success: 9 (22), Remaining PSPs: 530
June Osammy damages Zombie Warrior: 2 (2 Physical)
You manifest Project Force
Ghast damages Beck Dattian: 1 (1 Physical)
Post Reply