我已经使用python-valve库设置了一些代码来查找ark服务器及其数据。
我的问题是,如何让它也找到非官方的服务器?
我用来查找所有欧洲服务器的当前代码如下:
import logging
from gevent.pool import Pool
from valve.source.master_server import MasterServerQuerier
from valve.source.a2s import ServerQuerier, NoResponseError
from valve.source.messages import BrokenMessageError
MASTER_HOST = 'hl2master.steampowered.com'
MASTER_TIMEOUT = 60
SERVER_TIMEOUT = 5
pool = Pool(size=50)
def get_server_stats(address):
server = ServerQuerier(address, timeout=SERVER_TIMEOUT)
try:
info = server.info()
logging.info(u'Updated {0}:{1} █ {player_count}/{max_players} █ {server_name} █ {map} █ {server_type}'.format(
address[0], address[1], **info)
)
return True
except (NotImplementedError, NoResponseError, BrokenMessageError):
pass
def find_servers():
count = 0
greenlets = []
master = MasterServerQuerier(
address=(MASTER_HOST, 27011), timeout=MASTER_TIMEOUT
)
try:
for address in master.find(region='eu',
gamedir=u"ark_survival_evolved"):
greenlets.append(pool.spawn(get_server_stats, address))
count += 1
except NoResponseError as e:
# Protocol is UDP so there's no "end"
if u'Timed out' not in e.message:
logging.warning('Error querying master server: {0}'.format(e))
finally:
logging.info('Found {0} addresses'.format(count))
return greenlets
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
results = find_servers()
logging.info('Counting results...')
results = [result.get() for result in results]
logging.info('Collected {0}'.format(len(results)))
答案 0 :(得分:0)
显然将区域更改为rest
可以完成工作
for address in master.find(region='rest',
gamedir=u"ark_survival_evolved"):