- Home /
Network Client Connecting with different Maps
Hey guys,
Does anyone know whether there is a way to get the data like the comment from a registered host/server when connenting to its ip? I need that because the comment is the name of the map which is needed in the script which let the player connect to the server.
Btw. If someone knows an easier way to send the name of the map to the client so that i can load the right scene then answered that.
I hope someone can help me with my problem.
Update: I just thought about a lobby which would be a scene which would be loaded before the real map gets loaded and on which the server and the client can exchange the server name. The map name would be stored in a variable/gameObject in the "Lobby"-Scene and then can get a accesed by the clients.
If there is a better way please answer. This are just the thoughts i had after posting the question. If it is the best way then please let me know and i will close the question
I was going to say, I use the comment on a $$anonymous$$asterServer to store lots of things, but I'm not sure that was what you were after?
$$anonymous$$y problem is that when i store the name of the map f.e. in the comment how can i access only that specific comment when i'm connect through the ip. I know that there is this fetchlist-thing but I can't figure out how to get the comment when i'm connecting without a server-list. Hope this clears things up and know someone knows the answer.
@whydoidoit you store a lot of things in the comments so how do you get the information out of the comments. I did use the comments for the name of the server like "Player's Game" or something like this until i implemented multiple maps. Do you use Fethhostlist or something else and how do you do it when someone directly connects?
So I store a class serialized as X$$anonymous$$L in the $$anonymous$$asterServer comment. All of my players are initially registered with the $$anonymous$$asterServer as servers, but when one is invited then it connects to the invitor. So I have the list of invited players, serialized in a class, serialized as as string in the comments. The clients keep getting the list from the master server every few seconds and deserialize the comment to get the class and see whether they are invited, or other data...
Answer by ExTheSea · Jun 07, 2012 at 07:51 PM
So I was making it like I said in my answer. After a little while I found out that this is not working. It works when the Server and the client is the same computer. That's why I didn't noticed it until I made a web Player Build. Now I found a way that works:
if(Network.isClient){
for (var myElement in multiplayerScript.sortedHostList)
{
var element=multiplayerScript.hostData[myElement];
if(element.ip[0]==PlayerPrefs.GetString("connectIP")){
if(element.comment=="FPSscenetest"){
Map1=true; Map2=false;
}
if(element.comment=="Level2test"){
Map1=false; Map2=true;
}
}
}
if(Map1)
Application.LoadLevel(1);
if(Map2)
Application.LoadLevel(2);
}
}
This is the interesting part. Important is also that the server sets the MapName as the comment when he registers himself at the masterserver.
Another thing is that sortedHostlist is just what you think. It's a sorted List of the servers.
One problem with this method is if the server changes map just after the client grabs the map list the client will load in with the wrong scene and messed up viewIDs. Does anyone know of a way to reliably communicate with a server before syncing/replicating everything?
http://docs.unity3d.com/Documentation/Components/net-NetworkLevelLoad.html
I actually changed to another method which is based of the above script but changed a bit around to support multiple maps.
Answer by ubigame · May 30, 2012 at 05:17 PM
If you have any knowledge of PHP & SQL you can store your data in a Database and get it with the Unity's WWW & WWWForm classes. Just send a form to your PHP page that will search your database for the requested information and return as a string in www.text (www as an WWW object).
Sadly I don't have any knowledge about it and i think for my purpuse there should be an easier way but thanks for your answer as it is interesting.
Answer by Bunny83 · Jun 10, 2012 at 11:19 AM
The usual way is to send an RPC call with the level to load. There are unlimited ways how you can implement networking, so it's hard to give suggestions. If you use buffered RPCs and Network.Instantiate in your game (as shown by the documentation) you simply send a loadLevel RPC right at start of the server.
For more details see the Network LevelLoad tutorial
Thanks for your answer. I'm currently using another way like I described in my answer. When I run into problems I will use the way described in the link.