mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-13 07:05:12 +01:00
Write out server messages on the stats page
This commit is contained in:
parent
ae23c0c4c2
commit
839972cabc
@ -641,14 +641,23 @@ class Broker(SocketServer.UDPServer):
|
||||
def enqueue_message(self, sending_peer, message):
|
||||
# Store last 10 messages
|
||||
self.messages = self.messages[-9:] + [message]
|
||||
all_msgs = []
|
||||
|
||||
for addr, peer in self.peers.iteritems():
|
||||
all_msgs.append(message.message)
|
||||
if peer != sending_peer:
|
||||
peer.send_packet(message.marshal())
|
||||
stats.set_messages(all_msgs)
|
||||
|
||||
try:
|
||||
stats.generate_html(self.stat_html)
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
def dequeue_old_messages(self):
|
||||
now = time.mktime(time.localtime())
|
||||
to_delete = 0
|
||||
all_msgs = []
|
||||
|
||||
for msg in self.messages:
|
||||
diff = now - msg.get_timestamp()
|
||||
@ -658,6 +667,14 @@ class Broker(SocketServer.UDPServer):
|
||||
log_info("Deleting old message")
|
||||
self.messages = self.messages[ to_delete : ]
|
||||
|
||||
for msg in self.messages:
|
||||
all_msgs.append(msg.message)
|
||||
stats.set_messages(all_msgs)
|
||||
try:
|
||||
stats.generate_html(self.stat_html)
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
def ping_all_peers(self):
|
||||
"""Ping all peers (to see that they are alive)"""
|
||||
for k,v in self.peers.iteritems():
|
||||
|
@ -6,6 +6,7 @@ class Container:
|
||||
self.total_connections = 0
|
||||
self.country_count = {}
|
||||
self.last_10 = []
|
||||
self.messages = []
|
||||
self.nr_active = 0
|
||||
self.nr_waiting = 0
|
||||
|
||||
@ -17,11 +18,12 @@ class Container:
|
||||
|
||||
def copy_from_other(self, other):
|
||||
try:
|
||||
self.nr_active = 0 # Always reset
|
||||
self.nr_waiting = 0
|
||||
self.total_connections = other.total_connections
|
||||
self.country_count = other.country_count
|
||||
self.last_10 = other.last_10
|
||||
self.nr_active = 0 # Always reset
|
||||
self.nr_waiting = 0
|
||||
self.messages = other.messages
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -33,6 +35,9 @@ class Container:
|
||||
|
||||
self.country_count[country] = cur + 1
|
||||
|
||||
def set_messages(self, messages):
|
||||
self.messages = messages
|
||||
|
||||
def add_connection(self, who, country):
|
||||
time_now = time.strftime("%Y-%m-%d %H:%M", time.gmtime())
|
||||
s = "%s - %s (%s)" % (time_now, who, country)
|
||||
@ -71,6 +76,11 @@ class HtmlGenerator:
|
||||
outf.write("<TR><TD colspan=3><H3>List of countries</H3></TD></TR>\n")
|
||||
count = 1
|
||||
|
||||
outf.write("<H3>Last server messages</H3>\n")
|
||||
for msg in self.container.messages:
|
||||
outf.write("<br>%s\n" % (msg))
|
||||
outf.write("<br><br>")
|
||||
|
||||
n_countries = len(sorted_countries)
|
||||
for i in range(0, n_countries / 3):
|
||||
c1, n1 = sorted_countries[i]
|
||||
@ -124,6 +134,9 @@ def update_peer_nr(waiting, active):
|
||||
def add_connection(who, country):
|
||||
g_stat.add_connection(who, country)
|
||||
|
||||
def set_messages(messages):
|
||||
g_stat.set_messages(messages)
|
||||
|
||||
if __name__ == "__main__":
|
||||
load("/tmp/vobb")
|
||||
for i in range(0, 10):
|
||||
@ -133,6 +146,7 @@ if __name__ == "__main__":
|
||||
add_connection("SIMONK", "Sweden")
|
||||
add_connection("Linda", "Germany")
|
||||
add_connection("Linda", "Germany")
|
||||
set_messages(["Hej", "Who framed Roger Rabbit?", "IK+ at 19.00 CET?"])
|
||||
save("/tmp/vobb")
|
||||
|
||||
hg = HtmlGenerator(g_stat)
|
||||
|
Loading…
Reference in New Issue
Block a user