Handle autosetup and tell packets correctly.
This commit is contained in:
parent
c18937d3ba
commit
2d6ef25081
2 changed files with 36 additions and 9 deletions
|
|
@ -9,6 +9,7 @@ from twisted.internet import reactor, task
|
||||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src import logger
|
from src import logger
|
||||||
|
from src import session_mgr
|
||||||
from src.imc2.packets import *
|
from src.imc2.packets import *
|
||||||
from src.imc2.trackers import *
|
from src.imc2.trackers import *
|
||||||
from src.imc2 import reply_listener
|
from src.imc2 import reply_listener
|
||||||
|
|
@ -66,16 +67,23 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
||||||
"""
|
"""
|
||||||
SERVER Sends: PW <servername> <serverpw> version=<version#> <networkname>
|
SERVER Sends: PW <servername> <serverpw> version=<version#> <networkname>
|
||||||
"""
|
"""
|
||||||
if line[:2] == "PW":
|
line_split = line.split(' ')
|
||||||
line_split = line.split(' ')
|
pw_present = line_split[0] == 'PW'
|
||||||
|
autosetup_present = line_split[0] == 'autosetup'
|
||||||
|
|
||||||
|
if pw_present:
|
||||||
self.server_name = line_split[1]
|
self.server_name = line_split[1]
|
||||||
self.network_name = line_split[4]
|
self.network_name = line_split[4]
|
||||||
self.is_authenticated = True
|
elif autosetup_present:
|
||||||
self.sequence = int(time())
|
logger.log_infomsg("IMC2: Autosetup response found.")
|
||||||
logger.log_infomsg("IMC2: Successfully authenticated to the '%s' network." % self.network_name)
|
self.server_name = line_split[1]
|
||||||
# Let everyone know we've arrived.
|
self.network_name = line_split[3]
|
||||||
#self.send_packet(IMC2PacketKeepAliveRequest())
|
self.is_authenticated = True
|
||||||
self.send_packet(IMC2PacketIsAlive())
|
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(IMC2PacketIsAlive())
|
||||||
|
#self.send_packet(IMC2PacketKeepAliveRequest())
|
||||||
|
|
||||||
def _handle_channel_mappings(self, packet):
|
def _handle_channel_mappings(self, packet):
|
||||||
"""
|
"""
|
||||||
|
|
@ -124,6 +132,14 @@ class IMC2Protocol(StatefulTelnetProtocol):
|
||||||
reply_listener.handle_whois_reply(packet)
|
reply_listener.handle_whois_reply(packet)
|
||||||
elif packet.packet_type == 'close-notify':
|
elif packet.packet_type == 'close-notify':
|
||||||
IMC2_MUDLIST.remove_mud_from_packet(packet)
|
IMC2_MUDLIST.remove_mud_from_packet(packet)
|
||||||
|
elif packet.packet_type == 'tell':
|
||||||
|
sessions = session_mgr.find_sessions_from_username(packet.target)
|
||||||
|
for session in sessions:
|
||||||
|
session.msg("%s@%s IMC tells: %s" %
|
||||||
|
(packet.sender,
|
||||||
|
packet.origin,
|
||||||
|
packet.optional_data.get('text',
|
||||||
|
'ERROR: No text provided.')))
|
||||||
|
|
||||||
class IMC2ClientFactory(ClientFactory):
|
class IMC2ClientFactory(ClientFactory):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Session manager, handles connected players.
|
Session manager, handles connected players.
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from src.config.models import ConfigValue
|
from src.config.models import ConfigValue
|
||||||
from src import logger
|
from src import logger
|
||||||
from src.util import functions_general
|
from src.util import functions_general
|
||||||
|
|
@ -10,6 +10,17 @@ from src.util import functions_general
|
||||||
# Our list of connected sessions.
|
# Our list of connected sessions.
|
||||||
session_list = []
|
session_list = []
|
||||||
|
|
||||||
|
def find_sessions_from_username(username):
|
||||||
|
"""
|
||||||
|
Given a username, return any matching sessions.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
uobj = User.objects.get(username=username)
|
||||||
|
uid = uobj.id
|
||||||
|
return [session for session in session_list if session.uid == uid]
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
def add_session(session):
|
def add_session(session):
|
||||||
"""
|
"""
|
||||||
Adds a session to the session list.
|
Adds a session to the session list.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue