View Single Post
Old 11-09-2009, 03:45 PM   #1
Graham
New Member
 
Join Date: Apr 2009
Posts: 9
Graham is on a distinguished road
Persistence in a MUD server

Hello everyone,

I've been programming for around a total of 9 years now, and programming Java for around 3 years. Recently I've wanted to develop a MUD server (in Java), mainly for experience and the fact that it'll be pretty cool, and perhaps there is a remote chance that I might actually run it.

I've had a look through several Java codebases, and found them to mostly seem incomplete or pretty old (and therefore not able to take advantage of some more recent additions to the Java API e.g. NIO). One that seems more complete is CoffeMud, however, that seems to be very large (and maybe over-complicated) and I'd rather not spend time stripping things out and understanding how the whole thing works.

So basically, I've decided to work on my own. I can handle the networking code (having done that in other projects) but one thing I am having problems over is the persistence code.

I've attempted a few attempts but none of them seem to work the way I would like, and am wondering if anyone here has any input on the methods I've been using or perhaps have some great idea that's better than the things I've tried :P.

The options I considered were:I didn't do anything with Java's inbuilt serialization, anybody who has used it will know that it isn't really going to be suited to this sort of thing - problems usually manifest if you add more fields to objects, take fields away from objects, etc.

The next thing I looked at was using something like Hibernate, which maps your objects into tables in a traditional RDBMS (more info about ORM can be found here: ).

I wrote a basic server which used the ORM approach but I found some problems: I ended up writing a lot of XML to tell Hibernate which objects and fields to map. This became cumbersone, so I switched to Hibernate Annotations which can automatically do this for you, but that didn't provide the correct level of configuration I wanted. I also had problems getting the keys set correctly without manually inserting SQL (and the whole point is to avoid it!), which would cause performance issues as my DB grew larger. Inserting the SQL cannot be done manually afaik, you had to write it into the config files, as Hibernate makes changes to the tables each time you start it in case you add new fields to your objects etc.

So I've gone back to choosing between a RDBMS and a flat-file based system. Most MUDs, especially the more traditional C or C++ ones, use flat-files but I'm wondering how good this is. Some of the file formats used for configuring areas seem less than ideal, probably as they were hacked together quickly, although I guess that they are edited by the server themselves with the online editing functionality.

The main problems I'm seeing with an RDBMS or flat-file system is that I'll have to write the persistence code for everything manually (if you can get an ORM tool like Hibernate to work correctly, adding a new class to be persisted it or changing it is supposed to be easy).

At the moment, I'm leaning towards a RDBMS because it'll allow much greater capabilities: data can be sorted/organized easily, and there could also be some form of web interface done easily. Also you don't have to worry about corruption, redudancy, etc. as a properly-configured db server can do that all for you.

This leads me into another point: how the persistence code actually works on the server. I haven't studied the code from existing MUDs in a lot of detail, but most seem to cache a lot of things such as areas into memory upon startup. I'm thinking this is the best approach, but just wondering about people's views on it.

So essentially, what I'm wondering about is people's opinions on how the persistence in the MUD should work. Which system do you feel is more appropriate? If you could scrap all the past versions of MUD servers which may be restricted to a particular technique for historical reasons, which one would you use in a brand new server?

Any tips/ideas/suggestions would be appreciated, however, I've tried the easy way out (ORM) and believe that I'm going to have to put some hard work into a relation database system :P.

Also a quick thing which is loosely related to what I am talking about, but I'd also be interested in, is an approach to how the objects would work in the actual server code. Most MUDs use an approach with classes for an Item, Area, Room, Player, Npc, etc. However, I've also seen a pretty cool use of a more monolithic system with a single MudObject class which was used for everything. (In the 16k MUD written in Java somewhere on this page ).

This post is pretty long (sorry about that!), and perhaps I seem like I'm moaning about how none of this persistence stuff is any good for getting something down quickly and simply, but I'd like to hear about other user's experiences on the subject (rather than looking at other MUD's code) and perhaps gain some more useful insight into the subject.

Thanks!
Graham is offline   Reply With Quote