small changes here and there. a debug function (SPOT), css, start of a navigation bar.

This commit is contained in:
phear 2005-09-20 07:05:05 +00:00
parent 8f5568bcd0
commit a901d5f237
35 changed files with 511 additions and 71 deletions

373
default.css Normal file
View file

@ -0,0 +1,373 @@
body {
background-position: top center;
background-attachment: fixed;
background-repeat: no-repeat;
text-align: center;
margin: 0;
padding: 0;
font-family: verdana, lucida, arial, helvetica, sans-serif;
}
#main {
background: none;
width: 600px;
padding: 0px;
margin-left: auto;
margin-right: auto;
}
#main h1, h2, h3 {
font-family: sans-serif, arial;
font-weight: normal;
letter-spacing: 0.05em;
color: #acacac;
font-variant: small-caps;
padding: 0 1em;
text-align: left;
}
#main h1 {
font-size: 2em;
}
#main h2 {
font-size: 1.5em;
}
#main h3 {
font-size: 1.2em;
}
#head {
width: 600px;
height: 120px;
margin: 0;
padding: 0;
background-image: url(cryptobox-img/vault_pingu.png);
background-position: top right;
background-attachment: scroll;
background-repeat: no-repeat;
}
#content {
margin: 0;
padding: 0;
width: 600px;
font-size: 0.9em;
}
#content a {
line-height: 1.2em;
color: #000000;
text-decoration: none;
font-weight: bold;
font-size: 0.9em;
}
#content a:hover {
text-decoration: underline;
}
#content a:visited {
color: #acacac;
}
#content p {
font-size: 0.9em;
padding: 0 1em;
text-align: justify;
}
#menu {
text-align: center;
border-top: 1px solid #5e5e5e;
border-bottom: 1px solid #5e5e5e;
background-color: #ACE149;
}
#menu a:link, #menu a:visited {
color: #5e5e5e;
margin: 5px;
text-decoration: none;
border: none;
padding: 4px;
font-size: 0.8em;
}
#menu a:hover {
color: #8e8e8e;
}
#words {
width: 565px;
padding: 1.1em 0em 1.1em 1.1em;
margin-top: 0;
}
#words h1{
font-size: 1.8em;
}
#words h2{
font-size: 1.4em;
}
#words ol, #words ul {
font-size: 0.9em;
}
#words ol li {
padding: 0 1em;
line-height: 1.7em;
}
#words ul li {
padding: 0 1em;
line-height: 1.7em;
list-style: none;
background: url(cryptobox-img/list.gif) center left no-repeat;
}
#footer {
clear: both;
text-align: center;
border-top: 1px solid #5e5e5e;
border-bottom: 1px solid #5e5e5e;
background-color: #ACE149;
font-size: 0.8em;
color: #5e5e5e;
}
#footer a:link, #footer a:visited {
color: white;
margin: 5px;
text-decoration: none;
border: none;
padding: 4px;
color: #5e5e5e;
}
#footer a:hover {
text-decoration: underline;
}
#confirmtext span {
color: red;
font-weight: bold;
}
/* -------=-=-=- warnings, errors and success messages-=-=-=-------- */
#words div.warning,div.error,div.success {
margin-top: 20px;
margin-bottom: 20px;
padding-top: 10px;
padding-bottom: 15px;
color: #707070;
}
#words .warning,.error,.success {
border: 1px dashed #808080;
text-align: center;
color: #5e5e5e;
text-decoration: none;
font-weight: bold;
font-size: 0.9em;
padding-left: 40px;
padding-right: 40px;
}
#words .warning {
background-color: #f5f5f5;
}
#words .error {
background-color: #f5f5f5;
}
#words .success {
/* background-color: #90EE90; */
}
#words div.warning,div.error,div.success h1,h2 {
color: #808080;
}
#words .warning,.error,.success a {
// TODO: WHY line-height???
// line-height: 5em;
color: #5e5e5e;
text-decoration: none;
font-weight: bold;
font-size: 0.9em;
}
#words .note {
text-align: center;
color: #F48659;
font-style: italic;
}
/* ----------------------=-=-=- Forms -=-=-=--------------------- */
/* pretty forms and buttons */
input {
border: 1px solid #333333;
color: #333333;
background: #fff;
padding: 2px 5px 1px 5px;
font-size: 1em;
}
input:hover {
background: #fff;
border: 1px solid #ACE149;
color: #7DA721;
font-size: 1em;
}
textarea {
font-family: arial, verdana, helvetica;
font-size: 1.1em;
border: 1px solid #BFBFBF;
color: #949494;
padding: 2px 5px 1px 5px;
width: 450px;
}
textarea:hover {
background: #fff;
border: 1px solid #ACE149;
color: #7DA721;
}
/* the submit buttons have to have id="submit" for the following style: ------------------------------------- */
input#submit {
background-color: #ACE149;
border: 1px solid #222222;
color: #222;
font-size: 0.8em;
font-weight: bold;
cursor: pointer;
}
input#submit:hover {
background-color: #fff;
border: 1px solid #222;
color: #222;
font-size: 0.8em;
font-weight: bold;
cursor: pointer;
}
/* the submit buttons have to have id="goban" for the following style, for use in goban display ------------- */
input#goban {
padding: 0px;
border: 0px;
cursor: pointer;
}
#words form label {
min-width: 20em;
}
#words form p {
text-align: center;
}
/* ------------=-=-=- language selection -=-=-=------------- */
#lang {
position: fixed;
float: right;
right: 5px;
top: 5px;
text-align: right;
}
#lang a {
color: #acacac;
font-family: verdana, lucida, arial, helvetica, sans-serif;
font-size: smaller;
}
#lang a:hover {
color: #707070;
}
/* ------------=-=-=- documentation -=-=-=------------- */
#doc ol,ul li {
text-align: left;
margin-left: 20px;
}
#doc dl dt {
text-align: left;
margin-left: 20px;
font-style: italic;
}
#doc h1 {
padding-top: 25px;
}
#doc h2 {
padding-top: 20px;
}
#doc h3 {
padding-top: 10px;
}
/* ------------=-=-=- special things -=-=-=------------- */
#partition_info p {
margin-left: 10%;
margin-right: 10%;
font-family: monospace
}
#words a.popup {
line-height: inherit;
color: inherit;
text-decoration: inherit;
font-weight: inherit;
font-size: inherit;
}
#words a.popup:hover {
text-decoration: inherit;
}
#words a.popup span {
display: none;
position: fixed;
bottom: 10px;
left: 9%;
width: 80%;
background: #f0f0f0;
padding: 10px;
border-color: #e0e0e0;
border-width: 2px;
border-style: solid;
margin: 0;
}
#words a.popup:hover span {
display: inline;
}
#words a.popup span p {
text-align: left;
}
#words a.popup span h3 {
color: #909090;
margin-top: 0px;
}

View file

@ -1,5 +1,7 @@
import psql,login import psql,login
DEBUG = 1
def delete_game(gamename,username): def delete_game(gamename,username):
""" """
get name of game and name of user. get name of game and name of user.
@ -24,7 +26,8 @@ def main(req,form):
manage the removal of game from game slots of players and manage the removal of game from game slots of players and
delete game from database. delete game from database.
""" """
req.write(str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>") if DEBUG:
req.write(str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
try: try:
gamename = form["game"] gamename = form["game"]
except: except:
@ -41,7 +44,7 @@ def main(req,form):
#delete table #delete table
psql.drop_table(gamename) psql.drop_table(gamename)
#now display game overview form. #now display game overview form.
login.game_overview_form(req,player,form["sessionid"]) login.game_overview_form(req,form,player,form["sessionid"])
else: else:
req.write('Error: You have to select a game to delete it!') req.write('Error: You have to select a game to delete it!')

View file

@ -0,0 +1,16 @@
this file describes the database of the game.
there are currently 2 types of tables in the game.
One is the user table. this table is unique.
do the following to get the details:
cd webgo
python
import psql
print psql.create_user_table.__doc__
the other one is a goban table. for each game there exists one goban
table. do the following to get the details:
cd webgo
python
import psql
print psql.create_goban_table.__doc__

View file

@ -0,0 +1 @@
this is webgo, a browser-based version of go.

View file

@ -1,6 +1,8 @@
from mod_python import * from mod_python import *
import psql,helper,login import psql,helper,login
DEBUG = 1
def display_game_creation_form(req,sessionid,username): def display_game_creation_form(req,sessionid,username):
""" """
prints a html form with multiple drop-down lists for choosing players, prints a html form with multiple drop-down lists for choosing players,
@ -21,7 +23,7 @@ def display_game_creation_form(req,sessionid,username):
<p>Goban Size: %s fields </p> <p>Goban Size: %s fields </p>
<input type="hidden" name="sessionid" value="%s"> <input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type="submit" name="create" value="create game"> <input type="submit" id="submit" name="create" value="create game">
</form> </form>
""" % (p1data,p2data,gobansize,sessionid,username) """ % (p1data,p2data,gobansize,sessionid,username)
@ -54,7 +56,7 @@ def process_creation_form(req,form):
#display form again #display form again
display_game_creation_form(req,form["sessionid"],username) display_game_creation_form(req,form["sessionid"],username)
#TODO:game created, now display game overview form #TODO:game created, now display game overview form
login.game_overview_form(req,username,form["sessionid"]) login.game_overview_form(req,form,username,form["sessionid"])
else: else:
#give error message #give error message
req.write("Sorry, you must be one of the players!<br>") req.write("Sorry, you must be one of the players!<br>")
@ -97,7 +99,8 @@ def main(req,form):
gets a request object and a util.FieldStorage form. gets a request object and a util.FieldStorage form.
returns nothing. returns nothing.
""" """
req.write(str(form.keys())+"<hr>") if DEBUG:
req.write(str(form.keys())+"<hr>")
username = form["username"] username = form["username"]
#TODO:check if valid session id #TODO:check if valid session id

View file

@ -2,7 +2,7 @@
""" """
a simple script using pil to generate the goban from background, grid and stone images. a simple script using pil to generate the goban from background, grid and stone images.
""" """
import Image import Image,ImageOps
gridlist = ["bottomleftline","bottomline","bottomrightline", gridlist = ["bottomleftline","bottomline","bottomrightline",
"centerline","hoshi","leftline","rightline", "centerline","hoshi","leftline","rightline",
"topleftline", "topline","toprightline"] "topleftline", "topline","toprightline"]
@ -15,11 +15,13 @@ for item in gridlist:
bg = Image.open("imgsource/background.png").convert("RGBA") bg = Image.open("imgsource/background.png").convert("RGBA")
img = Image.open("imgsource/"+item+".png").convert("RGBA") img = Image.open("imgsource/"+item+".png").convert("RGBA")
bg.paste(img,None,img) bg.paste(img,None,img)
#bg = Image.composite(img,bg,img)
bg.save("img/"+item+".png") bg.save("img/"+item+".png")
tmp = bg #for the black stones tmp = bg #for the white stones
tmp2 = bg #for the black stones
#filling with white stones #filling with white stones
bg.paste(whitestone,None,whitestone) tmp.paste(whitestone,None,whitestone)
bg.save("img/"+item+"_white.png") tmp.save("img/"+item+"_white.png")
#filling with black stones #filling with black stones
tmp.paste(blackstone,None,blackstone) tmp2.paste(blackstone.convert("RGB"),None,blackstone)
tmp.save("img/"+item+"_black.png") tmp2.save("img/"+item+"_black.png")

View file

@ -1,5 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
DEBUG = 1
import sys,string import sys,string
import cgi import cgi
@ -24,7 +25,7 @@ def display_goban(goban,req,form):
hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)] hoshis9x9 = [(3,3),(3,7),(5,5),(7,3),(7,7)]
data += '<form method="post">' data += '<p><form method="post">'
data += """<input type="hidden" name="sessionid" value="%s"> data += """<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type="hidden" name="game" value="%s"> <input type="hidden" name="game" value="%s">
@ -49,30 +50,30 @@ def display_goban(goban,req,form):
sy = str(y) sy = str(y)
# check position: # check position:
if (x == 1) and (y == 1): # upper left if (x == 1) and (y == 1): # upper left
data += '<input type=image src="img/topleftline'+stone+'.png" name="('+sx+','+sy+')">' data += '<input type=image id="goban" src="img/topleftline'+stone+'.png" name="('+sx+','+sy+')">'
elif (x == 1) and (y == size): # upper right elif (x == 1) and (y == size): # upper right
data += '<input type=image src="img/toprightline'+stone+'.png" name="('+sx+','+sy+')"><br>' data += '<input type=image id="goban" src="img/toprightline'+stone+'.png" name="('+sx+','+sy+')"><br>'
elif (x == size) and (y == size): # lower right elif (x == size) and (y == size): # lower right
data += '<input type=image src="img/bottomrightline'+stone+'.png" name="('+sx+','+sy+')"><br>' data += '<input type=image id="goban" src="img/bottomrightline'+stone+'.png" name="('+sx+','+sy+')"><br>'
elif (x == size) and (y == 1): # lower left elif (x == size) and (y == 1): # lower left
data += '<input type=image src="img/bottomleftline'+stone+'.png" name="('+sx+','+sy+')">' data += '<input type=image id="goban" src="img/bottomleftline'+stone+'.png" name="('+sx+','+sy+')">'
elif (y == 1): #left line elif (y == 1): #left line
data += '<input type=image src="img/leftline'+stone+'.png" name="('+sx+','+sy+')">' data += '<input type=image id="goban" src="img/leftline'+stone+'.png" name="('+sx+','+sy+')">'
elif (x == 1): # top line elif (x == 1): # top line
data += '<input type=image src="img/topline'+stone+'.png" name="('+sx+','+sy+')">' data += '<input type=image id="goban" src="img/topline'+stone+'.png" name="('+sx+','+sy+')">'
elif (y == size): # right line elif (y == size): # right line
data += '<input type=image src="img/rightline'+stone+'.png" name="('+sx+','+sy+')"><br>' data += '<input type=image id="goban" src="img/rightline'+stone+'.png" name="('+sx+','+sy+')"><br>'
elif (x == size): #bottom line elif (x == size): #bottom line
data += '<input type=image src="img/bottomline'+stone+'.png" name="('+sx+','+sy+')">' data += '<input type=image id="goban" src="img/bottomline'+stone+'.png" name="('+sx+','+sy+')">'
else: # hoshi or empty inner field else: # hoshi or empty inner field
defaultfield = '<input type=image src="img/centerline'+stone+'.png" name="('+sx+','+sy+')">' defaultfield = '<input type=image id="goban" src="img/centerline'+stone+'.png" name="('+sx+','+sy+')">'
#too lazy to make special images for hoshi fields with stones: #too lazy to make special images for hoshi fields with stones:
if goban[(x,y)] == 1: if goban[(x,y)] == 1:
hoshifield = '<input type=image src="img/centerline_white.png" name="('+sx+','+sy+')">' hoshifield = '<input type=image id="goban" src="img/centerline_white.png" name="('+sx+','+sy+')">'
elif goban[(x,y)] == 2: elif goban[(x,y)] == 2:
hoshifield = '<input type=image src="img/centerline_black.png" name="('+sx+','+sy+')">' hoshifield = '<input type=image id="goban" src="img/centerline_black.png" name="('+sx+','+sy+')">'
else: #empty hoshi else: #empty hoshi
hoshifield = '<input type=image src="img/hoshi.png" name="('+sx+','+sy+')">' hoshifield = '<input type=image id="goban" src="img/hoshi.png" name="('+sx+','+sy+')">'
if size == 19: # 9 hoshis if size == 19: # 9 hoshis
if (x,y) in hoshis19x19: if (x,y) in hoshis19x19:
data += hoshifield data += hoshifield
@ -89,7 +90,7 @@ def display_goban(goban,req,form):
else: else:
data += defaultfield data += defaultfield
data += '\n<input type="hidden" name="play" value="foo">' data += '\n<input type="hidden" name="play" value="foo">'
data += '\n</form>' data += '\n</form></p>'
return data return data

View file

@ -1,14 +1,39 @@
import string import string
DEBUG = 1
def header(): def header():
"""return html header""" """return html header"""
data = """ data = """
<html><HEAD>
<?xml version="1.0" encoding="utf-8"?>
</HEAD><body> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WebGo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<link rel="stylesheet" media="screen" href="default.css" type="text/css" />
</head>
<body>
<h1> WebGo </h1>
""" """
return data return data
def debug(req,form, optstr = ""):
"""
print various debug infos, e.g. form content.
gets request, util.FieldStorage form, optional extra string.
returns nothing, writes with request.write.
"""
if DEBUG:
if optstr == "":
req.write(str(form.keys()))
else:
req.write(optstr)
def footer(): def footer():
"""return html footer""" """return html footer"""
data = """ data = """

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -1,6 +1,5 @@
import psql import psql
def clear(): def clear():
try: try:
psql.drop_table("users") psql.drop_table("users")

View file

@ -5,17 +5,16 @@ def process_form(req,form):
""" """
reads username and password from form reads username and password from form
""" """
req.write(str(form.keys()))
#req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>") #req.write("<br>"+"name="+form['name']+", password="+form['password']+"<hr>")
if form.keys() != []: if form.keys() != []:
if ("name" in form.keys()) and ("password" in form.keys()): if ("name" in form.keys()) and ("password" in form.keys()):
#extract name and password #extract name and password
name = form["name"] name = form["name"]
password = form["password"] password = form["password"]
sessionid = form["sessionid"] sessionid = form["sessionid"]
origpassword = psql.get_user_info(name,"password") origpassword = psql.get_user_info(name,"password")
req.write('<hr>--password:'+str(password)+' ---origpassword:'+str(origpassword)+'<hr>') #debug:
helper.debug(req,form,'<hr>--password:'+str(password)+' ---origpassword:'+str(origpassword)+'<hr>')
#check if user exists (else we would get an error string) #check if user exists (else we would get an error string)
if origpassword != "no such user": #no error message, now check password if origpassword != "no such user": #no error message, now check password
if password == origpassword: if password == origpassword:
@ -23,7 +22,7 @@ def process_form(req,form):
psql.set_user_sessionid(name,sessionid) psql.set_user_sessionid(name,sessionid)
psql.set_user_timeout(name) psql.set_user_timeout(name)
#now display list of games. #now display list of games.
game_overview_form(req,name,sessionid) game_overview_form(req,form,name,sessionid)
else: else:
req.write("Login incorrect. Please try again.<br>") req.write("Login incorrect. Please try again.<br>")
req.write(login_form()) req.write(login_form())
@ -35,9 +34,9 @@ def process_form(req,form):
req.write(login_form()) req.write(login_form())
def game_overview_form(req,user,sessionid): def game_overview_form(req,form,user,sessionid):
""" """
gets the name of a user and the queue of games. gets: request object, util.FieldStorage form, name of user, sessionid.
prints a form with the option to select,create and delete games. prints a form with the option to select,create and delete games.
""" """
data = helper.header()+ """ data = helper.header()+ """
@ -45,7 +44,8 @@ def game_overview_form(req,user,sessionid):
<form method="post"> <form method="post">
""" """
gamelist = psql.get_user_game_list(user) gamelist = psql.get_user_game_list(user)
req.write(str(gamelist)+"<hr>\n") #debug
helper.debug(req,form,str(gamelist)+"<hr>\n")
#display list of current games #display list of current games
counter = 10 counter = 10
tmp = "" tmp = ""
@ -61,16 +61,16 @@ def game_overview_form(req,user,sessionid):
tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid tmp += '<input type="hidden" name="sessionid" value="%s">\n' % sessionid
tmp += '<input type="hidden" name="username" value="%s">\n' % user tmp += '<input type="hidden" name="username" value="%s">\n' % user
data += tmp data += tmp
data += '<input type=submit name="play" value="Play selected game">\n<input type=submit name="delete" value="Delete selected game">\n</form>' data += '<input type=submit id="submit" name="play" value="Play selected game">\n<input type=submit id="submit" name="delete" value="Delete selected game">\n</form>'
#now comes the option for creating new games. #now comes the option for creating new games.
data += "<h2>Start a new Game</h2>\n" data += "<h2>New Game:</h2>\n"
if counter > 0: if counter > 0:
data+= "You have %s free game slots.<br>" % counter data+= "You have %s free game slots.<br>" % counter
data += """ data += """
<form method="post"> <form method="post">
<input type="hidden" name="sessionid" value="%s"> <input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s"> <input type="hidden" name="username" value="%s">
<input type=submit name="create" value="Start a new game"> <input type=submit id="submit" name="create" value="Start a new game">
</form> </form>
""" % (sessionid, user) """ % (sessionid, user)
else: else:
@ -92,27 +92,44 @@ def login_form():
<p>Pasword:<br> <p>Pasword:<br>
<input name="password" size="40"></p> <input name="password" size="40"></p>
<input type="hidden" name="sessionid" value="%s"> <input type="hidden" name="sessionid" value="%s">
<p><input type="submit" value="login"></p> <p><input type="submit" id ="submit" value="login"></p>
</form> </form>
""" % helper.generate_session_id() """ % helper.generate_session_id()
data += helper.footer() data += helper.footer()
return data return data
def navigation_bar(username,sessionid):
"""
gets username and sessionid
writes the following to req:
- a button to return to the game overview
- a logout button
returns string
"""
#TODO: buttons
data="""
<form method="post">
<input type="hidden" name="sessionid" value="%s">
<input type="hidden" name="username" value="%s">
<input type="submit" id="submit" name="logout" value="logout">
<input type="submit" id="submit" name="game overview" value="game overview">
</form>
""" % (username,sessionid)
return(data)
def main(req,form): def main(req,form):
req.write((str(form.keys())+"<hr>")) #debug
helper.debug(req,form)
#req.write(helper.footer())
if "sessionid" not in form.keys(): if "sessionid" not in form.keys():
req.write(login_form()) req.write(login_form())
elif ("create" in form.keys()) and ("username" in form.keys()): elif ("create" in form.keys()) and ("username" in form.keys()):
#user wants to create a new game
#gamecreation = apache.import_module("gamecreation")
#gamecreation.main(req,form)
#gamecreation.main(req,form)
pass pass
elif ("game overview" in form.keys()) and ("username" in form.keys()) and ("sessionid" in form.keys()):
game_overview_form(req,form,form["username"],form["sessionid"])
else: else:
process_form(req,form) process_form(req,form)

37
main.py
View file

@ -1,9 +1,3 @@
#!/usr/bin/python
"""
simple cgi wrapper for a cgi script, prints the error of the script as html
taken from http://gnosis.cx/publish/programming/feature_5min_python.html
modified a little
"""
import sys, traceback,string,time import sys, traceback,string,time
import init_webgo,psql import init_webgo,psql
@ -32,22 +26,27 @@ def handler(req):
#if sessionid=sesssionid and time < timeout: #if sessionid=sesssionid and time < timeout:
# set_timeout # set_timeout
helper = apache.import_module("helper")
if (psql.get_user_info(username,'timeout') > int(time.time())) and (sessionid == psql.get_user_info(username,'sessionid')): if (psql.get_user_info(username,'timeout') > int(time.time())) and (sessionid == psql.get_user_info(username,'sessionid')):
psql.set_user_timeout(username) psql.set_user_timeout(username)
if "create" in form.keys(): if "create" in form.keys():
gamecreation = apache.import_module("gamecreation") gamecreation = apache.import_module("gamecreation")
gamecreation.main(req,form) gamecreation.main(req,form)
elif "delete" in form.keys(): elif "delete" in form.keys():
deletegame = apache.import_module("deletegame") deletegame = apache.import_module("deletegame")
deletegame.main(req,form) deletegame.main(req,form)
elif ("play" in form.keys()): elif ("play" in form.keys()):
playgame = apache.import_module("playgame") playgame = apache.import_module("playgame")
playgame.main(req,form) playgame.main(req,form)
else:
#call login.py
login = apache.import_module("login")
login.main(req,form)
else: else:
#call login.py #call login.py
login = apache.import_module("login") login = apache.import_module("login")
login.main(req,form) login.main(req,form)
return apache.OK return apache.OK
except: except:
errtime = '----- '+ time.ctime(time.time()) +' -----\n' errtime = '----- '+ time.ctime(time.time()) +' -----\n'
@ -92,7 +91,3 @@ def ErrorMsg(escape=0):
import cgi import cgi
body = cgi.escape(body) body = cgi.escape(body)
return body return body
#start(req)

View file

@ -1,6 +1,8 @@
import goban,helper,psql import goban,helper,psql,login
import string import string
DEBUG = 1
def is_my_turn(req,form,gobandict): def is_my_turn(req,form,gobandict):
""" """
gets request and util.FiedStorage form. gets request and util.FiedStorage form.
@ -74,11 +76,12 @@ def main(req,form):
if is_my_turn(req,form,gobandict): if is_my_turn(req,form,gobandict):
data += ("Its your turn.<br>") data += ("Its your turn.<br>")
else: else:
data+= ("This is not your turn. Look, but don't touch ;)<br>") data+= ("This is not your turn. You have to wait for the move of the other player.<br>")
#print goban #print goban
data += goban.display_goban(gobandict,req,form) data += goban.display_goban(gobandict,req,form)
data += login.navigation_bar(form["username"],form["sessionid"])
data += helper.footer() data += helper.footer()
req.write(data) req.write(data)

View file

@ -1,6 +1,8 @@
import helper import helper
import pgdb,sys import pgdb,sys
DEBUG = 1
dbusername="webgouser" dbusername="webgouser"
dbpassword="webgopassword" dbpassword="webgopassword"
dbname="webgo" dbname="webgo"