diff --git a/gamecreation.py b/gamecreation.py index efc558f..3da8f9a 100644 --- a/gamecreation.py +++ b/gamecreation.py @@ -1,5 +1,5 @@ from mod_python import * -import psql,helper +import psql,helper,login def display_game_creation_form(req,sessionid,username): """ @@ -8,13 +8,11 @@ def display_game_creation_form(req,sessionid,username): gets a mod_python request, prints to req.write. """ data = helper.header() - p1data = create_user_dropdown_list("playerone",username) - p2data = create_user_dropdown_list("playertwo") + p1data = create_user_dropdown_list("player1",username) + p2data = create_user_dropdown_list("player2") gobansize = create_goban_size_dropdown_list("gobansize") #start form - #choose player one (black) - #choose player two (white) - #choose goban size + #choose player one (black),choose player two (white),choose goban size #'hidden' session id and username data += """
' #now comes the option for creating new games. diff --git a/main.py b/main.py index c7cb91a..47fbf2b 100755 --- a/main.py +++ b/main.py @@ -18,20 +18,22 @@ def handler(req): req.content_type = "text/html"#was:text/html try: # use explicit exception handling #reinitialize database + + #init_webgo.clear() + #init_webgo.create() #init_webgo.main() + #load form, then delegate request form = util.FieldStorage(req) if "create" in form.keys(): gamecreation = apache.import_module("gamecreation") gamecreation.main(req,form) - return apache.OK else: #call login.py login = apache.import_module("login") login.main(req,form) - return apache.OK - + return apache.OK except: import time errtime = '----- '+ time.ctime(time.time()) +' -----\n' diff --git a/psql.py b/psql.py index f75c495..d309386 100755 --- a/psql.py +++ b/psql.py @@ -63,9 +63,9 @@ def sql_one_liner(data): cursor.close() -def create_goban_table(size): +def create_goban_table(player1,player2,size): """ - gets:size of goban. + gets:player1, player2, size of goban. creates postgresql table containing goban data. returns: name of created table. @@ -79,19 +79,25 @@ def create_goban_table(size): turn_number size name + player1 + player2 and the meaning of these fields: (xn,yn) is a field of the goban, (turn_number,x1) is the current turn, (size,x1) is the length of a side of the goban, (name,x1) is the name of this goban. + (player1,x1) is the name of one player. + (player2,x1) is the name of the other player. + + """ - tablename="test" - data="line varchar(15)" + tablename = helper.generate_game_name() + data="line text" for i in range(1,size+1): if data != "": data += ", " - data += "x"+str(i) + ' varchar(15)' + data += "x"+str(i) + ' text' create_table(tablename,data) #table created, now fill the table for i in range(1,size+1): @@ -116,6 +122,16 @@ def create_goban_table(size): tmplist.append("name") tmplist.append(tablename) insert_into_table(tablename,str(tuple(tmplist))) + #name of player1 + tmplist=[] + tmplist.append("player1") + tmplist.append(player1) + insert_into_table(tablename,str(tuple(tmplist))) + #name of player2 + tmplist=[] + tmplist.append("player2") + tmplist.append(player2) + insert_into_table(tablename,str(tuple(tmplist))) return tablename def create_user_table(): @@ -130,9 +146,9 @@ def create_user_table(): timeout - when does session time out? """ data = "username varchar(15)" - data += ", password varchar(15)" + data += ", password text" for i in range(1,11): - data += ", game"+str(i)+" varchar(15)" + data += ", game"+str(i)+" text" data += ", sessionid text" data += ", timeout int" create_table("users",data) @@ -215,7 +231,6 @@ def update_database_field(table,column,line,data): gets: table name, column name, line name, new content for field. executes an SQL UPDATE statement for line. """ - #TODO:schreiben executestring ="UPDATE %s SET %s = '%s' WHERE line = '%s'" %(table,column,data,line) sql_one_liner(executestring) @@ -287,7 +302,34 @@ def get_users_with_free_game_slots(): tmplist = cursor.fetchall() ret = [item[0] for item in tmplist] return ret - + +def get_free_game_slot(username): + """ + gets a username + returns the name of a free game slot or "" if none found. + """ + ret = "" + for i in range(1,11): + cursor=db.cursor() + data = "SELECT username FROM users WHERE username='%s' AND game%s IS NULL" % (username,i) + cursor.execute(data) + # Commit the changes + db.commit() + tmp = [item[0] for item in cursor.fetchall()] + if tmp != []: + ret = "game"+str(i) + return ret + +def set_game_slot(username,gameslot,gamename): + """ + gets username,game slot,game name. + sets the game slot for user username to game name ;> + """ + executestring ="UPDATE users SET %s = '%s' WHERE username = '%s'" %(gameslot,gamename, username) + sql_one_liner(executestring) + + + def test(): #create_table("test") drop_table("test")