(77d1794a) Tester's build January 10th, 2020

This commit is contained in:
juanjp600
2020-01-10 14:42:38 -03:00
parent c02da46ef5
commit e6a08d715b
4529 changed files with 1145046 additions and 218950 deletions
@@ -0,0 +1,30 @@
using System;
namespace Steamworks
{
public class AuthTicket : IDisposable
{
public byte[] Data;
public uint Handle;
/// <summary>
/// Cancels a ticket.
/// You should cancel your ticket when you close the game or leave a server.
/// </summary>
public void Cancel()
{
if ( Handle != 0 )
{
SteamUser.Internal.CancelAuthTicket( Handle );
}
Handle = 0;
Data = null;
}
public void Dispose()
{
Cancel();
}
}
}
@@ -0,0 +1,120 @@
using Steamworks.Data;
using System;
using System.Runtime.InteropServices;
namespace Steamworks
{
public class ConnectionInterface
{
public Connection Connection;
public bool Connected = false;
public bool Connecting = true;
public string ConnectionName
{
get => Connection.ConnectionName;
set => Connection.ConnectionName = value;
}
public long UserData
{
get => Connection.UserData;
set => Connection.UserData = value;
}
public void Close() => Connection.Close();
public override string ToString() => Connection.ToString();
public virtual void OnConnectionChanged( ConnectionInfo data )
{
switch ( data.State )
{
case ConnectionState.Connecting:
OnConnecting( data );
break;
case ConnectionState.Connected:
OnConnected( data );
break;
case ConnectionState.ClosedByPeer:
case ConnectionState.ProblemDetectedLocally:
case ConnectionState.None:
OnDisconnected( data );
break;
}
}
/// <summary>
/// We're trying to connect!
/// </summary>
public virtual void OnConnecting( ConnectionInfo data )
{
Connecting = true;
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public virtual void OnConnected( ConnectionInfo data )
{
Connected = true;
Connecting = false;
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public virtual void OnDisconnected( ConnectionInfo data )
{
Connected = false;
Connecting = false;
}
public void Receive( int bufferSize = 32 )
{
int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
try
{
processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnConnection( Connection, messageBuffer, bufferSize );
for ( int i = 0; i < processed; i++ )
{
ReceiveMessage( Marshal.ReadIntPtr( messageBuffer, i * IntPtr.Size ) );
}
}
finally
{
Marshal.FreeHGlobal( messageBuffer );
}
//
// Overwhelmed our buffer, keep going
//
if ( processed == bufferSize )
Receive( bufferSize );
}
internal unsafe void ReceiveMessage( IntPtr msgPtr )
{
var msg = Marshal.PtrToStructure<NetMsg>( msgPtr );
try
{
OnMessage( msg.DataPtr, msg.DataSize, msg.RecvTime, msg.MessageNumber, msg.Channel );
}
finally
{
//
// Releases the message
//
msg.Release( msgPtr );
}
}
public virtual void OnMessage( IntPtr data, int size, long messageNum, long recvTime, int channel )
{
}
}
}
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Steamworks.Data;
namespace Steamworks
{
public class SocketInterface
{
public List<Connection> Connecting = new List<Connection>();
public List<Connection> Connected = new List<Connection>();
public Socket Socket { get; internal set; }
public bool Close() => Socket.Close();
public override string ToString() => Socket.ToString();
public virtual void OnConnectionChanged( Connection connection, ConnectionInfo data )
{
switch ( data.State )
{
case ConnectionState.Connecting:
OnConnecting( connection, data );
break;
case ConnectionState.Connected:
OnConnected( connection, data );
break;
case ConnectionState.ClosedByPeer:
case ConnectionState.ProblemDetectedLocally:
case ConnectionState.None:
OnDisconnected( connection, data );
break;
}
}
/// <summary>
/// Default behaviour is to accept every connection
/// </summary>
public virtual void OnConnecting( Connection connection, ConnectionInfo data )
{
connection.Accept();
Connecting.Add( connection );
}
/// <summary>
/// Client is connected. They move from connecting to Connections
/// </summary>
public virtual void OnConnected( Connection connection, ConnectionInfo data )
{
Connecting.Remove( connection );
Connected.Add( connection );
}
/// <summary>
/// The connection has been closed remotely or disconnected locally. Check data.State for details.
/// </summary>
public virtual void OnDisconnected( Connection connection, ConnectionInfo data )
{
connection.Close();
Connecting.Remove( connection );
Connected.Remove( connection );
}
public void Receive( int bufferSize = 32 )
{
int processed = 0;
IntPtr messageBuffer = Marshal.AllocHGlobal( IntPtr.Size * bufferSize );
try
{
processed = SteamNetworkingSockets.Internal.ReceiveMessagesOnListenSocket( Socket, messageBuffer, bufferSize );
for ( int i = 0; i < processed; i++ )
{
ReceiveMessage( Marshal.ReadIntPtr( messageBuffer, i * IntPtr.Size ) );
}
}
finally
{
Marshal.FreeHGlobal( messageBuffer );
}
//
// Overwhelmed our buffer, keep going
//
if ( processed == bufferSize )
Receive( bufferSize );
}
internal unsafe void ReceiveMessage( IntPtr msgPtr )
{
var msg = Marshal.PtrToStructure<NetMsg>( msgPtr );
try
{
OnMessage( msg.Connection, msg.Identity, msg.DataPtr, msg.DataSize, msg.RecvTime, msg.MessageNumber, msg.Channel );
}
finally
{
//
// Releases the message
//
msg.Release( msgPtr );
}
}
public virtual void OnMessage( Connection connection, NetIdentity identity, IntPtr data, int size, long messageNum, long recvTime, int channel )
{
}
}
}