Author Topic: Multiplayer roguelike implentation through MySQL???  (Read 15417 times)

pangaea

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Multiplayer roguelike implentation through MySQL???
« on: March 31, 2014, 08:29:38 PM »
Sorry if this might be a long post. Okay I want to make a multiplayer game I have tried in the past but failed. I sort of wanted to make it for 7DRL, but that is a sort of biggish project.

So I should start with concentrate and hope for people help or advice.

What tools will I use?
1. Libtcod C++ for game client
2. MySQL to store everything
3. C++ for server client
4. Oryx tileset for graphics(Through I might change this to ascii since I might just put everyone in tanks)

The problem is that I'm not that good of a programmer, but I do put a lot of effort into learning. I plan to give client only read only access to the MySQL database and give the server read and write access. Through I have to be careful with this to stop hacking. But, this would solve some of my issues like race condition if the client can just read the database and I don't have to worry about that. Just have to worry about race condition when I send a message to the server. I think using TCP might solve this, but I don't really want to use TCP.

The other problem is getting bogged down in details like race condition if I'm doing it correct is such a nightmare. Through I don't have much spare time so I will try to not think to deeply and just do stuff quickly. http://vdzserver.org/mmorl/mmoRLserver/ I'm studying this to know how to implement a multiplayer game, but I think he does things sort of bad here.

But, anyway I'm now currently creating tables in MySQL one for mobs and one for environment. It would be simple to query a list of mobs in a table and create them. It would be simple to create a new mob on the server and then do a MySQL insert into the mobs list in the database. So I'm sure it would not be that hard to create a multiplayer game like this. Just have to make sure the client is reading the information correctly and then server is writing to the database correctly.

Sorry if this sounds like a dumb plan. This is the easiest solution I can come up with. Aren't all multiplayer games just a big database?
« Last Edit: March 31, 2014, 08:32:32 PM by pangaea »

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #1 on: March 31, 2014, 09:34:50 PM »
Uh, I think most online games have a game server acting as an intermediary between the client and game infrastructure like databases. I doubt that giving clients direct access to your database is a viable strategy.

I would also say that if you want to write a multiplayer roguelike, you should start by looking at existing examples like mangband and tomenet, if you haven't already. These are realtime games and they do not use databases for object persistence.

If you think you can create workable (as in playable by reasonable people), non-realtime mechanics in a persistent, non-cooperative multiplayer setting, I'd be interested to hear about it.

koiwai

  • Rogueliker
  • ***
  • Posts: 99
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #2 on: March 31, 2014, 11:11:20 PM »
You can start with a 2-player game. When one player starts a server, and another one connects to the server. TCP/IP probably makes more sense than UDP, becase it should not be a very time-sensitive real time game.

Some links on network programming:
http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html
http://gafferongames.com/networking-for-game-programmers/

I think, last year, there was a multiplayer 7DRL - you should try to run it. It should be a relatively small program, and hopefully understandable.

Why I think that a 2-player game is better that an MMO? Because once you have the networking code ready (= once you can send messages between two computers), you will be able to actually implement a simple game to work on a functional time system for n>1 players. Which should be quite non-trivial to design. (?)

Eventually, if your code is general enough, you will be able to extend the game to support more than two players, with login/logout, and other MMO functionality. But don't try to do this until you have basic mechanics implemented. Make the core mechanics first, make sure that you can handle a simple game for you and your friend to kill monsters together. Then, try to think big.

Update: And forget about the database for now. First, make a generic roguelike, where you kill goblins, for two (or maybe more) players. And make it so that at least one or both players can connect to the game from another computer via internet.
« Last Edit: March 31, 2014, 11:18:55 PM by koiwai »

sokol815

  • Rogueliker
  • ***
  • Posts: 85
  • Karma: +0/-0
  • Web Developer by Day, still Web Developer by night
    • View Profile
    • Email
Re: Multiplayer roguelike implentation through MySQL???
« Reply #3 on: April 01, 2014, 12:40:05 AM »
I completely agree. TCP/IP is going to be one of your best choices. MySQL could be good for storing high scores and game data (what monster killed the PC, how many turns it took to win... etc.)

If you aren't set on C++ (lots of memory management, low level class implementation) you could use C# express (or c# monogame if you are looking for cross-platform compatibility) which is free, easier to use, and works excellently.

If you do end up going the C# route, you could then utilize the TCP/IP & UDP library "lidgren" to handle all the dirty work of making a network enabled game.

I have worked on several network enabled c# games and found it to be very manageable.

I recommend taking the strategy of making it so any data (like characters, items, dungeons.. etc.) that you want to send across the networked game be their own separate class which has a constructor that can take a byte stream and read the stream to convert it into an instance of the class. Do the same to make it so you can pass an open byte stream to an instance of each class which will deconstruct the instance into bytes to be sent across the networked game and reassembled on the other side.

Say I have a dungeon map, that dungeon has items and characters in it. So, if I need to send the dungeon, I simply call the dungeon send function and pass it an open byte stream. It then goes through the data on the dungeon putting it into the open byte stream, then it gets to the items that need to be written and simply says I have 10 items, writes 10 to the stream, then loops through the items and the items write themselves to the stream. It then does the same thing with characters. On the receiving side of the stream, it basically just reconstructs the exact same things.

networking can be easy to use and work with if done properly. The above is just one of the things I have found that makes it not a pain to deal with.

Happy coding!

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #4 on: April 01, 2014, 01:00:29 AM »
Storing data in MySQL implies constant read/writes to the hard disk of your server, which will eventually become a performance bottleneck.  Better to store the game data in memory and only read/write to the database at server startup and shutdown.  Wish I knew more about how to program something like this!

Jaxian

  • Newcomer
  • Posts: 15
  • Karma: +0/-0
  • printf("%s", jax_title);
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #5 on: April 03, 2014, 08:41:49 PM »
First off, yes, it is possible to create a multiplayer roguelike using a MySQL database.  While the others here said that using this database as your server is a bad idea, I will only say that it is PROBABLY a bad idea.  It depends on what you're trying to accomplish, exactly.

I wouldn't use a MySQL database as a server for a game that I am planning on distributing for public consumption.  As the others said, the performance of the database will not be good.  If many people began playing the game at the same time, it is unlikely that your database would be able to perform.  Think about this: when one player makes a move, the other players need to be notified somehow.  The only way they can be notified is by reading from the database.  So they will each have to continually run select statements on the database, looking to see if any other player has inserted his move.  Lots of players all running select continuous selects will bog down the database.

If you want to use the database as your server, your game should meet the following criteria.  First, you should be trying to create a sample game to play between you and your friends, where you expect a handful of people to be playing at one time.  Second, the game should not require anything near real-time updates between players.  For example, if players can only act on their own turn, then it may not matter if players have to wait a few seconds in order to detect that a player has finished his turn.

If your game meets these criteria, then you may want to give it a shot.  Using a MySQL database as your server is the flat-out wrong tool for the job.  However, it is a tool that you know.  In programming, it is common to run into technology barriers: you want to create something, but you have tons of learning to do in order to do it the right way.  This can be discouraging.  In my opinion, while using the wrong tool is less than ideal, it is better than not programming anything at all.

If you want to try a server, then you'll need to understand where and how your server will exist.  Does it run on a computer you own?  Do you have some webspace you can run it on?  What technologies are supported there?  Perhaps your server can run in the same place as your MySQL database.

I also think that creating a server is not as hard as it sounds.  If you provide details about where you might be able to run the server and how your game will work (does everyone connect to the same server and play in the same world, like an MMO, or are there multiple game worlds running at a time?  Do players all take turns, or is the world moving in real-time?), then maybe I can help you walk through the process of picking technologies and getting a basic server setup.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #6 on: April 05, 2014, 01:32:40 AM »
Don't use SQL or TCP. These are simply the wrong technologies for an actively running game state on a server-- regardless of the genre.

You want to roll your own UDP protocol so that you can buffer/manage data in a domain-specific way. You also want to manage data in a matter that is active and efficient- a generalized database is just not good for this- latency from cache misses and DB look-up will be so obnoxiously awful that it'll provide a worse bottleneck than waiting for input actions via ping/user decision-making/faux TCP determinism. Even in an RTS, where something like TCP would make sense, the overhead isn't really worth the reduced responsiveness.


You may use SQL and TCP for saving game states, but it is not appropriate for an actively running process/state.

Just use normal data structures in your application. Why would you want SQL anyway? You have to have an authoritative server to ensure AI behaves consistently and to prevent cheating, so... it's not like your clients are communicating directly with the DB (unless you can somehow ensure fidelity across seeds/RNGs, but even then- no cheat prevention)-- there's really no reason to use it apart from persistence... but even that's not a good enough excuse.

That said- SQLite is probably fast /enough/, but I still wouldn't misuse it.

EDIT:
Why don't you just have the clients and server communicate directly?
« Last Edit: April 05, 2014, 01:53:07 AM by requerent »

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #7 on: April 07, 2014, 05:00:02 PM »
I attended a presentation at Desert Code Camp on Saturday where the speaker used a great turn of phrase about databases, that the database is "your data at rest".  In the application program, your data is "at work".  The database should be where it's stored when the application has downtime.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #8 on: April 07, 2014, 11:28:09 PM »
I attended a presentation at Desert Code Camp on Saturday where the speaker used a great turn of phrase about databases, that the database is "your data at rest".  In the application program, your data is "at work".  The database should be where it's stored when the application has downtime.

A good precursor of that, "A game is just a database with a UI." Not to be thought of literally as database software.

joeclark77

  • Rogueliker
  • ***
  • Posts: 90
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #9 on: April 09, 2014, 06:26:58 PM »
A good precursor of that, "A game is just a database with a UI." Not to be thought of literally as database software.
I don't know if I buy that quote.  The database implies a model of the "nouns" of the game world, and some of the logical relationships, but doesn't tell the "story" so to speak.  Your game should be more than just a UI.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Multiplayer roguelike implentation through MySQL???
« Reply #10 on: April 09, 2014, 08:57:32 PM »
A good precursor of that, "A game is just a database with a UI." Not to be thought of literally as database software.
I don't know if I buy that quote.  The database implies a model of the "nouns" of the game world, and some of the logical relationships, but doesn't tell the "story" so to speak.  Your game should be more than just a UI.

The UI is the manner in which a player interacts with that database. The story is a part of the UI.

Slash

  • Creator of Roguetemple
  • Administrator
  • Rogueliker
  • *****
  • Posts: 1203
  • Karma: +4/-1
    • View Profile
    • Slashie.net
    • Email
Re: Multiplayer roguelike implentation through MySQL???
« Reply #11 on: April 29, 2014, 11:31:24 AM »
what.


You need to create a simpler game first before even trying to delve into this.