Author Topic: A simple "who's online?" script  (Read 2196 times)

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
A simple "who's online?" script
« 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
« Last Edit: January 04, 2011, 01:51:20 pm by Gilrond »

Earowo

  • Veteran
  • *
  • Posts: 1463
    • View Profile
    • Guild Site
Re: A simple "who's online?" script
« Reply #1 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.
Dohmo: Please clean up your language immediately.
Me: as i just said, what i said, fits in the guidlines of rated PG, i was just explaining to the G guy
Dohmo: Sorry I tried to e nice
Dohmo: and i'm telling you to clean it up. last warning
Dohmo: now just do it
Dohmo: No more warnings

Abuse?

Sangwa

  • Forum Addict
  • *
  • Posts: 2083
  • Chars: Morwen and Gartheiz
    • View Profile
Re: A simple "who's online?" script
« Reply #2 on: January 03, 2011, 08:11:12 pm »
I like this one.
Disclaimer: This is my opinion and I can be reasoned with. I'm probably right, though.

Join the Dark Empire!

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #3 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.
« Last Edit: January 03, 2011, 09:25:54 pm by Gilrond »

novacadian

  • Hydlaa Notable
  • *
  • Posts: 960
    • View Profile
Re: A simple "who's online?" script
« Reply #4 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, just follow the Back 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 

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #5 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.

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: A simple "who's online?" script
« Reply #6 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 (or ZeroPing today), even with customizable character groups.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #7 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!'
« Last Edit: January 06, 2011, 03:09:07 pm by Gilrond »

novacadian

  • Hydlaa Notable
  • *
  • Posts: 960
    • View Profile
Re: A simple "who's online?" script
« Reply #8 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. That is the one that is scraped for the Characters Currently Online PS listing of The Cooperative Plot Creation Project.

- Nova
« Last Edit: January 04, 2011, 12:43:05 pm by novacadian »

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #9 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.

Sarva

  • Game Masters
  • Hydlaa Notable
  • *
  • Posts: 621
    • View Profile
Re: A simple "who's online?" script
« Reply #10 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

novacadian

  • Hydlaa Notable
  • *
  • Posts: 960
    • View Profile
Re: A simple "who's online?" script
« Reply #11 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

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #12 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

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.

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #13 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
« Last Edit: January 06, 2011, 07:11:14 pm by Gilrond »

Gilrond

  • Hydlaa Notable
  • *
  • Posts: 764
    • View Profile
Re: A simple "who's online?" script
« Reply #14 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.
« Last Edit: May 03, 2011, 10:56:55 am by Gilrond »