1
\$\begingroup\$

How to set up an architecture and a strategy allowing the persistence of the data of a MUD in a relational database?

Type of game:

My question relates to the design of a Multi User Dungeon (MUD).

A MUD is a textual online game, considered today as the ancestor of the MMORPG. Players create characters and then control them in a completely text-based world using commands. For example, they can move from room to room, kill monsters, collect items, equip themselves with armour and weapons, solve quests, etc.

From a technical point of view, it is simply a server written in C++. Players connect using MUD clients or directly via the telnet protocol.

My objective:

I would like to ensure the persistence of the game using a relational database.

For performance purposes, I do not intend to load and save my data from the database in real time.

I plan to:

  • load all my data in memory at the launch of the MUD
  • save only objects that will be modified during runtime at regular intervals of time (every minute for example)

If possible, I would obviously like the code that ensures the persistence of the data to be completely independent of the game data.

My problem:

I have a hard time knowing which architecture to set up.

For instance, I do not know how to manage the dependencies of the objects between them. For example:

  • an object of type Character has a pointer to an object of type Room
  • this object of type Room itself has a list of pointers of Objects placed on the ground
  • these Objects themselves have a pointer to their Prototype (a prototype corresponds to the model of the object)
  • etc.

How do I do to load all these dependencies properly? I could obviously hack a code that does it. However, I do not see how to do it cleanly. Is there a relatively simple way to do it, without coding an entire ORM for that?

All the examples that I find on the internet mention the different Design Patterns put in place by the ORMs. It looks complex. It must be a lot of code to write!

Or they give answers that do not seem satisfactory. For example:

“You may have objects that point to too many other objects for them to be loaded immediately. Sometimes linked objects will link to other objects further increasing the amount of data to be loaded if you want to load all dependencies at once. It may even happen that you encounter endless reference loops leading to stack overflows or script timeouts. This means that most of the time we need to make a judgment where to cut off the dependency chains.”

Source: https://pkp.sfu.ca/wiki/index.php/Data_Access_Objects_(DAO)#One-to-many_or_many-to-many_relations_of_independent_objects

I don’t want to cut the dependency chains. I just want my entire object graph. Not less. Not more!

The problem I encounter, however, seems relatively basic. It had to be solved millions of times. However, I can not find examples or solutions that are clear and relatively simple.

My first approach:

I could maybe:

  • load all my objects without any dependency
  • once all my objects are loaded and accessible in memory, some methods might have the task of solving all these dependencies and recreating all the links between the objects

In this case, does that mean that I will have to store the Primary Keys of the different objects directly in the objects? It would break the total independence of my game objects and the way I persist my data.

My question would be:

In the case of an online game and since my different game objects will be strongly linked to each other, what would be a possible strategy and architecture allowing the saving and the loading of these data in a relational database, while managing the dependencies of the objects between them?

How do people usually solve this problem?

\$\endgroup\$
4
  • \$\begingroup\$ What you are looking for is an ORM wrapper library. There are lots and lots of options available. Unfortunately we can not recommend you a specific one, because we generally don't give technology recommendations. \$\endgroup\$
    – Philipp
    Jul 2, 2019 at 14:57
  • \$\begingroup\$ I am not looking for an ORM. I would prefer to solve this problem by myself. I also read that in the C++ community, the use of ORMs was not very popular. It means that they are moving towards other solutions. And I would like to understand which ones. I am certainly not the only C++ user who wants to save his data in a relational database without using an ORM. \$\endgroup\$
    – Daily45
    Jul 2, 2019 at 17:25
  • \$\begingroup\$ Hey I'm just thinking out loud... Did you consider not using Classes/instances that use references to other objects, but using instead structs of data, handles to instances, and "systems" to act on this data? This would reflect the state of your database, allowing you to interface with it more easily. \$\endgroup\$
    – Vaillancourt
    Jul 2, 2019 at 20:12
  • \$\begingroup\$ You might check out CoffeeMud's documentation at coffeemud.net/guides/Programming.html. Though it is Java based, you might be able to glean some approaches to persistence. Specifically take a look at the Database Tables section (coffeemud.net/guides/Programming.html#DIG6) where the author discusses persistence and how his approach evolved. \$\endgroup\$
    – Tim Holt
    Jul 3, 2019 at 18:05

1 Answer 1

1
\$\begingroup\$

I know this question was asked a few months ago but I figured i'd go ahead and answer.

The way I do it in my mud, is every player / mob have a home area/home room, and a current area/room field in their code, and each of those is associated with an integer which corresponds with the area id_number / room id_number so when they go through exits, the numbers get updated. So when i save/load from the database, the system knows which area/room they are in (just make sure you load the areas/rooms first!).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .