public HttpResponseMessage GetCampaign(Int32 campaignId = 1, String token = "", String rand = "") { try { if (String.IsNullOrEmpty(ConfigurationManager.Instance.SearchUrl)) { campaignId = 8; } String campaignMaps; if (!WebConstants.FILE_CAMPAIGN.TryGetValue(campaignId, out campaignMaps)) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_SUCH_LEVELS })); } return(HttpResponseFactory.Response200Plain(campaignMaps)); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }
public HttpResponseMessage Register([FromBody] RegisterFormModel registerData) { try { if (registerData == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_REGISTER_DATA })); } this.dataAccess.RegisterUser(registerData.Name, registerData.Password, registerData.Email, this.Request.GetRemoteIPAddress()); return(HttpResponseFactory.Response200Json(new ResultJson { Result = StatusMessages.STR_SUCCESS })); } catch (PR2Exception ex) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ex.Message })); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }
public HttpResponseMessage GetMessages([FromBody] GetMessagesFormModel getMessagesData) { try { if (getMessagesData == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_FORM_DATA })); } SessionInstance mySession = SessionManager.Instance.GetSessionByToken(getMessagesData.Token); if (mySession == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NOT_LOGGED_IN })); } IEnumerable <Message> messages = this.dataAccess.GetMessages(mySession.AccounData.UserId, getMessagesData.Start, getMessagesData.Count); return(HttpResponseFactory.Response200Json(new MessageListJson() { Messages = messages.Select(m => new MessageJson { MessageId = m.Id, Message = m.Content, Time = m.DateSent, UserId = m.Sender.Id, Name = m.Sender.Username, Group = m.Sender.Group }).ToList(), Success = true })); } catch (PR2Exception ex) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ex.Message })); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }
public HttpResponseMessage GetPlayerInfo(String name = "", String token = "", String rand = "") { try { // TODO - Handle token to check if lookup player is friend and/or ignored. Account acc = this.dataAccess.GetAccountByUsername(name); if (acc == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_USER_WITH_SUCH_NAME })); } return(HttpResponseFactory.Response200Json(UserInfoJson.ToUserInfoJson(acc))); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }
public HttpResponseMessage GetServerStatus() { try { if (ServerManager.Instance.ServerCount <= 0) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_SERVERS })); } return(HttpResponseFactory.Response200Json(new ServerListJson { Servers = ServerManager.Instance.GetServers() })); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }
/// <summary> /// Performs search according to specified search query. /// </summary> /// <param name="searchData">Search query.</param> /// <returns>List of found maps.</returns> private HttpResponseMessage GetSearchResults(SearchLevelsFormModel searchData) { try { if (searchData == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_FORM_DATA })); } if (String.IsNullOrEmpty(ConfigurationManager.Instance.SearchUrl)) { // External level search web API is not specified, handle the request internally. List <LevelRowDTO> levels = null; if (searchData.Mode == SearchMode.User) { Account acc = this.mainDAL.GetAccountByUsername(searchData.Search_Str); if (acc == null) { return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_USER_WITH_SUCH_NAME)); } levels = this.levelsDAL.SearchLevelsByUserId(acc.Id, searchData.Order, searchData.Dir, searchData.Page); } else { levels = this.levelsDAL.SearchLevelsByTerm(searchData.Search_Str, searchData.Order, searchData.Dir, searchData.Page); } this.mainDAL.FillLevelListMetadata(levels); return(HttpResponseFactory.Response200Plain(levels.GetLevelListString())); } else { // Let the external API handle the level search. using (WebClient webClient = new WebClient()) { webClient.QueryString.Add("search_str", searchData.Search_Str); webClient.QueryString.Add("order", searchData.Order.ToString().ToLower()); webClient.QueryString.Add("mode", searchData.Mode.ToString().ToLower()); webClient.QueryString.Add("dir", searchData.Dir.ToString().ToLower()); webClient.QueryString.Add("page", (searchData.Page ?? 1).ToString()); webClient.QueryString.Add("rand", searchData.Rand); String result = webClient.DownloadString(ConfigurationManager.Instance.SearchUrl); return(HttpResponseFactory.Response200Plain(result)); } } } catch (PR2Exception ex) { return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message)); } }
public HttpResponseMessage Login([FromBody] LoginFormModel loginData) { try { // TODO - Cookie token processing, version check and more checks based on received data. if (loginData == null || String.IsNullOrEmpty(loginData.I)) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_LOGIN_DATA })); } String rawloginDataJSON = loginData.I.FromBase64ToString(); LoginDataJson loginDataJSON = JsonConvert.DeserializeObject <LoginDataJson>(rawloginDataJSON); // Check if such server even exists. ServerInstance server = ServerManager.Instance.GetServer(loginDataJSON.Server.Server_name); if (server == null) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ErrorMessages.ERR_NO_SUCH_SERVER })); } Account acc = null; AccountDataDTO accData = null; // First of all, lets try to authenticate him using session token. Example use case - Level Editor relog. SessionInstance session = SessionManager.Instance.GetSessionByToken(loginData.Token); if (session == null) { // Did not work. Lets try to authenticate him using credentials instead. acc = this.dataAccess.AuthenticateUser(loginDataJSON.UserName, loginDataJSON.UserPass, this.Request.GetRemoteIPAddress()); accData = acc.ToAccountDataDTO(); session = SessionManager.Instance.GetSessionByUsername(acc.Username); if (session != null) { // He already has session. Lets remove it and raise error. HubCtxProvider.Instance.ForceLogout(server.SignalRClientId, session.AccounData.UserId, null); SessionManager.Instance.RemoveSession(session); } session = new SessionInstance( Guid.NewGuid(), loginDataJSON.LoginId, accData, loginDataJSON.Server.Server_name, this.Request.GetRemoteIPAddress(), this.Request.GetRemotePort()); SessionManager.Instance.StoreSession(session); } else { // He has session, lets try to log him out of GameServer and update his session. HubCtxProvider.Instance.ForceLogout(server.SignalRClientId, session.AccounData.UserId, null); acc = this.dataAccess.AuthenticateUser(session.AccounData.Username, this.Request.GetRemoteIPAddress()); accData = acc.ToAccountDataDTO(); session.LoginId = loginDataJSON.LoginId; session.AccounData = accData; session.Server = loginDataJSON.Server.Server_name; session.IP = this.Request.GetRemoteIPAddress(); session.Port = this.Request.GetRemotePort(); session.Extend(); } HubCtxProvider.Instance.LoginSuccessful(server.SignalRClientId, session.LoginId, accData); this.dataAccess.UpdateAccountStatus( acc, String.Concat(StatusMessages.STR_PLAYING_ON, session.Server), this.Request.GetRemoteIPAddress()); return(HttpResponseFactory.Response200Json(new LoginReplyJson { Ant = false, // TODO - Has Ant set. Email = false, // TODO - Has email set. Emblem = "", // TODO - Guild emblem URL. Guild = "0", // TODO - Guild id. GuildName = "", // TODO - Guild name. GuildOwner = 0, // TODO - Guild owner uid. LastRead = 0, // TODO - Seconds since UNIX time when user last read PMs. LastRecv = 0, // TODO - Seconds since UNIX time when user last received PM. Status = StatusMessages.STR_SUCCESS, Time = 0, // TODO - Seconds since UNIX time. Token = session.Token.ToString(), UserId = acc.Id })); } catch (PR2Exception ex) { return(HttpResponseFactory.Response200Json(new ErrorJson { Error = ex.Message })); } catch (Exception ex) { return(HttpResponseFactory.Response500Plain(ex.Message)); } }