Beispiel #1
0
        public async Task <ConnectionPayload> GetConnection(RconPayload rconPayload)
        {
            var client            = new MongoClient(this.settings);
            var db                = client.GetDatabase(database);
            var coll              = db.GetCollection <ConnectionPayload>(collectionName);
            var currentConnection = await coll.Find(x => x.AccessToken == rconPayload.AccessToken).SingleOrDefaultAsync();

            if (currentConnection?.Password != null)
            {
                currentConnection.Password = VinzClortho.Decrypt(currentConnection.Password, secKey + rconPayload.Salt);
            }
            return(currentConnection);
        }
Beispiel #2
0
        public async Task <RconPayload> GetRconPayload()
        {
            string parameter   = req.Query["param"];
            string accessToken = req.Query["accessToken"];
            string salt        = req.Query["salt"];

            accessToken = accessToken ?? req.Headers["accessToken"];
            salt        = salt ?? req.Headers["salt"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var    data        = JsonConvert.DeserializeObject <JObject>(requestBody);

            if (data != null)
            {
                parameter = parameter ?? (data.ContainsKey("param") ? data.GetValue("param").ToString() : null);
            }

            long tempVal;
            long?saltNumber = Int64.TryParse(salt, out tempVal) ? Int64.Parse(salt) : (long?)null;

            if (!string.IsNullOrWhiteSpace(parameter))
            {
                parameter = parameter.Trim();
                var myWriter = new StringWriter();
                HttpUtility.HtmlDecode(parameter, myWriter);
                parameter = myWriter.ToString();
            }
            else
            {
                parameter = "";
            }
            var parameterArray = parameter.Split(' ');

            var result = new RconPayload {
                AccessToken = accessToken,
                Salt        = saltNumber,
                Parameter   = parameterArray
            };

            result.IsValid = this.isValid(result);
            return(result);
        }