new table for transfer of players

This commit is contained in:
Enno Rehling 2002-04-07 12:07:36 +00:00
parent b68713a18b
commit e78d6351de
4 changed files with 30 additions and 19 deletions

View File

@ -214,11 +214,12 @@ def ShowInfo(custid, Password):
Display(output, "Kundendaten #"+str(custid)) Display(output, "Kundendaten #"+str(custid))
Errors = "" Errors = ""
def TransferFaction(sid, faction, newuser, game): def TransferFaction(sid, faction, olduser, newuser, game, gid):
db = MySQLdb.connect(db=dbname) db = MySQLdb.connect(db=dbname)
update = db.cursor() 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: 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)) update.execute("UPDATE subscriptions set status='TRANSFERED', user=" + str(newuser) + " where id="+str(sid))
SendTransfer(newuser, faction, game); SendTransfer(newuser, faction, game);
db.close() db.close()
@ -258,15 +259,15 @@ def Save(custid, Password):
else: else:
update.execute('delete from subscriptions where user='+str(int(custid))+' and game='+str(int(gid))) 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: while nfactions > 0:
game, sid, faction = cursor.fetchone() gid, game, sid, faction = cursor.fetchone()
if Form.has_key("cancel_"+faction): if Form.has_key("cancel_"+faction):
update = db.cursor() update = db.cursor()
update.execute("UPDATE subscriptions set status='CANCELLED' where id="+str(int(sid))) update.execute("UPDATE subscriptions set status='CANCELLED' where id="+str(int(sid)))
elif Form.has_key("transfer_"+faction): elif Form.has_key("transfer_"+faction):
newuser = int(Form["transfer_"+faction].value) newuser = int(Form["transfer_"+faction].value)
TransferFaction(sid, faction, newuser, game) TransferFaction(sid, faction, custid, newuser, game, gid)
nfactions = nfactions - 1 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") 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: if i==0:
update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(int(sid))) update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(int(sid)))
else: else:
Errors=Errors+"Du hast bereits eine Aktive Partei in "+game+"<br> Errors=Errors+"Du hast bereits eine Aktive Partei in "+game+"<br>\n"
nfactions = nfactions - 1 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") 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")

View File

@ -89,12 +89,13 @@ if (password!=None) & (custid!=None):
output="" output=""
if cursor.execute("select firstname, lastname, email, id from users where password='"+password+"' and id="+str(int(custid)))==1: 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() 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: while c>0:
c=c-1 c=c-1
sid, gid, newpass, faction = cursor.fetchone() sid, gid, newpass, faction, uid = cursor.fetchone()
if Form.has_key("accept_"+str(int(sid))): if Form.has_key("accept_"+str(int(sid))):
update = db.cursor() 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))) 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.<br>" output=output+"Die Partei " + faction + " wurde Dir überschrieben. Eine Email mit dem Passwort und weiteren Hinweisen ist unterwegs zu Dir.<br>"
server=smtplib.SMTP(smtpserver) server=smtplib.SMTP(smtpserver)

View File

@ -1,5 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# merge two accounts. not used.
# needs to be checked before used.
# does not update the TRANSFERS table
import MySQLdb import MySQLdb
import sys import sys

View File

@ -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') os.system('mysql ' + dbname + ' < ' + patchdir+'/patch-'+str(int(patch))+'.sql')
cursor.execute('update games set patch='+str(int(patch))+' where id='+str(gid)) 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." print "Removing "+str(int(k))+" transfered subscriptions."
SetUser(cursor, int(k), 0) 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." print "Removing "+str(int(k))+" cancelled subscriptions."
SetUser(cursor, int(k), 0) 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." 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: if k:
print "Cancelling subscriptions with 3+ NMRs." 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)) cursor.execute("SELECT count(*) from transactions where date='"+date+"' and description='ZAT-"+str(gid)+"'")
while k!=0: 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 k=k-1
user = int(cursor.fetchone()[0]) user = int(cursor.fetchone()[0])
update=db.cursor() update=db.cursor()
update.execute("INSERT INTO transactions (user,date,balance,description) VALUES ("+str(user)+", '"+date+"', -"+str(price)+", 'ZAT-"+str(gid)+"')") 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."