Exemple #1
0
        /// <summary>
        /// Send an asynchronous rcon query to the sa-mp server.
        /// </summary>
        /// <param name="ipEnd">The ip end.</param>
        /// <param name="password">The password.</param>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public async Task SendRconQueryAsync(IPEndPoint ipEnd, string password, string command)
        {
            var query = new SampQuery(ipEnd);

            var receivedPacketsTask = query.ReceiveAsync();
            await query.SendRconAsync(password, command);

            //var rPackets = await receivedPacketsTask;
        }
Exemple #2
0
        /// <summary>
        /// Send an asynchronous query to the sa-mp server.
        /// Type param must be an inherits of SampQueryResult
        /// return depend from it.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ipEnd">An IPendpoint instance.</param>
        /// <returns></returns>
        public async Task <T> SendQueryAsync <T>(IPEndPoint ipEnd) where T : SampQueryResult, new()
        {
            var query = new SampQuery(ipEnd);
            var obj   = new T();

            var receivedPacketsTask = query.ReceiveAsync();
            var sendQueryTask       = query.SendAsync(obj.OpCode);

            await Task.WhenAll(receivedPacketsTask, sendQueryTask);

            var rPackets = receivedPacketsTask.Result;

            if (rPackets != null)
            {
                obj.IsCompleted = true;
                obj.Deserialize(rPackets);
            }

            return(obj);
        }