コード例 #1
0
 public override void Disconnect(string reason)
 {
     if (_connection == null)
     {
         return;
     }
     _connection.Close();
     _connection._OnConnected         = null;
     _connection._OnDisconnected      = null;
     _connection._OnMessage           = null;
     _connection._OnConnectionChanged = null;
     _connection = null;
     SocketMan.SetSocketStatus(ClientSocketStatus.Disconnected, reason);
 }
コード例 #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);
                    }
                };
            }
        }