* 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.
This commit is contained in:
parent
317a4f1532
commit
31a78f9fb6
7 changed files with 213 additions and 45 deletions
|
|
@ -2,14 +2,16 @@
|
|||
IMC2 client module. Handles connecting to and communicating with an IMC2 server.
|
||||
"""
|
||||
import telnetlib
|
||||
import time
|
||||
from time import time
|
||||
from twisted.internet.protocol import ClientFactory
|
||||
from twisted.protocols.basic import LineReceiver
|
||||
from twisted.internet import reactor, task
|
||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||
from django.conf import settings
|
||||
from src.imc2.packets import *
|
||||
from src import logger
|
||||
from src.imc2.packets import *
|
||||
from src.imc2.trackers import *
|
||||
from src.imc2 import reply_listener
|
||||
|
||||
# The active instance of IMC2Protocol. Set at server startup.
|
||||
IMC2_PROTOCOL_INSTANCE = None
|
||||
|
|
@ -20,8 +22,9 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
|||
authentication, and all necessary packets.
|
||||
"""
|
||||
def __init__(self):
|
||||
print "IMC2: Client connecting to %s:%s..." % (settings.IMC2_SERVER_ADDRESS,
|
||||
settings.IMC2_SERVER_PORT)
|
||||
logger.log_infomsg("IMC2: Client connecting to %s:%s..." % (
|
||||
settings.IMC2_SERVER_ADDRESS,
|
||||
settings.IMC2_SERVER_PORT))
|
||||
global IMC2_PROTOCOL_INSTANCE
|
||||
IMC2_PROTOCOL_INSTANCE = self
|
||||
self.is_authenticated = False
|
||||
|
|
@ -34,9 +37,9 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
|||
"""
|
||||
Triggered after connecting to the IMC2 network.
|
||||
"""
|
||||
print "IMC2: Connected to network server."
|
||||
logger.log_infomsg("IMC2: Connected to network server.")
|
||||
self.auth_type = "plaintext"
|
||||
print "IMC2: Sending authentication packet."
|
||||
logger.log_infomsg("IMC2: Sending authentication packet.")
|
||||
self.send_packet(IMC2PacketAuthPlaintext())
|
||||
|
||||
def send_packet(self, packet):
|
||||
|
|
@ -50,7 +53,7 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
|||
|
||||
packet.imc2_protocol = self
|
||||
packet_str = packet.assemble()
|
||||
print "IMC2: SENT> %s" % packet_str
|
||||
logger.log_infomsg("IMC2: SENT> %s" % packet_str)
|
||||
self.sendLine(packet_str)
|
||||
|
||||
def _parse_auth_response(self, line):
|
||||
|
|
@ -66,8 +69,11 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
|||
self.server_name = line_split[1]
|
||||
self.network_name = line_split[4]
|
||||
self.is_authenticated = True
|
||||
self.sequence = int(time.time())
|
||||
print "IMC2: Successfully authenticated to the '%s' network." % self.network_name
|
||||
self.sequence = int(time())
|
||||
logger.log_infomsg("IMC2: Successfully authenticated to the '%s' network." % self.network_name)
|
||||
# Let everyone know we've arrived.
|
||||
#self.send_packet(IMC2PacketKeepAliveRequest())
|
||||
self.send_packet(IMC2PacketIsAlive())
|
||||
|
||||
def lineReceived(self, line):
|
||||
"""
|
||||
|
|
@ -78,8 +84,14 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
|||
self._parse_auth_response(line)
|
||||
else:
|
||||
logger.log_infomsg("PACKET: %s" % line)
|
||||
logger.log_infomsg(IMC2Packet(packet_str = line))
|
||||
#print "receive:", line
|
||||
packet = IMC2Packet(packet_str = line)
|
||||
logger.log_infomsg(packet)
|
||||
if packet.packet_type == 'is-alive':
|
||||
IMC2_MUDLIST.update_mud_from_packet(packet)
|
||||
elif packet.packet_type == 'whois-reply':
|
||||
reply_listener.handle_whois_reply(packet)
|
||||
elif packet.packet_type == 'close-notify':
|
||||
IMC2_MUDLIST.remove_mud_from_packet(packet)
|
||||
|
||||
class IMC2ClientFactory(ClientFactory):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue