include "sbox/glue_networking.h"
include "../steam/steamnetworkingfakeip.h"

[small]
native struct HSteamListenSocket as Sandbox.Network.HSteamListenSocket;

[small]
native struct HSteamNetPollGroup as Sandbox.Network.HSteamNetPollGroup;

[small]
native struct HSteamNetConnection as Sandbox.Network.HSteamNetConnection;

[small]
native enum ESteamNetworkingAvailability as Steamworks.SteamNetworkingAvailability;

[small]
native enum EBeginAuthSessionResult as Steamworks.BeginAuthResult;

[small]
native struct HAuthTicket as Steamworks.Data.HAuthTicket;

managed class Sandbox.Network.SteamNetwork
{
	static void OnSocketConnection( HSteamListenSocket socket, HSteamNetConnection connection );
	static void OnSocketDisconnection( HSteamListenSocket socket, HSteamNetConnection connection );
	static bool ShouldAcceptConnection( HSteamListenSocket socket, HSteamNetConnection connection );
	static void OnDisconnection( HSteamNetConnection connection, int reasonCode, string reasonString );
	static void OnSessionEstablished( ulong steamId );
	static void OnSessionFailed( HSteamListenSocket socket, ulong steamId );
}

native class Glue.Networking
{
	static void RunCallbacks();
	static void SetDebugFunction( int level, void* func );

	//
	// sockets
	//
	static ESteamNetworkingAvailability GetAuthenticationStatus( IntPtr debugMsg );
	static ESteamNetworkingAvailability GetRelayNetworkStatus( IntPtr debugMsg );
	static HSteamListenSocket CreateSocket( int virtualPort );
	static HSteamListenSocket CreateIpBasedSocket( bool useFakeIP );
	static void CloseSocket( HSteamListenSocket socket );
	static string GetSocketAddress( HSteamListenSocket socket );
	static void BeginAsyncRequestFakeIP();
	static string GetIdentity();

	//
	// poll groups
	//
	static HSteamNetPollGroup CreatePollGroup();
	static void DestroyPollGroup( HSteamNetPollGroup group );
	static void SetPollGroup( HSteamNetConnection connection, HSteamNetPollGroup group );
	static int GetPollGroupMessages( HSteamNetPollGroup group, void* array_of_pointers, int maxmessages );

	//
	// connections
	//
	static HSteamNetConnection ConnectToSteamId( ulong steamid, int virtualPort );
	static HSteamNetConnection ConnectToIpAddress( string address );
	static void CloseConnection( HSteamNetConnection c, int reason, string debugReason );
	static void AcceptConnection( HSteamNetConnection c );
	static void FlushMessagesOnConnection( HSteamNetConnection c );
	static EResult SendMessage( HSteamNetConnection c, void* data, int length, int flags );
	static int GetConnectionMessages( HSteamNetConnection c, void* array_of_pointers, int maxmessages );
	static int GetConnectionState( HSteamNetConnection c );
	static string GetConnectionDescription( HSteamNetConnection c );
	static ulong GetConnectionSteamId( HSteamNetConnection c );
}