Hello all, I couldn't find any answers online so I created an account and decided to post it here.
So basically, I'm developing an mmorpg and after I created the server and server thread to handle new connections, I couldn't think of a way to share the game world with multiple people. So basically, the world is in its own class/thread and will always be running,(well, as long as the server's running), and when you connect to the server, you get your own personal copy/instance of the game, and your character is "dropped" into the world. I'm not sure how to get the code for the world to the client, since they're on seperate machines, so that you can enter the world, however. Here's my server class:
My server thread class:
My client class:
My world class:
And finally my world thread class:
I placed all my server and world classes in a separate package, just so I could export the classes as separate runnable jar files. Again, I need the client to be able to get their own instance of the world and put their character into it.
I don't know how MMOs usually work, but I imagine that clients will already have their own copy of the world data, and they perform all the events and animations by themselves. What the server does is synchronize those happenings between different clients. The server sends information around about player/creature positions, actions, statuses and actions. The clients interpret that data by themselves.
So clients should download the "world" ahead of time, and should only be allowe to play with other clients if they have the same version of the world. I guess most MMOs do this by forcing clients to have the latest available version.
i'm no expert either but just to mention a couple of points. in some games(UO) players can build house and all players can see them. that is why some servers(shards) restrict the number of houses allowed(in this case some world data is on the server). also some servers(shards) allow older clients and some don't. if you have older client your play is limited however. some servers(shards) also require downloading patches to add to the client world view.
if you google around a bit you can probably find several sites devoted to this subject.
UO is the only one i played a lot. i once(2005) downloaded the server(two free servers to choose from). it presented me with a "blank" world. all the buildings and trees and mountains etc but no creatures. i only played with it for a little while, but it let me "spawn" creatures(sheep, orcs, whatever) wherever i wanted. so it seems to me, in that game, the client and the server both have a copy of the "world".
after thinking about it for a while, i see a MVC pattern here.
the World is the Model, the Player is the View, the server-side code does all the Controller stuff and has a reference to the model and probably the view as well
Stephan van Hulst
Joined: Sep 20, 2010
A player isn't a view. A player is just an object in the world. The client has a view based on the position of its respective player in that world. I doubt the server has any such view.
Yes, the world is the model, and each client and server has a separate copy of it. However, the server is probably not the only controller. It's more of a mediator. If the server decided everything that should happen in a world, that would be way too much overhead, and the application would not scale at all.
Each client completely determines everything that happens in its own private copy of the world. It communicates its actions with the server, who then determines if those actions are valid and communicates them back to all clients.
For instance, let's think of battling a creature, together with other players. The world, the enemy and everything is already available to the client. You decide to attack the creature. While your player's animation starts hacking away, the server is being informed of this action. It then tells other clients you've started attacking. These clients too will then make their copy of your player attack the creature. The server then determines in its private copy when and how damage is dealt, and tells the clients about this. They update the situation accordingly.
I've very briefly tried a bit of World of Warcraft, to see what it was about. Occasionally, connection with the server would be bad, but I could still walk around and do stuff. However, after a few seconds, the client would try to sync with the server, and since there was no confirmation coming of the actions, they would be "rolled back", and my character would be repositioned to where it was when the connection problems started.