/// <summary> /// On disconnect we need to remove the ship from our list of ships within the gameHandler. /// This also means we need to notify clients that the ship has been removed. /// </summary> public void OnDisconnected(string connectionId) { lock (_locker) { try { if (_userHandler.UserExistsAndReady(connectionId)) { User user = _userHandler.GetUser(connectionId); IHubContext context = Game.GetContext(); //It's possible for a controller to disconnect without a ship if (!user.Controller) { //user.MyShip.Dispose(); user.Connected = false; context.Clients.All.ChatRemoveUser(user.RegistrationTicket.UserId); } else { // Remove me from the ship hosts remote controllers //if (user.MyShip != null) //{ // user.MyShip.Host.RemoteControllers.Remove(user); // user.MyShip.Host.NotificationManager.Notify("Detached controller."); // user.MyShip = null; //} _userHandler.RemoveUser(connectionId); } // Leave the leaderboard group just in case user was in it //context.Groups.Remove(connectionId, Leaderboard.LEADERBOARD_REQUESTEE_GROUP); // Clear controllers /*foreach (User u in user.RemoteControllers) * { * //u.MyShip = null; * context.Clients.Client(u.ConnectionID).stopController("Primary account has been stopped!"); * } */ //user.RemoteControllers.Clear(); } } catch (Exception e) { Game.Instance.bc.writeExceptionToLog(e); } } }
/// <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.UserId); if (user == null) { // checkuserMaximum - not more than one million users if (UserHandler.TotalActiveUsers >= 1000000) { return(new { ServerFull = true }); } else { user = new User(connectionId, rc) { Controller = false }; UserHandler.AddUser(user); } } else { string previousConnectionID = user.ConnectionID; UserHandler.ReassignUser(connectionId, user); 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); } // var fields = bc.getUserBordersData(rc.UserId); /* * object[] result; * result = new object[fields.Count]; * for (int i = 0; i < 2; i++) * { * result[i] = fields[i]; * } * return new { x = result }; */ object ret = new { //Configuration = Configuration, ServerFull = false //BorderMap = bc.getUserBordersData(rc.UserId)[0] //works //BorderMap = fields /*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 }; return(ret); } catch (Exception e) { this.bc.writeExceptionToLog(e); } } return(null); }