CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

isteamgameservernetworking.cs (16458B)


      1 // This file is provided under The MIT License as part of Steamworks.NET.
      2 // Copyright (c) 2013-2019 Riley Labrecque
      3 // Please see the included LICENSE.txt for additional information.
      4 
      5 // This file is automatically generated.
      6 // Changes to this file will be reverted when you update Steamworks.NET
      7 
      8 #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
      9 	#define DISABLESTEAMWORKS
     10 #endif
     11 
     12 #if !DISABLESTEAMWORKS
     13 
     14 using System.Runtime.InteropServices;
     15 using IntPtr = System.IntPtr;
     16 
     17 namespace Steamworks {
     18 	public static class SteamGameServerNetworking {
     19 		/// <summary>
     20 		/// <para>//////////////////////////////////////////////////////////////////////////////////////////</para>
     21 		/// <para> UDP-style (connectionless) networking interface.  These functions send messages using</para>
     22 		/// <para> an API organized around the destination.  Reliable and unreliable messages are supported.</para>
     23 		/// <para> For a more TCP-style interface (meaning you have a connection handle), see the functions below.</para>
     24 		/// <para> Both interface styles can send both reliable and unreliable messages.</para>
     25 		/// <para> Automatically establishes NAT-traversing or Relay server connections</para>
     26 		/// <para> Sends a P2P packet to the specified user</para>
     27 		/// <para> UDP-like, unreliable and a max packet size of 1200 bytes</para>
     28 		/// <para> the first packet send may be delayed as the NAT-traversal code runs</para>
     29 		/// <para> if we can't get through to the user, an error will be posted via the callback P2PSessionConnectFail_t</para>
     30 		/// <para> see EP2PSend enum above for the descriptions of the different ways of sending packets</para>
     31 		/// <para> nChannel is a routing number you can use to help route message to different systems 	- you'll have to call ReadP2PPacket()</para>
     32 		/// <para> with the same channel number in order to retrieve the data on the other end</para>
     33 		/// <para> using different channels to talk to the same user will still use the same underlying p2p connection, saving on resources</para>
     34 		/// </summary>
     35 		public static bool SendP2PPacket(CSteamID steamIDRemote, byte[] pubData, uint cubData, EP2PSend eP2PSendType, int nChannel = 0) {
     36 			InteropHelp.TestIfAvailableGameServer();
     37 			return NativeMethods.ISteamNetworking_SendP2PPacket(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDRemote, pubData, cubData, eP2PSendType, nChannel);
     38 		}
     39 
     40 		/// <summary>
     41 		/// <para> returns true if any data is available for read, and the amount of data that will need to be read</para>
     42 		/// </summary>
     43 		public static bool IsP2PPacketAvailable(out uint pcubMsgSize, int nChannel = 0) {
     44 			InteropHelp.TestIfAvailableGameServer();
     45 			return NativeMethods.ISteamNetworking_IsP2PPacketAvailable(CSteamGameServerAPIContext.GetSteamNetworking(), out pcubMsgSize, nChannel);
     46 		}
     47 
     48 		/// <summary>
     49 		/// <para> reads in a packet that has been sent from another user via SendP2PPacket()</para>
     50 		/// <para> returns the size of the message and the steamID of the user who sent it in the last two parameters</para>
     51 		/// <para> if the buffer passed in is too small, the message will be truncated</para>
     52 		/// <para> this call is not blocking, and will return false if no data is available</para>
     53 		/// </summary>
     54 		public static bool ReadP2PPacket(byte[] pubDest, uint cubDest, out uint pcubMsgSize, out CSteamID psteamIDRemote, int nChannel = 0) {
     55 			InteropHelp.TestIfAvailableGameServer();
     56 			return NativeMethods.ISteamNetworking_ReadP2PPacket(CSteamGameServerAPIContext.GetSteamNetworking(), pubDest, cubDest, out pcubMsgSize, out psteamIDRemote, nChannel);
     57 		}
     58 
     59 		/// <summary>
     60 		/// <para> AcceptP2PSessionWithUser() should only be called in response to a P2PSessionRequest_t callback</para>
     61 		/// <para> P2PSessionRequest_t will be posted if another user tries to send you a packet that you haven't talked to yet</para>
     62 		/// <para> if you don't want to talk to the user, just ignore the request</para>
     63 		/// <para> if the user continues to send you packets, another P2PSessionRequest_t will be posted periodically</para>
     64 		/// <para> this may be called multiple times for a single user</para>
     65 		/// <para> (if you've called SendP2PPacket() on the other user, this implicitly accepts the session request)</para>
     66 		/// </summary>
     67 		public static bool AcceptP2PSessionWithUser(CSteamID steamIDRemote) {
     68 			InteropHelp.TestIfAvailableGameServer();
     69 			return NativeMethods.ISteamNetworking_AcceptP2PSessionWithUser(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDRemote);
     70 		}
     71 
     72 		/// <summary>
     73 		/// <para> call CloseP2PSessionWithUser() when you're done talking to a user, will free up resources under-the-hood</para>
     74 		/// <para> if the remote user tries to send data to you again, another P2PSessionRequest_t callback will be posted</para>
     75 		/// </summary>
     76 		public static bool CloseP2PSessionWithUser(CSteamID steamIDRemote) {
     77 			InteropHelp.TestIfAvailableGameServer();
     78 			return NativeMethods.ISteamNetworking_CloseP2PSessionWithUser(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDRemote);
     79 		}
     80 
     81 		/// <summary>
     82 		/// <para> call CloseP2PChannelWithUser() when you're done talking to a user on a specific channel. Once all channels</para>
     83 		/// <para> open channels to a user have been closed, the open session to the user will be closed and new data from this</para>
     84 		/// <para> user will trigger a P2PSessionRequest_t callback</para>
     85 		/// </summary>
     86 		public static bool CloseP2PChannelWithUser(CSteamID steamIDRemote, int nChannel) {
     87 			InteropHelp.TestIfAvailableGameServer();
     88 			return NativeMethods.ISteamNetworking_CloseP2PChannelWithUser(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDRemote, nChannel);
     89 		}
     90 
     91 		/// <summary>
     92 		/// <para> fills out P2PSessionState_t structure with details about the underlying connection to the user</para>
     93 		/// <para> should only needed for debugging purposes</para>
     94 		/// <para> returns false if no connection exists to the specified user</para>
     95 		/// </summary>
     96 		public static bool GetP2PSessionState(CSteamID steamIDRemote, out P2PSessionState_t pConnectionState) {
     97 			InteropHelp.TestIfAvailableGameServer();
     98 			return NativeMethods.ISteamNetworking_GetP2PSessionState(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDRemote, out pConnectionState);
     99 		}
    100 
    101 		/// <summary>
    102 		/// <para> Allow P2P connections to fall back to being relayed through the Steam servers if a direct connection</para>
    103 		/// <para> or NAT-traversal cannot be established. Only applies to connections created after setting this value,</para>
    104 		/// <para> or to existing connections that need to automatically reconnect after this value is set.</para>
    105 		/// <para> P2P packet relay is allowed by default</para>
    106 		/// </summary>
    107 		public static bool AllowP2PPacketRelay(bool bAllow) {
    108 			InteropHelp.TestIfAvailableGameServer();
    109 			return NativeMethods.ISteamNetworking_AllowP2PPacketRelay(CSteamGameServerAPIContext.GetSteamNetworking(), bAllow);
    110 		}
    111 
    112 		/// <summary>
    113 		/// <para>//////////////////////////////////////////////////////////////////////////////////////////</para>
    114 		/// <para> LISTEN / CONNECT connection-oriented interface functions</para>
    115 		/// <para> These functions are more like a client-server TCP API.  One side is the "server"</para>
    116 		/// <para> and "listens" for incoming connections, which then must be "accepted."  The "client"</para>
    117 		/// <para> initiates a connection by "connecting."  Sending and receiving is done through a</para>
    118 		/// <para> connection handle.</para>
    119 		/// <para> For a more UDP-style interface, where you do not track connection handles but</para>
    120 		/// <para> simply send messages to a SteamID, use the UDP-style functions above.</para>
    121 		/// <para> Both methods can send both reliable and unreliable methods.</para>
    122 		/// <para>//////////////////////////////////////////////////////////////////////////////////////////</para>
    123 		/// <para> creates a socket and listens others to connect</para>
    124 		/// <para> will trigger a SocketStatusCallback_t callback on another client connecting</para>
    125 		/// <para> nVirtualP2PPort is the unique ID that the client will connect to, in case you have multiple ports</para>
    126 		/// <para>		this can usually just be 0 unless you want multiple sets of connections</para>
    127 		/// <para> unIP is the local IP address to bind to</para>
    128 		/// <para>		pass in 0 if you just want the default local IP</para>
    129 		/// <para> unPort is the port to use</para>
    130 		/// <para>		pass in 0 if you don't want users to be able to connect via IP/Port, but expect to be always peer-to-peer connections only</para>
    131 		/// </summary>
    132 		public static SNetListenSocket_t CreateListenSocket(int nVirtualP2PPort, uint nIP, ushort nPort, bool bAllowUseOfPacketRelay) {
    133 			InteropHelp.TestIfAvailableGameServer();
    134 			return (SNetListenSocket_t)NativeMethods.ISteamNetworking_CreateListenSocket(CSteamGameServerAPIContext.GetSteamNetworking(), nVirtualP2PPort, nIP, nPort, bAllowUseOfPacketRelay);
    135 		}
    136 
    137 		/// <summary>
    138 		/// <para> creates a socket and begin connection to a remote destination</para>
    139 		/// <para> can connect via a known steamID (client or game server), or directly to an IP</para>
    140 		/// <para> on success will trigger a SocketStatusCallback_t callback</para>
    141 		/// <para> on failure or timeout will trigger a SocketStatusCallback_t callback with a failure code in m_eSNetSocketState</para>
    142 		/// </summary>
    143 		public static SNetSocket_t CreateP2PConnectionSocket(CSteamID steamIDTarget, int nVirtualPort, int nTimeoutSec, bool bAllowUseOfPacketRelay) {
    144 			InteropHelp.TestIfAvailableGameServer();
    145 			return (SNetSocket_t)NativeMethods.ISteamNetworking_CreateP2PConnectionSocket(CSteamGameServerAPIContext.GetSteamNetworking(), steamIDTarget, nVirtualPort, nTimeoutSec, bAllowUseOfPacketRelay);
    146 		}
    147 
    148 		public static SNetSocket_t CreateConnectionSocket(uint nIP, ushort nPort, int nTimeoutSec) {
    149 			InteropHelp.TestIfAvailableGameServer();
    150 			return (SNetSocket_t)NativeMethods.ISteamNetworking_CreateConnectionSocket(CSteamGameServerAPIContext.GetSteamNetworking(), nIP, nPort, nTimeoutSec);
    151 		}
    152 
    153 		/// <summary>
    154 		/// <para> disconnects the connection to the socket, if any, and invalidates the handle</para>
    155 		/// <para> any unread data on the socket will be thrown away</para>
    156 		/// <para> if bNotifyRemoteEnd is set, socket will not be completely destroyed until the remote end acknowledges the disconnect</para>
    157 		/// </summary>
    158 		public static bool DestroySocket(SNetSocket_t hSocket, bool bNotifyRemoteEnd) {
    159 			InteropHelp.TestIfAvailableGameServer();
    160 			return NativeMethods.ISteamNetworking_DestroySocket(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, bNotifyRemoteEnd);
    161 		}
    162 
    163 		/// <summary>
    164 		/// <para> destroying a listen socket will automatically kill all the regular sockets generated from it</para>
    165 		/// </summary>
    166 		public static bool DestroyListenSocket(SNetListenSocket_t hSocket, bool bNotifyRemoteEnd) {
    167 			InteropHelp.TestIfAvailableGameServer();
    168 			return NativeMethods.ISteamNetworking_DestroyListenSocket(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, bNotifyRemoteEnd);
    169 		}
    170 
    171 		/// <summary>
    172 		/// <para> sending data</para>
    173 		/// <para> must be a handle to a connected socket</para>
    174 		/// <para> data is all sent via UDP, and thus send sizes are limited to 1200 bytes; after this, many routers will start dropping packets</para>
    175 		/// <para> use the reliable flag with caution; although the resend rate is pretty aggressive,</para>
    176 		/// <para> it can still cause stalls in receiving data (like TCP)</para>
    177 		/// </summary>
    178 		public static bool SendDataOnSocket(SNetSocket_t hSocket, byte[] pubData, uint cubData, bool bReliable) {
    179 			InteropHelp.TestIfAvailableGameServer();
    180 			return NativeMethods.ISteamNetworking_SendDataOnSocket(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, pubData, cubData, bReliable);
    181 		}
    182 
    183 		/// <summary>
    184 		/// <para> receiving data</para>
    185 		/// <para> returns false if there is no data remaining</para>
    186 		/// <para> fills out *pcubMsgSize with the size of the next message, in bytes</para>
    187 		/// </summary>
    188 		public static bool IsDataAvailableOnSocket(SNetSocket_t hSocket, out uint pcubMsgSize) {
    189 			InteropHelp.TestIfAvailableGameServer();
    190 			return NativeMethods.ISteamNetworking_IsDataAvailableOnSocket(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, out pcubMsgSize);
    191 		}
    192 
    193 		/// <summary>
    194 		/// <para> fills in pubDest with the contents of the message</para>
    195 		/// <para> messages are always complete, of the same size as was sent (i.e. packetized, not streaming)</para>
    196 		/// <para> if *pcubMsgSize &lt; cubDest, only partial data is written</para>
    197 		/// <para> returns false if no data is available</para>
    198 		/// </summary>
    199 		public static bool RetrieveDataFromSocket(SNetSocket_t hSocket, byte[] pubDest, uint cubDest, out uint pcubMsgSize) {
    200 			InteropHelp.TestIfAvailableGameServer();
    201 			return NativeMethods.ISteamNetworking_RetrieveDataFromSocket(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, pubDest, cubDest, out pcubMsgSize);
    202 		}
    203 
    204 		/// <summary>
    205 		/// <para> checks for data from any socket that has been connected off this listen socket</para>
    206 		/// <para> returns false if there is no data remaining</para>
    207 		/// <para> fills out *pcubMsgSize with the size of the next message, in bytes</para>
    208 		/// <para> fills out *phSocket with the socket that data is available on</para>
    209 		/// </summary>
    210 		public static bool IsDataAvailable(SNetListenSocket_t hListenSocket, out uint pcubMsgSize, out SNetSocket_t phSocket) {
    211 			InteropHelp.TestIfAvailableGameServer();
    212 			return NativeMethods.ISteamNetworking_IsDataAvailable(CSteamGameServerAPIContext.GetSteamNetworking(), hListenSocket, out pcubMsgSize, out phSocket);
    213 		}
    214 
    215 		/// <summary>
    216 		/// <para> retrieves data from any socket that has been connected off this listen socket</para>
    217 		/// <para> fills in pubDest with the contents of the message</para>
    218 		/// <para> messages are always complete, of the same size as was sent (i.e. packetized, not streaming)</para>
    219 		/// <para> if *pcubMsgSize &lt; cubDest, only partial data is written</para>
    220 		/// <para> returns false if no data is available</para>
    221 		/// <para> fills out *phSocket with the socket that data is available on</para>
    222 		/// </summary>
    223 		public static bool RetrieveData(SNetListenSocket_t hListenSocket, byte[] pubDest, uint cubDest, out uint pcubMsgSize, out SNetSocket_t phSocket) {
    224 			InteropHelp.TestIfAvailableGameServer();
    225 			return NativeMethods.ISteamNetworking_RetrieveData(CSteamGameServerAPIContext.GetSteamNetworking(), hListenSocket, pubDest, cubDest, out pcubMsgSize, out phSocket);
    226 		}
    227 
    228 		/// <summary>
    229 		/// <para> returns information about the specified socket, filling out the contents of the pointers</para>
    230 		/// </summary>
    231 		public static bool GetSocketInfo(SNetSocket_t hSocket, out CSteamID pSteamIDRemote, out int peSocketStatus, out uint punIPRemote, out ushort punPortRemote) {
    232 			InteropHelp.TestIfAvailableGameServer();
    233 			return NativeMethods.ISteamNetworking_GetSocketInfo(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket, out pSteamIDRemote, out peSocketStatus, out punIPRemote, out punPortRemote);
    234 		}
    235 
    236 		/// <summary>
    237 		/// <para> returns which local port the listen socket is bound to</para>
    238 		/// <para> *pnIP and *pnPort will be 0 if the socket is set to listen for P2P connections only</para>
    239 		/// </summary>
    240 		public static bool GetListenSocketInfo(SNetListenSocket_t hListenSocket, out uint pnIP, out ushort pnPort) {
    241 			InteropHelp.TestIfAvailableGameServer();
    242 			return NativeMethods.ISteamNetworking_GetListenSocketInfo(CSteamGameServerAPIContext.GetSteamNetworking(), hListenSocket, out pnIP, out pnPort);
    243 		}
    244 
    245 		/// <summary>
    246 		/// <para> returns true to describe how the socket ended up connecting</para>
    247 		/// </summary>
    248 		public static ESNetSocketConnectionType GetSocketConnectionType(SNetSocket_t hSocket) {
    249 			InteropHelp.TestIfAvailableGameServer();
    250 			return NativeMethods.ISteamNetworking_GetSocketConnectionType(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket);
    251 		}
    252 
    253 		/// <summary>
    254 		/// <para> max packet size, in bytes</para>
    255 		/// </summary>
    256 		public static int GetMaxPacketSize(SNetSocket_t hSocket) {
    257 			InteropHelp.TestIfAvailableGameServer();
    258 			return NativeMethods.ISteamNetworking_GetMaxPacketSize(CSteamGameServerAPIContext.GetSteamNetworking(), hSocket);
    259 		}
    260 	}
    261 }
    262 
    263 #endif // !DISABLESTEAMWORKS