[Reality] getting started?

Eric Wong reality@twistedmatrix.com
Thu, 28 Aug 2003 09:29:55 -0700


--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, Aug 28, 2003 at 05:26:39AM -0400, Christopher Armstrong wrote:
> On Wed, Aug 27, 2003 at 11:45:21PM -0700, Eric Wong wrote:
[cut]
> > Should I send in patches?  For example, I subclassed wiring.TextServer
> > to deal with multiple player logins (to the prosaically named
> > 'MultiPlayerTextServer').  Or is this the sort of system-specific change
> > that doesn't need to be distributed?
> 
> Well, for one, this is an extremely generic piece of functionality
> (for our target audience -- reality is all about being multiplayer :)
> which definitely should be included anyway. For two, Reality will
> probably have a good bit of system-specific stuff -- it *will* be just
> a "virtual world *engine*", but we learned from Python that a strong
> standard library is an *excellent* thing to have.
>
> Anyway, how does your MultiPlayerTextServer do its authentication? 
> Does it use the (new) APIs in twisted.cred?

Actually deals with the problem by ignoring it completely.
No authentication is done.  Anyone can log in with any name and more
than one user can have the same name at once (just like Life, eh?)
There's just a stub called loginUser() that anyone can override for
system-specific implementations.  It was mainly to let me log in with
multiple users so I could see how they interact with one another.

It's this way because I'm not sure what (if any) sort of object-
persistance architecture is envisioned for TR.  Some sort of file-based
database (like Cold or LPC, which I currently prefer) or a large
monolithic db (like the venerable LambdaMOO or maybe pickling the
entire world) or a relational-database-backed db (although I don't quite
understand why anyone would want to do this) or what-not-and-not.

Anyhow, my patch is attached.

Eric



--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="wiring.py.patch"

Index: wiring.py
===================================================================
RCS file: /cvs/NewReality/reality/wiring.py,v
retrieving revision 1.14
diff -u -r1.14 wiring.py
--- wiring.py	6 Jul 2003 02:01:46 -0000	1.14
+++ wiring.py	28 Aug 2003 16:26:19 -0000
@@ -6,6 +6,7 @@
 from reality.text.common import INoun, IThinker, express, IDescribeable
 from reality.things import EventReceiver, IEventReceiver, IMoveListener, Refusal
 from reality import errors
+from reality import things
 
 import traceback
 
@@ -98,4 +99,47 @@
     def buildProtocol(self, addr):
         p = ServerFactory.buildProtocol(self, addr)
         p.setAvatar(self.person)
+        return p
+
+
+##########################################################
+########################################################## for multi-player
+##########################################################
+
+class MultiPlayerTextServer(TextServer):
+
+    startRoom = None
+
+    def connectMessage(self):
+        return """
+Twisted Reality - MultiPlayerTextServer
+
+name: """
+
+    def telnet_Command(self, cmd):
+        if self.avatar:
+            TextServer.telnet_Command( self, cmd )
+        else:
+            self.loginUser( cmd )
+
+    def loginUser(self, cmd):
+        """This is where the authentication stuff would go.
+           Do the auth, make the user object, set the avatar
+           to that object and move it to the start room or
+           home."""
+        self.setAvatar( things.Actor( cmd ) )
+        self.avatar.moveTo( self.startRoom )
+        self.write(self.commandPrompt())
+
+class MultiPlayerTextFactory(ServerFactory):
+    protocol = MultiPlayerTextServer
+
+    startRoom = None
+
+    def __init__(self, startRoom):
+        self.startRoom = startRoom 
+
+    def buildProtocol(self, addr):
+        p = ServerFactory.buildProtocol(self, addr)
+        p.startRoom = self.startRoom
         return p

--pWyiEgJYm5f9v55/--