Exemple #1
0
        private string sendCommand(string command, bool isMultiPacketresponse)
        {
            var    rconMsg  = Util.MergeByteArrays(RconQuery, Util.StringToBytes(ChallengeId), Util.StringToBytes(" \"" + RConPass + "\" " + command));
            var    recvData = new byte[2000];
            string s;

            if (string.IsNullOrEmpty(command))
            {
                recvData = socket.GetResponse(rconMsg, EngineType.GoldSource, isMultiPacketresponse);
            }
            else
            {
                recvData = socket.GetResponse(rconMsg, EngineType.GoldSource, isMultiPacketresponse);
            }
            try
            {
                s = Util.BytesToString(recvData).Remove(0, 1);
            }
            catch (Exception e)
            {
                e.Data.Add("ReceivedData", recvData == null ? new byte[1] : recvData);
                throw;
            }
            return(s);
        }
Exemple #2
0
        private ServerInfo getInfo()
        {
            byte[]     recvData   = null;
            ServerInfo serverInfo = null;

            try
            {
                byte[] Query = QueryMsg.InfoQuery;
                if (IsObsolete)
                {
                    Query = QueryMsg.ObsoleteInfoQuery;
                }

                recvData = new byte[UdpSocket.BufferSize];

                Stopwatch sw = Stopwatch.StartNew();
                recvData = UdpSocket.GetResponse(Query, Type);
                sw.Stop();
                Latency = sw.ElapsedMilliseconds;
                switch (recvData[0])
                {
                case 0x49: serverInfo = Current(recvData); break;

                case 0x6D: serverInfo = Obsolete(recvData); break;

                default: throw new InvalidHeaderException("packet header is not valid");
                }
            }
            catch (Exception e)
            {
                e.Data.Add("ReceivedData", recvData == null ? new byte[1] : recvData);
                throw;
            }
            return(serverInfo);
        }
Exemple #3
0
 internal Server(ConnectionInfo conInfo, EngineType type, bool?isObsolete)
 {
     ConInfo   = conInfo;
     EndPoint  = conInfo.EndPoint;
     UdpSocket = new UdpQuery(conInfo);
     Type      = type;
     if (isObsolete == null)
     {
         try
         {
             if (UdpSocket.GetResponse(QueryMsg.ObsoleteInfoQuery, Type)[0] == 0x6D)
             {
                 IsObsolete = true;
             }
         }
         catch (SocketException e)
         {
             if (e.SocketErrorCode == SocketError.TimedOut)
             {
                 IsObsolete = false;
             }
         }
     }
     else
     {
         IsObsolete = isObsolete == true ? true : false;
     }
 }