コード例 #1
0
ファイル: UserHandler.cs プロジェクト: JTtheGeek/ShootR
        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;
            }
        }
コード例 #2
0
ファイル: UserHandler.cs プロジェクト: JTtheGeek/ShootR
        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;
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: EugeneWang/ShootR
        /// <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;
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: EugeneWang/ShootR
        /// <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;
        }
コード例 #5
0
ファイル: PayloadManager.cs プロジェクト: AbhiLegend/ShootR
 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
     };
 }
コード例 #6
0
ファイル: UserHandler.cs プロジェクト: JTtheGeek/ShootR
 public void ReassignUser(string connectionId, User user)
 {
     _userList.TryRemove(user.ConnectionID, out user);
     user.ConnectionID = connectionId;
     _userList.TryAdd(connectionId, user);
 }