Ejemplo n.º 1
0
        public void AddUser(User user)
        {
            _userList.TryAdd(user.ConnectionID, user);
            user.IdleManager.OnIdle += _gameHandler.RemoveShipFromGame;
            user.IdleManager.OnIdleTimeout += DisconnectUser;
            user.IdleManager.OnComeBack += _gameHandler.AddShipToGame;

            if (!user.Controller)
            {
                user.MyShip.OnFire += _gameHandler.AddBulletToGame;
            }
        }
Ejemplo n.º 2
0
        public void DisconnectUser(User user)
        {
            RemoveUser(user.ConnectionID);
            foreach (User u in user.RemoteControllers)
            {
                DisconnectUser(u);
            }

            if (user.Connected)
            {
                Game.GetContext().Clients.Client(user.ConnectionID).disconnect();
            }

            user.Connected = false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves the game's configuration
        /// </summary>
        /// <returns>The game's configuration</returns>
        public object initializeController(string connectionId, RegisteredClient rc)
        {
            if (!UserHandler.UserExistsAndReady(connectionId))
            {
                try
                {
                    User main = UserHandler.FindUserByIdentity(rc.Identity);

                    if (main != null)
                    {
                        User controllerUser = new User(connectionId, rc) { Controller = true };

                        controllerUser.MyShip = main.MyShip;

                        UserHandler.AddUser(controllerUser);
                        main.RemoteControllers.Add(controllerUser);

                        main.NotificationManager.Notify("Controller attached.");

                        return new
                        {
                            Configuration = Configuration,
                            CompressionContracts = new
                            {
                                PayloadContract = _payloadManager.Compressor.PayloadCompressionContract,
                                CollidableContract = _payloadManager.Compressor.CollidableCompressionContract,
                                ShipContract = _payloadManager.Compressor.ShipCompressionContract,
                                BulletContract = _payloadManager.Compressor.BulletCompressionContract,
                                LeaderboardEntryCompressionContract = _payloadManager.Compressor.LeaderboardEntryCompressionContract
                            }
                        };
                    }
                    else
                    {
                        return new
                        {
                            FailureMessage = "Could not find logged in user to control."
                        };
                    }
                }
                catch (Exception e)
                {
                    ErrorLog.Instance.Log(e);
                }
            }

            return null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves the game's configuration
        /// </summary>
        /// <returns>The game's configuration</returns>
        public object initializeClient(string connectionId, RegisteredClient rc)
        {
            if (!UserHandler.UserExistsAndReady(connectionId))
            {
                try
                {
                    lock (_locker)
                    {
                        User user = UserHandler.FindUserByIdentity(rc.Identity);
                        Ship ship;

                        if (user == null)
                        {
                            if (UserHandler.TotalActiveUsers >= RuntimeConfiguration.MaxServerUsers)
                            {
                                return new
                                {
                                    ServerFull = true
                                };
                            }
                            else
                            {
                                ship = new Ship(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager);
                                ship.Name = rc.DisplayName;
                                user = new User(connectionId, ship, rc) { Controller = false };
                                UserHandler.AddUser(user);
                            }
                        }
                        else
                        {
                            string previousConnectionID = user.ConnectionID;
                            UserHandler.ReassignUser(connectionId, user);
                            ship = user.MyShip;

                            if (user.Connected) // Check if it's a duplicate login
                            {
                                GetContext().Clients.Client(previousConnectionID).controlTransferred();
                                user.NotificationManager.Notify("Transfering control to this browser.  You were already logged in.");
                            }
                            else
                            {
                                ship.Disposed = false;
                                ship.LifeController.HealFull();
                                user.Connected = true;
                            }

                            user.IdleManager.RecordActivity();
                            user.IdleManager.Idle = false;
                        }

                        GameHandler.AddShipToGame(ship);
                    }

                    return new
                    {
                        Configuration = Configuration,
                        ServerFull = false,
                        CompressionContracts = new
                        {
                            PayloadContract = _payloadManager.Compressor.PayloadCompressionContract,
                            CollidableContract = _payloadManager.Compressor.CollidableCompressionContract,
                            ShipContract = _payloadManager.Compressor.ShipCompressionContract,
                            BulletContract = _payloadManager.Compressor.BulletCompressionContract,
                            LeaderboardEntryContract = _payloadManager.Compressor.LeaderboardEntryCompressionContract,
                            PowerupContract = _payloadManager.Compressor.PowerupCompressionContract
                        },
                        ShipID = UserHandler.GetUserShip(connectionId).ID,
                        ShipName = UserHandler.GetUserShip(connectionId).Name
                    };
                }
                catch (Exception e)
                {
                    ErrorLog.Instance.Log(e);
                }
            }

            return null;
        }
Ejemplo n.º 5
0
 public Payload GetInitializedPayload(int playerCount, int bulletCount, User user)
 {
     return new Payload()
     {
         LeaderboardPosition = user.CurrentLeaderboardPosition,
         Kills = user.MyShip.StatRecorder.Kills,
         Deaths = user.MyShip.StatRecorder.Deaths,
         ShipsInWorld = playerCount,
         BulletsInWorld = bulletCount,
         Experience = user.MyShip.LevelManager.Experience,
         ExperienceToNextLevel = user.MyShip.LevelManager.ExperienceToNextLevel,
         Notification = user.NotificationManager.PullNotification(),
         LastCommandProcessed = user.LastCommandID
     };
 }
Ejemplo n.º 6
0
 public void ReassignUser(string connectionId, User user)
 {
     _userList.TryRemove(user.ConnectionID, out user);
     user.ConnectionID = connectionId;
     _userList.TryAdd(connectionId, user);
 }