Skip to content

Commit

Permalink
fix: fixing cloud scripts not pinging api (#2097)
Browse files Browse the repository at this point in the history
* adding logs to api updater

* fixing cloud api
  • Loading branch information
James-Frowen committed Jul 15, 2020
1 parent e4cc85c commit 8e545ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Assets/Mirror/Cloud/ListServer/ListServerServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ IEnumerator ping()
while (pingFails <= MaxPingFails)
{
yield return new WaitForSeconds(PingInterval);
if (skipNextPing) { continue; }
if (skipNextPing)
{
skipNextPing = false;
continue;
}

sending = true;
UnityWebRequest request = requestCreator.Patch("servers/" + serverId, new EmptyJson());
Expand Down
9 changes: 7 additions & 2 deletions Assets/Mirror/Examples/Cloud/GUI/Scripts/ApiUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Mirror.Cloud.Example
/// </summary>
public class ApiUpdater : MonoBehaviour
{
static readonly ILogger logger = LogFactory.GetLogger<ApiUpdater>();

NetworkManagerListServer manager;
ApiConnector connector;
public string gameName = "Game";
Expand Down Expand Up @@ -36,13 +38,15 @@ void onPlayerListChanged(int playerCount)
if (connector.ListServer.ServerApi.ServerInList)
{
// update player count so that other players can see
if (playerCount < 2)
if (playerCount < manager.maxConnections)
{
if (logger.LogEnabled()) logger.Log($"Updating Server, player count: {playerCount} ");
connector.ListServer.ServerApi.UpdateServer(playerCount);
}
// remove server when there is more thasn 2 players
// remove server when there is max players
else
{
if (logger.LogEnabled()) logger.Log($"Removing Server, player count: {playerCount}");
connector.ListServer.ServerApi.RemoveServer();
}
}
Expand All @@ -51,6 +55,7 @@ void onPlayerListChanged(int playerCount)
// if not in list, and player counts drops below 2, add server to list
if (playerCount < 2)
{
if (logger.LogEnabled()) logger.Log($"Adding Server, player count: {playerCount}");
AddServer(playerCount);
}
}
Expand Down

0 comments on commit 8e545ac

Please sign in to comment.