Exemplo n.º 1
0
        public SpaceObjectsViewModel(IAuthenticationService authenticationService, IObjectService objectService, string objectType, string objectName, int X, int Y, int Z, string cookie = "")
        {
            this.X          = X;
            this.Y          = Y;
            this.Z          = Z;
            this.ObjectName = objectName;
            this.ObjectType = objectType;

            _authenticationService = authenticationService;
            _objectService         = objectService;

            AllSpaceObjects = new List <SpaceObject>();
            AllSpaceObjects.AddRange(_objectService.GetAllSpaceObjects());

            // For personalization, load in some player details.
            if (!string.IsNullOrEmpty(cookie))
            {
                // Try to look up the player using their session Identifier (just a basic cookie)
                GetPlayerByCookieResponse playerByWebCookie = _authenticationService.GetPlayerByWebCookie(cookie);
                // The method returns a container object that has .Success property set to TRUE when the
                // player was found via a cookie that was not expired.
                if (playerByWebCookie.Success == true)
                {
                    _player = playerByWebCookie.Player;
                    if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(objectType))
                    {
                        if (_player.IsAdmin)
                        {
                            SpaceObject newSpaceObject = new SpaceObject(objectType, objectName);
                            newSpaceObject.X = X;
                            newSpaceObject.Y = Y;
                            newSpaceObject.Z = Z;
                            if (_objectService.SaveNewSpaceObject(newSpaceObject))
                            {
                                _message = "Saved new space object: " + newSpaceObject.Name;
                            }
                            else
                            {
                                _message = "Was unable to save object. Try saving a 'Moon', 'Asteroid', or 'Planet'?";
                            }
                        }
                        else
                        {
                            _message = "You are not an administrator and can't save.";
                        }
                    }
                    else
                    {
                        _message = "You may create a new space object here.";
                    }
                }
                else
                {
                    // Is this necessary?
                    _player = null;
                }
            }
        }
 public GalaxyIndexViewModel(IAuthenticationService authenticationService, IObjectService objectService, int seed, bool saveSeed, string galaxyName = "Default", string cookie = "")
 {
     _seed    = seed;
     _success = false;
     _authenticationService = authenticationService;
     _objectService         = objectService;
     _galaxy = CasualGodComplex.Galaxy.Generate(new CasualGodComplex.Galaxies.Spiral(), new Random(seed)).Result;
     // For personalization, load in some player details.
     if (!string.IsNullOrEmpty(cookie))
     {
         // Try to look up the player using their session Identifier (just a basic cookie)
         GetPlayerByCookieResponse playerByWebCookie = _authenticationService.GetPlayerByWebCookie(cookie);
         // The method returns a container object that has .Success property set to TRUE when the
         // player was found via a cookie that was not expired.
         if (playerByWebCookie.Success == true)
         {
             _player = playerByWebCookie.Player;
             if (saveSeed == true)
             {
                 if (_player.IsAdmin)
                 {
                     GalaxyContainer ctr = new GalaxyContainer(galaxyName);
                     ctr.SetGalaxy(_galaxy);
                     SaveGalaxyResponse response = _objectService.SaveGalaxyContainer(ctr);
                     _success = response.Success;
                     if (_success)
                     {
                         _message = "Saved galaxy as " + galaxyName;
                     }
                     else
                     {
                         _message = "Tried to save galaxy as " + galaxyName + " but failed.";
                     }
                 }
                 else
                 {
                     _success = false;
                     _message = "Cannot save galaxy because you are not an administrator.";
                 }
             }
             else
             {
                 _message = "Fill in the form to save this galaxy.";
             }
         }
         else
         {
             // Is this necessary?
             _player  = null;
             _message = "You are not logged in, no attempt to save will be made.";
         }
     }
 }
        /// <summary>
        /// Check the database for something in the cookie collection that is valid, then retrieve the matching player.
        /// </summary>
        /// <param name="cookie">A long-lived session token usually issued to players on logging on the website.</param>
        public GetPlayerByCookieResponse GetPlayerByWebCookie(string cookie)
        {
            GetPlayerByCookieResponse result = new GetPlayerByCookieResponse();
            WebSession webSession            = _wrapper.WebSessionRepository.GetOne <WebSession>(f => f.SessionCookie == cookie);

            if (webSession != null && webSession.Expiry > DateTime.UtcNow)
            {
                result.Player  = _wrapper.PlayerRepository.GetOne <Player>(f => f.Id == webSession.UserId);
                result.Success = true;
            }
            else
            {
                result.Player  = new Player();
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public ItemsIndexViewModel(IAuthenticationService authenticationService, IObjectService objectService, string cookie = "")
        {
            _authenticationService = authenticationService;
            _objectService         = objectService;
            _shipTemplates         = new List <ShipTemplate>();
            _shipModules           = new List <ShipModule>();
            GetAllShipTemplatesResponse templatesResponse = _objectService.GetAllShipTemplates();
            GetAllShipModulesResponse   modulesResponse   = _objectService.GetAllShipModules();

            if (templatesResponse.Success == true)
            {
                _shipTemplates = templatesResponse.ShipTemplates;
            }
            else
            {
                _shipTemplates = new List <ShipTemplate>();
            }

            if (modulesResponse.Success == true)
            {
                _shipModules = modulesResponse.ShipModules;
            }
            else
            {
                _shipModules = new List <ShipModule>();
            }

            // For personalization, load in some player details.
            if (!string.IsNullOrEmpty(cookie))
            {
                // Try to look up the player using their session Identifier (just a basic cookie)
                GetPlayerByCookieResponse playerByWebCookie = _authenticationService.GetPlayerByWebCookie(cookie);
                // The method returns a container object that has .Success property set to TRUE when the
                // player was found via a cookie that was not expired.
                if (playerByWebCookie.Success == true)
                {
                    _player = playerByWebCookie.Player;
                }
                else
                {
                    // Is this necessary?
                    _player = null;
                }
            }
        }
Exemplo n.º 5
0
        public IActionResult Index()
        {
            var    viewModel = new AccountIndexViewModel();
            string sessionId = _cookie.Get("SpacePlanetsSession");

            if (string.IsNullOrEmpty(sessionId))
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                GetPlayerByCookieResponse playerByCookie = _authenticationService.GetPlayerByWebCookie(sessionId);
                if (playerByCookie.Success == true)
                {
                    viewModel.Message = "Welcome, " + playerByCookie.Player.Username;
                    viewModel.GetCharactersByPlayerIdResponse = _gameService.GetCharactersByPlayerId(playerByCookie.Player.Id);
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            return(View(viewModel));
        }