From 1d9925c287b318ec21343e2682b51ab6a36ae8db Mon Sep 17 00:00:00 2001 From: Diego Roversi Date: Sun, 8 Sep 2019 18:12:27 +0200 Subject: initial commit from cvs 1.6.2 --- http2/.cvsignore | 2 + http2/config.txt | 1 + http2/data/bab.png | Bin 0 -> 1902 bytes http2/data/baub.png | Bin 0 -> 1736 bytes http2/data/beab.png | Bin 0 -> 1677 bytes http2/data/beb.png | Bin 0 -> 1587 bytes http2/data/biab.png | Bin 0 -> 1679 bytes http2/data/bib.png | Bin 0 -> 1655 bytes http2/data/biob.png | Bin 0 -> 1531 bytes http2/data/bob.png | Bin 0 -> 1682 bytes http2/data/boob.png | Bin 0 -> 1617 bytes http2/data/bub.png | Bin 0 -> 1490 bytes http2/data/byb.png | Bin 0 -> 2592 bytes http2/data/checked.png | Bin 0 -> 1032 bytes http2/data/close.png | Bin 0 -> 478 bytes http2/data/confirm.html | 34 +++ http2/data/disabled.png | Bin 0 -> 814 bytes http2/data/hat1.png | Bin 0 -> 202 bytes http2/data/hat2.png | Bin 0 -> 310 bytes http2/data/header.png | Bin 0 -> 11619 bytes http2/data/index.html | 292 ++++++++++++++++++++ http2/data/lbab.png | Bin 0 -> 2592 bytes http2/data/lbeb.png | Bin 0 -> 1583 bytes http2/data/lbib.png | Bin 0 -> 1663 bytes http2/data/lbiob.png | Bin 0 -> 1520 bytes http2/data/name.html | 189 +++++++++++++ http2/data/new.html | 271 ++++++++++++++++++ http2/data/options.html | 285 +++++++++++++++++++ http2/data/sfbob.png | Bin 0 -> 1785 bytes http2/data/sfbub.png | Bin 0 -> 1664 bytes http2/data/stop.html | 101 +++++++ http2/data/unchecked.png | Bin 0 -> 327 bytes http2/data/wave1.png | Bin 0 -> 307 bytes http2/data/wave2.png | Bin 0 -> 327 bytes http2/data/wave3.png | Bin 0 -> 313 bytes http2/header.png | Bin 0 -> 11619 bytes http2/httppages.py | 705 +++++++++++++++++++++++++++++++++++++++++++++++ http2/sf/bb12.py | 274 ++++++++++++++++++ http2/sf/sfbub.png | Bin 0 -> 1664 bytes http2/sf/started.html | 44 +++ 40 files changed, 2198 insertions(+) create mode 100644 http2/.cvsignore create mode 100644 http2/config.txt create mode 100644 http2/data/bab.png create mode 100644 http2/data/baub.png create mode 100644 http2/data/beab.png create mode 100644 http2/data/beb.png create mode 100644 http2/data/biab.png create mode 100644 http2/data/bib.png create mode 100644 http2/data/biob.png create mode 100644 http2/data/bob.png create mode 100644 http2/data/boob.png create mode 100644 http2/data/bub.png create mode 100644 http2/data/byb.png create mode 100644 http2/data/checked.png create mode 100644 http2/data/close.png create mode 100644 http2/data/confirm.html create mode 100644 http2/data/disabled.png create mode 100644 http2/data/hat1.png create mode 100644 http2/data/hat2.png create mode 100644 http2/data/header.png create mode 100644 http2/data/index.html create mode 100644 http2/data/lbab.png create mode 100644 http2/data/lbeb.png create mode 100644 http2/data/lbib.png create mode 100644 http2/data/lbiob.png create mode 100644 http2/data/name.html create mode 100644 http2/data/new.html create mode 100644 http2/data/options.html create mode 100644 http2/data/sfbob.png create mode 100644 http2/data/sfbub.png create mode 100644 http2/data/stop.html create mode 100644 http2/data/unchecked.png create mode 100644 http2/data/wave1.png create mode 100644 http2/data/wave2.png create mode 100644 http2/data/wave3.png create mode 100644 http2/header.png create mode 100644 http2/httppages.py create mode 100755 http2/sf/bb12.py create mode 100644 http2/sf/sfbub.png create mode 100644 http2/sf/started.html (limited to 'http2') diff --git a/http2/.cvsignore b/http2/.cvsignore new file mode 100644 index 0000000..5be8cea --- /dev/null +++ b/http2/.cvsignore @@ -0,0 +1,2 @@ +*.py[co] +config.txt diff --git a/http2/config.txt b/http2/config.txt new file mode 100644 index 0000000..0af71a3 --- /dev/null +++ b/http2/config.txt @@ -0,0 +1 @@ +{'queen': {}, '*': {'finalboard': '100', 'beginboard': '1', 'extralife': '50000', 'autoreset': 'n', 'lvlend': 'y', 'lifegainlimit': '1', 'metapublish': 'y', 'limit': 'n', 'file': 'levels/Levels.bin', 'time': '1567957746.48', 'lives': '3', 'stepboard': '1'}} diff --git a/http2/data/bab.png b/http2/data/bab.png new file mode 100644 index 0000000..b97b8fc Binary files /dev/null and b/http2/data/bab.png differ diff --git a/http2/data/baub.png b/http2/data/baub.png new file mode 100644 index 0000000..8d85660 Binary files /dev/null and b/http2/data/baub.png differ diff --git a/http2/data/beab.png b/http2/data/beab.png new file mode 100644 index 0000000..443d20a Binary files /dev/null and b/http2/data/beab.png differ diff --git a/http2/data/beb.png b/http2/data/beb.png new file mode 100644 index 0000000..8aa3368 Binary files /dev/null and b/http2/data/beb.png differ diff --git a/http2/data/biab.png b/http2/data/biab.png new file mode 100644 index 0000000..9de577d Binary files /dev/null and b/http2/data/biab.png differ diff --git a/http2/data/bib.png b/http2/data/bib.png new file mode 100644 index 0000000..c2ec110 Binary files /dev/null and b/http2/data/bib.png differ diff --git a/http2/data/biob.png b/http2/data/biob.png new file mode 100644 index 0000000..211e023 Binary files /dev/null and b/http2/data/biob.png differ diff --git a/http2/data/bob.png b/http2/data/bob.png new file mode 100644 index 0000000..f01ca02 Binary files /dev/null and b/http2/data/bob.png differ diff --git a/http2/data/boob.png b/http2/data/boob.png new file mode 100644 index 0000000..eef411a Binary files /dev/null and b/http2/data/boob.png differ diff --git a/http2/data/bub.png b/http2/data/bub.png new file mode 100644 index 0000000..22742de Binary files /dev/null and b/http2/data/bub.png differ diff --git a/http2/data/byb.png b/http2/data/byb.png new file mode 100644 index 0000000..716988b Binary files /dev/null and b/http2/data/byb.png differ diff --git a/http2/data/checked.png b/http2/data/checked.png new file mode 100644 index 0000000..df0201c Binary files /dev/null and b/http2/data/checked.png differ diff --git a/http2/data/close.png b/http2/data/close.png new file mode 100644 index 0000000..6d9534b Binary files /dev/null and b/http2/data/close.png differ diff --git a/http2/data/confirm.html b/http2/data/confirm.html new file mode 100644 index 0000000..928764d --- /dev/null +++ b/http2/data/confirm.html @@ -0,0 +1,34 @@ + + + + + +See you + + + +

Confirmation

+ +

%(count > 1 and ('There are %d clients'%count) or 'There is a client')s +still connected to your server.

+ +

Are you sure you want to stop the server now? +           + +

+ +
+ + + +
+ + +
+<<< Cancel +           +Yes, Really Quit >>> +
+
+ + diff --git a/http2/data/disabled.png b/http2/data/disabled.png new file mode 100644 index 0000000..922c394 Binary files /dev/null and b/http2/data/disabled.png differ diff --git a/http2/data/hat1.png b/http2/data/hat1.png new file mode 100644 index 0000000..b3684d1 Binary files /dev/null and b/http2/data/hat1.png differ diff --git a/http2/data/hat2.png b/http2/data/hat2.png new file mode 100644 index 0000000..6494580 Binary files /dev/null and b/http2/data/hat2.png differ diff --git a/http2/data/header.png b/http2/data/header.png new file mode 100644 index 0000000..c9a8566 Binary files /dev/null and b/http2/data/header.png differ diff --git a/http2/data/index.html b/http2/data/index.html new file mode 100644 index 0000000..08dcc2f --- /dev/null +++ b/http2/data/index.html @@ -0,0 +1,292 @@ + + + + + +The Bub's Brothers + + +  +
+ +%( +externaltarget = running and ' target="new"' or '' +)s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
  Stop this program 
   
 The Bub's Brothers 
   
   
  + Web Home page - + Player Names & Teams - + Configuration       + 
   
  + + + + + +
New game + + + + + +
%( +if running: + print '
' + print '' % tim + print '' + print '' + print '

' + if juststarted: + print 'Server started!' + elif justconnected: + print 'Playing' + elif count == 0: + print 'No client is connected to your server at the moment.' + elif count == 1: + print 'One connected client.' + else: + print '%d connected clients.' % count + print '

' + print '

' % (running[0][0], running[0][1], self.httpport, tim), + print 'Join your own game now at %s:%s

' % ( + running[0]) +##if metapublish: +## import time +## print '

' % time.time() +## if self.globaloptions.metapublish == 'y': +## self.has_been_published = 1 +## metaquery = metaquery or [] +## metaquery.insert(0, 'desc='+fndesc) +## s = 'a=' + metapublish +## if s not in metaquery: +## metaquery.insert(0, s) +## print 'Register again', +## else: +## print 'Register (after all)', +## print 'your server to the SourceForge meta-server
' +## print '' % time.time() +## print 'Unregister your server', +## print '(it is unregistered automatically after some time', +## print 'when other people cannot find it, or', +## print 'if you stop it with the link Stop this program at the top of the page)

' +)s +
+ +%( +if self.Game: + print '' + else: + print 'value="Start a new game">' +else: + print 'You need the complete version to start a new game.
With this version you can only connect to existing servers and only over fast links!' +)s +
+
+
+
 
   
   
 %( +servers = self.getlocalservers()[:] + +found = [] +def show((addr, (info, ping)), found=found): + import socket + infolst = info.split(':') or ['?'] + if len(infolst) >= 3: + httpport = infolst.pop(2) + else: + httpport = 'off' + print '' % ( + addr[0], addr[1], httpport, tim) + host, port = addr + #host = socket.gethostbyaddr(host)[0] + if ping is not None: + infolst.append('ping: %dms' % int(ping*1000)) + if (addr, infolst[0]) == running: + infolst.append('this is your own server') + found.append(1) + infolst = map(htmlquote, infolst) + print '%s:%s playing %s' % ( + host, port, infolst[0]) + if len(infolst) > 1: + print ' (%s)' % ' · · '.join(infolst[1:]) + +if servers is None: + rowspan = 1 +else: + rowspan = (len(servers) or 1)+1 +)s + + + ' + for s in servers[1:]: + print '' + print ' +
+ + Local games + + +%( +if servers is not None: + if servers: + show(servers[0]) + else: + print "(no server found)" + print '
' + show(s) + print '
' +)s + + + +
+%( +if running and not found: + import hostchooser, gamesrv + if gamesrv.displaysockport(gamesrv.openpingsocket()) != hostchooser.UDP_PORT: + print '

Note: your server does not appear in this list' + print 'because the UDP port %d is already in use (is another Bub & Bob server running on this machine?).' % hostchooser.UDP_PORT + print 'Use the full server address %s:%s

' % running[0] +)s +
+ + +
+
+

+ + Or connect to server: + + (host or host:port) + +

+
+
 
   
   
  + + + + + +
Internet games + + + + + +

Go to the Internet servers page

+

Don't forget to give a name + to your dragons before you join a server! +

+
+
 
  
   
+ + + + diff --git a/http2/data/lbab.png b/http2/data/lbab.png new file mode 100644 index 0000000..24fd915 Binary files /dev/null and b/http2/data/lbab.png differ diff --git a/http2/data/lbeb.png b/http2/data/lbeb.png new file mode 100644 index 0000000..a04a9e0 Binary files /dev/null and b/http2/data/lbeb.png differ diff --git a/http2/data/lbib.png b/http2/data/lbib.png new file mode 100644 index 0000000..191142a Binary files /dev/null and b/http2/data/lbib.png differ diff --git a/http2/data/lbiob.png b/http2/data/lbiob.png new file mode 100644 index 0000000..afc809f Binary files /dev/null and b/http2/data/lbiob.png differ diff --git a/http2/data/name.html b/http2/data/name.html new file mode 100644 index 0000000..dab24f9 --- /dev/null +++ b/http2/data/name.html @@ -0,0 +1,189 @@ + + + + + +Name Bub's Brothers + + +  + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +%( +buttons = { +0: """ +""", +1: """ +"""} +for id, img, bgcolor in [ + (0, 'bub.png', '#c0ffc0'), + (1, 'bob.png', '#c0c0ff'), + (2,'boob.png', '#ffc0c0'), + (3, 'beb.png', '#ffc000'), + (4,'biob.png', '#ffff00'), + (5, 'bab.png', '#c04040'), + (6, 'bib.png', '#c0c0c0'), + (7,'baub.png', '#fc60ff'), + (8,'beab.png', '#4fa4ff'), + (9,'biab.png', '#0ab237'), + ]: + keyid = "player%d" % id + playername = options.get(keyid) or '' + playername = playername.strip() + for team in [1,2]: + if playername.endswith('(%d)' % team): + playername = playername[:-3].strip() + break + else: + team = 'off' + def nameval(value, team=team, teamid="team%d" % id): + s = 'value="%s"' % (value,) + if team == value: + s += ' selected' + return s + print """ + + + + + + + +""" % (bgcolor, img, bgcolor, keyid, playername, + bgcolor, id, nameval('off'), nameval(1), nameval(2)) +)s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
   
   
   
 Player Names 
   
   
  + Back to the main page + 
   
    + +  
   
  +    +    + + 
   
   
   
   
   
  
   
+ + +
+
+ + + diff --git a/http2/data/new.html b/http2/data/new.html new file mode 100644 index 0000000..1709c8d --- /dev/null +++ b/http2/data/new.html @@ -0,0 +1,271 @@ + + + + + +New Bub's Brothers Server + + +  + +
+ + +%( +def nameval(name, value, default=0, options=options): + s = getattr(options, name) + if s == value or (default and not s): + s = 'checked ' + else: + s = '' + return s + 'name="%s" value="%s"' % (name, value) +)s + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +%( +if running: print ''' + + + + + +''')s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
   
   
   
 New Server 
   
   
  + Back to the main page + 
   
  + + + + + +
Level file + + + + + +
+
+
+
 
  + + + + + + +
Levels to play + Start at level +and go on ... + + +  to the end of the level file
+  to level
+ skipping levels: + +
+
 
  + + + + + +
Limited lives +  no limited lives --- just run for points!
+  limit to lives (with an extra life for each points)
+  limit lifegain to max. life per level +
+
 
  + + + + + +
Permanent server +  Automatically restart the server after the end is reached, forever
+ Non-permanent servers time out after 2 hours of inactivity +
+
 
  + + + + + +
Internet game + + + + + +

 register the server on the Bub-'n-Bros meta-server, allowing it to appear on everybody's Internet Games list

+
+
 
   
  + + 
  +Note: this will replace the server already running on this machine. + 
   
   
   
   
   
  
   
+
+ + + diff --git a/http2/data/options.html b/http2/data/options.html new file mode 100644 index 0000000..8ded787 --- /dev/null +++ b/http2/data/options.html @@ -0,0 +1,285 @@ + + + + + +Settings - The Bub's Brothers + +  + +%( +def nameval(type, name, value=None, default=None, mangling=1, options=options): + if mangling: + name = mode.unique_id() + '_' + name + s = getattr(options, name) or default + checked = s == value + if type == 'option': + return 'option %svalue="%s"' % (checked and 'selected ' or '', value) + elif type == 'select': + return 'select name="%s"' % name + elif type == 'text': + return 'input type=text name="%s" value="%s"' % ( + name, htmlquote(s)) + else: + return 'input type=%s %sname="%s" value="%s"' % ( + type, checked and 'checked ' or '', name, value) + +def begingroup(text, fgcolor, bgcolor, lightbgcolor, img, nbitems): + global groupinfo + print '' + print '' % (nbitems or 1, bgcolor) + print '%s' % (fgcolor, text) + print '' + groupinfo = [lightbgcolor, bgcolor, fgcolor, 0, 0, img] + if not nbitems: + begingroupitem() + endgroupitem() +def begingroupitem(highlight=0): + if groupinfo[4]: + print '' + groupinfo[4] += 1 + groupinfo[3] = highlight + print '' % groupinfo[highlight] + print '' +def endgroupitem(): + print '
' + if groupinfo[3]: + print '' % groupinfo[-1] + print '
' + print '' +def endgroup(): + pass + +def beginmode(): + highlight = mode in currentmodes + begingroupitem(highlight) + + print '' + err = mode.imperror() + if highlight: + url = None + err = err or "selected" + print 'selected' + elif err: + url = None + print '%s' % err + else: + url = "options.html?%s=%s&savetime=%s" % (mode.prefix, mode.name, + time.time()) + err = "select" + print 'select' % url + print '' + + print '' + if url: print '' % url, + print htmlquote(err), + if url: print '', + print '' + + print '', + print htmlquote(mode.name), + print '' + if mode.url: + print '    -   web site' % mode.url + print '
' + print htmlquote(mode.descr) + return highlight + +def beginmodeoptions(): + print '
' + print '
' + +def endmodeoptions(): + print '' + print '' + print '
' + +def endmode(): + print '' + endgroupitem() + +def modeitems(modelist): + global mode + for mode in modelist: + if beginmode(): + txt = mode.htmloptionstext(nameval) + if txt: + beginmodeoptions() + print txt + endmodeoptions() + endmode() +)s + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
   
   
   
 Settings 
   
   
  + Technical documentation - + Back to the main page       + 
   
  + +
+ + + + + +%( +graphicmodes = self.graphicmodeslist() +currentmodes = self.localmodes() +begingroup('Display driver', '#800000', '#FFC000', '#C0C0C0', + 'lbeb.png', len(graphicmodes)) +modeitems(graphicmodes) +endgroup() +)s + + + + + +%( +soundmodes = self.soundmodeslist() +java = graphicmodes[0] in currentmodes +begingroup('Sound driver', '#800000', '#FFFF00', '#C0C0C0', + 'lbiob.png', java and 1 or len(soundmodes)) +if java: + begingroupitem(1) + print '' + endgroupitem() +else: + modeitems(soundmodes) +endgroup() +)s + + + +%( +begingroup('Network options', '#004000', '#80FF00', None, 'lbib.png', 1) +begingroupitem(1) +)s + +%( +endgroupitem() +endgroup() +)s + +
  
Java Applet always does sounds, but', + print 'background music is not implemented
  
+ + + + +
+

Network ports are automatically assigned, but you can optionally choose fixed + ones and let them in through your firewall. Clients using the + "Internet games" meta-server can usually connect even through firewalls. + Moreover servers can re-route UDP traffic to clients behind firewalls over TCP. +%( +if java: + print "These settings don't apply to the Java applet." +)s

+ +

TCP game server port: <%(nameval("text", "port_LISTEN", default="", mangling=0))s>
+ HTTP server port: <%(nameval("text", "port_HTTP", default="", mangling=0))s>

+ +

Client incoming UDP port (or host:port if redirected): <%(nameval("text", "port_CLIENT", default="", mangling=0))s>
+ <%(nameval("radio", "datachannel", "ucp", mangling=0))s>always UDP + <%(nameval("radio", "datachannel", "tcp", mangling=0))s>no UDP, only TCP + <%(nameval("radio", "datachannel", "auto", default="auto", mangling=0))s>Auto-detect
+ Client incoming TCP port (metaserver-directed back-connections): <%(nameval("text", "port_BACK", default="", mangling=0))s>

+
+ Help!

+ +
+
+
+ +
 
   
  +
+ + +
+
 
   
+ + + diff --git a/http2/data/sfbob.png b/http2/data/sfbob.png new file mode 100644 index 0000000..388d446 Binary files /dev/null and b/http2/data/sfbob.png differ diff --git a/http2/data/sfbub.png b/http2/data/sfbub.png new file mode 100644 index 0000000..142f3b3 Binary files /dev/null and b/http2/data/sfbub.png differ diff --git a/http2/data/stop.html b/http2/data/stop.html new file mode 100644 index 0000000..464ed36 --- /dev/null +++ b/http2/data/stop.html @@ -0,0 +1,101 @@ + + + + + +See you + + + +
+ + + + + + +
See you !   
+ +
+
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  
   
  +I hope you enjoyed this game! +

+http://bub-n-bros.sourceforge.net +
 
   
  +Almost all sprite images, sounds, background musics and +some of the levels are directly taken from the MacOS version of +Bub & Bob 1 by McSebi, and redistributed with his gracious +permission. +Most graphics have been improved or remade by David Gowers. + +

+ http://www.mcsebi.de +

+ +
 
   
 
+

Authors

+ +
    +
  • Programming: Armin Rigo +
  • Art: David Gowers, based on graphics from McSebi +
  • Levels: Gio & Odie & Michel-Stéphane & Armin +
  • Special thanks: Odie & Brachamutanda +
  • Beta-testers: IMA Connection +
+ +
 
   
+ + + diff --git a/http2/data/unchecked.png b/http2/data/unchecked.png new file mode 100644 index 0000000..0b20e95 Binary files /dev/null and b/http2/data/unchecked.png differ diff --git a/http2/data/wave1.png b/http2/data/wave1.png new file mode 100644 index 0000000..3424216 Binary files /dev/null and b/http2/data/wave1.png differ diff --git a/http2/data/wave2.png b/http2/data/wave2.png new file mode 100644 index 0000000..758f47d Binary files /dev/null and b/http2/data/wave2.png differ diff --git a/http2/data/wave3.png b/http2/data/wave3.png new file mode 100644 index 0000000..93fd6d3 Binary files /dev/null and b/http2/data/wave3.png differ diff --git a/http2/header.png b/http2/header.png new file mode 100644 index 0000000..c9a8566 Binary files /dev/null and b/http2/header.png differ diff --git a/http2/httppages.py b/http2/httppages.py new file mode 100644 index 0000000..3f90093 --- /dev/null +++ b/http2/httppages.py @@ -0,0 +1,705 @@ +import os, sys, random +from cStringIO import StringIO +import socket, time + +PLAYERNAMES = ['Bub', 'Bob', 'Boob', 'Beb', + 'Biob', 'Bab', 'Bib', + 'Baub', 'Beab', 'Biab'] + +try: + FILE = __file__ +except NameError: + FILE = sys.argv[0] +LOCALDIR = os.path.abspath(os.path.dirname(FILE)) + +sys.path.insert(0, os.path.abspath(os.path.join(LOCALDIR, os.pardir))) +sys.path.insert(0, os.path.abspath(os.path.join(LOCALDIR, os.pardir,'common'))) +import gamesrv, httpserver, hostchooser +from metaserver import metaclient +from httpserver import HTTPRequestError + + +class Options: + def __init__(self, dict={}): + self.update(dict) + def dict(self): + return self.__dict__.copy() + def update(self, dict): + self.__dict__.update(dict) + def copy(self): + return Options(self.__dict__) + def clear(self): + self.__dict__.clear() + def __getattr__(self, attr): + if not attr.startswith('_'): + return None + else: + raise AttributeError, attr + + +class PageServer: + CONFIGFILE = 'config.txt' + localservers = None + + def __init__(self, Game): + self.Game = Game + self.seed = hex(random.randrange(0x1000, 0x10000)) + #self.unique_actions = {} + self.localhost = gamesrv.HOSTNAME + self.filename = os.path.join(LOCALDIR, self.CONFIGFILE) + data = self.loadoptionfile() + self.globaloptions = Options(data.get('*', {})) + self.localoptions = Options(data.get(self.localhost, {})) + self.reloadports() + #self.inetserverlist = None + #self.inetservers = {} + #self.has_been_published = 0 + + def registerpages(self): + prefix = '%s/' % self.seed + #httpserver.register('controlcenter.html', self.controlcenterloader) + httpserver.register(prefix, self.indexloader) + httpserver.register(prefix+'index.html', self.indexloader) + #httpserver.register(prefix+'list.html', self.listloader) + httpserver.register(prefix+'new.html', self.newloader) + httpserver.register(prefix+'run.html', self.runloader) + httpserver.register(prefix+'stop.html', self.stoploader) + httpserver.register(prefix+'join.html', self.joinloader) + #httpserver.register(prefix+'register.html',self.registerloader) + httpserver.register(prefix+'options.html', self.optionsloader) + httpserver.register(prefix+'name.html', self.nameloader) + for fn in os.listdir(os.path.join(LOCALDIR, 'data')): + path = prefix + fn + if not httpserver.is_registered(path): + httpserver.register(path, httpserver.fileloader( + os.path.join(LOCALDIR, 'data', fn))) + + def opensocket(self): + hs = gamesrv.openhttpsocket() + if hs is None: + return 0 + self.httpport = port = gamesrv.displaysockport(hs) + self.indexurl = 'http://127.0.0.1:%d/%s/' % (port, self.seed) + if self.Game: + print self.Game.FnDesc, + print 'server is ready at', self.indexurl + return 1 + + def getlocalservers(self): + if self.localservers is None: + self.searchlocalservers() + return self.localservers + + def searchlocalservers(self): + servers = hostchooser.find_servers().items() + servers = filter(self.filterserver, servers) + servers.sort() + self.localservers = servers + +## def parse_inetserv(self, s): +## try: +## host, port, udpport, httpport = s.split(':') +## return host, int(port), int(udpport) +## except (ValueError, IndexError): +## return None, None, None + +## def getinetservers(self): +## if self.inetserverlist is None: +## return None +## result = [] +## for s in self.inetserverlist: +## host, port, udpport = self.parse_inetserv(s) +## addr = host, port +## if addr in self.inetservers: +## result.append((addr, self.inetservers[addr])) +## return result + +## def setinetserverlist(self, lst): +## self.inetserverlist = lst + +## def checkinetserverlist(self): +## ulist = [] +## for s in self.inetserverlist: +## host, port, udpport = self.parse_inetserv(s) +## if host is not None: +## ulist.append((host, udpport)) +## srvs = hostchooser.find_servers(ulist, delay=0.8) +## self.inetservers = {} +## for srv in srvs.items(): +## if not self.filterserver(srv): +## continue +## (host, port), info = srv +## try: +## host = socket.gethostbyaddr(host)[0] +## except socket.error: +## pass +## self.inetservers[host, port] = info +## #print 'hostchooser:', self.inetserverlist, '->', self.inetservers + + def filterserver(self, ((host, port), info)): + for c in host+str(port): + if c not in "-.0123456789:@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_abcdefghijklmnopqrstuvwxyz": + return 0 + return 1 + +## def statusservers(self): +## result = [], [] +## for s in self.inetserverlist: +## host, port, udpport = self.parse_inetserv(s) +## addr = host, port +## found = addr in self.inetservers +## result[found].append(s) +## return result + + def loadoptionfile(self): + try: + f = open(self.filename, 'r') + data = f.read().strip() + f.close() + except IOError: + data = None + return eval(data or '{}', {}, {}) + + def saveoptions(self): + data = self.loadoptionfile() + data['*'] = self.globaloptions.dict() + data[self.localhost] = self.localoptions.dict() + try: + f = open(self.filename, 'w') + print >> f, `data` + f.close() + except IOError, e: + print >> sys.stderr, "! Cannot save config file: " + str(e) + + def reloadports(self): + import msgstruct + msgstruct.PORTS.clear() + for key, value in self.localoptions.dict().items(): + if key.startswith('port_'): + key = key[5:] + if key == 'CLIENT' and type(value) == str and ':' in value: + udphostname, value = value.split(':') + msgstruct.PORTS['sendudpto'] = udphostname + try: + value = int(value) + except: + continue + msgstruct.PORTS[key] = value + + def startgame(self): + self.reloadports() + options = self.globaloptions + kwds = {} + if options.beginboard is not None: + kwds['beginboard'] = int(options.beginboard) + if options.lvlend is not None and options.lvlend.startswith('n'): + kwds['finalboard'] = int(options.finalboard) + if options.stepboard is not None: + kwds['stepboard'] = int(options.stepboard) + if options.limit is not None and options.limit.startswith('y'): + kwds['limitlives'] = int(options.lives) + if options.limitlifegain is not None: + kwds['lifegainlimit'] = int(options.lifegainlimit) + if options.extralife is not None: + kwds['extralife'] = int(options.extralife) + if options.autoreset is not None: + kwds['autoreset'] = options.autoreset.startswith('y') + if options.metapublish is not None: + kwds['metaserver'] = options.metapublish.startswith('y') + self.Game(options.file, **kwds) + + ### loaders ### + + def metaserverpage(self, headers): + metaserver_url = metaclient.METASERVER_URL + myhost = my_host(headers) + joinurl = quote_plus('%s/%s' % (myhost, self.seed)) + return metaserver_url + '?join=%s&time=%s' % (joinurl, time.time()) + + def mainpage(self, headers, juststarted=0, justconnected=0): + running = my_server() + count = len(gamesrv.clients) + tim = time.time() + #if running: + # metapublish = my_server_meta_address() + # fndesc = quote_plus(gamesrv.game.FnDesc) + #else: + # metapublish = None + return httpserver.load(os.path.join(LOCALDIR, 'data', 'index.html'), + 'text/html', locals=locals()) + + def indexloader(self, headers, cheat=[], **options): + if cheat: + import __builtin__ + for c in cheat: + getattr(__builtin__, '__cheat')(c) + else: + self.localservers = None + return self.mainpage(headers, juststarted=('juststarted' in options)) + + def controlcenterloader(self, headers, **options): + host = headers['remote host'] + host = socket.gethostbyname(host) + if host != '127.0.0.1': + raise HTTPRequestError, "Access denied" + return None, self.indexurl + +## def listloader(self, headers, s=[], **options): +## self.setinetserverlist(s) +## self.checkinetserverlist() +## query = [] +## missing, found = self.statusservers() +## for s in missing: +## query.append('d=' + s) +## for s in found: +## query.append('a=' + s) +## return self.mainpage(headers, query) + + def newloader(self, headers, **options): + if not self.Game: + raise HTTPRequestError, "Complete bub-n-bros installation needed" + locals = { + 'Game': self.Game, + 'options': self.globaloptions, + 'running': gamesrv.game is not None, + } + return httpserver.load(os.path.join(LOCALDIR, 'data', 'new.html'), + 'text/html', locals=locals) + + def runloader(self, headers, **options): + self.globaloptions.metapublish = 'n' + self.globaloptions.autoreset = 'n' + for key, value in options.items(): + if len(value) == 1: + setattr(self.globaloptions, key, value[0]) + self.saveoptions() + self.startgame() + return None, 'index.html?juststarted=%s' % time.time() + + def stoploader(self, headers, really=[], **options): + count = len(gamesrv.clients) + if count == 0 or really: + locals = { + 'self': self, + #'metaserver': METASERVER, + #'metapublish': gamesrv.game and my_server_meta_address(), + #'localdir': LOCALDIR, + } + gamesrv.closeeverything() + return httpserver.load(os.path.join(LOCALDIR, 'data', 'stop.html'), + 'text/html', locals=locals) + else: + locals = { + 'count': count, + } + return httpserver.load(os.path.join(LOCALDIR, 'data', 'confirm.html'), + 'text/html', locals=locals) + +## def registerloader(self, headers, a=[], d=[], **options): +## if a: # the lists 'a' and 'd' contain dummies !! +## self.globaloptions.metapublish = 'y' +## self.has_been_published = 1 +## kwd = 'a' +## else: +## self.globaloptions.metapublish = 'n' +## kwd = 'd' +## url = "%s?cmd=register&%s=%s" % (METASERVER, +## kwd, my_server_meta_address()) +## if a and gamesrv.game: +## url += '&desc=' + quote_plus(gamesrv.game.FnDesc) +## return None, url + + def joinloader(self, headers, host=[], port=[], httpport=[], + m=[], **options): + args = self.buildclientoptions() + assert len(host) == 1 + host = host[0] + if len(port) == 1: + port = port[0] + else: + try: + host, port = host.split(':') + except: + port = None + if args is None: + # redirect to the Java applet + try: + httpport = int(httpport[0]) + except (ValueError, IndexError): + if port: + raise HTTPRequestError, "This server is not running HTTP." + else: + raise HTTPRequestError, "Sorry, I cannot connect the Java applet to a server using this field." + return None, 'http://%s:%s/' % (host, httpport) + + # now is a good time to generate the color files if we can + file = os.path.join(LOCALDIR, os.pardir, 'bubbob', 'images', + 'buildcolors.py') + if os.path.exists(file): + g = {'__name__': '__auto__', '__file__': file} + execfile(file, g) + + if port: + address = '%s:%s' % (host, port) + else: + address = host + nbclients = len(gamesrv.clients) + script = os.path.join(LOCALDIR, os.pardir, 'display', 'Client.py') + script = no_quote_worries(script) + if m: + args.insert(0, '-m') + args = [script] + args + [address] + schedule_launch(args) + if m: + time.sleep(0.5) + s = 'Connecting to %s.' % address + return None, self.metaserverpage(headers) + '&head=' + quote_plus(s) + #elif my_server_address() == address: + # endtime = time.time() + 3.0 + # while gamesrv.recursiveloop(endtime, []): + # if len(gamesrv.clients) > nbclients: + # break + return self.mainpage(headers, justconnected=1) + + def optionsloader(self, headers, reset=[], savetime=[], **options): + if reset: + self.localoptions.clear() + self.globaloptions.clear() + self.saveoptions() + elif savetime: + self.localoptions.port_CLIENT = None + self.localoptions.port_LISTEN = None + self.localoptions.port_HTTP = None + for key, value in options.items(): + setattr(self.localoptions, key, value[0]) + self.saveoptions() + locals = { + 'self' : self, + 'options': self.localoptions, + } + return httpserver.load(os.path.join(LOCALDIR, 'data', 'options.html'), + 'text/html', locals=locals) + + def nameloader(self, headers, **options): + MAX = len(PLAYERNAMES) + if options: + anyname = None + for id in range(MAX): + keyid = 'player%d' % id + if keyid in options: + value = options[keyid][0] + anyname = anyname or value + teamid = 'team%d' % id + if teamid in options: + team = options[teamid][0] + if len(team) == 1: + value = '%s (%s)' % (value, team) + setattr(self.localoptions, keyid, value) + if 'c' in options: + for id in range(MAX): + keyid = 'player%d' % id + try: + delattr(self.localoptions, keyid) + except AttributeError: + pass + if 'f' in options: + for id in range(MAX): + keyid = 'player%d' % id + if not getattr(self.localoptions, keyid): + setattr(self.localoptions, keyid, + anyname or PLAYERNAMES[id]) + else: + anyname = getattr(self.localoptions, keyid) + self.saveoptions() + if 's' in options: + return self.mainpage(headers) + locals = { + 'options': self.localoptions.dict(), + } + return httpserver.load(os.path.join(LOCALDIR, 'data', 'name.html'), + 'text/html', locals=locals) + + def graphicmodeslist(self): + try: + return self.GraphicModesList + except AttributeError: + import display.modes + self.GraphicModesList = display.modes.graphicmodeslist() + javamode = display.modes.GraphicMode( + 'java', 'Java Applet (for Java browsers)', []) + javamode.low_priority = 1 + javamode.getmodule = lambda : None + self.GraphicModesList.insert(0, javamode) + return self.GraphicModesList + + def soundmodeslist(self): + try: + return self.SoundModesList + except AttributeError: + import display.modes + self.SoundModesList = display.modes.soundmodeslist() + return self.SoundModesList + + def localmodes(self): + import display.modes + currentmodes = [] + options = self.localoptions + for name, lst in [(options.dpy_, self.graphicmodeslist()), + (options.snd_, self.soundmodeslist())]: + try: + mode = display.modes.findmode(name, lst) + except KeyError: + try: + mode = display.modes.findmode(None, lst) + except KeyError, e: + print >> sys.stderr, str(e) # no mode! + mode = None + currentmodes.append(mode) + return currentmodes + + def buildclientoptions(self): + dpy, snd = self.localmodes() + if dpy.getmodule() is None: + return None # redirect to the Java applet + if dpy is None or snd is None: + raise HTTPRequestError, "No installed graphics or sounds drivers. See the settings page." + options = self.localoptions + result = ['--cfg='+no_quote_worries(self.filename)] + for key, value in options.dict().items(): + if key.startswith('port_') and value: + result.append('--port') + result.append('%s=%s' % (key[5:], value)) + if options.datachannel == 'tcp': result.append('--tcp') + if options.datachannel == 'udp': result.append('--udp') + if options.music == 'no': result.append('--music=no') + for optname, mode in [('--display', dpy), + ('--sound', snd)]: + result.append(optname + '=' + mode.name) + uid = mode.unique_id() + '_' + for key, value in options.dict().items(): + if key.startswith(uid): + result.append('--%s=%s' % (key[len(uid):], value)) + return result + +def my_host(headers): + return headers.get('host') or httpserver.my_host() + +def my_server(): + if gamesrv.game: + s = gamesrv.opentcpsocket() + return ((gamesrv.HOSTNAME, gamesrv.displaysockport(s)), + gamesrv.game.FnDesc) + else: + return None + +def my_server_address(): + running = my_server() + if running: + (host, port), info = running + return '%s:%d' % (host, port) + else: + return None + +##def my_server_meta_address(): +## s = gamesrv.opentcpsocket() +## ps = gamesrv.openpingsocket() +## hs = gamesrv.openhttpsocket() +## fullname = gamesrv.HOSTNAME +## try: +## fullname = socket.gethostbyaddr(fullname)[0] +## except socket.error: +## pass +## return '%s:%s:%s:%s' % (fullname, +## gamesrv.displaysockport(s), +## gamesrv.displaysockport(ps), +## gamesrv.displaysockport(hs)) + +##def meta_register(): +## # Note: this tries to open a direct HTTP connection to the meta-server +## # which may not work if the proxy is not configured in $http_proxy +## try: +## import urllib +## except ImportError: +## print >> sys.stderr, "cannot register with the meta-server: Python's urllib missing" +## return +## print "registering with the meta-server...", +## sys.stdout.flush() +## addr = my_server_meta_address() +## try: +## f = urllib.urlopen('%s?a=%s&desc=%s' % ( +## METASERVER, addr, quote_plus(gamesrv.game.FnDesc))) +## f.close() +## except Exception, e: +## print +## print >> sys.stderr, "cannot contact the meta-server (check $http_proxy):" +## print >> sys.stderr, "%s: %s" % (e.__class__.__name__, e) +## else: +## print "ok" +## unregister_at_exit(addr) + +##def meta_unregister(addr): +## import urllib +## print "unregistering from the meta-server...", +## sys.stdout.flush() +## try: +## f = urllib.urlopen(METASERVER + '?d=' + addr) +## f.close() +## except Exception, e: +## print "failed" +## else: +## print "ok" + +##def unregister_at_exit(addr, firsttime=[1]): +## if firsttime: +## import atexit +## atexit.register(meta_unregister, addr) +## del firsttime[:] + +QuoteTranslation = {} +for c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789' '_.-'): + QuoteTranslation[c] = c +del c +QuoteTranslation[' '] = '+' + +def quote_plus(s): + """Quote the query fragment of a URL; replacing ' ' with '+'""" + getter = QuoteTranslation.get + return ''.join([getter(c, '%%%02X' % ord(c)) for c in s]) + + +def main(Game, save_url_to=None, quiet=0): + #gamesrv.openpingsocket(0) # try to reserve the standard UDP port + srv = PageServer(Game) + srv.registerpages() + if not srv.opensocket(): + print >> sys.stderr, "server aborted." + sys.exit(1) + if quiet: + if Game: + Game.Quiet = 1 + import stdlog + f = stdlog.LogFile() + if f: + print "Logging to", f.filename + sys.stdout = sys.stderr = f + if save_url_to: + data = srv.indexurl + '\n' + def try_to_unlink(fn): + try: + os.unlink(fn) + except: + pass + import atexit + atexit.register(try_to_unlink, save_url_to) + try: + fno = os.open(save_url_to, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, + 0600) + if os.write(fno, data) != len(data): + raise OSError + os.close(fno) + except: + f = open(save_url_to, 'w') + f.write(data) + f.close() + #if webbrowser: + # srv.launchbrowser() + + +# ____________________________________________________________ +# Hack hack hack - workaround for the fact that on Windows +# the socket is inherited by the subprocess, which is quite +# bad because it keeps the browser-server connexion alive +# and the browser gets confused + + +def schedule_launch(args): + httpserver.actions_when_finished.append(lambda args=args: launch(args)) + +def launch(args): + # platform-specific hacks + print 'Running client -> ', ' '.join(args) + if 0: # OLD CODE sys.platform == 'darwin': # must start as a UI process + import tempfile + cmdname = tempfile.mktemp('_BubBob.py') + f = open(cmdname, 'w') + print >> f, 'import sys, os' + print >> f, 'try: os.unlink(%r)' % cmdname + print >> f, 'except OSError: pass' + print >> f, 'sys.argv[:] = %r' % (args,) + print >> f, '__file__ = %r' % cmdname + print >> f, 'execfile(%r)' % args[0] + f.close() + os.system('/usr/bin/open -a PythonLauncher "%s"' % cmdname) + else: + args.insert(0, sys.executable) + # try to close the open fds first + if hasattr(os, 'fork'): + try: + from resource import getrlimit, RLIMIT_NOFILE, error + except ImportError: + pass + else: + try: + soft, hard = getrlimit(RLIMIT_NOFILE) + except error: + pass + else: + if os.fork(): + return # in parent -- done, continue + # in child + for fd in range(3, min(16384, hard)): + try: + os.close(fd) + except OSError: + pass + os.execv(args[0], args) + # this point should never be reached + # fall-back + # (quoting sucks on Windows) ** 42 + if sys.platform == 'win32': + args[0] = '"%s"' % (args[0],) + if hasattr(os, 'P_DETACH'): + mode = os.P_DETACH + elif hasattr(os, 'P_NOWAIT0'): + mode = os.P_NOWAIT0 + else: + mode = os.P_NOWAIT + os.spawnv(mode, sys.executable, args) + +if sys.platform != "win32": + def no_quote_worries(s): + return s +else: + def no_quote_worries(s): # quoting !&?+*:-( + s = os.path.normpath(os.path.abspath(s)) + absroot = os.path.join(LOCALDIR, os.pardir) + absroot = os.path.normpath(os.path.abspath(absroot)) + ROOTDIR = os.curdir + while os.path.normpath(os.path.abspath(ROOTDIR)) != absroot: + if ROOTDIR == os.curdir: + ROOTDIR = os.pardir + else: + ROOTDIR = os.path.join(ROOTDIR, os.pardir) + if len(ROOTDIR) > 200: + # cannot find relative path! try with absolute one anyway + ROOTDIR = absroot + break + assert s.startswith(absroot) + if absroot.endswith(os.sep): # 'C:\' + absroot = absroot[:-1] + assert s[len(absroot)] == os.sep + relpath = s[len(absroot)+1:] + result = os.path.join(ROOTDIR, relpath) + print "no_quote_worries %r => %r" % (s, result) + return result + + +if __name__ == '__main__': + if (len(sys.argv) != 3 or sys.argv[1] != '--quiet' or + not sys.argv[2].startswith('--saveurlto=')): + print >> sys.stderr, "This script should only be launched by BubBob.py." + sys.exit(2) + main(None, sys.argv[2][len('--saveurlto='):], quiet=1) + gamesrv.mainloop() diff --git a/http2/sf/bb12.py b/http2/sf/bb12.py new file mode 100755 index 0000000..7ea6e6e --- /dev/null +++ b/http2/sf/bb12.py @@ -0,0 +1,274 @@ +#! /usr/bin/python + +import cgi, os, string, time +form = cgi.FieldStorage() + +def txtfilter(s): + l = filter(lambda c: c in "!$*,-.0123456789:@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}", s) + return string.join(l, '') + +def identity(s): + return s + +def fieldlist(name, filter=txtfilter): + result = [] + if form.has_key(name): + field = form[name] + if type(field) is type([]): + for f in field: + result.append(filter(f.value)) + else: + result.append(filter(field.value)) + return result + +def goodmatch(addr1, addr2): + l1 = string.split(addr1, '.') + if len(l1) >= 4: del l1[-1] + l2 = string.split(addr2, '.') + if len(l2) >= 4: del l2[-1] + return l1 == l2 + + +class Entry: + Notice = '' + FIELDS = [('server', 128), ('desc', 128), ('icon', 64), + ('orig', 64), ('dele1', 64), ('dele2', 64)] + + def __init__(self, f): + self.pos = f.tell() + for fname, flen in self.FIELDS: + s = f.read(flen) + if not s: + self.filled = 0 + break + setattr(self, fname, string.rstrip(s)) + else: + self.filled = 1 + + def __nonzero__(self): + return self.filled + + def write(self, f): + if not getattr(self, 'icon', ''): + try: + import random + lst = os.listdir('../htdocs/images') + except: + pass + else: + lst = filter(lambda x: x[-4:]=='.png' and 'A'<=x[0]<='Z', lst) + if lst: + self.icon = random.choice(lst) + f.seek(self.pos) + for fname, flen in self.FIELDS: + data = getattr(self, fname, '')[:flen] + f.write(data + ' '*(flen-len(data))) + + +def main(): + DATABASE = 'servers' + SIZEMAX = 65536 + Serv = 0 + Orig = 1 + Dele1 = 2 + REMOTE_ADDR = os.environ['REMOTE_ADDR'] + REMOTE_ID = REMOTE_ADDR + time.strftime('@%d%m', time.localtime(time.time())) + OPS = {} + + for srv in fieldlist('d'): + OPS[srv] = 'd' + for srv in fieldlist('a'): + OPS[srv] = 'a' + desc = (fieldlist('desc', identity) or [''])[0] + + f = open(DATABASE, 'r+b') + freelist = [] + published = [] + while 1: + e = Entry(f) + if not e: + break + if e.server: + if OPS.get(e.server) == 'a': + validdesc = desc and goodmatch(REMOTE_ADDR, e.orig) + if e.dele1 or e.dele2 or (validdesc and desc != e.desc): + e.dele1 = e.dele2 = '' # re-enable server + if validdesc: e.desc = desc + e.write(f) + del OPS[e.server] + elif OPS.get(e.server) == 'd': + if goodmatch(REMOTE_ADDR, e.orig) or ( + REMOTE_ID != e.dele1 and REMOTE_ID != e.dele2): + if goodmatch(REMOTE_ADDR, e.orig): + e.server = '' # remove server + elif e.dele1 == '': + e.dele1 = REMOTE_ID + elif e.dele2 == '': + e.dele2 = REMOTE_ID + else: + e.server = '' # remove server + e.write(f) + Entry.Notice = 'd' + if e.server: + published.append((e.pos, e)) + else: + freelist.append(e) + + for srv, action in OPS.items(): + if action == 'a': + if freelist: + e = freelist[-1] + del freelist[-1] + else: + f.seek(0, 2) + e = Entry(f) + if e.pos >= SIZEMAX: + raise Exception("Sorry, server database too big") + hostname = string.split(srv, ':')[0] + if '.' not in hostname: + Entry.Notice = 'Server hostname "%s" incomplete.' % hostname + else: + import socket + try: + result = socket.gethostbyaddr(hostname) + except socket.error, e: + Entry.Notice = ('%s: %s' % (hostname, e)) + else: + if result[0] == 'projects.sourceforge.net': # ???? + Entry.Notice = ('Server hostname "%s" does not exist.' % + hostname) + else: + e.server = srv + e.icon = '' + e.desc = desc + e.orig = REMOTE_ADDR + e.dele1 = e.dele2 = '' + e.write(f) + published.append((e.pos, e)) + Entry.Notice = 'a' + + f.close() + + published.sort() + return map(lambda (pos, e): e, published) + + +def publish_list(serverlist): + url = (fieldlist('url', identity) or ['http://127.0.0.1:8000'])[0] + query = [] + for s in fieldlist('redirected'): + query.append('redirected=' + s) + for s in serverlist: + query.append('s=' + txtfilter(s.server)) + url = url + '?' + string.join(query, '&') + for s in fieldlist('frag'): + url = url + '#' + s + print 'Content-Type: text/html' + print 'Location:', url + print + print '' + print 'Please click here to continue.' % url + print '' + +def publish_default(serverlist): + import htmlentitydefs + text_to_html = {} + for key, value in htmlentitydefs.entitydefs.items(): + text_to_html[value] = '&' + key + ';' + for i in range(32): + text_to_html[chr(i)] = '?' + def htmlquote(s, getter=text_to_html.get): + lst = [] + for c in s: lst.append(getter(c, c)) + return string.join(lst, '') + + REMOTE_ADDR = os.environ['REMOTE_ADDR'] + f = open('started.html', 'r') + header, row, footer = string.split(f.read(), '\\') + f.close() + import sys + print 'Content-Type: text/html' + print + sys.stdout.write(header % "List of registered Internet Servers") + counter = 0 + for s in serverlist: + if s.icon: + s1 = '' % s.icon + else: + s1 = '' + lst = string.split(txtfilter(s.server), ':') + hostname, port, udpport, httpport = (lst+['?','?','?','?'])[:4] + s2 = '%s' % hostname + try: + int(httpport) + except ValueError: + pass + else: + s2 = '%s:%s' % (hostname, httpport, + s2, port) + s2 = '' + s2 + '' + if s.desc: + s2 = s2 + '   playing  %s' % htmlquote(s.desc) + if goodmatch(REMOTE_ADDR, s.orig): + s2 = s2 + '      (if this server is dead, click here to remove it)' % s.server + sys.stdout.write(row % (s1, ('#C0D0D0', '#E0D0A8')[counter&1], s2)) + counter = counter + 1 + if not serverlist: + sys.stdout.write(row % ('', '#FFFFFF', 'There is no registered server at the moment.')) + sys.stdout.write(footer % "If your browser understands Java, you can click on a server to join the game. Note however that you will still need to install the whole Python client to benefit from the background musics, as this feature is missing from the Java client.

This list might contain already-dead servers; such 'zombies' disappear after some time.") + +def publish_raw(serverlist): + print 'Content-Type: text/plain' + print + print 'Raw list produced for', os.environ['REMOTE_ADDR'] + print + for s in serverlist: + print repr((s.server, s.desc, s.icon, s.orig)) + +def publish_img(serverlist): + import sys + print 'Content-Type: image/png' + print + f = open('sfbub.png', 'rb') + sys.stdout.write(f.read()) + f.close() + +def publish_register(serverlist): + if Entry.Notice == 'a': + banner = 'The game server is now registered to SourceForge.' + elif Entry.Notice == 'd': + banner = ('Server unregistered ' + 'from SourceForge.') + elif Entry.Notice == '': + if fieldlist('a'): + banner = "The game server is already registered to SourceForge." + elif fieldlist('d'): + banner = 'The game server was already absent from SourceForge.' + else: + publish_default(serverlist) + return + else: # errors + banner = ('%s

' % Entry.Notice + + 'If you are behind a firewall or NAT device (e.g. ADSL routers) you can still make your server reachable but it requires manual configuration. (Instructions not available yet -- sorry)') + f = open('started.html', 'r') + header, row, footer = string.split(f.read(), '\\') + f.close() + import sys + print 'Content-Type: text/html' + print + sys.stdout.write(header % banner) + sys.stdout.write(footer % 'Press Back to come back to the main page.') + + +try: + slist = main() + cmd = (fieldlist('cmd') or ['?'])[0] + publish = globals().get('publish_'+cmd, publish_default) + publish(slist) +except: + import traceback, sys + print "Content-Type: text/plain" + print + print "ERROR REPORT" + print + traceback.print_exc(file=sys.stdout) diff --git a/http2/sf/sfbub.png b/http2/sf/sfbub.png new file mode 100644 index 0000000..142f3b3 Binary files /dev/null and b/http2/sf/sfbub.png differ diff --git a/http2/sf/started.html b/http2/sf/started.html new file mode 100644 index 0000000..14c24e3 --- /dev/null +++ b/http2/sf/started.html @@ -0,0 +1,44 @@ + +The (old) Bub's Brothers on SourceForge + + + +

The (old) Bub's Brothers on SourceForge

+ +
+ +

This meta-server is now obsolete

+

It has never been too useful because nowadays everybody is behind firewalls and NAT translation devices (e.g. ADSL routers). So:

+

There is a much better meta-server somewhere else that works with the next version of Bub-n-bros. Upgrade to Bub-n-bros 1.3 and enjoy !

+

This page is left here just in case it is useful to someone, but you should really update if you want to enjoy a cool meta-server :-)

+ +




+ + + + + + + + + + + + + + + + + + +
   %s
  
  +\ + + + +\ +
%s       %s
+


+

%s

+

SourceForge.net Logo

+ -- cgit v1.2.3