Advertisement
Azelphur

Conky server status

Oct 12th, 2011
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. import SourceLib, threading, socket
  2.  
  3. def GetInMS(seconds):
  4.     minutes = seconds / 60
  5.     seconds -= 60*minutes
  6.     return "%02d:%02d" % (minutes, seconds)
  7.  
  8. srcdsservers = ['Surf.TF2.Azelphur.com', 'Fun.TF2.Azelphur.com', 'Vanilla.TF2.Azelphur.com', 'FortWars.TF2.Azelphur.com']
  9. results = {}
  10. total = 0
  11. totalmax = 0
  12. threads = 0
  13.  
  14. class TF2 ( threading.Thread ):
  15.     def setserver(self, server):
  16.         self.server = server
  17.  
  18.     def run ( self ):
  19.         for i in range(0, 5):
  20.             try:
  21.                 query = SourceLib.SourceQuery.SourceQuery(self.server, 27015)
  22.                 info = query.info()
  23.                 rules = query.rules()
  24.                 players = query.player()
  25.  
  26.                 l = []
  27.                 l.append("%s" % (self.server))
  28.                 l.append("${goto 15}Map: %s" % (info['map']))
  29.                 l.append("${goto 15}Next Map: %s" % (rules['sm_nextmap']))
  30.                 l.append("${goto 15}Players: %s / %s" % (info['numplayers'], info['maxplayers']))
  31.                 l.append("${voffset -6}")
  32.                 results[self.server] = l
  33.  
  34.                 global total, totalmax
  35.                 total += int(info['numplayers'])
  36.                 totalmax += int(info['maxplayers'])
  37.                 break
  38.             except:
  39.                 l = []
  40.                 l.append("%s" % (self.server))
  41.                 l.append("${goto 15}Map: ?")
  42.                 l.append("${goto 15}Next Map: ?")
  43.                 l.append("${goto 15}Players: ? / ?")
  44.                 l.append("${voffset -6}")
  45.                 results[self.server] = l
  46.         global threads
  47.         threads -= 1
  48.            
  49.         self.checkresults()
  50.  
  51.     def checkresults(self):
  52.         if threads != 0:
  53.             return
  54.        
  55.         global total, totalmax
  56.         print "Total: %d / %d (%d%%)" % (total, totalmax, (total*100)/totalmax)
  57.         print
  58.         for server in srcdsservers:
  59.             for line in results[server]:
  60.                 print line
  61.         exit()
  62.  
  63.  
  64. for server in srcdsservers:
  65.     threads += 1
  66.     p = TF2()
  67.     p.setserver(server)
  68.     p.start()
  69.  
  70. #print
  71. #print "${alignc}Players"
  72. #plist = []
  73. #for player in players:
  74. #   plist.append((player['kills'], player['name'].replace("$", '$$'), GetInMS(int(player['time']))))
  75. #plist = sorted(plist)
  76. #for player in reversed(plist):
  77. #   print "%s${goto 210}%s${alignr}%s" % (player[1], player[0], player[2])
  78. #for i in range(0, 32-len(plist)):
  79. #   print i+len(plist)
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement