예제 #1
0
 private void InternalDisconnect(int connId, HSteamNetConnection socket)
 {
     OnDisconnected.Invoke(connId);
     SteamNetworkingSockets.CloseConnection(socket, 0, "Graceful disconnect", false);
     connToMirrorID.Remove(connId);
     steamIDToMirrorID.Remove(connId);
     Debug.Log($"Client with ConnectionID {connId} disconnected.");
 }
예제 #2
0
    // Token: 0x0600098D RID: 2445 RVA: 0x00046164 File Offset: 0x00044364
    public bool Flush()
    {
        this.SendQueuedPackages();
        HSteamNetConnection con = this.m_con;

        SteamNetworkingSockets.FlushMessagesOnConnection(this.m_con);
        return(this.m_sendQueue.Count == 0);
    }
예제 #3
0
        private async void Connect(string host)
        {
            cancelToken          = new CancellationTokenSource();
            c_onConnectionChange = Callback <SteamNetConnectionStatusChangedCallback_t> .Create(OnConnectionStatusChanged);

            try
            {
                hostSteamID       = new CSteamID(UInt64.Parse(host));
                connectedComplete = new TaskCompletionSource <Task>();
                OnConnected      += SetConnectedComplete;

                SteamNetworkingIdentity smi = new SteamNetworkingIdentity();
                smi.SetSteamID(hostSteamID);

                SteamNetworkingConfigValue_t[] options = new SteamNetworkingConfigValue_t[] { };
                HostConnection = SteamNetworkingSockets.ConnectP2P(ref smi, 0, options.Length, options);

                Task connectedCompleteTask = connectedComplete.Task;
                Task timeOutTask           = Task.Delay(ConnectionTimeout, cancelToken.Token);

                if (await Task.WhenAny(connectedCompleteTask, timeOutTask) != connectedCompleteTask)
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        Debug.LogError($"The connection attempt was cancelled.");
                    }
                    else if (timeOutTask.IsCompleted)
                    {
                        Debug.LogError($"Connection to {host} timed out.");
                    }

                    OnConnected -= SetConnectedComplete;
                    OnConnectionFailed();
                }

                OnConnected -= SetConnectedComplete;
            }
            catch (FormatException)
            {
                Debug.LogError($"Connection string was not in the right format. Did you enter a SteamId?");
                Error = true;
                OnConnectionFailed();
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message);
                Error = true;
                OnConnectionFailed();
            }
            finally
            {
                if (Error)
                {
                    Debug.LogError("Connection failed.");
                    OnConnectionFailed();
                }
            }
        }
예제 #4
0
    // Token: 0x06000988 RID: 2440 RVA: 0x00046094 File Offset: 0x00044294
    private void OnNewConnection(HSteamNetConnection con)
    {
        EResult eresult = SteamNetworkingSockets.AcceptConnection(con);

        ZLog.Log("Accepting connection " + eresult);
        if (eresult == EResult.k_EResultOK)
        {
            this.QueuePendingConnection(con);
        }
    }
예제 #5
0
    // Token: 0x06000980 RID: 2432 RVA: 0x00045B94 File Offset: 0x00043D94
    public ZSteamSocket(HSteamNetConnection con)
    {
        ZSteamSocket.RegisterGlobalCallbacks();
        this.m_con = con;
        SteamNetConnectionInfo_t steamNetConnectionInfo_t;

        SteamNetworkingSockets.GetConnectionInfo(this.m_con, out steamNetConnectionInfo_t);
        this.m_peerID = steamNetConnectionInfo_t.m_identityRemote;
        ZLog.Log("Connecting to " + this.m_peerID.ToString());
        ZSteamSocket.m_sockets.Add(this);
    }
예제 #6
0
 // Token: 0x06000984 RID: 2436 RVA: 0x00045ED4 File Offset: 0x000440D4
 private static ZSteamSocket FindSocket(HSteamNetConnection con)
 {
     foreach (ZSteamSocket zsteamSocket in ZSteamSocket.m_sockets)
     {
         if (zsteamSocket.m_con == con)
         {
             return(zsteamSocket);
         }
     }
     return(null);
 }
예제 #7
0
    protected EResult SendSocket(HSteamNetConnection conn, byte[] data, int channelId)
    {
        Array.Resize(ref data, data.Length + 1);
        data[data.Length - 1] = (byte)channelId;

        GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
        IntPtr   pData       = pinnedArray.AddrOfPinnedObject();
        int      sendFlag    = channelId == Channels.Unreliable ? Constants.k_nSteamNetworkingSend_Unreliable : Constants.k_nSteamNetworkingSend_Reliable;
        EResult  res         = SteamNetworkingSockets.SendMessageToConnection(conn, pData, (uint)data.Length, sendFlag, out long _);

        if (res != EResult.k_EResultOK)
        {
            Debug.LogWarning($"Send issue: {res}");
        }

        pinnedArray.Free();
        return(res);
    }
예제 #8
0
 static bool Prefix(ZSteamSocket __instance, Queue <byte[]> ___m_sendQueue, ref int ___m_totalSent, HSteamNetConnection ___m_con)
 {
     if (!__instance.IsConnected())
     {
         return(false);
     }
     while (___m_sendQueue.Count > 0)
     {
         byte[] source = ___m_sendQueue.Peek();
         IntPtr num    = Marshal.AllocHGlobal(source.Length);
         Marshal.Copy(source, 0, num, source.Length);
         // This was k_nSteamNetworkingSend_ReliableNoNagle before
         EResult connection = SteamNetworkingSockets.SendMessageToConnection(___m_con, num, (uint)source.Length, Constants.k_nSteamNetworkingSend_Reliable, out long _);
         Marshal.FreeHGlobal(num);
         if (connection == EResult.k_EResultOK)
         {
             ___m_totalSent += source.Length;
             ___m_sendQueue.Dequeue();
         }
         else
         {
             ZLog.Log("Failed to send data " + connection);
             break;
         }
     }
     return(false);
 }
		/// Called to send a rendezvous message to the remote peer.  This may be called
		/// from any thread, at any time, so you need to be thread-safe!  Don't take
		/// any locks that might hold while calling into SteamNetworkingSockets functions,
		/// because this could lead to deadlocks.
		///
		/// Note that when initiating a connection, we may not know the identity
		/// of the peer, if you did not specify it in ConnectP2PCustomSignaling.
		///
		/// Return true if a best-effort attempt was made to deliver the message.
		/// If you return false, it is assumed that the situation is fatal;
		/// the connection will be closed, and Release() will be called
		/// eventually.
		///
		/// Signaling objects will not be shared between connections.
		/// You can assume that the same value of hConn will be used
		/// every time.
		public bool SendSignal(HSteamNetConnection hConn, ref SteamNetConnectionInfo_t info, IntPtr pMsg, int cbMsg) {
			return NativeMethods.SteamAPI_ISteamNetworkingConnectionSignaling_SendSignal(ref this, hConn, ref info, pMsg, cbMsg);
		}
예제 #10
0
    // Token: 0x06000989 RID: 2441 RVA: 0x000460C8 File Offset: 0x000442C8
    private void QueuePendingConnection(HSteamNetConnection con)
    {
        ZSteamSocket item = new ZSteamSocket(con);

        this.m_pendingConnections.Enqueue(item);
    }
예제 #11
0
		/// Called when the signal represents a request for a new connection.
		///
		/// If you want to ignore the request, just return NULL.  In this case,
		/// the peer will NOT receive any reply.  You should consider ignoring
		/// requests rather than actively rejecting them, as a security measure.
		/// If you actively reject requests, then this makes it possible to detect
		/// if a user is online or not, just by sending them a request.
		///
		/// If you wish to send back a rejection, then use
		/// ISteamNetworkingSockets::CloseConnection() and then return NULL.
		/// We will marshal a properly formatted rejection signal and
		/// call SendRejectionSignal() so you can send it to them.
		///
		/// If you return a signaling object, the connection is NOT immediately
		/// accepted by default.  Instead, it stays in the "connecting" state,
		/// and the usual callback is posted, and your app can accept the
		/// connection using ISteamNetworkingSockets::AcceptConnection.  This
		/// may be useful so that these sorts of connections can be more similar
		/// to your application code as other types of connections accepted on
		/// a listen socket.  If this is not useful and you want to skip this
		/// callback process and immediately accept the connection, call
		/// ISteamNetworkingSockets::AcceptConnection before returning the
		/// signaling object.
		///
		/// After accepting a connection (through either means), the connection
		/// will transition into the "finding route" state.
		public IntPtr OnConnectRequest(HSteamNetConnection hConn, ref SteamNetworkingIdentity identityPeer, int nLocalVirtualPort) {
			return NativeMethods.SteamAPI_ISteamNetworkingSignalingRecvContext_OnConnectRequest(ref this, hConn, ref identityPeer, nLocalVirtualPort);
		}