from __future__ import print_function

from twisted.internet import reactor, protocol, threads, defer
from twisted.protocols.basic import LineReceiver

from nethud.proto.client import NethackFactory


class TelnetConnection(LineReceiver):
    def __init__(self, users):
        self.users = users
        self.uname = ''

    def connectionLost(self, reason):
        if NethackFactory.client:
            NethackFactory.client.deassoc_client(self.uname)
        if self.uname in self.users:
            del self.users[self.uname]
        self.uname = ''
        print(reason)

    def lineReceived(self, line):
        msg_split = line.split()
        if msg_split[0] == 'AUTH':
            if len(msg_split) != 2:
                self.sendLine("ERR 406 Invalid Parameters.")
                return
            self.handle_auth(msg_split[1])
        elif msg_split[0] == 'QUIT':
            self.transport.loseConnection()
        else:
            self.sendLine("ERR 452 Invalid Command")

    def handle_auth(self, uname):
        self.users[uname] = self
        self.uname = uname
        if NethackFactory.client:
            NethackFactory.client.assoc_client(uname, self)



def TelnetFactory(protocol.Factory):
    def __init__(self):
        self.users = {}

    def buildProtocol(self, addr):
        return TelnetConnection(users = self.users)

from __future__ import print_function

from twisted.internet import reactor, protocol, threads, defer
from twisted.protocols.basic import LineReceiver

from nethud.proto.client import NethackFactory


class TelnetConnection(LineReceiver):
    def __init__(self, users):
        self.users = users
        self.uname = ''

    def connectionLost(self, reason):
        if NethackFactory.client:
            NethackFactory.client.deassoc_client(self.uname)
        if self.uname in self.users:
            del self.users[self.uname]
        self.uname = ''
        print(reason)

    def lineReceived(self, line):
        msg_split = line.split()
        if msg_split[0] == 'AUTH':
            if len(msg_split) != 2:
                self.sendLine("ERR 406 Invalid Parameters.")
                return
            self.handle_auth(msg_split[1])
        elif msg_split[0] == 'QUIT':
            self.transport.loseConnection()
        else:
            self.sendLine("ERR 452 Invalid Command")

    def handle_auth(self, uname):
        self.users[uname] = self
        self.uname = uname
        if NethackFactory.client:
            NethackFactory.client.assoc_client(uname, self)



class TelnetFactory(protocol.Factory):
    def __init__(self):
        self.users = {}

    def buildProtocol(self, addr):
        return TelnetConnection(users = self.users)

Define class with `class`, not `def`
Define class with `class`, not `def`

I don't make calsses much, can you tell?
