Exemple #1
0
        public string CreateWebSessionFromDiscordId(string discordUserId)
        {
            ReportUser reportUser = _wrapper.ReportUserRepository.GetOne <ReportUser>(f => f.DiscordId == discordUserId);

            if (reportUser != null)
            {
                WebSession webSession = this.CreateWebSession(reportUser.Username);
                return(webSession.SessionCookie);
            }
            else
            {
                if (SystemShouldAutoCreateAccounts())
                {
                    ReportUser newUser = new ReportUser();
                    newUser.PasswordHash        = HashPassword(GenerationHelper.CreateRandomString(true, true, false, 20));
                    newUser.Username            = discordUserId;
                    newUser.IsOrganizationAdmin = false;
                    newUser.OrganizationRoles   = new List <string>();
                    _wrapper.ReportUserRepository.AddOne <ReportUser>(newUser);
                    WebSession webSession = this.CreateWebSession(newUser.Username);
                    return(webSession.SessionCookie);
                }
                else
                {
                    return("");
                }
            }
        }
        /// <summary>
        /// Creates a new web session and return it for a given user.
        /// </summary>
        /// <param name="username">The username for which the session is for.</param>
        /// <returns>A WebSession</returns>
        public WebSession CreateWebSession(string username)
        {
            Player     player     = _wrapper.PlayerRepository.GetOne <Player>(f => f.Username == username);
            WebSession webSession = new WebSession();

            webSession.Expiry        = DateTime.UtcNow.AddDays(14);
            webSession.UserId        = player.Id;
            webSession.ForUsername   = username;
            webSession.SessionCookie = GenerationHelper.CreateRandomString(true, true, false, 32);
            _wrapper.WebSessionRepository.AddOne <WebSession>(webSession);
            return(webSession);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new web session and return it for a given user.
        /// </summary>
        /// <param name="username">The username for which the session is for.</param>
        /// <returns>A WebSession</returns>
        public WebSession CreateWebSession(string username)
        {
            WebSession webSession = new WebSession();
            ReportUser reportUser = _wrapper.ReportUserRepository.GetOne <ReportUser>(f => f.Username == username);

            if (reportUser != null)
            {
                webSession.Expiry            = DateTime.UtcNow.AddDays(14);
                webSession.ReportUserId      = reportUser.Id;
                webSession.ForReportUsername = username;
                webSession.SessionCookie     = GenerationHelper.CreateRandomString(true, true, false, 32);
                _wrapper.WebSessionRepository.AddOne <WebSession>(webSession);
            }
            return(webSession);
        }
        /// <summary>
        /// Adds a new access token for a given user with a default lifetime.
        /// </summary>
        /// <param name="username">The user in question.</param>
        /// <returns>Resulting AccessToken</returns>
        public AccessToken CreateGameplayToken(string username)
        {
            AccessToken accessToken = new AccessToken();

            accessToken.Content              = GenerationHelper.CreateRandomString(true, true, false, 20);
            accessToken.Expiry               = DateTime.UtcNow.AddMinutes(5);
            accessToken.RefreshToken         = new RefreshToken();
            accessToken.RefreshToken.Content = GenerationHelper.CreateRandomString(true, true, false, 20);
            accessToken.RefreshToken.Expiry  = DateTime.UtcNow.AddMinutes(10);
            Player player = _wrapper.PlayerRepository.GetOne <Player>(f => f.Username == username);

            accessToken.PlayerId = player.Id;
            _wrapper.AccessTokenRepository.AddOne <AccessToken>(accessToken);
            return(accessToken);
        }
Exemple #5
0
        public void GenerateGalaxy(string galaxyName)
        {
            Galaxy galaxy = new Galaxy();

            galaxy.SizeX = _random.Next(50, 200);
            galaxy.SizeY = galaxy.SizeX; //_random.Next(200, 350);
            galaxy.SizeZ = _random.Next(1, 25);
            if (!string.IsNullOrEmpty(galaxyName))
            {
                galaxy.Name = galaxyName;
            }
            else
            {
                galaxy.Name = "Galaxy " + GenerationHelper.CreateRandomString(true, true, false, 5);
            }
            int volume      = galaxy.SizeX * galaxy.SizeY * galaxy.SizeZ;
            int lowerBoundX = (galaxy.SizeX / 2) * -1;
            int lowerBoundY = (galaxy.SizeY / 2) * -1;
            int lowerBoundZ = (galaxy.SizeZ / 2) * -1;
            int upperBoundX = lowerBoundX * -1;
            int upperBoundY = lowerBoundY * -1;
            int upperBoundZ = lowerBoundZ * -1;

            for (int Xctr = lowerBoundX; Xctr <= upperBoundX; Xctr++)
            {
                for (int Yctr = lowerBoundY; Yctr <= upperBoundY; Yctr++)
                {
                    for (int Zctr = lowerBoundZ; Zctr <= upperBoundZ; Zctr++)
                    {
                        // make random number to decide if this is a place a star should go.
                        int starChance = _random.Next(1, 1000);
                        if (starChance <= 2)
                        {
                            // create star
                            StarSystem starSystem = new StarSystem();
                            starSystem.Name = "System " + GenerationHelper.CreateRandomString(true, false, false, 6) + " " + GenerationHelper.CreateRandomString(false, true, false, 2);
                            starSystem.CreateRandomizedSpaceObjects(_random);
                            galaxy.StarSystems.Add(starSystem);
                        }
                    }
                }
            }
            _wrapper.GalaxyRepository.AddOne <Galaxy>(galaxy);
        }
Exemple #6
0
 public ErrorFromServer(string message)
 {
     this.ErrorId = GenerationHelper.CreateRandomString(true, true, false, 6);
     this.Message = message;
 }
Exemple #7
0
 public static void UpdateServerWithShipPosition(int changeX, int changeY)
 {
     if (_gameStatus == GameStatus.LoggedIn)
     {
         _shipMovementStatus = ShipMovementStatus.NotReady;
         connection.InvokeAsync("UpdateShipPosition", GetAuthorizationTokenContainer(), new ShipMovementContainer()
         {
             ShipId = selectedShip, ChangeX = changeX, ChangeY = changeY, ConfirmationId = GenerationHelper.CreateRandomString(true, true, false, 10)
         });
     }
 }
Exemple #8
0
 public PingRequest()
 {
     PingId = GenerationHelper.CreateRandomString(true, true, false, 7);
 }