PlaneShift

Support => Server Status => Topic started by: Gilrond on January 03, 2011, 06:17:56 pm

Title: A simple "who's online?" script
Post by: Gilrond on January 03, 2011, 06:17:56 pm
I put this together just for quick checks (for Zeroping). May be it'll be useful for someone. It's not too flexible, but works for current page.

Code: [Select]
#!/bin/bash

wget -q 'http://62.173.168.9/index.php?page=char_stats' -O - | grep -A 4 'Players Online' | tail -n 1 | ruby -n -e 'print $_.strip.gsub(/,\s*/, "\n")' | sort
Title: Re: A simple "who's online?" script
Post by: Earowo on January 03, 2011, 08:08:32 pm
Tryin to be positive here but, for ingame you can do /who
and if you look in the mods section of the forum, i believe you will find a downloadable app to find out who's online without having to log in.
Title: Re: A simple "who's online?" script
Post by: Sangwa on January 03, 2011, 08:11:12 pm
I like this one.
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 03, 2011, 09:07:27 pm
The whole point is to get the list without the client, so it works without logging in. It just cuts the list from here: http://62.173.168.9/index.php?page=char_stats and simply sorts it. May be there are simpler ways to get the list, I just don't know about them.
Title: Re: A simple "who's online?" script
Post by: novacadian on January 03, 2011, 09:14:10 pm

If you would like to know a little more about some of the folks who are presently logged on PS (http://trollkeep.com/cgi-bin/ps/ps_current_online.pl), just follow the Back (http://trollkeep.com/PS/) link and register. The bold names are click-able to registered users. You will be able to get a lot of OOC info on the character.

- Nova 
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 03, 2011, 09:22:45 pm
Thanks. Is there a page which just purely shows the list, or some web service which dumps XML or something? It would be neater to use, rather than cutting a regular html page.
Title: Re: A simple "who's online?" script
Post by: LigH on January 04, 2011, 02:22:17 am
Long, long time ago, the server XML report was available semi-publicly. In those times already I wrote a script that reads and interprets it to show active guild members on guild websites.

That must have been the reason to hide it (or to not make it public again after a server move): It contained Character-Guild relations, even for secret guilds.

So for now, interpreting the HTML output seems to be the only way. And as Earowo mentioned: Aiwendil already wrote a Small script to see who is online on laanx (http://www.hydlaaplaza.com/smf/index.php?topic=36145.0) (or ZeroPing today), even with customizable character groups.
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 04, 2011, 12:19:40 pm
Thanks.

If you save the above script as let's say zeroping_online.sh, you can highlight buddies (let's say Foo and Bar) with:

Code: [Select]
ps_online.sh | egrep --color 'Foo|Bar|$'
Or if one needs to just filter them, you can do:

Code: [Select]
ps_online.sh | egrep 'Foo|Bar'
You can make it periodic with some sleeps and loops too. And show some alerts with something like:
Code: [Select]
notify-send 'Foo is on-line!'
Title: Re: A simple "who's online?" script
Post by: novacadian on January 04, 2011, 12:39:55 pm
Thanks. Is there a page which just purely shows the list, or some web service which dumps XML or something? It would be neater to use, rather than cutting a regular html page.

Yep, just go to derula's list (http://psstatus.uglyhorst.de/chars_list.txt). That is the one that is scraped for the Characters Currently Online PS (http://trollkeep.com/cgi-bin/ps/ps_current_online.pl) listing of The Cooperative Plot Creation Project (http://trollkeep.com/PS).

- Nova
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 04, 2011, 12:49:18 pm
I see, thanks :) The actual server could actually also produce a pure list just for convenience. There is no need to include guilds information there, if it's considered secret.
Title: Re: A simple "who's online?" script
Post by: Sarva on January 04, 2011, 12:59:55 pm
If you just want to see who is online try http://62.173.168.9/index.php?page=char_stats (http://62.173.168.9/index.php?page=char_stats)
Title: Re: A simple "who's online?" script
Post by: novacadian on January 04, 2011, 01:02:09 pm
I see, thanks :) The actual server could actually also produce a pure list just for convenience. There is no need to include guilds information there, if it's considered secret.

It is my understanding that derula's list is made available to keep unnessasary load off the main server. His list is updated every 10 minutes or something like that. So for that reason the PS listing is meant for real eyeballs.  ;)

- Nova
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 04, 2011, 01:05:28 pm
If you just want to see who is online try http://62.173.168.9/index.php?page=char_stats (http://62.173.168.9/index.php?page=char_stats)

Thanks Sarva, that's exactly what I used to extract the list in the script above :)

It is my understanding that derula's list is made available to keep unnessasary load off the main server. His list is updated every 10 minutes or something like that. So for that reason the PS listing is meant for real eyeballs.  ;)
Ah, this makes sense. 10 minutes though is rather long for rapid alerts, but it unloads the server, yes.
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 06, 2011, 03:08:34 pm
Some more bash fun.

Save your buddies list in some file (~/.PlaneShift/buddies.txt let's say), and the above list script as zeroping_online.sh
Create this script below in the same directory as show_ps_buddies.sh let's say (for examplel in ~/bin, so we have ~/bin/show_ps_buddies.sh and etc.):

Code: [Select]
#!/bin/bash

zeroping_online="`dirname ${BASH_SOURCE[0]}`/zeroping_online.sh"

if (($# < 1)) || (($# > 2))
then
   echo -e "\nInvalid number of arguments specified!\n\
Usage: `basename $0` <buddies_list_file> [all]\n\
Note : If 'all' (or actually anything) is provided as a second parameter, buddies will be highlighted in the full list, instead of being filtered from it."
   exit 1
fi

if (($# == 1))
then
   show_all=false
else
   show_all=true
fi

col_prefix=${buddies_color:-'\e[1;32m'}
col_suffix='\e[0m'
buddies_list_file=$1

if [ ! -f "$buddies_list_file" ]; then echo "Invalid buddies list file ${buddies_list_file} specified!"; exit 2; fi

online_list=( `$zeroping_online` )
buddies_list=( `sort -u $buddies_list_file` )

echo -e "Total users on-line: ${#online_list[*]}\n\
------------------------"

i=0
j=0
while [ $i -lt ${#online_list[*]} ] && [ $j -lt ${#buddies_list[*]} ]
do
   if [[ "${online_list[$i]}" < "${buddies_list[$j]}" ]]
   then
      if $show_all; then echo ${online_list[$i]}; fi
      ((i++))
   elif [[ "${online_list[$i]}" == "${buddies_list[$j]}" ]]
   then
      echo -e ${col_prefix}${online_list[$i]}${col_suffix}
      ((i++))
      ((j++))
   else
      ((j++))
   fi
done

while $show_all && [ $i -lt ${#online_list[*]} ]
do
   echo ${online_list[$i]}
   ((i++))
done

Now just run it with path to buddies list and optional second parameter (if present it includes full list).
Override buddies_color to change highlighting color. For example:

Code: [Select]
buddies_color='\e[1;33m' ~/bin/show_ps_buddies.sh ~/.PlaneShift/buddies.txt all
Title: Re: A simple "who's online?" script
Post by: Gilrond on January 06, 2011, 05:49:47 pm
And some wrapper around it, for periodic updates (place it in the same directory as other scripts, and name let's say ps_buddies.sh):

Code: [Select]
#!/bin/bash

if (($# > 0))
then
  show_all='all'
else
  show_all=''
fi

show_ps_buddies="`dirname ${BASH_SOURCE[0]}`/show_ps_buddies.sh"

xterm -bg black -fg white -cr '#001' -fn '-*-fixed-medium-r-*-*-15-*-*-*-*-*-*-*' -geometry 24x60 -e bash -c \
"echo -ne \"\033]0;Zeroping\007\"; \
while true; \
 do \
  clear; \
  date +%T; \
  $show_ps_buddies ${HOME}/.PlaneShift/buddies.txt $show_all; \
  sleep 60; \
done" > /dev/null 2>&1 &

Period is set to 60 seconds. Increase it if you don't need updates that often. You can change the font (experiment with xfontsel, or just search for some) and other xterm parameters there to better suit your needs. If run as is - shows filtered list. If with any parameters - shows full list.