Example #1
0
 public static bool ConnectToRcon(SourceRcon Sr, string IP, int Port, string Pass, string ServerName)
 {
     if (Sr != null && !Sr.Connected)
     {
         int DotCount = 0;
         for (int i = 0; i < IP.Length; i++)
         {
             if (IP[i] == '.')
             {
                 DotCount++;
             }
         }
         if (DotCount != 3)
         {
             IPAddress[] ips = Dns.GetHostAddresses(IP);
             if (ips.Length > 0)
             {
                 IP = ips[0].ToString();
             }
         }
         if (IPAddress.TryParse(IP, out IPAddress iP))
         {
             bool Connect = Sr.Connect(new IPEndPoint(iP, Port), Pass);
             int  Counter = 0;
             while (!Sr.Connected)
             {
                 Thread.Sleep(100);
                 if (Counter++ > 3)
                 {
                     AtlasServerManager.GetInstance().Log("[Rcon->ConnectToRcon] " + ServerName + " Something is wrong with connection");
                     return(false);
                 }
                 else if (Sr.Connected)
                 {
                     break;
                 }
             }
         }
     }
     return(true);
 }
Example #2
0
        internal void ParseFromBytes(byte[] bytes, SourceRcon parent)
        {
            int          BPtr = 0;
            ArrayList    stringcache;
            UTF8Encoding utf = new UTF8Encoding();

            // First 4 bytes are ReqId.
            RequestId = BitConverter.ToInt32(bytes, BPtr);
            BPtr     += 4;
            // Next 4 are server data.
            ServerDataReceived = (SERVERDATA_rec)BitConverter.ToInt32(bytes, BPtr);
            BPtr += 4;
            // string1 till /0
            stringcache = new ArrayList();
            while (bytes[BPtr] != 0)
            {
                stringcache.Add(bytes[BPtr]);
                BPtr++;
            }
            String1 = utf.GetString((byte[])stringcache.ToArray(typeof(byte)));
            BPtr++;

            // string2 till /0

            stringcache = new ArrayList();
            while (bytes[BPtr] != 0)
            {
                stringcache.Add(bytes[BPtr]);
                BPtr++;
            }
            String2 = utf.GetString((byte[])stringcache.ToArray(typeof(byte)));
            BPtr++;

            // Repeat if there's more data?

            if (BPtr != bytes.Length)
            {
                parent.OnServerOutput("Error: " + "Urk, extra data!");
            }
        }