webgo/deletegame.py

47 lines
1.2 KiB
Python
Raw Normal View History

import psql,login
def delete_game(gamename,username):
"""
get name of game and name of user.
remove game from game slot of user.
"""
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):
"""
get the name of a game,request,util.FieldStorage.
manage the removal of game from game slots of players and
delete game from database.
"""
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!')