/// <summary> /// Retrieves the game's configuration /// </summary> /// <returns>The game's configuration</returns> public object initializeClient(string connectionId, RegisteredClient rc) { if (!UserHandler.UserExistsAndReady(connectionId)) { _gameLock.Wait(); try { User user = null;//UserHandler.FindUserByIdentity(rc.Identity); Ship ship = null; if (user == null) { if (UserHandler.TotalActiveUsers >= 50 /*RuntimeConfiguration.MaxServerUsers*/) { return(new { ServerFull = true }); } else { ship = new Ship(this, RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager); ship.Name = rc.DisplayName; user = new User(connectionId, ship, rc) { Controller = false }; UserHandler.AddUser(user); } } 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 { } finally { _gameLock.Release(); } } return(null); }
public void SpawnAIShips(int number) { for (int i = 0; i < number; i++) { string connectionidAI = Guid.NewGuid().ToString(); ShipAI shipAI = new ShipAI(RespawnManager.GetRandomStartPosition(), GameHandler.BulletManager, this); UserAI userAI = new UserAI(connectionidAI, shipAI) { Controller = false }; UserHandler.AddUser(userAI); GameHandler.AddShipToGame(shipAI); } }
/// <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); }
public ShipManager(GameHandler gameHandler, Game game) { _respawnManager = new RespawnManager(gameHandler, game); }
public ShipManager(GameHandler gameHandler) { Ships = new ConcurrentDictionary<string, Ship>(); _gameHandler = gameHandler; _respawnManager = new RespawnManager(_gameHandler); }
public ShipManager(GameHandler gameHandler) { Ships = new ConcurrentDictionary <string, Ship>(); _gameHandler = gameHandler; _respawnManager = new RespawnManager(_gameHandler); }