2005-09-14 16:29:58 +02:00
|
|
|
import psql,login
|
2005-09-12 19:30:02 +02:00
|
|
|
|
|
|
|
def delete_game(gamename,username):
|
|
|
|
"""
|
|
|
|
get name of game and name of user.
|
|
|
|
remove game from game slot of user.
|
|
|
|
"""
|
|
|
|
|
2005-09-14 16:29:58 +02:00
|
|
|
def get_game_slot_of_game(player, gamename):
|
|
|
|
"""
|
|
|
|
gets playername and game name,
|
|
|
|
searches through the game slots and returns the game slot used by the game.
|
|
|
|
"""
|
|
|
|
slotlist = psql.get_user_game_list(player)
|
|
|
|
ret = ""
|
|
|
|
for i in range(0,len(slotlist)):
|
|
|
|
if slotlist[i] == gamename:
|
|
|
|
ret = "game" + str(i+1)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def main(req,form):
|
2005-09-12 19:30:02 +02:00
|
|
|
"""
|
|
|
|
get the name of a game,request,util.FieldStorage.
|
|
|
|
manage the removal of game from game slots of players and
|
|
|
|
delete game from database.
|
2005-09-14 16:29:58 +02:00
|
|
|
"""
|
|
|
|
req.write(str(form.keys())+" sessionid in form:"+form["sessionid"]+"<hr>")
|
|
|
|
try:
|
|
|
|
gamename = form["game"]
|
|
|
|
except:
|
|
|
|
gamename = ""
|
|
|
|
if gamename != "":
|
|
|
|
#get player names from game table in database
|
|
|
|
players = psql.get_players_for_game(gamename)
|
|
|
|
#free game slots of players
|
|
|
|
for player in players:
|
|
|
|
gameslot = get_game_slot_of_game(player,gamename)
|
|
|
|
if gameslot != "":
|
|
|
|
psql.set_game_slot(player,gameslot,"")
|
|
|
|
|
|
|
|
#delete table
|
|
|
|
psql.drop_table(gamename)
|
|
|
|
#now display game overview form.
|
|
|
|
login.game_overview_form(req,player,form["sessionid"])
|
|
|
|
|
|
|
|
else:
|
|
|
|
req.write('Error: You have to select a game to delete it!')
|