Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Name: JoshMUD
- Description: Multi User Dungeon
- Developer: Josh Lee from Josh Lee Software
- '''
- from TextHandling import *
- from time import *
- import random
- import datetime
- from twisted.internet import protocol, reactor
- from twisted.protocols import basic
- class MUDProtocol(basic.LineReceiver):
- def __init__(self):
- self.sessionStat = "login"
- self.name = ""
- print "[" + self.factory.getTime() + "] " + "A new session has been created."
- def connectionMade(self):
- self.factory.connectedUsers += 1
- self.transport.write("Welcome to JoshMUD. Please enter your name for a temporary character: \r\n\r\n")
- print "[" + self.factory.getTime() + "] " + "Connection established from: " + str(self.transport.getPeer().host)
- print "[" + self.factory.getTime() + "] " + "Current users connected: " + str(self.factory.connectedUsers)
- def lineReceived(self,line):
- if self.sessionStat == "login":
- if line != "":
- self.name = line
- self.transport.write("Thank you, "+ line +". You have had a temporary character created. Enjoy the game!\r\n")
- self.sessionStat = "playing"
- self.factory.createChar(line)
- print "[" + self.factory.getTime() + "] " + str("\r\n" + self.transport.getPeer().host) + " identified itself as \"" + self.name + "\". \r\n"
- else:
- self.transport.write("Please enter a name, not a blank space.")
- elif self.sessionStat == "playing":
- if line != "":
- self.factory.parseCommand(line)
- print "[" + self.factory.getTime() + "] " + "User " + self.name + " (" + str(self.transport.getPeer().host) + ") entered commmand to be parsed: \"" + line + "\""
- def connectionLost(self,reason):
- self.factory.connectedUsers -= 1
- self.factory.removeChar(self.name)
- self.sessionStat = "login"
- print "[" + self.factory.getTime() + "] " + "Connection has been terminated from user " + self.name + " - Reason: "+ str(reason)
- class MUDFactory(protocol.ServerFactory):
- protocol = MUDProtocol
- def __init__(self):
- self.connectedUsers = 0
- print "JoshMUD initiliazed - now accepting connections"
- def parseCommand(self,text):
- pass
- def createChar(self,name):
- pass
- def removeChar(self,name):
- pass
- def getTime(self):
- return datetime.datetime.now().time().hour + ":" + datetime.datetime.now().time().minute + "." + datetime.datetime.now().time().second
- reactor.listenTCP(23,MUDFactory())
- reactor.run()
- ===================================================================================== #TRACEBACK
- JoshMUD initiliazed - now accepting connections
- # THEN AFTER CONNECTING
- Unhandled Error
- Traceback (most recent call last):
- File "C:\Python27\lib\site-packages\twisted\python\log.py", line 69, in callWithContext
- return context.call({ILogContext: newCtx}, func, *args, **kw)
- File "C:\Python27\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
- return self.currentContext().callWithContext(ctx, func, *args, **kw)
- File "C:\Python27\lib\site-packages\twisted\python\context.py", line 81, in callWithContext
- return func(*args,**kw)
- File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 146, in _doReadOrWrite
- why = getattr(selectable, method)()
- --- <exception caught here> ---
- File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 942, in doRead
- protocol = self.factory.buildProtocol(self._buildAddr(addr))
- File "C:\Python27\lib\site-packages\twisted\internet\protocol.py", line 96, in buildProtocol
- p = self.protocol()
- File "C:\Documents and Settings\Josh\My Documents\Projects\Python\JoshMUD\MainModule.py", line 20, in __init__
- print "[" + self.factory.getTime() + "] " + "A new session has been created."
- exceptions.AttributeError: MUDProtocol instance has no attribute 'factory'
Add Comment
Please, Sign In to add comment