From e78d6351de5c4697fa1be5e4feeac6800c6b6c43 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 7 Apr 2002 12:07:36 +0000 Subject: [PATCH] new table for transfer of players --- scripts/cgi-bin/info.py | 13 +++++++------ scripts/cgi-bin/standin.py | 5 +++-- scripts/register/account-merge.py | 4 ++++ scripts/register/zat.py | 27 ++++++++++++++++----------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/scripts/cgi-bin/info.py b/scripts/cgi-bin/info.py index e90e7ea34..acf772513 100755 --- a/scripts/cgi-bin/info.py +++ b/scripts/cgi-bin/info.py @@ -214,11 +214,12 @@ def ShowInfo(custid, Password): Display(output, "Kundendaten #"+str(custid)) Errors = "" -def TransferFaction(sid, faction, newuser, game): +def TransferFaction(sid, faction, olduser, newuser, game, gid): db = MySQLdb.connect(db=dbname) update = db.cursor() - exist = update.execute("select id from users where id="+str(newuser)) + exist = update.execute("select id from users where id="+str(int(newuser))) if exist==1: + update.execute("INSERT into transfers (subscription, src, dst, reason) values ("+str(int(sid))+", "+str(int(olduser))+", "+str(int(newuser))+", 'TRANSFER')") update.execute("UPDATE subscriptions set status='TRANSFERED', user=" + str(newuser) + " where id="+str(sid)) SendTransfer(newuser, faction, game); db.close() @@ -258,15 +259,15 @@ def Save(custid, Password): else: update.execute('delete from subscriptions where user='+str(int(custid))+' and game='+str(int(gid))) - nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id") + nfactions = cursor.execute("select g.id, g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id") while nfactions > 0: - game, sid, faction = cursor.fetchone() + gid, game, sid, faction = cursor.fetchone() if Form.has_key("cancel_"+faction): update = db.cursor() update.execute("UPDATE subscriptions set status='CANCELLED' where id="+str(int(sid))) elif Form.has_key("transfer_"+faction): newuser = int(Form["transfer_"+faction].value) - TransferFaction(sid, faction, newuser, game) + TransferFaction(sid, faction, custid, newuser, game, gid) nfactions = nfactions - 1 nfactions = cursor.execute("select g.id, g.name, s.id, faction from games g, subscriptions s where s.status='TRANSFERED' and s.user="+str(custid) + " and s.game=g.id") @@ -278,7 +279,7 @@ def Save(custid, Password): if i==0: update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(int(sid))) else: - Errors=Errors+"Du hast bereits eine Aktive Partei in "+game+"
+ Errors=Errors+"Du hast bereits eine Aktive Partei in "+game+"
\n" nfactions = nfactions - 1 nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='CANCELLED' and s.user="+str(custid) + " and s.game=g.id") diff --git a/scripts/cgi-bin/standin.py b/scripts/cgi-bin/standin.py index 00c3434de..0bbd9431a 100755 --- a/scripts/cgi-bin/standin.py +++ b/scripts/cgi-bin/standin.py @@ -89,12 +89,13 @@ if (password!=None) & (custid!=None): output="" if cursor.execute("select firstname, lastname, email, id from users where password='"+password+"' and id="+str(int(custid)))==1: firstname, lastname, email, custid = cursor.fetchone() - c = cursor.execute("SELECT id, game, password, faction from subscriptions where status='CANCELLED'") + c = cursor.execute("SELECT id, game, password, faction, user from subscriptions where status='CANCELLED'") while c>0: c=c-1 - sid, gid, newpass, faction = cursor.fetchone() + sid, gid, newpass, faction, uid = cursor.fetchone() if Form.has_key("accept_"+str(int(sid))): update = db.cursor() + update.execute("INSERT into transfers (subscription, src, dst, reason) values ("+str(int(sid))+", "+str(int(uid))+", "+str(int(custid))+", ''STANDIN')") update.execute("UPDATE subscriptions set user=" + str(int(custid)) + ", status='ACTIVE' where id=" + str(int(sid))) output=output+"Die Partei " + faction + " wurde Dir überschrieben. Eine Email mit dem Passwort und weiteren Hinweisen ist unterwegs zu Dir.
" server=smtplib.SMTP(smtpserver) diff --git a/scripts/register/account-merge.py b/scripts/register/account-merge.py index 8031a2ffc..61229a6ff 100755 --- a/scripts/register/account-merge.py +++ b/scripts/register/account-merge.py @@ -1,5 +1,9 @@ #!/usr/bin/env python +# merge two accounts. not used. +# needs to be checked before used. +# does not update the TRANSFERS table + import MySQLdb import sys diff --git a/scripts/register/zat.py b/scripts/register/zat.py index d6418f89c..0b38b1c24 100755 --- a/scripts/register/zat.py +++ b/scripts/register/zat.py @@ -39,25 +39,30 @@ while os.access(patchdir+'/patch-'+str(int(patch+1))+'.sql', os.F_OK): os.system('mysql ' + dbname + ' < ' + patchdir+'/patch-'+str(int(patch))+'.sql') cursor.execute('update games set patch='+str(int(patch))+' where id='+str(gid)) -k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='TRANSFERED' and updated<'"+date+"'") +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='TRANSFERED' and user!=0 and updated<'"+date+"'") print "Removing "+str(int(k))+" transfered subscriptions." SetUser(cursor, int(k), 0) -k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='CANCELLED' and updated<'"+date+"'") +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='CANCELLED' and user!=0 and updated<'"+date+"'") print "Removing "+str(int(k))+" cancelled subscriptions." SetUser(cursor, int(k), 0) -k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and status='DEAD'") +k = cursor.execute("select user, faction from subscriptions where game="+str(gid)+" and user!=0 and status='DEAD'") print "Removing "+str(int(k))+" dead subscriptions." -k = cursor.execute("UPDATE subscriptions SET status='CANCELLED' where game="+str(int(game))+" and status='ACTIVE' and lastturn+3<="+str(lastturn)) +k = cursor.execute("UPDATE subscriptions SET status='CANCELLED' where game="+str(gid)+" and status='ACTIVE' and lastturn+3<="+str(lastturn)) if k: print "Cancelling subscriptions with 3+ NMRs." -k = cursor.execute("SELECT users.id FROM users, subscriptions WHERE users.id=subscriptions.user and subscriptions.status='ACTIVE' and subscriptions.game="+str(gid)) -while k!=0: - k=k-1 - user = int(cursor.fetchone()[0]) - update=db.cursor() - update.execute("INSERT INTO transactions (user,date,balance,description) VALUES ("+str(user)+", '"+date+"', -"+str(price)+", 'ZAT-"+str(gid)+"')") - +cursor.execute("SELECT count(*) from transactions where date='"+date+"' and description='ZAT-"+str(gid)+"'") +k = cursor.fetchone()[0] +if k==0: + k = cursor.execute("SELECT users.id FROM users, subscriptions WHERE users.id=subscriptions.user and subscriptions.status='ACTIVE' and subscriptions.game="+str(gid)) + print "Billing "+str(int(k))+" users." + while k!=0: + k=k-1 + user = int(cursor.fetchone()[0]) + update=db.cursor() + update.execute("INSERT INTO transactions (user,date,balance,description) VALUES ("+str(user)+", '"+date+"', -"+str(price)+", 'ZAT-"+str(gid)+"')") +else: + print "ERROR: ZAT for game "+str(gid)+" has already been done."