Using Networking to Send Clients A Map, they then have to load it.

Hi,

So there is a server and clients.

Client connects to server >
Server sends client a map <
Client loads map >

I need someone to point me in the correct direction, I am not using an libraries such as LibGDX, I’ve programmed my engine using Javas basics (Canvas, game loop, object handler…)

Here are the things I’m worried about:

  • The player can crack the program and change the loaded map given by the server. How do I circumvent this from happening?

  • What format of the data will the map sent back to the client be? (i.e. it wouldn’t make sense to send back a text file)

Thanks!

What are the consequences if this happens? I.e. Does it give potential for cheating? Any data sent to the client is out of your hands, but if you are expecting a response back based on potentially compromised data, then perhaps you need to verify it server-side somehow? Alternatively, if the consequences aren’t major, then don’t worry about it.

What I would do is, depending on how big your map is, split it into small chunks. Send chunk packets with the map data to the client for the user to load back together. That way you won’t send one big array, just lots of small little arrays.

You could store your map as a 2d array of byte for tile ids.

Thanks for your responses, I’ve just got to say a little bit more :smiley:

You got me thinking better now, it seems the hacker could change their screen but it wouldn’t modify anything server side because if the hacker sent something, the server needs to validate it.

Great idea, chunks! I’ve seen the 2d array thing been done storing the map. The thing is with the 2d array, I have to specify how many elements there will be. I know I might overshoot it, so it feels a bit weird to use a 2d array. Do you know of any other alternatives to a 2d array when it comes to storing maps?

What do you mean, you might overshoot it? How are you handling your map at the moment? Normally you want to define how big your map is, even if you are randomly generating it. If you aren’t going for a set map size and want to do something more like Minecraft, then make a new chunk every 16x16 tiles (16 if thats how big your chunk is).

For me I find a 2d array works best.

//This is a 64x64 map.
byte[][] tileIds = new byte[64][64]
  • Each element stores a tile id
  • When the game renders a portion of the map, it calls getTile(x, y).render()
  • getTile(int x, int y) returns a static Tile object that defines the tile look and properties