Ignore idle players

This commit is contained in:
Stefan `Sec` Zehl 2011-12-29 04:12:20 +01:00
parent b0ec9d6579
commit 4492b80976
1 changed files with 15 additions and 10 deletions

View File

@ -21,16 +21,12 @@ right=0.0
cntr=0 cntr=0
cntl=0 cntl=0
info={} info={}
idle={}
def sendpos(): def sendpos():
global right, left global right, left
global cntr, cntl global cntr, cntl
global info global info
sstr="{ \"right\": %s, \"cntr\": %s , \"cntl\": %s, \"left\": %s }"%(right,cntr,cntl,left)
if pong:
pong.write_message(sstr)
# print sstr
threading.Timer(.1,sendpos).start()
for (id,(b,t,r)) in info.items(): for (id,(b,t,r)) in info.items():
if(t+5<time.time()): if(t+5<time.time()):
# print "time=%s"%(time.time()) # print "time=%s"%(time.time())
@ -40,6 +36,11 @@ def sendpos():
cntr=0.0 cntr=0.0
cntl=0.0 cntl=0.0
for (id,(b,t,r)) in info.items(): for (id,(b,t,r)) in info.items():
if b != 0:
idle[id]=time.time()
if idle[id]+30<time.time():
print "idle-ignoring %s"%(id)
else:
if r==1: if r==1:
cntr+=1 cntr+=1
else: else:
@ -63,7 +64,11 @@ def sendpos():
left=0 left=0
else: else:
left=suml/cntl left=suml/cntl
# print "right=%s left=%s"%(right,left) sstr="{ \"right\": %s, \"cntr\": %s , \"cntl\": %s, \"left\": %s }"%(right,cntr,cntl,left)
if pong:
pong.write_message(sstr)
# print sstr
threading.Timer(.1,sendpos).start()
sendpos() sendpos()