Guest User

Untitled

a guest
Nov 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. '''
  2. Name: JoshMUD
  3. Description: Multi User Dungeon
  4. Developer: Josh Lee from Josh Lee Software
  5. '''
  6.  
  7. from TextHandling import *
  8. from time import *
  9. import random
  10. import datetime
  11.  
  12. from twisted.internet import protocol, reactor
  13. from twisted.protocols import basic
  14.  
  15.  
  16. class MUDProtocol(basic.LineReceiver):
  17. def __init__(self):
  18. self.sessionStat = "login"
  19. self.name = ""
  20. print "[" + self.factory.getTime() + "] " + "A new session has been created."
  21.  
  22. def connectionMade(self):
  23. self.factory.connectedUsers += 1
  24. self.transport.write("Welcome to JoshMUD. Please enter your name for a temporary character: \r\n\r\n")
  25. print "[" + self.factory.getTime() + "] " + "Connection established from: " + str(self.transport.getPeer().host)
  26. print "[" + self.factory.getTime() + "] " + "Current users connected: " + str(self.factory.connectedUsers)
  27.  
  28. def lineReceived(self,line):
  29. if self.sessionStat == "login":
  30. if line != "":
  31. self.name = line
  32. self.transport.write("Thank you, "+ line +". You have had a temporary character created. Enjoy the game!\r\n")
  33. self.sessionStat = "playing"
  34. self.factory.createChar(line)
  35. print "[" + self.factory.getTime() + "] " + str("\r\n" + self.transport.getPeer().host) + " identified itself as \"" + self.name + "\". \r\n"
  36. else:
  37. self.transport.write("Please enter a name, not a blank space.")
  38. elif self.sessionStat == "playing":
  39. if line != "":
  40. self.factory.parseCommand(line)
  41. print "[" + self.factory.getTime() + "] " + "User " + self.name + " (" + str(self.transport.getPeer().host) + ") entered commmand to be parsed: \"" + line + "\""
  42.  
  43. def connectionLost(self,reason):
  44. self.factory.connectedUsers -= 1
  45. self.factory.removeChar(self.name)
  46. self.sessionStat = "login"
  47. print "[" + self.factory.getTime() + "] " + "Connection has been terminated from user " + self.name + " - Reason: "+ str(reason)
  48.  
  49.  
  50.  
  51.  
  52. class MUDFactory(protocol.ServerFactory):
  53. protocol = MUDProtocol
  54.  
  55. def __init__(self):
  56. self.connectedUsers = 0
  57. print "JoshMUD initiliazed - now accepting connections"
  58.  
  59. def parseCommand(self,text):
  60. pass
  61.  
  62. def createChar(self,name):
  63. pass
  64.  
  65. def removeChar(self,name):
  66. pass
  67.  
  68. def getTime(self):
  69. return datetime.datetime.now().time().hour + ":" + datetime.datetime.now().time().minute + "." + datetime.datetime.now().time().second
  70.  
  71.  
  72. reactor.listenTCP(23,MUDFactory())
  73. reactor.run()
  74.  
  75.  
  76. ===================================================================================== #TRACEBACK
  77. JoshMUD initiliazed - now accepting connections
  78. # THEN AFTER CONNECTING
  79. Unhandled Error
  80. Traceback (most recent call last):
  81. File "C:\Python27\lib\site-packages\twisted\python\log.py", line 69, in callWithContext
  82. return context.call({ILogContext: newCtx}, func, *args, **kw)
  83. File "C:\Python27\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
  84. return self.currentContext().callWithContext(ctx, func, *args, **kw)
  85. File "C:\Python27\lib\site-packages\twisted\python\context.py", line 81, in callWithContext
  86. return func(*args,**kw)
  87. File "C:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 146, in _doReadOrWrite
  88. why = getattr(selectable, method)()
  89. --- <exception caught here> ---
  90. File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 942, in doRead
  91. protocol = self.factory.buildProtocol(self._buildAddr(addr))
  92. File "C:\Python27\lib\site-packages\twisted\internet\protocol.py", line 96, in buildProtocol
  93. p = self.protocol()
  94. File "C:\Documents and Settings\Josh\My Documents\Projects\Python\JoshMUD\MainModule.py", line 20, in __init__
  95. print "[" + self.factory.getTime() + "] " + "A new session has been created."
  96. exceptions.AttributeError: MUDProtocol instance has no attribute &#039;factory&#039;
Add Comment
Please, Sign In to add comment