Beispiel #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))
            {
                return(null);
            }

            try
            {
                User main = UserHandler.FindUserByIdentity(rc.Identity);

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

                    controllerUser.MySquare = main.MySquare;

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

                    return(new
                    {
                        Configuration = Configuration,
                    });
                }
                else
                {
                    return(new
                    {
                        FailureMessage = "Could not find logged in user to control."
                    });
                }
            }
            catch (Exception e)
            {
                //ErrorLog.Instance.Log(e);
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Sends down batches of data to the clients in order to update their screens
        /// </summary>
        private void Draw()
        {
            UserHandler.Update();

            ConcurrentDictionary <string, object[]> payloads = _payloadManager.GetGamePayloads(UserHandler.GetUsers(), UserHandler.TotalActiveUsers, _world);
            IHubContext context = GetContext();

            foreach (string connectionID in payloads.Keys)
            {
                UserHandler.GetUser(connectionID).PushToClient(payloads[connectionID], context);
            }
        }
Beispiel #3
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))
            {
                return(null);                // user already exists
            }
            // user does not exist. setup client
            try
            {
                lock (_locker)
                {
                    User   user = UserHandler.FindUserByIdentity(rc.Identity);
                    Square square;

                    if (user == null)
                    {
                        // user doesn't exist

                        if (UserHandler.TotalActiveUsers >= RuntimeConfiguration.MaxServerUsers)
                        {
                            // server is full!
                            return(new
                            {
                                ServerFull = true
                            });
                        }
                        else
                        {
                            // server is not full! generate a square for user
                            square      = new Square();
                            square.Name = rc.DisplayName;
                            user        = new User(connectionId, square, rc)
                            {
                                Controller = false
                            };
                            UserHandler.AddUser(user);
                        }
                    }
                    else
                    {
                        // user exists!
                        string previousConnectionID = user.ConnectionID;
                        UserHandler.ReassignUser(connectionId, user);
                        square = user.MySquare;

                        if (user.Connected)
                        {
                            // user already logged in
                            GetContext().Clients.Client(previousConnectionID).controlTransferred();
                        }
                        else
                        {
                            // user was not connected
                            square.Disposed = false;
                            user.Connected  = true;
                        }
                    }

                    GameHandler.AddSquareToGame(square);
                }

                return(new
                {
                    Configuration = Configuration,
                    ServerFull = false,
                    SquareID = UserHandler.GetUserSquare(connectionId).ID,
                    SquareName = UserHandler.GetUserSquare(connectionId).Name,
                    CompressionContracts = new
                    {
                        PayloadContract = _payloadManager.Compressor.PayloadCompressionContract,
                        SquareContract = _payloadManager.Compressor.SquareCompressionContract,
                        CollidableContract = _payloadManager.Compressor.CollidableCompressionContract,
                        EnemyContract = _payloadManager.Compressor.EnemyCompressionContract,
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                //ErrorLog.Instance.Log(e);
            }

            return(null);
        }
Beispiel #4
0
 public ConnectionManager(UserHandler userHandler, object locker)
 {
     _userHandler = userHandler;
     _locker      = locker;
 }