/// <summary>
        /// Converts dbUser to User and adds it to Users list
        /// </summary>
        /// <param name="dbUser"></param>
        public void addUserFromDB(DBUser dbUser)
        {
            User user = new User(dbUser, this);

            Ship ship = new ShipBuilder().BuildShip(user,
                new PresetShipRepository().GetShip(dbUser.ShipPresetId),
                dbUser.CellTypes);

            //Form array of Cells to be used in JavaScript
            ArrayInstance[] array = new ArrayInstance[ship.cells.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = user.engine.Array.New(ship.cells[i]);

                for (int j = 0; j < ship.cells[i].Length; j++)
                {
                    if (ship.cells[i][j] is CellEngine)
                    {
                        ((CellEngine)ship.cells[i][j]).repository = this;
                    }
                }
            }
            user.engine.SetGlobalValue("cells", user.engine.Array.New(array));
            user.engine.SetGlobalValue("radar", new Radar(user));

            Action<string> logAction = delegate(string s) { user.Log.Add(s); };
            user.engine.SetGlobalFunction("log", logAction);

            user.Login = dbUser.Username;
            user.PasswordHash = dbUser.PasswordHash;
            user.Code = dbUser.Code;
            user.Credits = dbUser.Credits;
            user.ship = ship;
            _users.Add(user);
        }
Exemple #2
0
        /// <summary>
        /// Converts dbUser to User and adds it to Users list
        /// </summary>
        /// <param name="dbUser"></param>
        public void addUserFromDB(DBUser dbUser)
        {
            User user = new User(dbUser, this);

            Ship ship = new ShipBuilder().BuildShip(user,
                                                    new PresetShipRepository().GetShip(dbUser.ShipPresetId),
                                                    dbUser.CellTypes);

            //Form array of Cells to be used in JavaScript
            ArrayInstance[] array = new ArrayInstance[ship.cells.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = user.engine.Array.New(ship.cells[i]);

                for (int j = 0; j < ship.cells[i].Length; j++)
                {
                    if (ship.cells[i][j] is CellEngine)
                    {
                        ((CellEngine)ship.cells[i][j]).repository = this;
                    }
                }
            }
            user.engine.SetGlobalValue("cells", user.engine.Array.New(array));
            user.engine.SetGlobalValue("radar", new Radar(user));

            Action <string> logAction = delegate(string s) { user.Log.Add(s); };

            user.engine.SetGlobalFunction("log", logAction);

            user.Login        = dbUser.Username;
            user.PasswordHash = dbUser.PasswordHash;
            user.Code         = dbUser.Code;
            user.Credits      = dbUser.Credits;
            user.ship         = ship;
            _users.Add(user);
        }