A
A
Alexander2016-08-19 23:58:15
C++ / C#
Alexander, 2016-08-19 23:58:15

C#. How to implement the execution of actions on the server in real-time?

Let's describe the essence of the issue using the example of a multiplayer online game. Let's say we have some game where there is a "build unit" functionality. This unit is not built immediately, but the n-th amount of time (5 minutes, let's say). The user-player initiates the construction of the unit. How on the server side can (or better, how should it be?) implement this "deferred event" so that after five minutes the number of units the player has increased by one?
What is best to use for this and which way to look: quartz, timer, etc?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
MrDywar Pichugin, 2016-08-20
@Dywar

real time does not happen in practice, windows is not a real time system.
Since the question is about the game, watch the video:
1) Writing a game server and creating a client on U...
2) Creating Counter Strike. Network FPS shooter on Un...

E
epeshk, 2016-08-20
@epeshk

You don't need any timers on the server.
The time when the unit is built is recorded. And the whole process of building a unit is just rendering on the client.

M
MADm, 2016-08-22
@MADm

On a real example of a browser:
1 at the beginning of crafting, we write to the database what the player is crafting (to lock it), and write datetime when the end of crafting
2 on the client, we start a reverse timer that once every n sec polls the server what crafting is there, the server returns the difference between the current server time and end time of crafting, the client watches the difference between the client countdown and the server one, adjusts if necessary.
3 on the server there is a timer that once every n seconds gets all the players whose crafting end time has already passed compared to the current time, starts crafting end processing for each. I have a timer hung in static at the start of the application and locked so that it does not slip. but it seems to me that such a solution is bad and it is better to use owin of the quartz type or the windows service in general

O
Ogoun Er, 2016-08-24
@Ogoun

I already posted the code here for a similar question , I like this solution with low resource consumption, for everything about everything there is one timer. Works stably. The state can be easily swapped to disk and restored when the server is restarted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question