Closed Desocode closed 5 years ago
I tested this again in a fresh script and the callback does work successfully. I'm not really sure why it wasn't working previously. I've reformatted it to a lambda expression within the same method and it seems to be working fine now.
I'm not knowledable enough to know what was blocking the callback, maybe someone else can answer this. Bearing in mind my previous code worked fine for all other OnLobbyUpdated callbacks, people leaving/joining lobby etc.
New Code:
public void StartGame()
{
SteamServer ss = new SteamServer();
if (ss.StartSteamServer())
{
Debug.Log("Steam Server Started");
Client.Instance.Lobby.SetGameServer(Server.Instance.PublicIp, ss.gamePort);
Client.Instance.Lobby.CurrentLobbyData.SetData("GameStarted", "Yes");
Client.Instance.Lobby.OnLobbyDataUpdated = () =>
{
if (Client.Instance.Lobby.CurrentLobbyData.GetData("GameStarted") == "Yes")
{
var ticket = Client.Instance.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
ulong serverid = Client.Instance.Lobby.GameServerSteamId;
Client.Instance.Networking.SendP2PPacket(serverid, ticketBinary, ticketBinary.Length, Networking.SendType.Reliable, 1);
Debug.Log("Start Authorization");
}
};
}
else Debug.LogError("Server failed to start");
}
Previous code:
Client.Instance.Lobby.OnLobbyDataUpdated = OnLobbyUpdated
void OnLobbyUpdated()
{
if (Client.Instance.Lobby.CurrentLobbyData.GetData("GameStarted") == "Yes")
{
var ticket = Client.Instance.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
ulong serverid = Client.Instance.Lobby.GameServerSteamId;
Client.Instance.Networking.SendP2PPacket(serverid, ticketBinary, ticketBinary.Length, Networking.SendType.Reliable, 1);
Debug.Log("Start Authorization");
}
}
public void StartGame()
{
SteamServer ss = new SteamServer();
if (ss.StartSteamServer())
{
Debug.Log("Steam Server Started");
Client.Instance.Lobby.SetGameServer(Server.Instance.PublicIp, ss.gamePort);
Client.Instance.Lobby.CurrentLobbyData.SetData("GameStarted", "Yes");
}
else Debug.LogError("Server failed to start");
}
Client.Instance.Lobby.OnLobbyDataUpdated += OnLobbyDataUpdated;
Callback is being listened for and works when players join.
The above is set successfully but does not trigger the OnLobbyDataUpdated callback.