mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 11:29:24 +01:00
Generate statistics on current number of active and waiting players
This commit is contained in:
parent
eef344a740
commit
115a12b958
@ -604,15 +604,16 @@ class Broker(SocketServer.UDPServer):
|
||||
|
||||
def log_connection(self, who, country):
|
||||
stats.add_connection(who, country)
|
||||
stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers))
|
||||
|
||||
try:
|
||||
stats.save(self.stat_data)
|
||||
except Exception, e:
|
||||
error_log("saving stats failed with %s" % str(e) )
|
||||
log_error("saving stats failed with %s" % str(e) )
|
||||
try:
|
||||
stats.generate_html(self.stat_html)
|
||||
except Exception, e:
|
||||
error_log("generating HTML failed with %s" % str(e) )
|
||||
log_error("generating HTML failed with %s" % str(e) )
|
||||
|
||||
def send_data(self, dst, data):
|
||||
self.socket.sendto(data, dst)
|
||||
@ -672,6 +673,7 @@ class Broker(SocketServer.UDPServer):
|
||||
self.active_peers[ peer.addr ] = peer
|
||||
except Exception, e:
|
||||
log_error("Moving peer %s to active failed: %s" % (str(peer.addr), str(e)))
|
||||
stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers))
|
||||
|
||||
def remove_peer(self, peer):
|
||||
try:
|
||||
@ -685,6 +687,8 @@ class Broker(SocketServer.UDPServer):
|
||||
del self.waiting_peers[peer.addr]
|
||||
|
||||
self.data_store.remove_peer(peer)
|
||||
stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers))
|
||||
print "VOBB: ", len(self.waiting_peers), len(self.active_peers)
|
||||
except Exception, e:
|
||||
log_error("Could not remove %s (probably wrong version): %s" %
|
||||
(str(peer.addr), str(e)))
|
||||
|
@ -6,12 +6,22 @@ class Container:
|
||||
self.total_connections = 0
|
||||
self.country_count = {}
|
||||
self.last_10 = []
|
||||
self.nr_active = 0
|
||||
self.nr_waiting = 0
|
||||
|
||||
def set_nr_active(self, nr_active):
|
||||
self.nr_active = nr_active
|
||||
|
||||
def set_nr_waiting(self, nr_waiting):
|
||||
self.nr_waiting = nr_waiting
|
||||
|
||||
def copy_from_other(self, other):
|
||||
try:
|
||||
self.total_connections = other.total_connections
|
||||
self.country_count = other.country_count
|
||||
self.last_10 = other.last_10
|
||||
self.nr_active = other.nr_active
|
||||
self.nr_waiting = other.nr_waiting
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -41,6 +51,7 @@ class HtmlGenerator:
|
||||
outf.write("<html><body>\n")
|
||||
outf.write("<H2>Frodo-Wii network statistics</H2>\n")
|
||||
outf.write("The total number of connections is <b>%d</b><br><br>\n" % (self.container.total_connections))
|
||||
outf.write("There are currently <b>%d</b> players waiting for connections and <b>%d</b> players playing<br><br>\n" % (self.container.nr_waiting, self.container.nr_active))
|
||||
outf.write("<TABLE border=\"0\" cellpadding=\"0\">\n")
|
||||
outf.write("<TR><TD><H3>Last %d connections</H3></TD><TD> </TD<TD colspan=4><H3>Random connection screenshots</TD></TR>\n" %
|
||||
(len(self.container.last_10)) )
|
||||
@ -106,6 +117,10 @@ def load(filename):
|
||||
except:
|
||||
pass
|
||||
|
||||
def update_peer_nr(waiting, active):
|
||||
g_stat.set_nr_waiting(waiting)
|
||||
g_stat.set_nr_active(active)
|
||||
|
||||
def add_connection(who, country):
|
||||
g_stat.add_connection(who, country)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user