diff --git a/createaccount.py b/createaccount.py index 4393509..b333d7d 100644 --- a/createaccount.py +++ b/createaccount.py @@ -32,11 +32,9 @@ class CreateAccount:

Please retype your Password:

- -

- """ % helper.generate_session_id() + """ data += helper.footer() return(data) diff --git a/default.css b/default.css index f223147..0864743 100644 --- a/default.css +++ b/default.css @@ -173,8 +173,6 @@ td { font-weight: bold; } - - /* ----------------------=-=-=- Forms -=-=-=--------------------- */ /* pretty forms and buttons */ input { @@ -213,3 +211,13 @@ input.submit:hover { font-weight: bold; cursor: pointer; } + + +/* The Board--------------------------------------------------------------------------- --------------------------------- */ +#board a, a:link, a:visited { + border: none; +} + +#board img { + border:none; +} \ No newline at end of file diff --git a/goban.py b/goban.py index 14f9924..849c315 100755 --- a/goban.py +++ b/goban.py @@ -3,101 +3,14 @@ DEBUG = 1 import sys,string -import cgi import helper,gnugo,database - -picklefile = "goban.pickledump" +from cherrypy import cpg +from cherrypy.lib import httptools ############################################################################### -def display_goban(goban,req,form): - """ - gets: dictionary containing the layout of the used goban. - returns: string containing the HTML code for a clickable goban. - """ - data = "" - - hoshis19x19 = [(4,4),(4,10),(4,16),(10,4),(10,10),(10,16),(16,4),(16,10),(16,16)] - hoshis13x13 = [(4,4),(4,10),(7,7),(10,4),(10,10)] - hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)] - - - data += '\n

\n

\n' - data += """ - - - """ % (form["sessionid"],form["username"],form["game"]) - - #TODO: check form[game] before the following asignment - mygame = database.GobanTable.byName(form["game"]) - sgf = mygame.sgf - helper.debug(req,form,sgf) - gobandict = gnugo.parse_static_gnugo_sgf(sgf) - - try: - size = goban["size"] - except: - #TODO: proper error management - raise "[EE] display_goban: got broken goban dictionary." - sys.exit(1) - for x in range(1,size+1): - for y in range(1,size+1): - # check for white or black stone - if gobandict[(x,y)] == 1: - stone = "_white" - elif gobandict[(x,y)] == 2: - stone = "_black" - else: - stone = "" - sx = str(x) - sy = str(y) - # check position: - if (x == 1) and (y == 1): # upper left - data += '' - elif (x == 1) and (y == size): # upper right - data += '' - elif (x == size) and (y == size): # lower right - data += '
\n' - elif (x == size) and (y == 1): # lower left - data += '' - elif (y == 1): #left line - data += '' - elif (x == 1): # top line - data += '' - elif (y == size): # right line - data += '' - elif (x == size): #bottom line - data += '' - else: # hoshi or empty inner field - defaultfield = '' - #too lazy to make special images for hoshi fields with stones: - if gobandict[(x,y)] == 1: - hoshifield = '' - elif gobandict[(x,y)] == 2: - hoshifield = '' - else: #empty hoshi - hoshifield = '' - if size == 19: # 9 hoshis - if (x,y) in hoshis19x19: - data += hoshifield - else: - data += defaultfield - elif size == 13: - if (x,y) in hoshis13x13: - data += hoshifield - else: - data += defaultfield - elif size == 9: - if (x,y) in hoshis9x9: - data += hoshifield - else: - data += defaultfield - data += '\n' - data += '\n

' - return data - diff --git a/login.py b/login.py index 6f99b48..c16d4cd 100755 --- a/login.py +++ b/login.py @@ -148,12 +148,11 @@ class Overview: tmp += "" tmp += "" tmp += "" - for item in helper.clean_list(gamelist): + for item in gamelist: if (item != None) and (item != "None"): - tmp += '\n' - tmp += '\n' % username + tmp += '\n\n' tmp += '\n' % item - tmp += '\n' + tmp += '\n' mygame = database.GobanTable.get(item) description = mygame.description if (description == None) or (description == "None") or (description == ""): diff --git a/main.py b/main.py index fd94ff9..565ff98 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import sys, traceback,string,time -import login,createaccount,helper,gamecreation +import login,createaccount,helper,gamecreation,playgame from cherrypy import cpg class WebGoSite: @@ -18,12 +18,14 @@ cpg.root.createaccount = createaccount.CreateAccount() cpg.root.login = login.Login() cpg.root.overview = login.Overview() cpg.root.gamecreation = gamecreation.GameCreation() +cpg.root.playgame = playgame.PlayGame() cpg.server.start(configMap={'sessionStorageType' : 'ram', 'sessionCookieName' : 'WebGoSessionCookie', 'sessionTimeout' : 15, #Session expires in n minutes 'staticContentList': - [['default.css','default.css']] + [['default.css','default.css'], + ['img','img']] } ) diff --git a/playgame.py b/playgame.py index edeee15..daa8710 100644 --- a/playgame.py +++ b/playgame.py @@ -1,5 +1,7 @@ import goban,helper,database,login,gnugo import string +from cherrypy import cpg +from cherrypy.lib import httptools DEBUG = 1 @@ -87,3 +89,100 @@ def main(req,form): else: req.write('Error: You have to select a game to play it!') + +class PlayGame: + """ + displays a game and processes user input. + """ + def index(self,game,coord=None): + username = cpg.request.sessionMap["username"] + myuser = database.Users.byUsername(username) + sessionid = cpg.request.sessionMap["_sessionId"] + print game + if myuser.sessionid == sessionid: + if coord != None: + return coord + else: + return self.display_goban(game) + + else: + httptools.redirect("/login") + + def display_goban(self,gamename): + """ + gets: dictionary containing the layout of the used goban. + returns: string containing the HTML code for a clickable goban. + """ + data = helper.header() + data += '
' + hoshis19x19 = [(4,4),(4,10),(4,16),(10,4),(10,10),(10,16),(16,4),(16,10),(16,16)] + hoshis13x13 = [(4,4),(4,10),(7,7),(10,4),(10,10)] + hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)] + + + #TODO: check form[game] before the following asignment + mygame = database.GobanTable.get(gamename) + sgf = mygame.sgf + gobandict = gnugo.parse_static_gnugo_sgf(sgf) + size = mygame.size + + for x in range(1,size+1): + for y in range(1,size+1): + # check for white or black stone + if gobandict[(x,y)] == 1: + stone = "_white" + elif gobandict[(x,y)] == 2: + stone = "_black" + else: + stone = "" + sx = str(x) + sy = str(y) + # check position: + if (x == 1) and (y == 1): # upper left + #data += '' + data += '' % (sx,sy,gamename,stone) + elif (x == 1) and (y == size): # upper right + data += '
' % (sx,sy,gamename,stone) + elif (x == size) and (y == size): # lower right + data += '
' % (sx,sy,gamename,stone) + elif (x == size) and (y == 1): # lower left + data += '' % (sx,sy,gamename,stone) + elif (y == 1): #left line + data += '' % (sx,sy,gamename,stone) + elif (x == 1): # top line + data += '' % (sx,sy,gamename,stone) + elif (y == size): # right line + data += '
' % (sx,sy,gamename,stone) + elif (x == size): #bottom line + data += '' % (sx,sy,gamename,stone) + else: # hoshi or empty inner field + defaultfield = '' % (sx,sy,gamename,stone) + #too lazy to make special images for hoshi fields with stones: + if gobandict[(x,y)] == 1: + hoshifield = '' % (sx,sy,gamename) + elif gobandict[(x,y)] == 2: + hoshifield = '' % (sx,sy,gamename) + else: #empty hoshi + hoshifield = '' % (sx,sy,gamename) + if size == 19: # 9 hoshis + if (x,y) in hoshis19x19: + data += hoshifield + else: + data += defaultfield + elif size == 13: + if (x,y) in hoshis13x13: + data += hoshifield + else: + data += defaultfield + elif size == 9: + if (x,y) in hoshis9x9: + data += hoshifield + else: + data += defaultfield + data += '
' + data += helper.footer() + return data + + + + index.exposed = True \ No newline at end of file
Name of gameWhiteBlackTime of CreationTime of last move