14 Replies - 1343 Views - Last Post: 06 May 2010 - 10:28 AM Rate Topic: -----

#1 Shadow5138  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 24-June 08

Question about casting system in MMO I'm writing

Posted 02 May 2010 - 09:57 PM

Hi! I'm currently working on an MMO, and have hit a road block on the server design.

The scenario:
In the game, let's say there's a move called "hit". Say this move takes 5 seconds
to cast, and requires you to stand in place while casting.

What's the best way to manage the time in between the player pressing the "hit" move,
and the actual move taking effect?

To elaborate, what's the best way to manage potentially thousands of cast timers at once, preferably all on one thread? (And have them cast correctly at the precise time)

My thought was to have an cast event queue and just have a separate thread run down the list and cast what needs to be cast.

TIA for your help!

Is This A Good Question/Topic? 0
  • +

Replies To: Question about casting system in MMO I'm writing

#2 Recoil  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 292
  • Joined: 28-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 05:03 AM

In my opinion, the "spell" being handled, if it requires creating a timer then just the amount of time needs to be saved with the spell itself, and passed off to the client. This still allows the server to control all the aspects of the spell, and the only information coming from the server would be the amount of time. This makes processing threads a lot simpler because you don't have to make a thousand threads for all the timers, just a thousand commands to be processed.

I might be wrong though, and if corrected need to re-work the way I am handling things on my game :D
Was This Post Helpful? 3
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 06:19 AM

I believe client should be responsible for handling the timer. Send a message to the server that the client is casting, the client enters casting mode. Once casting is done let the server know. If somebody attacks the client, through the server, interupt the casting. Just realized that is what the above poster was saying.
Was This Post Helpful? 2
  • +
  • -

#4 Recoil  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 292
  • Joined: 28-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 08:44 AM

umm, Yeah, what he said which I thought I was saying, but didn't come across as simply as I thought it might have should...

(Or something like that :D )

:genius:
Was This Post Helpful? 1
  • +
  • -

#5 Shadow5138  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 24-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 09:41 AM

Thanks for your help recoil and six, that's a really good idea!

So, just to confirm the theory, would this work?

Client tells server to cast spell "X".
Server tells client that the spell can be cast, and the timer is 5 seconds.
Client keeps timer, and after 5 seconds, tells the server to cast the spell.
Server double checks to see that the time is correct (in case the client tries to cast the spell too soon), then sends the spell.

That's actually a very good idea, because it puts the timer on the client, and saves the client a LOT of work.

Thanks again for your help!!

EDIT: Also, one problem I just thought of is: what happens when the client has a bad ping? I'd assume that would make his casting take longer? (The client could compensate by sending the cast command earlier, I suppose..)

This post has been edited by Shadow5138: 03 May 2010 - 09:43 AM

Was This Post Helpful? 0
  • +
  • -

#6 Recoil  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 292
  • Joined: 28-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 10:12 AM

Here's my logic behind what I was taking about.

The client already know that it has an instance of Spell(X), and knows the timers length for casting.

Client requests to use Spell(X).

Server checks to see if it is a valid action.

Server sends response to client.

Client gets response from server, then starts the timer.

After 5 seconds, the timer stops, Spell(X) is initiated.

Client sends action to the server.

The server determines damage/healing/whatever that spell did.

Server updates the information for all the clients.

A good combination for the ping issue is to use both TCP and UDP packets. The spell stuff like this would be sent as TCP to guarantee delivery...I think.
Was This Post Helpful? 1
  • +
  • -

#7 Shadow5138  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 24-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 10:19 AM

I agree. Thanks for your help, recoil!

Good luck with your game!
Was This Post Helpful? 0
  • +
  • -

#8 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 04:55 PM

View PostRecoil, on 03 May 2010 - 12:12 PM, said:

Client requests to use Spell(X).

Server checks to see if it is a valid action.

Server sends response to client.

Client gets response from server, then starts the timer.

After 5 seconds, the timer stops, Spell(X) is initiated.

Client sends action to the server.

The server determines damage/healing/whatever that spell did.

Server updates the information for all the clients.


That is too much traffic. You want to keep communication between client/server minimal as bandwidth is limited, there is also lag, lost packets, and packets coming in the wrong order as well. Try and have the client as responsible for as much as you can, especially in a game with a lot of players online. As the number of players increases bandwidth increases alomst exponentially. Remember that for data to travel between New York City and Los Angeles it takes about 20ms for data to travel one way. Every router between the two will add between 5ms and 50ms and every cable modem/DSL will add another 10ms. The roundtrip latency over the internet can easily reach 500ms. That is only two trips per second. If your game is updating at about 30fps it is only getting data 1/15th the time.

It is important for the server to know what the client is doing, position, direction, etc. but it doesn't need to know in real time. For example, if the player casts a spell it doesn't have to be managed on the central server. You should code the spell in such a way that the server can predict what will happen and where it will effect and pass that to the appropriate clients. It is up to the client to determine the effect. A shot from one player can appear to hit another player from the player who is firing the shot's perspective but on the other client it maybe off by a few degrees. The server should never determine if a kill happens. That should be handled by the clients. The server should let the clients know the outcome of events, not control them. You do have to worry about hacking and such, packets being changed by a client before being sent out, etc.
Was This Post Helpful? 2
  • +
  • -

#9 Recoil  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 292
  • Joined: 28-June 08

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 05:31 PM

Great post...very informative!

I do have one question to ask though, you say the server doesn't need to know what the client is doing in real time. Does this mean stuff like a character moving and checking the next tile should be handled on the client? The reason I am asking is my server checks for each move before it confirms and updates the clients.

So far this has caused no lag issues, but of course I am only using computers on my LAN to verify that this works, and not hindered by the thousands of milliseconds of packet lag, which I now know I will have to contend with after the detailed explanation you gave (if anyone ever plays my game :) )

I have several checks in place for my game to check the packets to help keep from packet hacking, but now that I think about it from your explanation, the only thing the server is going to handle will be the connections and the storage...everything else will be done by the clients?

Sorry for the questions, but it seems after 2 years of researching and building I still don't have the logic down right and I'm giving some bad advice :sad3:
Was This Post Helpful? 0
  • +
  • -

#10 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Question about casting system in MMO I'm writing

Posted 03 May 2010 - 09:49 PM

Quote

I do have one question to ask though, you say the server doesn't need to know what the client is doing in real time.
It's not a question of need. It's a question of feasibility. Real time verification is not possible. You must find another solution.

Quote

Does this mean stuff like a character moving and checking the next tile should be handled on the client?
In a sense. The client will be out of sync with the server between data updates. It shouldn't be idling during this time. You should allow the user to play normally between these updates.

Quote

So far this has caused no lag issues, but of course I am only using computers on my LAN to verify that this works, and not hindered by the thousands of milliseconds of packet lag


Quote

I have several checks in place for my game to check the packets to help keep from packet hacking,
It's not just packet hacking you have to defend yourself against by the way.

Here's the thing, you cannot trust the clients. But you can't rely on realtime verification. You need to reliably handle this disparity. Clients play normally, but update every so often. Server needs to verify and update appropriately. Doing this reliably, efficiently and seamlessly is a big question. You'll revisit verification issues over and over in building an MMO.
Was This Post Helpful? 1
  • +
  • -

#11 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Question about casting system in MMO I'm writing

Posted 04 May 2010 - 12:39 AM

View PostSixOfEleven, on 03 May 2010 - 05:19 AM, said:

I believe client should be responsible for handling the timer. Send a message to the server that the client is casting, the client enters casting mode. Once casting is done let the server know. If somebody attacks the client, through the server, interupt the casting. Just realized that is what the above poster was saying.


Bad idea, especially for an MMO. Usually trusting clients is more lenient for peer-to-peer games like fps games. For MMORPG's trust the client as little as possible.
Was This Post Helpful? 1
  • +
  • -

#12 Recoil  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 292
  • Joined: 28-June 08

Re: Question about casting system in MMO I'm writing

Posted 04 May 2010 - 05:05 AM

I am really not trying to hijack this thread here, but these responses have now left me quite confused about the client/server relationship for a multiplayer RPG. While they have been able to clarify points, there is still a huge gap that I believe I am missing. The only difference between the OP and my game is that I'm not building something to handle a massive amount of players.


I'm not going to go through my initial logic about how this works because it is apparently flawed, calling for a serious re-write of what I have been working on for over 2 years now. But does anyone have a diagram, logical explanation, link, or something about what the clients should handle and what the server should handle?

I do know that the clients should have absolutely no access to the DB, and everything needs to go through the server for verification before it gets updated. Clients verify their information through the server. And that is where I am now lost at from the above posts.
Was This Post Helpful? 0
  • +
  • -

#13 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Question about casting system in MMO I'm writing

Posted 04 May 2010 - 03:41 PM

View Postsparkart, on 04 May 2010 - 02:39 AM, said:

View PostSixOfEleven, on 03 May 2010 - 05:19 AM, said:

I believe client should be responsible for handling the timer. Send a message to the server that the client is casting, the client enters casting mode. Once casting is done let the server know. If somebody attacks the client, through the server, interupt the casting. Just realized that is what the above poster was saying.


Bad idea, especially for an MMO. Usually trusting clients is more lenient for peer-to-peer games like fps games. For MMORPG's trust the client as little as possible.


Yes, you can't always trust the client. The client does have to be created so that there is no cheating. Game security is paramount when dealing with client/server releationships. If you give the client too much freedom and you are asking for a world of trouble. I mentioned in a later post that the server and client both need prediction and smoothing algorithms in place to handle network latency, lost packets, and packets arriving out of order. I should have added the server needs security and validation algorithms as well. If the client replies in such a way that would break the rules of the game what it is sending should be rejected of course.

To be honest I've never tried to design an MMO server/client. There is far too much, in my opinion, for one person to accomplish realisticly. I believe you need strong security, validation, prediction, and smoothing algorithms. I believe there should also be a good compression algorithm to reduce the size of packets to get as much into it as possible. I believe it is impossible for the server to do real time validation for every move that a client makes, especially as the number of clients increases.

Again, I don't claim to be an expert here. I've never written an MMO and I don't see myself ever writing an MMO on my own. Just far too much to consider.

View PostRecoil, on 04 May 2010 - 07:05 AM, said:

I am really not trying to hijack this thread here, but these responses have now left me quite confused about the client/server relationship for a multiplayer RPG. While they have been able to clarify points, there is still a huge gap that I believe I am missing. The only difference between the OP and my game is that I'm not building something to handle a massive amount of players.


I'm not going to go through my initial logic about how this works because it is apparently flawed, calling for a serious re-write of what I have been working on for over 2 years now. But does anyone have a diagram, logical explanation, link, or something about what the clients should handle and what the server should handle?

I do know that the clients should have absolutely no access to the DB, and everything needs to go through the server for verification before it gets updated. Clients verify their information through the server. And that is where I am now lost at from the above posts.


There is a difference between a multiplayer game and a massively multiplayer game of course. At the moment I can't think of a good resource for what you are looking at. Having a game with 30 or so players max is much different than a game that has 1000s of players online at once. You have more lee way with fewer players and can rely on the server more.
Was This Post Helpful? 1
  • +
  • -

#14 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Question about casting system in MMO I'm writing

Posted 05 May 2010 - 02:59 AM

View PostRecoil, on 04 May 2010 - 12:05 PM, said:

I'm not going to go through my initial logic about how this works because it is apparently flawed, calling for a serious re-write of what I have been working on for over 2 years now. But does anyone have a diagram, logical explanation, link, or something about what the clients should handle and what the server should handle?


You might want to take a look at http://sites.google....ames.com/frost/ It's a blog one of my old college friends has been using to document the process of creating a small-scale MMORPG in DarkBASIC, although he may have stalled out (it's been about a month since the last post, where it had previously averaged 1-2/week). Still, though, he talks a lot about the logic behind (code) design decisions and has gotten as far as building the network transport layer, user login, and (in the latest post) movement prediction, so I expect there should be something there that's relevant to your concerns.
Was This Post Helpful? 1
  • +
  • -

#15 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: Question about casting system in MMO I'm writing

Posted 06 May 2010 - 10:28 AM

View PostRecoil, on 04 May 2010 - 04:05 AM, said:

I am really not trying to hijack this thread here, but these responses have now left me quite confused about the client/server relationship for a multiplayer RPG. While they have been able to clarify points, there is still a huge gap that I believe I am missing. The only difference between the OP and my game is that I'm not building something to handle a massive amount of players.


I'm not going to go through my initial logic about how this works because it is apparently flawed, calling for a serious re-write of what I have been working on for over 2 years now. But does anyone have a diagram, logical explanation, link, or something about what the clients should handle and what the server should handle?

I do know that the clients should have absolutely no access to the DB, and everything needs to go through the server for verification before it gets updated. Clients verify their information through the server. And that is where I am now lost at from the above posts.


That's for you to decide. As the developer, you need to make the compromise between security and efficiency. If it was a perfect world and bandwidth/cpu consumption was an infinite resource, then the server should be responsible for everything.

That is not the case, however. For a simple example, let's look at the issue regarding movement. Leaving the workload off of the server is pretty good. It could simply relay the information from one client to everyone else (within the vicinity), but obviously you compromise security. To fix this, perhaps you would do a sanity check like checking that the distance change isn't something absurd. This fixed most movement hack issues, however.... since it only checks the distance, it is possible for the client to pass something impassible but within the distance check, thus performing an illegal move that is passed as legal. Personally, I would keep the server responsible for any collisions (a necessary compromise).

Bandwidth and cpu/memory are very important resource, although the latter isn't as important as the former.

The best advice I could give you based on past experience is that you should trust as little information as possible from the client but at the same time, keep as little work off the server as possible.

Let's look at an example: timed spell-casting.

At first glance, we know that timing a spell cast on the server is a terrible idea. So as a first alternative we simply leave the responsibility of timing the cast to the caster and when it casts the spell, it simply tells the server and the server tells everyone else the spell was cast. This removes a lot of workload from the server. It has one severe problem: extremely unsecure. So our second alternative is that the client should contact the server when it starts a cast, then again when it completes a cast. When the server gets contacted the second time, it takes the time from the initial contact to now and determines whether this is even possible. Thus we achieve our goal: "not trusting the client and keeping workload off server".

EDIT:
SixOfEleven is right a very big task. It is great for the experience, however, remember the odds of you completing an MMORPG that many will be playing. That is why I discontinued. I was never discouraged by the many experienced programmers laughing at the idea of a person developing an MMO. I was discouraged by the idea that the odds of a lot of players playing is slim. Without a lot of players, what is the point of making the MMO in the first place? Comprendes?

If you don't believe me, try to find a bunch of open source MMO's online and do a consensus on the amount of people playing. There's quite a few successful open source MMO's, but the playerbase is very laughable.

This post has been edited by sparkart: 06 May 2010 - 10:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1