/// <summary> /// response for game status /// </summary> /// <param name="body"></param> /// <param name="gameid"></param> /// <param name="brief"></param> private void GetGameStatus(string body, string gameid, string brief) { HttpStatusCode httpStatus; GameInfo game; if (brief.Equals("yes")) { game = service.GetGameStatus(gameid, "yes", out httpStatus); } else { game = service.GetGameStatus(gameid, "no", out httpStatus); } string res = ("HTTP/1.1 " + (int)httpStatus + " " + httpStatus + "\r\n"); if ((int)httpStatus / 100 == 2) { string result = JsonConvert.SerializeObject(game); res += ("Content-Type: application/json\r\n"); res += ("Content-Length: " + Encoding.UTF8.GetByteCount(result) + "\r\n"); res += "\r\n"; res += result; } else { res += "\r\n"; } socket.BeginSend(res, (x, y) => { socket.Shutdown(SocketShutdown.Both); }, null); }
/// <summary> /// Given the proper parameters, it runs the correct method in our BoggleServer and sends the response message. /// This is essentially covering the functionality of IBoggleService from before. /// </summary> /// <param name="Type"></param> /// <param name="GameID"></param> /// <param name="IsBrief"></param> /// <param name="content"></param> private void ParseMessage(string Type, string Url, string GameID, string IsBrief, dynamic content) { HttpStatusCode status; // Each method we call should return the object we to JSON encoded if (Type == "POST") { // CreateUser if (Url == "users") { UserID ReturnID = server.CreateUser(content, out status); CompileMessage(status, ReturnID); } // JoinGame else if (Url == "games") { GameIDReturn IDReturn = server.JoinGame(content, out status); CompileMessage(status, IDReturn); } } else if (Type == "PUT") { // CancelJoinRequest if (Url == "games" && GameID == string.Empty) { server.CancelJoinRequest(content, out status); CompileMessage(status, null); } // PlayWord else { ScoreReturn Score = server.PlayWord(content, GameID, out status); CompileMessage(status, Score); } } // GetGameStatus else { Game CurrentGame = new Game(); CurrentGame = server.GetGameStatus(GameID, IsBrief, out status); CompileMessage(status, CurrentGame); } }