private string PostRequest(string request, IHttpResponse httpResponse, ServerProperties serverProperties) { var game = ((TicTacToeGame) serverProperties.ServiceSpecificObjectsWrapper); var data = WebUtility.UrlDecode(request.Remove(0, request.LastIndexOf("\r\n\r\n", StringComparison.Ordinal) + 4)); var move = data.Substring(0, data.IndexOf("&", StringComparison.Ordinal)) .Replace("box=", ""); if (move.StartsWith("-") && move.EndsWith("-") && move.Length > 2) { move = move.Replace("-", ""); } var ticTacToeBox = new TicTacToeBoxClass.TicTacToeBox( ListModule.OfSeq(GetBoxValues(data))); var errorMesageCode = Game.isUserInputCorrect(ticTacToeBox, move, game.Setting.playerGlyph, game.Setting.aIGlyph); if (errorMesageCode == Translate.Blank) { ticTacToeBox = (TicTacToeBoxClass.TicTacToeBox) game.Play(ticTacToeBox, CleanInput.SanitizeHumanPickedPlace(move, 9)); } httpResponse.SendHeaders(new List <string> { "HTTP/1.1 200 OK\r\n", "Cache-Control: no-cache\r\n", "Content-Type: text/html\r\n", "Content-Length: " + GetByteCount(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties)) + "\r\n\r\n" }); httpResponse .SendBody(GetByte(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties)), GetByteCount(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties))); return("200 OK"); }
private string ProcessRequestWithJson( string request, IHttpResponse httpResponse, ServerProperties serverProperties) { var game = ((ServiceDependents) serverProperties.ServiceSpecificObjectsWrapper) .Game; var converter = ((ServiceDependents) serverProperties.ServiceSpecificObjectsWrapper) .Converter; var jSonData = request.Remove(0, request.IndexOf("\r\n\r\n", StringComparison.Ordinal) + 4); var ticTacToeBox = converter .DeserializeTicTacToeBox(jSonData); var move = converter .DeserializeMove(jSonData); var errorMesageCode = Game.isUserInputCorrect(ticTacToeBox, move, game.Setting.playerGlyph, game.Setting.aIGlyph); if (errorMesageCode == Translate.Blank) { ticTacToeBox = (TicTacToeBoxClass.TicTacToeBox) game.Play(ticTacToeBox, CleanInput.SanitizeHumanPickedPlace(move, 9)); } var ticTacToeJson = converter .SerializeTicTacToeBox(ticTacToeBox); if (GameOver(ticTacToeBox, game)) { ticTacToeJson = ticTacToeJson .Replace(@"""gameOver"" : ""false""", @"""gameOver"" : ""true"""); } SendData(ticTacToeJson, httpResponse); return("200 OK"); }