mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
send using old message format to old clients, new to new
This commit is contained in:
parent
9b5607d829
commit
7d81083d7d
1 changed files with 24 additions and 7 deletions
|
@ -70,6 +70,16 @@ def getPendingMsgs( con, typ ):
|
||||||
if g_debug: print "getPendingMsgs=>", result
|
if g_debug: print "getPendingMsgs=>", result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def addClntVers( con, rows ):
|
||||||
|
query = """select clntVers[%s] from games where connname = '%s';"""
|
||||||
|
cur = con.cursor()
|
||||||
|
for row in rows:
|
||||||
|
cur.execute( query % (row['hid'], row['connname']))
|
||||||
|
if cur.rowcount == 1: row['clntVers'] = cur.fetchone()[0]
|
||||||
|
else: print "bad row count: ", cur.rowcount
|
||||||
|
con.commit()
|
||||||
|
return rows
|
||||||
|
|
||||||
def deleteMsgs( con, msgIDs ):
|
def deleteMsgs( con, msgIDs ):
|
||||||
if 0 < len( msgIDs ):
|
if 0 < len( msgIDs ):
|
||||||
query = "DELETE from msgs where id in (%s);" % ",".join(msgIDs)
|
query = "DELETE from msgs where id in (%s);" % ",".join(msgIDs)
|
||||||
|
@ -99,18 +109,22 @@ def asGCMIds(con, devids, typ):
|
||||||
cur.execute( query )
|
cur.execute( query )
|
||||||
return [elem[0] for elem in cur.fetchall()]
|
return [elem[0] for elem in cur.fetchall()]
|
||||||
|
|
||||||
def notifyGCM( devids, typ, msg, connname, hid ):
|
def notifyGCM( target, devids, typ, msg, connname, hid ):
|
||||||
success = False
|
success = False
|
||||||
if typ == DEVTYPE_GCM:
|
if typ == DEVTYPE_GCM:
|
||||||
connname = "%s/%d" % (connname, hid)
|
if 3 <= target['clntVers']:
|
||||||
|
connname = "%s/%d" % (connname, hid)
|
||||||
|
data = { 'msg64': msg,
|
||||||
|
'connname': connname,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
data = { 'getMoves': True, }
|
||||||
values = {
|
values = {
|
||||||
'data' : { 'getMoves': True,
|
'data' : data,
|
||||||
'msg64': msg,
|
|
||||||
'connname': connname,
|
|
||||||
},
|
|
||||||
'registration_ids': devids,
|
'registration_ids': devids,
|
||||||
}
|
}
|
||||||
params = json.dumps( values )
|
params = json.dumps( values )
|
||||||
|
|
||||||
req = urllib2.Request("https://android.googleapis.com/gcm/send", params )
|
req = urllib2.Request("https://android.googleapis.com/gcm/send", params )
|
||||||
req.add_header( 'Content-Type' , 'application/x-www-form-urlencoded;charset=UTF-8' )
|
req.add_header( 'Content-Type' , 'application/x-www-form-urlencoded;charset=UTF-8' )
|
||||||
req.add_header( 'Authorization' , 'key=' + mykey.myKey )
|
req.add_header( 'Authorization' , 'key=' + mykey.myKey )
|
||||||
|
@ -211,6 +225,7 @@ def main():
|
||||||
if g_debug: print
|
if g_debug: print
|
||||||
devids = getPendingMsgs( g_con, typ )
|
devids = getPendingMsgs( g_con, typ )
|
||||||
if 0 < len(devids):
|
if 0 < len(devids):
|
||||||
|
devids = addClntVers( g_con, devids )
|
||||||
targets = targetsAfterBackoff( devids )
|
targets = targetsAfterBackoff( devids )
|
||||||
if 0 < len(targets):
|
if 0 < len(targets):
|
||||||
if 0 < emptyCount: print ""
|
if 0 < emptyCount: print ""
|
||||||
|
@ -223,7 +238,9 @@ def main():
|
||||||
connname = target['connname']
|
connname = target['connname']
|
||||||
hid = target['hid']
|
hid = target['hid']
|
||||||
msg = target['msg64']
|
msg = target['msg64']
|
||||||
if notifyGCM( asGCMIds( g_con, [devid], typ ), typ, msg, connname, hid ):
|
if notifyGCM( target, asGCMIds( g_con, [devid], typ ), \
|
||||||
|
typ, msg, connname, hid ) \
|
||||||
|
and 3 <= target['clntVers']:
|
||||||
toDelete.append( str(target['id']) )
|
toDelete.append( str(target['id']) )
|
||||||
pruneSent( devids )
|
pruneSent( devids )
|
||||||
deleteMsgs( g_con, toDelete )
|
deleteMsgs( g_con, toDelete )
|
||||||
|
|
Loading…
Add table
Reference in a new issue