Automate LAN Matchmaking
Options
Aidan
✭
in Photon Bolt
Hi all,
Right now I have a client/server setup where one person chooses server and then the other chooses client.
Instead, I just want BOLT to handle this step in the background and automatically connect two (or more) people on the same local network.
I can think of some hacky ways of doing this, but I was wondering if there's built-in functionality to accomplish this.
Thank you!
Right now I have a client/server setup where one person chooses server and then the other chooses client.
Instead, I just want BOLT to handle this step in the background and automatically connect two (or more) people on the same local network.
I can think of some hacky ways of doing this, but I was wondering if there's built-in functionality to accomplish this.
Thank you!
0
Comments
-
Here's a modified version of the Photon Cloud example for LAN autoconnect. http://www.hatebin.com/hdabhpykqd
You can make it look for LAN and have the choice to join a non LAN session if no LAN available.0 -
I'm failing to see the "autoconnect" functionality, in fact this is the same script I used to set up what I have right now. I'm trying to get away from having to pick being the server or being the client.
The way I can do this now is check if the session list is empty and become the server, but it' sloppy and error-prone.0 -
A client will always need to check for available sessions in this scenario.0
-
Here's a hacky solution for anyone needing automated matchmaking (good for LAN multiplayer that just needs to kick off and work)
`IEnumerator AutoConnectManager() {
BoltLauncher.StartClient();
yield return new WaitUntil(() => BoltNetwork.isRunning && BoltNetwork.isClient);
int SecondsUntilTryServer = 5;
while (BoltNetwork.SessionList.Count == 0 && SecondsUntilTryServer > 0) {
SecondsUntilTryServer--;
yield return new WaitForSeconds(1f);
}
if (BoltNetwork.SessionList.Count == 0) {
Debug.Log("client start failed, becoming server.");
BoltLauncher.Shutdown();
BoltLauncher.StartServer();
yield return new WaitUntil(() => BoltNetwork.isRunning && BoltNetwork.isServer);
BoltNetwork.SetHostInfo("WitnessSession", new RoomProtocolToken {
ArbitraryData = "(MyCustomData)",
});
BoltNetwork.LoadScene("YourGameSceneName");
} else if (BoltNetwork.SessionList.Count > 0) {
foreach (var session in BoltNetwork.SessionList) {
Debug.Log("Automatically selecting first available session");
var token = session.Value.GetProtocolToken() as RoomProtocolToken;
ServerConnectToken connectToken = new ServerConnectToken {
data = "ConnectTokenData"
};
BoltNetwork.Connect(session.Value, connectToken);
break;
}
}
}`
Going to working on a version that quickly switches between becoming server and client to reduce wait times and possible fall throughs.0 -
Here's a hacky solution to automatically connect two people (good for LAN multiplayer where you just need it to kick off and start)
IEnumerator AutoConnectManager() {
BoltLauncher.StartClient();
yield return new WaitUntil(() => BoltNetwork.isRunning && BoltNetwork.isClient);
int SecondsUntilTryServer = 5;
while (BoltNetwork.SessionList.Count == 0 && SecondsUntilTryServer > 0) {
SecondsUntilTryServer--;
yield return new WaitForSeconds(1f);
}
if (BoltNetwork.SessionList.Count == 0) {
BoltLauncher.Shutdown();
BoltLauncher.StartServer();
yield return new WaitUntil(() => BoltNetwork.isRunning && BoltNetwork.isServer);
BoltNetwork.SetHostInfo("SessionName", new RoomProtocolToken {
ArbitraryData = "(MyCustomData)",
});
BoltNetwork.LoadScene("YourGameSceneName");
} else {
foreach (var session in BoltNetwork.SessionList) {
var token = session.Value.GetProtocolToken() as RoomProtocolToken;
ServerConnectToken connectToken = new ServerConnectToken {
data = "ConnectTokenData"
};
BoltNetwork.Connect(session.Value, connectToken);
break;
}
}
}
Going to try a version that quickly switches between being the server and client to reduce wait times and fall throughs.0