evennia/src/imc2/trackers.py
Greg Taylor 31a78f9fb6 * Added the 'imclist' command to show other games connected to IMC.
* Added the automatic cleaning/pruning code to weed out entries that are probably disconnected.
* Added 'imcwhois <player>' command. Still needs some sanitizing on the outgoing string.
* Added the beginnings of a -reply packet handler through reply_listener.py.
* Fleshed out a few more packets in packets.py.
Next up: Make the ANSI system a little more modular. Create a class for ANSI tables so developers can pick and choose different tables on their own, but keep the same API. This will be used so we don't have to copy/paste src/ansi.py to src/imc2/ansi.py and duplicate stuff.
2009-04-13 06:36:51 +00:00

44 lines
No EOL
1.7 KiB
Python

"""
Certain periodic packets are sent by connected MUDs (is-alive, user-cache,
etc). The IMC2 protocol assumes that each connected MUD will capture these and
populate/maintain their own lists of other servers connected. This module
contains stuff like this.
"""
from time import time
class IMC2Mud(object):
"""
Stores information about other games connected to our current IMC2 network.
"""
def __init__(self, packet):
self.name = packet.origin
self.versionid = packet.optional_data.get('versionid', None)
self.networkname = packet.optional_data.get('networkname', None)
self.url = packet.optional_data.get('url', None)
self.host = packet.optional_data.get('host', None)
self.port = packet.optional_data.get('port', None)
self.sha256 = packet.optional_data.get('sha256', None)
# This is used to determine when a Mud has fallen into inactive status.
self.last_updated = time()
class IMC2MudList(object):
"""
Keeps track of other MUDs connected to the IMC network.
"""
def __init__(self):
# Mud list is stored in a dict, key being the IMC Mud name.
self.mud_list = {}
def update_mud_from_packet(self, packet):
# This grabs relevant info from the packet and stuffs it in the
# Mud list for later retrieval.
mud = IMC2Mud(packet)
self.mud_list[mud.name] = mud
def remove_mud_from_packet(self, packet):
# Removes a mud from the Mud list when given a packet.
mud = IMC2Mud(packet)
del self.mud_list[mud.name]
# Use this instance to keep track of the other games on the network.
IMC2_MUDLIST = IMC2MudList()