how to create a lobby and multiple rooms to join

Im trying to Initialize multiple servers, with a MasterServer, so the hosts can decide on wich one to play.
(like connect to the server and then decide on wich room to play)

if i run diferent instances of the proyect, i can actually create multiple servers (one per unity game), and hosts can decide on wich one to play.

The problem is that i can not initialize multiple servers (as rooms) on one instance of the game.

any ideas how to figure this out?

Here is the Networking code i have:

#pragma strict

private var refreshing:boolean;
private var hostdata:HostData[];

var PlayerPrefab:GameObject;
var PlayerPos:Transform;

var servercount:int=0;

function Start () {

}

function Update () {
	if (refreshing)
	{
		if(MasterServer.PollHostList().Length >0)
		{
			Debug.Log(MasterServer.PollHostList().Length);
			refreshing=false;
			hostdata = MasterServer.PollHostList();
		}
	}


}

//iniciar Server
function StartServer(i:int) {

		Network.InitializeServer(4,25001+i,!Network.HavePublicAddress);
		MasterServer.RegisterHost("Tipo_De_Juego","nombre del juego" + i,"Comentario_Del_Juego" + i);

}

function RefreshHostList(){
	MasterServer.ClearHostList();
	Debug.Log(MasterServer.PollHostList().Length + "still refreshing");
	MasterServer.RequestHostList("Tipo_De_Juego");
	refreshing=true;
}

function OnConnectedToServer(){
	spawnplayer();
}

function spawnplayer(){
 Network.Instantiate(PlayerPrefab,PlayerPos.position,Quaternion.identity,0);
}

/*---mensajes---*/
function OnServerInitialized() {
	Debug.Log("Server Initialized!!");
	spawnplayer();
}

function OnMasterServerEvent (mse:MasterServerEvent){
	if (mse== MasterServerEvent.RegistrationSucceeded)
		Debug.Log("Registered Server!");
}
/*----------------*/


//botones
function OnGUI () {

			if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
			{
				Debug.Log("apreto, Starting server");
				var servername:int= MasterServer.PollHostList().Length +1;
				StartServer(servername);
			}
			
			if (GUI.Button(new Rect(100, 200, 250, 100), "Refresh"))
			{
				Debug.Log("apreto, Refreshing");
				RefreshHostList();
			}
			
			if (hostdata){
				for (var i:int = 0;i<hostdata.length;i++){
						if (GUI.Button(new Rect(400, 100*(i+1), 250, 100), i+ hostdata[i].gameName))
							{
							Network.Connect(hostdata[i]);
							}
			
				}
			}
}

Unity’s networking wasn’t build for this kind of setup.
you will need one instance per server.

Well , It’s not fully supported in buit in networking but you can use Network groups and some amount of code to simulate rooms. However master server can not have those data i think (not sure, maybe you can send it to master server as additional data).

Take a look at uLink, uLobby from www.muchdifferent.com for a lobby system and a networking solution similar to unity’s own but much more powerful.

Other middleware solutions support this kind of lobby and rooms as well by other means. Stuff like smartfox, photon, electrotank …

Thankz for the help! i’ll look this things up
sorry dont have rating yet to tumb u up!

My pleasure. Thumbs ups are not important. People are, their problem and solving them are :slight_smile:

I hope you to have fun while doing this.

Something to be very careful about is that Unity’s networking doesn’t offer any useful security, so a rogue client could connect to your server and trash all the game sessions in one blow. The only defence I know against this is to limit the number of clients that can connect to a session, so when the session is full no outsiders can join and spoil things. It kind of sucks though, it’s a shame there’s no more effective way for the server to manage client permissions.

You are right, And also when you want to choose secure or none secure RPCs and data in built in networking you only can choose to make everything secure (damn slow and CPU intensive) or everything none secure (which means you can not send any critical data to game server from client).

Again some middlewares solve this, I worked much with uLink for example. It has a OnPlayerApproval callback to reject/allow clients and you can choose on a per RPC basis wether to send it encrypted and secure or not. Others probably should support this in one way or another as well.

1 Like