コード例 #1
0
 private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
 {
     _readBuffer.LengthBytes = reader.UserDataSize;
     _readBuffer.Position    = 0;
     reader.GetBytes(_readBuffer.Data, reader.UserDataSize);
     SocketMan.HandleIncomingData(_readBuffer);
     reader.Recycle();
 }
コード例 #2
0
        public override void Connect(string host, int port)
        {
            if (_connection != null)
            {
                Disconnect("Connecting to new host");
            }

            if (ulong.TryParse(host, out ulong steamid))
            {
                _connection = SteamNetworkingSockets.ConnectRelay <SteamConnectionManager>(steamid);

                _connection._OnConnected = (connection) =>
                {
                    SocketMan.HandleConnected();
                };

                _connection._OnDisconnected = (connection) =>
                {
                    if ((int)connection.EndReason == 1999)
                    {
                        SocketMan.HandleDisconnected(DenyReason.MapChange.ToString());
                    }
                    else
                    {
                        SocketMan.HandleDisconnected(connection.State.ToString());
                    }
                };

                _connection._OnMessage = (data, size, msgNum, recvTime, channel) =>
                {
                    _readBuffer.LengthBytes = size;
                    _readBuffer.Position    = 0;
                    Marshal.Copy(data, _readBuffer.Data, 0, size);
                    SocketMan.HandleIncomingData(_readBuffer);
                };

                _connection._OnConnectionChanged = (info) =>
                {
                    if (info.State == ConnectionState.ProblemDetectedLocally)
                    {
                        _connection?.Close();
                        SocketMan.SetSocketStatus(ClientSocketStatus.ProblemDetected);
                    }
                };
            }
        }