示例#1
0
文件: steam.py 项目: mdevaev/slib
def sourceServerStatus(host_name, port) :
	host_name = ulib.validators.network.validRfcHost(host_name)
	port = ulib.validators.network.validPort(port)

	server = SourceLib.SourceQuery.SourceQuery(host_name, port)

	count = 1
	players_list = []
	for player_dict in server.player() :
		players_list.append([
				str(count),
				{ "nowrap" : None, "body" : player_dict["name"] },
				ulib.tools.fmt.formatTimeDelta(player_dict["time"]),
				str(player_dict["kills"])
			])
		count += 1
	players_table = html.tableWithHeader(["N", "Name", "Time", "Score"], players_list)

	info_dict = server.info()
	status_table = html.statusTable([
			("Server", info_dict["hostname"]),
			("Description", info_dict["gamedesc"]),
			("Game", info_dict["gamedir"]),
			("Map", info_dict["map"]),
			("Players", "%d / %d" % (info_dict["numplayers"], info_dict["maxplayers"])),
			("Password", ( "Yes" if info_dict["passworded"] else "No" )),
			("Secure", ( "Yes" if info_dict["secure"] else "No" )),
			("Version", info_dict["version"])
		])

	# XXX: https://developer.valvesoftware.com/wiki/Steam_browser_protocol
	join_button = html.buttonLink("JOIN", "steam://connect/%s:%d" % (host_name, port), ("big_button",))

	return (players_table, status_table, join_button)
示例#2
0
文件: system.py 项目: mdevaev/slib
def serverStatus() :
	server_status = html.statusTable([
			("Now", time.ctime()),
			("Uptime", ulib.tools.fmt.formatTimeDelta(ulib.tools.unix.uptime())),
			("Load average", ", ".join(map(str, ulib.tools.unix.loadAverage())))
		])
	return (server_status,)
示例#3
0
文件: kf.py 项目: mdevaev/slib
def playerStatisticsTable(stat_dict, user_id) :
	player_stat_dict = stat_dict[user_id]

	wins = player_stat_dict["WinsCount"]
	losts = player_stat_dict["LostsCount"]
	battles = wins + losts
	kills = player_stat_dict["KillsStat"]
	if battles != 0 :
		efficiency = float(kills) / float(battles)
		skill_factor = float(wins) / float(battles)
	else :
		efficiency = skill_factor = 0

	skill_factor_text = ( """
			<div style="float:left; text-align:left;">%.2f&nbsp;</div>
			<div style="float:right; text-align:right; width:70px;">%s</div>
		""" % (skill_factor, html.progressBar(skill_factor * 100)) )

	return html.statusTable([
			("Battles", str(battles)),
			("Wins", str(wins)),
			("Losts", str(losts)),
			("Skill factor", skill_factor_text),
			("Efficiency", "%2.f" % (efficiency)),
			("Last hope", str(player_stat_dict["SoleSurvivorWavesStat"])),
			("Kills", str(kills)),
			("Time played", ulib.tools.fmt.formatTimeDelta(player_stat_dict["TotalPlayTime"])),
		])