Example #1
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);
        }
Example #2
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);
        }