Skip to content

Commit

Permalink
Add checks to allow reconnection to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 2, 2024
1 parent ebb7f3c commit df0fa35
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Fika.Core/Coop/Utils/NetManagerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,25 @@ public static Task InitNetManager(bool isServer)
{
if (isServer)
{
return Singleton<FikaServer>.Instance.Init();
FikaServer server = Singleton<FikaServer>.Instance;
if (!server.Started)
{
return server.Init();
}
return Task.CompletedTask;
}
else
{
Singleton<FikaClient>.Instance.Init();
FikaClient client = Singleton<FikaClient>.Instance;
if (!client.Started)
{
client.Init();
}
return Task.CompletedTask;
}
}

logger.LogError("InitNetManager: FikaGameObject was null!");
return Task.CompletedTask;
}

Expand Down
12 changes: 12 additions & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public NetManager NetClient
public int Port { get; private set; }*/
public bool SpawnPointsReceived { get; private set; } = false;
private readonly ManualLogSource clientLogger = BepInEx.Logging.Logger.CreateLogSource("Fika.Client");
public bool Started
{
get
{
if (_netClient == null)
{
return false;
}
return _netClient.IsRunning;
}
}

public void Init()
{
Expand Down Expand Up @@ -111,6 +122,7 @@ public void Init()
};

FikaEventDispatcher.DispatchEvent(new FikaClientCreatedEvent(this));
Started = true;

Check failure on line 125 in Fika.Core/Networking/FikaClient.cs

View workflow job for this annotation

GitHub Actions / test

Property or indexer 'FikaClient.Started' cannot be assigned to -- it is read only

Check failure on line 125 in Fika.Core/Networking/FikaClient.cs

View workflow job for this annotation

GitHub Actions / test

Property or indexer 'FikaClient.Started' cannot be assigned to -- it is read only
}

public void SetupGameVariables(CoopPlayer coopPlayer)
Expand Down
11 changes: 11 additions & 0 deletions Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public NetManager NetServer
public bool hasHadPeer = false;
private readonly ManualLogSource serverLogger = BepInEx.Logging.Logger.CreateLogSource("Fika.Server");
private int _currentNetId;
public bool Started
{
get
{
if (_netServer == null)
{
return false;
}
return _netServer.IsRunning;
}
}

public async Task Init()
{
Expand Down

0 comments on commit df0fa35

Please sign in to comment.