doubts with send_data and struct list

Posted By: NeoNeper

doubts with send_data and struct list - 01/03/13 00:09

I'm working on a multi Massive Game ONLINE and came across the following problem.

Below a picture of the game running ONLINE.



I believe that is not possible I send data packets using different (structs lists) in client and server, if I'm wrong, please correct me!
So I'm a great difficulty to developing a communication in order to maintain an updated LIST of the Online Players in clients.

Below is another picture showing how I am working with structs communication on client and server



When the player enters the game, the server sends to him an updated list with all players online in moment.

On Client This struct list contains only one variable to the entity (handle) of the players.
Because this way, I can set all entities for you, and apply individual actions for (players entitys);

My problem is send this struct list to customers. because I can only send the same list of communication that I already use to send the information:
(path, angle, messages etc ...).

someone could tell me some suggestion?
How can I keep this list updated on the clients?
Posted By: Superku

Re: doubts with send_data and struct list - 01/03/13 07:40

The first byte of your structs should be an identification byte, f.i. as follows:

struct _DATA {
int type; // or short or char
};

struct _DATA_CHAT {
int type;
short player_id;
char msg[128];
};

struct _DATA_MOVE {
int type;
short player_id;
var input; // f.i holds the key inputs from the player
};

typedef struct _DATA DATA;
typedef struct _DATA_CHAT DATA_CHAT;
typedef struct _DATA_MOVE DATA_MOVE;

#define TYPE_CHAT 1
#define TYPE_MOVE 2

DATA_MOVE dm_player[16];

The first struct is not really necessary but IMO makes it nicer to handle.
Now you can proceed as follows:

received data/ buffer?
DATA* mydata = (DATA*)buffer;
if(mydata->type == TYPE_MOVE)
{
DATA_MOVE* move = (DATA_MOVE*)buffer;
dm_player[move->player_id].input = move->input;
}
if(mydata->type == TYPE_CHAT) ...


I hope this gives you an idea how to handle this situation (only programmed something like this once, so it may not be the best method, I don't know).
Additionally, I would suggest that you do not use synchronized global entities (and thus their handles) but only create local entities. If you know have let's say 20 players you simply create 20 player models on each machine locally and move and handle them using your data structs. This gives you full control over your simulation and you do not have to rely on or wait for the entity synchronization and so on.
Posted By: NeoNeper

Re: doubts with send_data and struct list - 01/03/13 19:22

ohh mannn. Thanks for the explanation!
I really knew not handle the "void * buffer" in this way. I am also grateful for the tip to use local entities!

if be done this way, security would not be more vulnerable?
Posted By: Superku

Re: doubts with send_data and struct list - 01/03/13 19:45

You're welcome!
I don't know much about security in multiplayer games but obviously your server should check and verify all input he gets from one client before he sends it to the remaining clients (valid movements/ actions, ...).
Just don't try to create something like WoW or another MMORPG and you will be fine, it's way too complicated (and expensive), even for some big studios.
Posted By: NeoNeper

Re: doubts with send_data and struct list - 01/06/13 23:19

I did some tests using local entities.
I used the "cheat engine" to do some basic hacks of the speed and position and noticed that with this is very easy to cheat the game.

Create validations on the server for each transmission of information would be very labor intensive and cost more processing time.

I'll make some tests using global entities and report the result

Could you give me more some informations?
doing this way you taught me. How could I send data packets containing struc array?
Posted By: Superku

Re: doubts with send_data and struct list - 01/07/13 11:20

Well I don't know about that program or multiplayer/ network security but a very simple yet maybe effective check on the server could be if the entity moved more than his maximum speed in the last frames (the server should then of course save the old position of every player).

Quote:
How could I send data packets containing struc array?

I don't know what you mean, could you explain in detail?
Sending something like
PL_INFO player_info[16];
could be realized as simple as
for(i = 0; i < max_player; i++) send_data_to(NULL,player_info[i],sizeof(PL_INFO));
Posted By: NeoNeper

Re: doubts with send_data and struct list - 01/07/13 16:09

Code:
PLAYERS* players[100];
...
players[0]=new(PLAYERS);
players[0].id = id;
players[0].sampla= sample;
...
send_data_to(NULL,players,sizeof(PLAYERS));



this way I did up there, it works, but I have no way of knowing what kind of data is being sent.
no have "_type" variable for *void in on receive.

So I need to send a simple struct containing an struct array within another struct

Sample:
Code:
typedef struct _PLAYERS
{

var id;
var sample;
...

}PLAYERS

typedef struct _clients
{

int _type;
struct _PLAYERS client[100]

}clients

...
send data
...

clients* players=new(clients);

players._type = PLAYERS_LIST;
players->client[0]=new(PLAYERS);
players->client[0].id = id;
players->client[0].id = id;

players->client[1]=new(PLAYERS);
players->client[1].id = id;
players->client[1].id = id;
...etc

send_data_to(NULL,players,sizeof(clients));



Its no work (T.T)

Posted By: Superku

Re: doubts with send_data and struct list - 01/07/13 16:44

Just do it as I suggested, use a simple struct to determine the type of the struct and then cast the void pointer to the appropriate struct:

received data/ buffer?
DATA* mydata = (DATA*)buffer;
if(mydata->type == TYPE_MOVE)

{
DATA_MOVE* move = (DATA_MOVE*)buffer;
dm_player[move->player_id].input = move->input;
}
if(mydata->type == TYPE_CHAT) ...

All structs have to have the same type variable as the first member.
Posted By: NeoNeper

Re: doubts with send_data and struct list - 01/18/13 00:42

Superku!
I'm working the way you taught me, usando using _type to identify data packets.
This works very well!.
But I still need learn to send and receive this type of list:

Code:
typedef struct _DATA_CLIENTS
{	
	int _type;
	struct _PLAYERS* client[100];
	
}DATA_CLIENTS;



I did not want to use a "for()" loop to this because it will be the server that will send this data packet.
I do not want to overload the server with many send_data_to inside a "for()" loop.


could you give me more this help? .
Tanks Superku! You is Brother (^.~)
Posted By: Superku

Re: doubts with send_data and struct list - 01/18/13 00:47

Glad that it works for you.
However, I don't think that this is possible as your struct here only contains 100 POINTERS, not there actual content. When you are using multiple send_data_to calls (or other send_... instructions) the engine does not send the data immediately but collects it and sends a bigger pack (there is some variable like dplay_packetsize or the like) then, thus it should be fine to use a loop and multiple send_ instructions. (I'm not a 100% sure, though.)
Posted By: NeoNeper

Re: doubts with send_data and struct list - 01/18/13 01:35

I'm Understanding!!.
I'll use the loop "for()" as you showed me!.
If I know something about this subject, I return to posting
Taaanks Superku.
© 2023 lite-C Forums