Lobby watching script for linux.

Did you create a mod, map, music, or a tool? Present them here and earn feedback!
Note: addon requests do not belong here.
Note, everything uploaded to this forum, MUST have a license!
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Lobby watching script for linux.

Post by NoQ »

Very simple one. :) It connects to the lobby web interface, does some parsing of the web page and plays some sound every five seconds if at least one game is waiting in the lobby. You'll need to modify it to use your favorite sound and audio player, and you can also change the beeping rate (check out the comments). You'll need the curl package for this to work. Then you can run it in the background while doing other things. I hope it won't overload the lobby server. Suggestions are welcome.

Code: Select all

#!/bin/sh
while [ 1 ]; do
	if [ "`curl wz2100.net/lobbyserver 2>&1 | grep 'Current games' -A3 | tail -n 1 | awk '{print $1}'`" != "</ul>" ]; then 
		mpg123 letsplay.mp3 # put your sound and probably another sound player here
	fi
	sleep 5 # put the delay amount here.
done
I'm not familiar with MacOS and other UNIX-like OSes, but i think it might be working under them as well.
Last edited by NoQ on 13 Apr 2010, 18:56, edited 1 time in total.
User avatar
macuser
Regular
Regular
Posts: 1052
Joined: 19 Mar 2010, 23:35
Location: USA

Re: Lobby watching script for linux.

Post by macuser »

Actually the game has the lobby built in but I see how u could use this for notifications. Just turn the time between connects down a bit :). BTW it looks like it would only work on mac/linux/unix.

-regards macuser
ArtRev Website

ImageImage

System: AMD Phenom II x4, 4GB RAM, 640GB HD, Nvidia GeForce GT 240 1GB, Mac OS X 10.6
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Lobby watching script for linux.

Post by NoQ »

Actually the game has the lobby built in
I know :)
But it doesn't auto-update and [therefore] doesn't beep when a game starts, and even if it did, it is not a pleasure to do something while an instance of warzone is running (even if you manage to "alt+tab", it still consumes some resources).
BTW it looks like it would only work on mac/linux/unix.
I've heared someone saying that windows is POSIX-compliant now, but even if it is, a typical windows user will still be unable to guess how to run this script. (And how is it supposed to beep? Run windows media player all the time? :lol2: )
Just turn the time between connects down a bit
Agreed. Edited my first message.
User avatar
macuser
Regular
Regular
Posts: 1052
Joined: 19 Mar 2010, 23:35
Location: USA

Re: Lobby watching script for linux.

Post by macuser »

Windows is only "posix" compliant IF youve installed "cygwin" http://www.cygwin.com/ which is a unix shell for windows - HOWEVER most ppl have never heard of it. If you want your script to be able to run on windows, you should include cygwin lite with it :).

-regards macuser
ArtRev Website

ImageImage

System: AMD Phenom II x4, 4GB RAM, 640GB HD, Nvidia GeForce GT 240 1GB, Mac OS X 10.6
stiv
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 876
Joined: 18 Jul 2008, 04:41
Location: 45N 86W

Re: Lobby watching script for linux.

Post by stiv »

macuser wrote: If you want your script to be able to run on windows, you should include cygwin lite with it
I suspect that if hao was concerned about Windows, he would have named his post something other than "Lobby watching script for linux".

The idea of including cygwin with a short shell script like this is amusing. And I say that as someone who has set up and used cygwin environments on Windows.
User avatar
Zarel
Elite
Elite
Posts: 5770
Joined: 03 Jan 2008, 23:35
Location: Minnesota, USA

Re: Lobby watching script for linux.

Post by Zarel »

Eeek, you're scraping wz2100.net/lobbyserver? Maybe we should offer XML/JSON output...
User avatar
Emdek
Regular
Regular
Posts: 1329
Joined: 24 Jan 2010, 13:14
Location: Poland

Re: Lobby watching script for linux.

Post by Emdek »

Zarel wrote:Maybe we should offer XML/JSON output...
Good idea, CSV would be also useful.
Maybe we could have kind of switch to get wanted format (?format=xml, or after slash: http://wz2100.net/lobbyserver/xml)?
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.


Beware! Mad Qt Evangelist.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Lobby watching script for linux.

Post by NoQ »

I acltually meant something like this:
http://en.wikipedia.org/wiki/Microsoft_ ... s_for_UNIX
(and it seems to be pretty similar to cygwin, but official).
(i've seen some windows lovers who used emacs via cygwin. but i think it must me at least 100mb heavy (since it must include an X server) (never tried actually))
(oh no, why all my topics end up in some windows vs. linux holywar :( )
Eeek, you're scraping wz2100.net/lobbyserver? Maybe we should offer XML/JSON output...
Wow, we could use some! On the other hand, i could've looked at the source and do something similar to what the game itself does (though it might be more complicated).
User avatar
macuser
Regular
Regular
Posts: 1052
Joined: 19 Mar 2010, 23:35
Location: USA

Re: Lobby watching script for linux.

Post by macuser »

Very interesting. However I am NOT about to start a "holy war" I have all 3 :wink: windows mac and linux and I use them all. However I hope your script can be facilitated by csv or whatever so as not to load down the server when 100 computers update every 5 secconds - poor server :augh: . Anyway good luck and keep working

-regards macuser
ArtRev Website

ImageImage

System: AMD Phenom II x4, 4GB RAM, 640GB HD, Nvidia GeForce GT 240 1GB, Mac OS X 10.6
User avatar
Buginator
Professional
Professional
Posts: 3285
Joined: 04 Nov 2007, 02:20

Re: Lobby watching script for linux.

Post by Buginator »

hao wrote: Wow, we could use some! On the other hand, i could've looked at the source and do something similar to what the game itself does (though it might be more complicated).
Or just use the lobby bot source code (svn/trunk/tools) ... python love! :ninja:
and it ends here.
stiv
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 876
Joined: 18 Jul 2008, 04:41
Location: 45N 86W

Re: Lobby watching script for linux.

Post by stiv »

hao wrote:oh no, why all my topics end up in some windows vs. linux holywar
Because no good deed goes unpunished? And because all the Windozers are jealous of your mad linux skillz and the elegant simplicity of your script? Don't Fear The Penguin!
User avatar
Zarel
Elite
Elite
Posts: 5770
Joined: 03 Jan 2008, 23:35
Location: Minnesota, USA

Re: Lobby watching script for linux.

Post by Zarel »

hao wrote:I acltually meant something like this:
http://en.wikipedia.org/wiki/Microsoft_ ... s_for_UNIX
(and it seems to be pretty similar to cygwin, but official).
(i've seen some windows lovers who used emacs via cygwin. but i think it must me at least 100mb heavy (since it must include an X server) (never tried actually))
(oh no, why all my topics end up in some windows vs. linux holywar :( )
1. Cygwin is fairly slow, and, afaik, does not include an X server.
2. Windows SFU is only available for the "Enterprise" and "Ultimate" versions of Windows - you can't even get it on Windows 7 Professional (and doesn't include an X server, either).

Really, X isn't exactly an inextricable part of POSIX.
stiv
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 876
Joined: 18 Jul 2008, 04:41
Location: 45N 86W

Re: Lobby watching script for linux.

Post by stiv »

Hao's script doesn't need an X server. Just a Bourne-like shell and the associated utilities.

POSIX is an operating system interface. Completely separate from X Windows.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Lobby watching script for linux.

Post by NoQ »

Script version 0.2.
It is even simplier now, and it reports only games with specific version.

Code: Select all

#!/bin/sh

# Preferred game version
VERSION="2.3"

# Beep command
COMMAND="mplayer mn.wav"

# Delays (in seconds)
SLEEP=5

while [ 1 ]; do
	if [ "`curl wz2100.net/lobbyserver 2>&1 | grep 'warzone://' | grep $VERSION`" != "" ]; then 
		$COMMAND
	fi
	sleep $SLEEP
done