Hello everyone!
so the first two times I have tried implementing networking features into a game I did something along the lines of have the client send the server info then the server disperses this information to all clients.
this worked fine, but quickly I realised that I needed a method to define which types of information was being sent and received from both the server and the client, by this I mean the client might send the server the player's x position, but then the server wont know what to do with it, it would just be a random number which could represent anything like the players x or y position or it's velocity etc.
Then I created a kind of "index" that defined what all the types of information being being sent and received meant. So say the client was sending the server it's x position then there would be a 1 at the beginning of the package that the server could then read and thus know what type of information the package contained. and if the client were to send it's y position it would have a 2 at the beginning of the package so the server knew it was a y position that it was receiving.
okay so what my question is really asking is, is there a better way to do this? after having more than a few different types of information being sent and received it started feeling a bit chaotic, or is this the correct method and should I be working on cleaning up my code and making improvements to make it less chaotic?
I'm using UDP and sfml2.0 by the way