Ejemplo n.º 1
0
        public HttpResponseMessage SubmitRating([FromBody] SubmitRatingFormModel ratingData)
        {
            try
            {
                if (ratingData == null || !ratingData.Level_Id.HasValue || !ratingData.Rating.HasValue)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(ratingData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                RatingDataDTO ratingResult = this.levelsDAL.SaveRating(ratingData.Level_Id.Value, ratingData.Rating.Value, mySession.AccounData.UserId, this.Request.GetRemoteIPAddress());

                return(HttpResponseFactory.Response200Plain(StatusKeys.MESSAGE, ratingResult.ToString()));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage SendMessage([FromBody] SendMessageFormModel sendMessageData)
        {
            try
            {
                if (sendMessageData == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(sendMessageData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.dataAccess.SendMessage(
                    mySession.AccounData.UserId,
                    sendMessageData.To_Name,
                    sendMessageData.Message,
                    this.Request.GetRemoteIPAddress());

                return(HttpResponseFactory.Response200Plain(StatusKeys.MESSAGE, StatusMessages.MESSAGE_SENT));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage RemoveLevel([FromBody] DeleteLevelFormModel levelData)
        {
            try
            {
                if (levelData == null || !levelData.Level_Id.HasValue)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_LEVEL_ID));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(levelData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                if (mySession.AccounData.Group < UserGroup.MODERATOR)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_RIGHTS));
                }

                this.levelsDAL.UnpublishLevel(levelData.Level_Id.Value);

                return(HttpResponseFactory.Response200Plain(StatusKeys.SUCCESS, StatusMessages.TRUE));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
        public HttpResponseMessage ChangePassword([FromBody] ChangePassFormModel changePassData)
        {
            try
            {
                if (changePassData == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(changePassData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.dataAccess.ChangePassword(mySession.AccounData.UserId, changePassData.Old_Pass, changePassData.New_Pass);

                return(HttpResponseFactory.Response200Plain(StatusKeys.MESSAGE, StatusMessages.PASSWORD_CHANGED));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 7
0
        public HttpResponseMessage PasswordCheck(Int64?courseID, String hash = "", String token = "", String rand = "")
        {
            try
            {
                if (!courseID.HasValue)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_LEVEL_ID));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                Boolean unlocked         = this.levelsDAL.CheckLevelPassword(courseID.Value, hash);
                String  serializedResult = JsonConvert.SerializeObject(new LevelPassCheckResultJson
                {
                    Access  = unlocked ? StatusMessages.ONE : StatusMessages.ZERO,
                    LevelId = courseID.Value.ToString(),
                    UserId  = mySession.AccounData.UserId.ToString()
                });
                String encodedResult = serializedResult.ToBase64();

                return(HttpResponseFactory.Response200Plain(StatusKeys.RESULT, encodedResult));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 8
0
        public HttpResponseMessage UploadLevel([FromBody] UploadLevelFormModel levelData)
        {
            try
            {
                if (levelData == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(levelData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.levelsDAL.SaveLevel(mySession.AccounData.UserId, mySession.AccounData.Username, levelData.ToDTO(), this.Request.GetRemoteIPAddress());

                return(HttpResponseFactory.Response200Plain(StatusKeys.MESSAGE, StatusMessages.SAVE_SUCCESSFUL));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 9
0
        public HttpResponseMessage DeleteLevel([FromBody] DeleteLevelFormModel levelData)
        {
            try
            {
                if (levelData == null || !levelData.Level_Id.HasValue)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(levelData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.levelsDAL.SoftDeleteLevel(mySession.AccounData.UserId, levelData.Level_Id.Value);

                return(HttpResponseFactory.Response200Plain(StatusKeys.SUCCESS, StatusMessages.TRUE));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 10
0
        public HttpResponseMessage DeleteMessage([FromBody] DeleteOrReportMessageFormModel reportMessageData)
        {
            try
            {
                if (reportMessageData == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(reportMessageData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.dataAccess.DeleteMessage(mySession.AccounData.UserId, reportMessageData.Message_Id);

                return(HttpResponseFactory.Response200Plain(StatusKeys.SUCCESS, StatusMessages.TRUE));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 11
0
 public HttpResponseMessage SearchLevelsPost([FromBody] SearchLevelsFormModel searchData)
 {
     try
     {
         return(GetSearchResults(searchData));
     }
     catch (Exception ex)
     {
         return(HttpResponseFactory.Response500Plain(ex.Message));
     }
 }
Ejemplo n.º 12
0
 public HttpResponseMessage GetPolicyFile()
 {
     try
     {
         return(HttpResponseFactory.Response200Xml(WebConstants.FILE_POLICY_XML));
     }
     catch (Exception ex)
     {
         return(HttpResponseFactory.Response500Plain(ex.Message));
     }
 }
Ejemplo n.º 13
0
        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));
            }
        }
Ejemplo n.º 14
0
        public HttpResponseMessage DownloadLevel(Int64?id, Int32?version = -1)
        {
            try
            {
                LevelDataDTO level = this.levelsDAL.GetLevel(id ?? -1, version ?? -1);

                return(HttpResponseFactory.Response200Plain(level.ToString()));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 15
0
        public HttpResponseMessage GetLevels(Byte?page, String token = "", String rand = "")
        {
            try
            {
                List <LevelRowDTO> levels = this.levelsDAL.GetNewestLevels(page);
                this.mainDAL.FillLevelListMetadata(levels);

                return(HttpResponseFactory.Response200Plain(levels.GetLevelListString()));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 16
0
        public HttpResponseMessage Ban([FromBody] BanFormModel banData)
        {
            try
            {
                if (banData == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }
                else if (!banData.Duration.HasValue || banData.Duration < 1)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_INVALID_DURATION));
                }

                SessionInstance issuerSession = SessionManager.Instance.GetSessionByToken(banData.Token);
                if (issuerSession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                Account bannedUser = this.dataAccess.Ban(
                    issuerSession.AccounData.UserId,
                    banData.Banned_Name,
                    banData.Duration.Value,
                    banData.Reason,
                    banData.Record,
                    banData.IsIPBan);

                // User has been banned, notify all registered game servers about this event.
                HubCtxProvider.Instance.ForceLogout(bannedUser.Id, (banData.IsIPBan) ? bannedUser.LoginIP : String.Empty);

                return(HttpResponseFactory.Response200Plain(StatusKeys.SUCCESS, StatusMessages.TRUE));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 17
0
        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));
            }
        }
Ejemplo n.º 18
0
        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));
            }
        }
Ejemplo n.º 19
0
        public HttpResponseMessage DeleteAllMessages(String token = "", String rand = "")
        {
            try
            {
                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                this.dataAccess.DeleteAllMessages(mySession.AccounData.UserId);

                return(HttpResponseFactory.Response200Plain(StatusKeys.SUCCESS, StatusMessages.TRUE));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 20
0
        public HttpResponseMessage ReportMessage([FromBody] DeleteOrReportMessageFormModel reportMessageData)
        {
            try
            {
                if (reportMessageData == null ||
                    !reportMessageData.Message_Id.HasValue)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NO_FORM_DATA));
                }

                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(reportMessageData.Token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_IMPLEMENTED));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 21
0
        public HttpResponseMessage GetLevels(String token = "", String rand = "")
        {
            try
            {
                SessionInstance mySession = SessionManager.Instance.GetSessionByToken(token);
                if (mySession == null)
                {
                    return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ErrorMessages.ERR_NOT_LOGGED_IN));
                }

                List <LevelRowDTO> levels = this.levelsDAL.GetUserLevels(mySession.AccounData.UserId);
                this.mainDAL.FillLevelListMetadata(levels);

                return(HttpResponseFactory.Response200Plain(levels.GetLevelListString()));
            }
            catch (PR2Exception ex)
            {
                return(HttpResponseFactory.Response200Plain(StatusKeys.ERROR, ex.Message));
            }
            catch (Exception ex)
            {
                return(HttpResponseFactory.Response500Plain(ex.Message));
            }
        }
Ejemplo n.º 22
0
        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));
            }
        }