Hello!

I am developing a game server for an existing game. It's a project that I started for fun and also for learning how to work with servers in Qt.

It's a game server for an RPG game. I'm not really sure on how to implement some things like:
  • A player gains hitpoints (and other stuff) each X seconds,
  • A player can click on the map and then the server should generate a path,
  • A player attacks someone and hits him each X seconds,
  • ...


I have never made a server with Qt so that's why I am asking for help. These are the designs I could think of.

Design 1
There is one instance of a game class (handles player movement, keeps track of items, ...). There is a QTcpServer that listens for connections. When someone connects, a QTcpSocket is made. That socket checks for incoming data and checks what to do with it (move player, say something, ...). These actions get executed by QtConcurrent (for example QtConcurrent::run(&Game::instance(), &Game::playerSpeak, player, message)).

Design 2
Again, there is a game class and a QTcpServer. When someone connects, a new SThread is made containing the QTcpSocket. The socket checks for incoming data (asynchronously) and checks what to do with it. The action gets executed (for example Game::instance().playerSpeak(player, message)). The game then contains mutexes in functions that change global or class variables.
But will this work? The game is created in the main thread and the function call is made in the socket thread. Will the function be executed asynchronously? And what about signals and slots?

Also, I need to check the player each X seconds (for example when attacking). Should I need to make a thread for each player, or should I just run a QTimer in the main thread that executes Game::playerAttack each X seconds?

I hope my explanation is clear and that someone can give me some advice :).
Thanks in advance!

Gillis