Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

REBOL MUD server -- a few easy questions

 [1/3] from: seth::chromick::earthlink::net at: 9-Nov-2003 2:38


I've never been content with the documentation I've found relating to the usage of tcp based ports. The official REBOL documentation lightly touches on them but it's never been detailed enough, at least in my opinion. So here I am, with a few questions for the list :] The ultimate end goal for this project is a simple MUD (if you don't know what a MUD is, you can generally think of it as a game like EverQuest without the graphics) or chat server, that clients connect to via. telnet. The finer details I can work out myself (I've been playing with Rebol for a long time now) but it seems to be the fundamentals I'm having problems with, those being: Accepting new incoming connections Keeping track of who is already connected Sending text from one client to all connected clients I have some clunky code I've patched together by looking at several other people's scripts and reading the docs. Here it is: --- REBOL [] print ["The MUD server has started on" now/date ", at" now/time] server-port: open/lines tcp://:23 ; listen for connections on port 23 (standard telnet port) connections: copy [] ; connections[] holds the list of port! objects forever [ connection-port: first server-port ; connection-port is the currently active connection -- should this be connection-port: WAIT first server-port? until [ wait connection-port ; wait until there is activity on the port append connections connection-port ; add the newest port into the connections[] block foreach connection connections [ ; in this loop i was going to have it check to see if any of the clients listed in 'connections[] are still active -- what is an easy way to do this? x: reform ["There are now " length? connections " clients connected."] insert connection x ] ] ] --- I am 200% open to suggestions on how to improve this code (and also -why- method X would be better/faster/etc. than method Y)... :] I want to make this code as good as possible because I have a lot of other things to focus on and they all depend on a reliable method for connecting and managing the connections! 1) How can I send text from one client to all the clients? Will I have to do anything special because I'm telneting to the server? (Using PuTTy) 2) What would be the best way to keep track of what clients are still connected and which ones have timed out or totally disconnected? 3) I have looked at Rugby and the examples on RebolForces for a 'server engine'. My project (as of right now) is basically sending text to and from telneted clients. Nothing very demanding, per say. When I start adding features to the MUD (i.e. actually making it into a game), it might get more resource hungry. Any suggestions of my current 'engine' versus a more complex one?

 [2/3] from: maarten:vrijheid at: 9-Nov-2003 10:27


Here is a (non-tested) sample: Portz: copy [] Server-port: open/no-wait tcp://:9090 Insert portz server-port Forever [ ;Use wait/all as all our ports are in one block current: wait/all portz ;If it's the server accept and add to the list either server-port = current [ append portz current ] ;it's data from a client [ ;get the data data: copy current ;if the data is none then the connection has closed either none? Data [ ;port closed, remove it from our block remove find portz current ] [ ;broadcast data, skip the server port foreach port at portz 2 [ insert port data ] ] ] ] Note that the port is opend in no-wait, meaning something like "This is a message" will be broadcasted as it is received, like "This i" "s a me" ssage for example. You can add buffering and line termination to this if you want to. Left as an exercise for the reader ;-) --Maarten

 [3/3] from: nitsch-lists:netcologne at: 9-Nov-2003 10:32


A telnet-chat-server is here: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=telnetchat.r could be extensible as a mud. -Volker Am Sonntag, 9. November 2003 08:38 schrieb Seth: