Skip to content

Commit

Permalink
fix: fixing SocketFactory errors when Listening is false
Browse files Browse the repository at this point in the history
SocketFactory can be null when listening is false. and if listening is false it should never be used (even for packet size)
  • Loading branch information
James-Frowen committed Feb 5, 2024
1 parent 02d0dfb commit 7ead256
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public void Stop()
public void StartServer(NetworkClient localClient = null)
{
ThrowIfActive();
ThrowIfSocketIsMissing();
if (Listening)
ThrowIfSocketIsMissing();

Application.quitting += Stop;
if (logger.LogEnabled()) logger.Log($"NetworkServer created, Mirage version: {Version.Current}");
Expand Down Expand Up @@ -251,14 +252,14 @@ public void StartServer(NetworkClient localClient = null)
};
}

var maxPacketSize = SocketFactory.MaxPacketSize;
NetworkWriterPool.Configure(maxPacketSize);

// Are we listening for incoming connections?
// If yes, set up a socket for incoming connections (we're a multiplayer game).
// If not, that's okay. Some games use a non-listening server for their single player game mode (Battlefield, Call of Duty...)
if (Listening)
{
var maxPacketSize = SocketFactory.MaxPacketSize;
NetworkWriterPool.Configure(maxPacketSize);

// Create a server specific socket.
var socket = SocketFactory.CreateServerSocket();

Expand Down

0 comments on commit 7ead256

Please sign in to comment.