Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -16,8 +16,9 @@ namespace Steamworks
{
public ISocketManager? Interface { get; set; }
public List<Connection> Connecting = new List<Connection>();
public List<Connection> Connected = new List<Connection>();
public HashSet<Connection> Connecting = new HashSet<Connection>();
public HashSet<Connection> Connected = new HashSet<Connection>();
public Socket Socket { get; internal set; }
public override string ToString() => Socket.ToString();
@@ -44,17 +45,23 @@ namespace Steamworks
public virtual void OnConnectionChanged( Connection connection, ConnectionInfo info )
{
//
// Some notes:
// - Update state before the callbacks, in case an exception is thrown
// - ConnectionState.None happens when a connection is destroyed, even if it was already disconnected (ClosedByPeer / ProblemDetectedLocally)
//
switch ( info.State )
{
case ConnectionState.Connecting:
if ( !Connecting.Contains( connection ) )
if ( !Connecting.Contains( connection ) && !Connected.Contains( connection ) )
{
Connecting.Add( connection );
OnConnecting( connection, info );
}
break;
case ConnectionState.Connected:
if ( !Connected.Contains( connection ) )
if ( Connecting.Contains( connection ) && !Connected.Contains( connection ) )
{
Connecting.Remove( connection );
Connected.Add( connection );
@@ -67,6 +74,9 @@ namespace Steamworks
case ConnectionState.None:
if ( Connecting.Contains( connection ) || Connected.Contains( connection ) )
{
Connecting.Remove( connection );
Connected.Remove( connection );
OnDisconnected( connection, info );
}
break;
@@ -81,7 +91,6 @@ namespace Steamworks
if ( Interface != null )
{
Interface.OnConnecting( connection, info );
return;
}
else
{
@@ -104,17 +113,17 @@ namespace Steamworks
/// </summary>
public virtual void OnDisconnected( Connection connection, ConnectionInfo info )
{
SteamNetworkingSockets.Internal?.SetConnectionPollGroup( connection, 0 );
connection.Close();
Connecting.Remove( connection );
Connected.Remove( connection );
Interface?.OnDisconnected( connection, info );
if ( Interface != null )
{
Interface.OnDisconnected( connection, info );
}
else
{
connection.Close();
}
}
public void Receive( int bufferSize = 32 )
public int Receive( int bufferSize = 32, bool receiveToEnd = true )
{
int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
@@ -137,8 +146,10 @@ namespace Steamworks
//
// Overwhelmed our buffer, keep going
//
if ( processed == bufferSize )
Receive( bufferSize );
if ( receiveToEnd && processed == bufferSize )
processed += Receive( bufferSize );
return processed;
}
internal unsafe void ReceiveMessage( IntPtr msgPtr )
@@ -162,4 +173,4 @@ namespace Steamworks
Interface?.OnMessage( connection, identity, data, size, messageNum, recvTime, channel );
}
}
}
}