Пример #1
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);
                    }
                };
            }
        }
Пример #2
0
 private void Listener_PeerDisconnectedEvent(NetPeer peer, DisconnectInfo disconnectInfo)
 {
     SocketMan.HandleDisconnected(disconnectInfo.Reason.ToString());
 }