mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 19:39: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):
|
def log_connection(self, who, country):
|
||||||
stats.add_connection(who, country)
|
stats.add_connection(who, country)
|
||||||
|
stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stats.save(self.stat_data)
|
stats.save(self.stat_data)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
error_log("saving stats failed with %s" % str(e) )
|
log_error("saving stats failed with %s" % str(e) )
|
||||||
try:
|
try:
|
||||||
stats.generate_html(self.stat_html)
|
stats.generate_html(self.stat_html)
|
||||||
except Exception, e:
|
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):
|
def send_data(self, dst, data):
|
||||||
self.socket.sendto(data, dst)
|
self.socket.sendto(data, dst)
|
||||||
@ -672,6 +673,7 @@ class Broker(SocketServer.UDPServer):
|
|||||||
self.active_peers[ peer.addr ] = peer
|
self.active_peers[ peer.addr ] = peer
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log_error("Moving peer %s to active failed: %s" % (str(peer.addr), str(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):
|
def remove_peer(self, peer):
|
||||||
try:
|
try:
|
||||||
@ -685,6 +687,8 @@ class Broker(SocketServer.UDPServer):
|
|||||||
del self.waiting_peers[peer.addr]
|
del self.waiting_peers[peer.addr]
|
||||||
|
|
||||||
self.data_store.remove_peer(peer)
|
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:
|
except Exception, e:
|
||||||
log_error("Could not remove %s (probably wrong version): %s" %
|
log_error("Could not remove %s (probably wrong version): %s" %
|
||||||
(str(peer.addr), str(e)))
|
(str(peer.addr), str(e)))
|
||||||
|
@ -6,12 +6,22 @@ class Container:
|
|||||||
self.total_connections = 0
|
self.total_connections = 0
|
||||||
self.country_count = {}
|
self.country_count = {}
|
||||||
self.last_10 = []
|
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):
|
def copy_from_other(self, other):
|
||||||
try:
|
try:
|
||||||
self.total_connections = other.total_connections
|
self.total_connections = other.total_connections
|
||||||
self.country_count = other.country_count
|
self.country_count = other.country_count
|
||||||
self.last_10 = other.last_10
|
self.last_10 = other.last_10
|
||||||
|
self.nr_active = other.nr_active
|
||||||
|
self.nr_waiting = other.nr_waiting
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -41,6 +51,7 @@ class HtmlGenerator:
|
|||||||
outf.write("<html><body>\n")
|
outf.write("<html><body>\n")
|
||||||
outf.write("<H2>Frodo-Wii network statistics</H2>\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("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("<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" %
|
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)) )
|
(len(self.container.last_10)) )
|
||||||
@ -106,6 +117,10 @@ def load(filename):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def update_peer_nr(waiting, active):
|
||||||
|
g_stat.set_nr_waiting(waiting)
|
||||||
|
g_stat.set_nr_active(active)
|
||||||
|
|
||||||
def add_connection(who, country):
|
def add_connection(who, country):
|
||||||
g_stat.add_connection(who, country)
|
g_stat.add_connection(who, country)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user