-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq3serverstats.py
More file actions
executable file
·76 lines (70 loc) · 1.94 KB
/
q3serverstats.py
File metadata and controls
executable file
·76 lines (70 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
__doc__ = '''
q3serverstats.py
Author - rob0r - github.com/rob0r
wrapper for pyquake3.py to make probing
quake3 servers easy. Allows loading multiple
servers from a config file
'''
from pyquake3 import *
import argparse
import os
def connect(server,password):
try:
q = PyQuake3(server, password)
return q
except:
print 'Failed to connect!'
quit(1)
def printserverinfo(qcon):
q = qcon
q.update()
print '%s : %s : %s : %s player(s).' % \
(q.get_address(), q.vars['sv_hostname'], q.vars['mapname'], len(q.players))
def printplayerinfo(qcon):
q = qcon
try:
q.rcon_update()
except:
print 'Failed to get player info! Wrong password for ' + q.get_address()
for player in q.players:
print ' |-%s : %s frags : %sms ping : %s ' % \
(player.name, player.frags, player.ping, player.address)
cliopts = argparse.ArgumentParser('Quake3 server stats')
cliopts.add_argument(
'--server',
default = None,
help = 'server ip:port or hostname:port',
type = str
)
cliopts.add_argument(
'--password',
default = None,
help = 'server rcon password',
type = str
)
cliopts.add_argument(
'--config',
default = 'config.py',
help = 'path to config file',
type = str
)
cliargs = cliopts.parse_args()
# cli arguments take preference over config file
if not cliargs.server:
if os.path.isfile(cliargs.config):
config = open(cliargs.config)
from config import *
for server in servers:
password = servers[server]
q = connect(server,password)
printserverinfo(q)
printplayerinfo(q)
else:
print 'No config or server specified!'
elif cliargs.server and cliargs.password:
q = connect(cliargs.server, cliargs.password)
printserverinfo(q)
printplayerinfo(q)
else:
print 'server and password required!'