Endless terrain in multiplayer

hi all,



im working on a multiplayer game with a seperated server and client. i want to use the endless terrain for my game and have a few questions about it. i hope someone can help me.



im trying to create some kind of dedicated server which stores and transfers level and object data in seperated folders for each terrainquad.

the quads themselves should be generated by the client application when a player reaches the “end” of a quad and a new one is loaded like

in TerrainFractalGridTest.java. when a new one is created the client sends a request message to the server whether or not the quad already exists and gets a reply on it how to go on. and there is my problem.



when a client is traveling over the map and generates a quad and the other client generates the quad beside it, is it said that the quads will fit to each other cause the noise generator always generates “the same map” on each client or will there be a gap? and if so, can i fill the generator with already existing quads to force him to fit to the neighbours?



thx for replies.



ah, and also, is it clever to solve it that way or is it better to let the server create the map ?

@wizz07 said:
when a client is traveling over the map and generates a quad and the other client generates the quad beside it, is it said that the quads will fit to each other cause the noise generator always generates "the same map" on each client or will there be a gap? and if so, can i fill the generator with already existing quads to force him to fit to the neighbours?



If you are using the same seed for the noise on each client, the noise will always be exactly the same on all clients and therefore it will be seamless.

thx for the fast reply. and by seed u mean this part ? cause i havent found a seed function yet



[java]

FractalSum terraingenerator = new FractalSum();



terraingenerator.setRoughness(0.7f);

terraingenerator.setFrequency(1.5f);

terraingenerator.setAmplitude(0.8f);

terraingenerator.setLacunarity(2.12f);

terraingenerator.setOctaves(8);

terraingenerator.setScale(0.02125f);

terraingenerator.addModulator(new NoiseModulator() {



@Override

public float value(float… in) {

return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1);

}

});

[/java]

I have to recommend against allowing the client to generate the terrain (unless its from a straight seeded value, no randoms involved) on the strongest possible terms.



Allowing the client to generate anything like that immediately opens up everything from basic map hacks to more serious problems such as players actually customizing what spawns in front of them. Absolutely everything the client does has to be at least validated, and ideally controlled, by the server. It’s the only thing you have control over and it won’t take you much searching to find that game cheats and hacks are big business.

i was also thinking about that, but i only want the client to generate the heightmap. items, objects etc. will be created by the server to prevent that (in the case that he is not playing in singleplayer). after at least getting the game to run properly i will try to check the transfered map from the client against the one from the server for the first 2 times to see if theres a difference in the heightmap. im not sure about managing that yet.



im trying to solve it this way because i want a join or singleplayer option in the client. so the noise is anyway implemented in the client. on the other hand i dont want to and dont know how to load and unload quads on the by myself without dealing with multiple cameras ? on the server to generate quads. dunno how the performance will be on the server then.



also im just reading into jmonkey as good as i can before spamming questions around, but its sometimes hard to understand how all works together and its my first project…so critic is always welcome :slight_smile:

Does the server or the client does collision? If the server does, the client can hack other terrain, it will simply not help at all if they cannot walk on it.

How much programming experience do you have?



Just remember that multi player is a LOT more complex than single player. I strongly recommend unless you have a lot of programming experience (and maybe even then) that you make your first game single player then take what you have learnt from that into your next project.

Yeah. A multiplayer game is probably 10 times harder (at least) than a single player game. And if you didn’t already know that then I’m wrong and it’s 100 times harder. :wink:

@EmpirePhoenix: the client will deal with the collision. i was planning to let the client also deal with collision in type of shoot that target and when it hits, it gives a damage update to the server.



@zarch: i think i have a decent understanding of java. i have also made a few games like a clone of crime fighter or 4 keys(if anyone remembers the games :/) with multiplayer chat and so on. but these were not in 3d and round based. the thing is that i have a prototype running in singleplayer mode where i can interact with objects like farming on trees and combining items in inventory. now i want to modify the game for multiplayer. im a fan of the game stranded 2 and it sucks(sry) that there is no multiplayer and since i always wanted to realize a project in jme, i gave it a try to create my own.

@wizz07 said:
@EmpirePhoenix: the client will deal with the collision. i was planning to let the client also deal with collision in type of shoot that target and when it hits, it gives a damage update to the server.


This will be the easiest game to cheat, ever. But maybe that isn't a concern. If cheating is easy then nearly everyone can do it and it becomes sort of a meta-game.

@wizz07 said:
@zarch: i think i have a decent understanding of java. i have also made a few games like a clone of crime fighter or 4 keys(if anyone remembers the games :/) with multiplayer chat and so on. but these were not in 3d and round based. the thing is that i have a prototype running in singleplayer mode where i can interact with objects like farming on trees and combining items in inventory. now i want to modify the game for multiplayer. im a fan of the game stranded 2 and it sucks(sry) that there is no multiplayer and since i always wanted to realize a project in jme, i gave it a try to create my own.


The network architecture should come much earlier in the process. You will likely have to rewrite most of the stuff at this point and so might as well reconsider the design in the process.

Yeah, sorry to seem negative. We’re just trying to give you the benefit of our experience. Multi player is easy to do terribly but hard to do well. Even quite a few commercial games have notoriously shoddy multi player.



You really need to think about how everything in your game ties together. What the server will run, what the client will run. Where the potential and risks for cheats and hacks are and which of those are acceptable and which need to be mitigated.



Just remember that absolutely any code that you run client side can and will be compromised by players at some point.

P.S.

Of course if the game is only run between friends on a lan or on a private server (think minecraft) then it’s not so bad as it’s down to the friends to handle cheating internally. If you have any sort of service where people play over the internet though (particularly competitively although not even always then) - even if it is just a vague idea that you might do that at some point - then you have a problem.

uhm, i didnt get it negative. like i said, first try and critic welcome. yeah the multiplayer aspect had to come early like i see in my modifying work now, but i wanted to get some basics first before trying the hard stuff. the thing with cheating is something i clearly see, but dont know how to prevent it in a way that i can have client and singleplayer in one project. i guess i have to decide to make a server client only game to manage the sinking boat of knowledge im experiencing atm :/. dont understand me wrong, im glad u show this to me but i also never saw a good example of how to manage multiplayer in a save way and for this problem, the only code i found for jme was way to large to go through since it was a finished project and not an example.

Single player:

game client → game systems



multiplayer

game client → networking → connection management → game systems



Keep the client code and “game system” code cleanly separated and you can do the above. Otherwise, you are basically going to have to write two games anyway… you just don’t know it yet. Trying to sync multiple clients together without moving some processing to the server will take the rest of your life.



In the above, only “game client” should need to change significantly. “Game systems” might have some slight reconfiguration to run optimally in the different environments.

What @pspeed said :slight_smile:



With the addition of a validation section in the multiplayer section that may not be there as part of the single player depending on how expensive the validation is and how worried you are about that side of things.



Essentially the rule of thumb is:

  1. Trust nothing the client sends you - always verify.
  2. Send nothing to the client unless it really really needs it or it is displaying it to the player.



    (For example a map hack is impossible if the client knows no more of the map than the player can see).



    In the case of 1 there are a number of ways to do it, some of the most common are:
  3. You can running the full engine on both the server and client in parallel (server headless of course). This tends to be done in FPS style games.
  4. You can run the engine on the server and just show results on the client (easy for turn based games, can be problematic for more realtime.
  5. You can run the engine on the client and just validate the results server side. (For example the player moves, then sends the server “I moved”, server then checks there wasn’t a wall in the way etc)



    None of these is easy - and we haven’t even got into synchronization and lag compensation stuff yet. A lot depends on the nature of the game as to what solution is right for you…

nice, thx both of you. im getting into it i guess. first i get out of this is that i will make it a client server only game and move a lot more to the server and make the client just to display and input. then i will have messages to the server in form like “combine inventory slot1 and 5” and the server will deal with it and only responds in sending the new inventory. the server will then also manage the moving with “started moving and stopped”. is that right so far?



my idea now was also to let the server create the map in a seperate thread as the player is moving out of it, but is there a way to get a specific quad from the generator ?

That’s certainly valid. I can’t say that it is “right” without knowing a lot more about your game and its architecture.



A lot of this stuff is more art than science and only experience can teach you where the cans of worms are.