- Home /
The question is answered, right answer was accepted
How to pass data threw server ?
Hello everyone !
Here is my scenario : Some players want to play my multiplayer game (yeah !). When a player creates a server, he chooses a nickname. When the others want to join the opened game, they choose a nickname too. How can I be sure of the unicity of the nicknames ?
In my opinion, HostData.comment could be an option. Like, when a player has chosen a name, I put it in the comment of the hostdata, when an other one wants to join, I check the comment and if it contains the nickname, I stop the second player and tell him to choose an other one. The trick would be to concatenate all the nicknames in the comment and separate them with a special key (to encode and decode it easily) which could not be in a nickname.
So here are my questions :
first : is my idea would be an option ?
second : is there an other and easier method to do what I want ?
Thanks !
EDIT : up .
Answer by MibZ · Oct 03, 2012 at 09:28 PM
I imagine since you have a multiplayer game that you have some kind of List filled with all players - in my mind it would be simpler to have a for loop that iterates through your list comparing the new nickname with existing ones. I'm not sure which method is more efficient, but both are definitely possible.
I feel like I'm not answering your question fully though, your title and body are asking different things.
You may be right, I badly explained myself... I don't have a playername list because I don't know where I can stock it since I change of scene. I supposed I could save it in the HostData.comment variable, but I'm looking for an easier way to do it.
The best way to preserve data between scene loads is to make an empty GameObject and attach a script to it that you store whatever data you want to keep between scene loads inside of.
In the Start function of the script add the line: DontDestroyOnLoad(gameObject); When you change scenes any object that line gets applied to will be maintained, but if you load the scene that it is placed in more than once you will end up with duplicates of the object, so my solution to that is that the first scene loaded plays a splash screen animation and creates the empty with DontDestroy, and after that the splash screen scene is never reloaded.
Ahhhh of course ! But in my example, this will be the player server who will be the first one in my "waiting scene", just after creating the game. $$anonymous$$y players client will be in it only after choosing their nickname.
So this means that they must connect to the game, check if the nickname is not already taken without being in the "waiting scene". If it is the case, they are disconnected of the game. Is it ?
Hm. I'm not the best person to ask about networking code, but I would imagine that when someone tries to connect to the server you could send a message from the client to the server with their chosen nickname, check if it is available on the server side when it receives the message, and if it is send a message back to the client telling them to start connecting/telling them to choose a different nickname.
EDIT: Typo
Yes, but from what I know it is not possible to talk with the server if you are not connected to it ?
Follow this Question
Related Questions
I'm making a multiplayer game but .. 0 Answers
Run PHP query On Players Disconnecting from game (Coroutine) 0 Answers
Send data through network between different objects/scenes 1 Answer
How I can convert data to Wifi/ Multiplayer/ Network 0 Answers
How to receive streaming data over a UDP connection? 1 Answer