Пример #1
0
        protected override async void HandlePOSTRequest(string httpUrl, IMemoryStreamWrapper ms, IStreamWriterWrapper outputStream)
        {
            var json = encryptor.DecryptStringFromBytes(ms.ToArray());

            switch (httpUrl)
            {
            case "/serverInfoUpdate":
            {
                var serverInfo       = JsonConvert.DeserializeObject <ServerInfo>(json);
                var serverWasUpdated = await serversProvider.UpdateServer(serverInfo);

                if (!serverWasUpdated)
                {
                    stripMessenger.StripMessage =
                        $"Added new server: {serverInfo.Name} - {serverInfo.Ip}:{serverInfo.Port} ({serverInfo.Region})";
                }
                return;
            }

            case "/getServerToConnectTo":
            {
                var playerInfo      = JsonConvert.DeserializeObject <PlayerInfo>(json);
                var serverJson      = serversProvider.SelectServerForPlayerJson(playerInfo);
                var serverInfoBytes = encryptor.EncryptStringToBytes(serverJson);
                outputStream.WriteThroughBaseStream(serverInfoBytes, 0, serverInfoBytes.Length);
                stripMessenger.StripMessage = "Query 'getServerToConnectTo' have been successfully processed";
                return;
            }
            }

            throw new Exception("Unknown query");
        }