예제 #1
0
 protected override void Dispose(bool disposing)
 {
     if (!IsDisposed)
     {
         if (disposing)
         {
             _socket?.Dispose();
             _socket = null;
         }
         base.Dispose(disposing);
         IsDisposed = true;
     }
 }
예제 #2
0
        private bool Reconnect()
        {
            if (_socket != null)
            {
                try
                {
                    _socket.Dispose();
                    _socket = null;
                }
                catch { }
            }

            _socket = new TcpQuery(_connInfo);

            //attempt to authorize this conenction
            var packet = new RconSrcPacket()
            {
                Body = _password, Id = (int)PacketId.ExecCmd, Type = (int)PacketType.Auth
            };
            var buffer = _socket.GetResponse(RconUtil.GetBytes(packet));

            if (buffer == null || buffer.Length < 4)
            {
                return(false);
            }

            var header = BitConverter.ToInt32(buffer, 4);

            if (header == -1)
            {
                return(false);
            }

            _socket.Init();
            return(true);
        }