From 680eb7619a453f5e74ceb570aad786eb650e435b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 19:45:06 +0000 Subject: [PATCH 1/3] Initial plan From 809420e49322bbf329439de813906e1540595a46 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 19:51:16 +0000 Subject: [PATCH 2/3] Improve exception handling and code quality in Turbo.Rooms Co-authored-by: billsonnn <1469194+billsonnn@users.noreply.github.com> --- Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs | 94 +-------- Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs | 104 ++-------- Turbo.Rooms/Grains/RoomGrain.cs | 4 - Turbo.Rooms/RoomService.cs | 204 +++++++++----------- Turbo.Rooms/Wired/WiredContext.cs | 4 +- 5 files changed, 121 insertions(+), 289 deletions(-) diff --git a/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs b/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs index 5ebd6af4..943e719a 100644 --- a/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs +++ b/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; using Turbo.Primitives.Action; using Turbo.Primitives.Furniture.Snapshots.WiredData; using Turbo.Primitives.Inventory.Snapshots; @@ -18,19 +19,7 @@ public sealed partial class RoomGrain { public async Task AddFloorItemAsync(IRoomFloorItem item, CancellationToken ct) { - try - { - if (!await _actionModule.AddFloorItemAsync(item, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.AddFloorItemAsync(item, ct); } public async Task PlaceFloorItemAsync( @@ -42,19 +31,7 @@ public async Task PlaceFloorItemAsync( CancellationToken ct ) { - try - { - if (!await _actionModule.PlaceFloorItemAsync(ctx, item, x, y, rot, ct)) - return false; - - return true; - } - catch (Exception) - { - // TODO handle exceptions - - return false; - } + return await _actionModule.PlaceFloorItemAsync(ctx, item, x, y, rot, ct); } public async Task MoveFloorItemByIdAsync( @@ -66,19 +43,7 @@ public async Task MoveFloorItemByIdAsync( CancellationToken ct ) { - try - { - if (!await _actionModule.MoveFloorItemByIdAsync(ctx, itemId, x, y, rot, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.MoveFloorItemByIdAsync(ctx, itemId, x, y, rot, ct); } public async Task RemoveFloorItemByIdAsync( @@ -87,19 +52,7 @@ public async Task RemoveFloorItemByIdAsync( CancellationToken ct ) { - try - { - if (!await _actionModule.RemoveFloorItemByIdAsync(ctx, itemId, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.RemoveFloorItemByIdAsync(ctx, itemId, ct); } public async Task UseFloorItemByIdAsync( @@ -109,19 +62,7 @@ public async Task UseFloorItemByIdAsync( int param = -1 ) { - try - { - if (!await _actionModule.UseFloorItemByIdAsync(ctx, itemId, ct, param)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.UseFloorItemByIdAsync(ctx, itemId, ct, param); } public async Task ClickFloorItemByIdAsync( @@ -131,19 +72,7 @@ public async Task ClickFloorItemByIdAsync( int param = -1 ) { - try - { - if (!await _actionModule.ClickFloorItemByIdAsync(ctx, itemId, ct, param)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.ClickFloorItemByIdAsync(ctx, itemId, ct, param); } public async Task ApplyWiredUpdateAsync( @@ -155,16 +84,11 @@ CancellationToken ct { try { - if (!await _actionModule.ApplyWiredUpdateAsync(ctx, itemId, update, ct)) - return false; - - return true; + return await _actionModule.ApplyWiredUpdateAsync(ctx, itemId, update, ct); } catch (Exception ex) { - Console.WriteLine(ex); - // TODO handle exceptions - + _logger.LogError(ex, "Failed to apply wired update for item {ItemId} in room {RoomId}", itemId, _roomId); return false; } } diff --git a/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs b/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs index ebeb2ea4..652749cc 100644 --- a/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs +++ b/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs @@ -14,19 +14,7 @@ public sealed partial class RoomGrain { public async Task AddWallItemAsync(IRoomWallItem item, CancellationToken ct) { - try - { - if (!await _actionModule.AddWallItemAsync(item, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.AddWallItemAsync(item, ct); } public async Task PlaceWallItemAsync( @@ -40,19 +28,7 @@ public async Task PlaceWallItemAsync( CancellationToken ct ) { - try - { - if (!await _actionModule.PlaceWallItemAsync(ctx, item, x, y, z, wallOffset, rot, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.PlaceWallItemAsync(ctx, item, x, y, z, wallOffset, rot, ct); } public async Task MoveWallItemByIdAsync( @@ -66,30 +42,16 @@ public async Task MoveWallItemByIdAsync( CancellationToken ct ) { - try - { - if ( - !await _actionModule.MoveWallItemByIdAsync( - ctx, - itemId, - newX, - newY, - newZ, - wallOffset, - newRot, - ct - ) - ) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.MoveWallItemByIdAsync( + ctx, + itemId, + newX, + newY, + newZ, + wallOffset, + newRot, + ct + ); } public async Task RemoveWallItemByIdAsync( @@ -98,19 +60,7 @@ public async Task RemoveWallItemByIdAsync( CancellationToken ct ) { - try - { - if (!await _actionModule.RemoveWallItemByIdAsync(ctx, itemId, ct)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.RemoveWallItemByIdAsync(ctx, itemId, ct); } public async Task UseWallItemByIdAsync( @@ -120,19 +70,7 @@ public async Task UseWallItemByIdAsync( int param = -1 ) { - try - { - if (!await _actionModule.UseWallItemByIdAsync(ctx, itemId, ct, param)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.UseWallItemByIdAsync(ctx, itemId, ct, param); } public async Task ClickWallItemByIdAsync( @@ -142,19 +80,7 @@ public async Task ClickWallItemByIdAsync( int param = -1 ) { - try - { - if (!await _actionModule.ClickWallItemByIdAsync(ctx, itemId, ct, param)) - return false; - - return true; - } - catch - { - // TODO handle exceptions - - return false; - } + return await _actionModule.ClickWallItemByIdAsync(ctx, itemId, ct, param); } public Task GetWallItemSnapshotByIdAsync( diff --git a/Turbo.Rooms/Grains/RoomGrain.cs b/Turbo.Rooms/Grains/RoomGrain.cs index e710025b..d48aa94f 100644 --- a/Turbo.Rooms/Grains/RoomGrain.cs +++ b/Turbo.Rooms/Grains/RoomGrain.cs @@ -235,10 +235,6 @@ await dbCtx.Rooms.AsNoTracking().SingleOrDefaultAsync(e => e.Id == (int)_roomId, LastUpdatedUtc = DateTime.UtcNow, }; } - catch (Exception) - { - throw; - } finally { await dbCtx.DisposeAsync(); diff --git a/Turbo.Rooms/RoomService.cs b/Turbo.Rooms/RoomService.cs index 13c33fac..d6e14704 100644 --- a/Turbo.Rooms/RoomService.cs +++ b/Turbo.Rooms/RoomService.cs @@ -39,42 +39,35 @@ public async Task OpenRoomForPlayerIdAsync( CancellationToken ct ) { - try - { - var playerPresence = _grainFactory.GetPlayerPresenceGrain(playerId); - var pendingRoom = await playerPresence.GetPendingRoomAsync().ConfigureAwait(false); - - if (pendingRoom.RoomId == roomId) - return; - - await playerPresence.ClearActiveRoomAsync(ct).ConfigureAwait(false); - await playerPresence.SetPendingRoomAsync(roomId, true).ConfigureAwait(false); - - // if owner => auto-approve - // if banned => reject - // if full => reject - // if passworded => reject (for now) - // if locked => reject (for now) - - var room = _grainFactory.GetRoomGrain(roomId); - var snapshot = await room.GetSnapshotAsync().ConfigureAwait(false); - - await playerPresence - .SendComposerAsync( - new OpenConnectionMessageComposer { RoomId = roomId }, - new RoomReadyMessageComposer - { - WorldType = snapshot.WorldType, - RoomId = roomId, - }, - new RoomRatingMessageComposer { Rating = 0, CanRate = false } - ) - .ConfigureAwait(false); - } - catch (Exception) - { - throw; - } + var playerPresence = _grainFactory.GetPlayerPresenceGrain(playerId); + var pendingRoom = await playerPresence.GetPendingRoomAsync().ConfigureAwait(false); + + if (pendingRoom.RoomId == roomId) + return; + + await playerPresence.ClearActiveRoomAsync(ct).ConfigureAwait(false); + await playerPresence.SetPendingRoomAsync(roomId, true).ConfigureAwait(false); + + // if owner => auto-approve + // if banned => reject + // if full => reject + // if passworded => reject (for now) + // if locked => reject (for now) + + var room = _grainFactory.GetRoomGrain(roomId); + var snapshot = await room.GetSnapshotAsync().ConfigureAwait(false); + + await playerPresence + .SendComposerAsync( + new OpenConnectionMessageComposer { RoomId = roomId }, + new RoomReadyMessageComposer + { + WorldType = snapshot.WorldType, + RoomId = roomId, + }, + new RoomRatingMessageComposer { Rating = 0, CanRate = false } + ) + .ConfigureAwait(false); } public async Task EnterPendingRoomForPlayerIdAsync( @@ -83,79 +76,72 @@ public async Task EnterPendingRoomForPlayerIdAsync( CancellationToken ct ) { - try - { - var playerPresence = _grainFactory.GetPlayerPresenceGrain(playerId); - var pendingRoom = await playerPresence.GetPendingRoomAsync().ConfigureAwait(false); - - if (pendingRoom.RoomId <= 0 || !pendingRoom.Approved) - return; - - var room = _grainFactory.GetRoomGrain(pendingRoom.RoomId); - - await room.EnsureRoomActiveAsync(ct).ConfigureAwait(false); - - var mapSnapshot = await room.GetMapSnapshotAsync(ct).ConfigureAwait(false); - var ownersSnapshot = await room.GetAllOwnersAsync(ct).ConfigureAwait(false); - var floorSnapshot = await room.GetAllFloorItemSnapshotsAsync(ct).ConfigureAwait(false); - var wallSnapshot = await room.GetAllWallItemSnapshotsAsync(ct).ConfigureAwait(false); - - await playerPresence - .SendComposerAsync( - new RoomEntryTileMessageComposer - { - X = mapSnapshot.DoorX, - Y = mapSnapshot.DoorY, - Rotation = mapSnapshot.DoorRotation, - }, - new HeightMapMessageComposer - { - Width = mapSnapshot.Width, - Size = mapSnapshot.Size, - Heights = mapSnapshot.TileEncodedHeights, - }, - new FloorHeightMapMessageComposer - { - ScaleType = _roomConfig.DefaultRoomScale, - FixedWallsHeight = _roomConfig.DefaultWallHeight, - ModelData = mapSnapshot.ModelData, - AreaHideData = [], - }, - new ObjectsMessageComposer - { - OwnerNames = ownersSnapshot, - FloorItems = floorSnapshot, - }, - new ItemsMessageComposer - { - OwnerNames = ownersSnapshot, - WallItems = wallSnapshot, - } - ) - .ConfigureAwait(false); - - var avatarSnapshot = await room.GetAllAvatarSnapshotsAsync(ct).ConfigureAwait(false); - - await playerPresence - .SendComposerAsync( - new UsersMessageComposer { Avatars = avatarSnapshot }, - new UserUpdateMessageComposer { Avatars = avatarSnapshot }, - new YouAreControllerMessageComposer - { - RoomId = pendingRoom.RoomId, - ControllerLevel = RoomControllerType.Owner, - }, - new WiredPermissionsEventMessageComposer { CanModify = true, CanRead = true }, - new YouAreOwnerMessageComposer { RoomId = pendingRoom.RoomId } - ) - .ConfigureAwait(false); - - await playerPresence.SetActiveRoomAsync(pendingRoom.RoomId, ct).ConfigureAwait(false); - } - catch (Exception) - { - throw; - } + var playerPresence = _grainFactory.GetPlayerPresenceGrain(playerId); + var pendingRoom = await playerPresence.GetPendingRoomAsync().ConfigureAwait(false); + + if (pendingRoom.RoomId <= 0 || !pendingRoom.Approved) + return; + + var room = _grainFactory.GetRoomGrain(pendingRoom.RoomId); + + await room.EnsureRoomActiveAsync(ct).ConfigureAwait(false); + + var mapSnapshot = await room.GetMapSnapshotAsync(ct).ConfigureAwait(false); + var ownersSnapshot = await room.GetAllOwnersAsync(ct).ConfigureAwait(false); + var floorSnapshot = await room.GetAllFloorItemSnapshotsAsync(ct).ConfigureAwait(false); + var wallSnapshot = await room.GetAllWallItemSnapshotsAsync(ct).ConfigureAwait(false); + + await playerPresence + .SendComposerAsync( + new RoomEntryTileMessageComposer + { + X = mapSnapshot.DoorX, + Y = mapSnapshot.DoorY, + Rotation = mapSnapshot.DoorRotation, + }, + new HeightMapMessageComposer + { + Width = mapSnapshot.Width, + Size = mapSnapshot.Size, + Heights = mapSnapshot.TileEncodedHeights, + }, + new FloorHeightMapMessageComposer + { + ScaleType = _roomConfig.DefaultRoomScale, + FixedWallsHeight = _roomConfig.DefaultWallHeight, + ModelData = mapSnapshot.ModelData, + AreaHideData = [], + }, + new ObjectsMessageComposer + { + OwnerNames = ownersSnapshot, + FloorItems = floorSnapshot, + }, + new ItemsMessageComposer + { + OwnerNames = ownersSnapshot, + WallItems = wallSnapshot, + } + ) + .ConfigureAwait(false); + + var avatarSnapshot = await room.GetAllAvatarSnapshotsAsync(ct).ConfigureAwait(false); + + await playerPresence + .SendComposerAsync( + new UsersMessageComposer { Avatars = avatarSnapshot }, + new UserUpdateMessageComposer { Avatars = avatarSnapshot }, + new YouAreControllerMessageComposer + { + RoomId = pendingRoom.RoomId, + ControllerLevel = RoomControllerType.Owner, + }, + new WiredPermissionsEventMessageComposer { CanModify = true, CanRead = true }, + new YouAreOwnerMessageComposer { RoomId = pendingRoom.RoomId } + ) + .ConfigureAwait(false); + + await playerPresence.SetActiveRoomAsync(pendingRoom.RoomId, ct).ConfigureAwait(false); } public async Task CloseRoomForPlayerAsync(PlayerId playerId, CancellationToken ct) diff --git a/Turbo.Rooms/Wired/WiredContext.cs b/Turbo.Rooms/Wired/WiredContext.cs index 729a8803..5731b914 100644 --- a/Turbo.Rooms/Wired/WiredContext.cs +++ b/Turbo.Rooms/Wired/WiredContext.cs @@ -68,7 +68,7 @@ CancellationToken ct { foreach (var sourceType in source) { - switch (sourceType) { } + // Player sources not yet implemented } } @@ -108,7 +108,7 @@ CancellationToken ct { foreach (var sourceType in source) { - switch (sourceType) { } + // Player sources not yet implemented } } From 45f78894ee49535b38fce034df3d0af33040be07 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 19:52:52 +0000 Subject: [PATCH 3/3] Add ConfigureAwait to simplified wrapper methods Co-authored-by: billsonnn <1469194+billsonnn@users.noreply.github.com> --- Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs | 14 +++++++------- Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs b/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs index 943e719a..3cec974f 100644 --- a/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs +++ b/Turbo.Rooms/Grains/RoomGrain.Furni.Floor.cs @@ -19,7 +19,7 @@ public sealed partial class RoomGrain { public async Task AddFloorItemAsync(IRoomFloorItem item, CancellationToken ct) { - return await _actionModule.AddFloorItemAsync(item, ct); + return await _actionModule.AddFloorItemAsync(item, ct).ConfigureAwait(false); } public async Task PlaceFloorItemAsync( @@ -31,7 +31,7 @@ public async Task PlaceFloorItemAsync( CancellationToken ct ) { - return await _actionModule.PlaceFloorItemAsync(ctx, item, x, y, rot, ct); + return await _actionModule.PlaceFloorItemAsync(ctx, item, x, y, rot, ct).ConfigureAwait(false); } public async Task MoveFloorItemByIdAsync( @@ -43,7 +43,7 @@ public async Task MoveFloorItemByIdAsync( CancellationToken ct ) { - return await _actionModule.MoveFloorItemByIdAsync(ctx, itemId, x, y, rot, ct); + return await _actionModule.MoveFloorItemByIdAsync(ctx, itemId, x, y, rot, ct).ConfigureAwait(false); } public async Task RemoveFloorItemByIdAsync( @@ -52,7 +52,7 @@ public async Task RemoveFloorItemByIdAsync( CancellationToken ct ) { - return await _actionModule.RemoveFloorItemByIdAsync(ctx, itemId, ct); + return await _actionModule.RemoveFloorItemByIdAsync(ctx, itemId, ct).ConfigureAwait(false); } public async Task UseFloorItemByIdAsync( @@ -62,7 +62,7 @@ public async Task UseFloorItemByIdAsync( int param = -1 ) { - return await _actionModule.UseFloorItemByIdAsync(ctx, itemId, ct, param); + return await _actionModule.UseFloorItemByIdAsync(ctx, itemId, ct, param).ConfigureAwait(false); } public async Task ClickFloorItemByIdAsync( @@ -72,7 +72,7 @@ public async Task ClickFloorItemByIdAsync( int param = -1 ) { - return await _actionModule.ClickFloorItemByIdAsync(ctx, itemId, ct, param); + return await _actionModule.ClickFloorItemByIdAsync(ctx, itemId, ct, param).ConfigureAwait(false); } public async Task ApplyWiredUpdateAsync( @@ -84,7 +84,7 @@ CancellationToken ct { try { - return await _actionModule.ApplyWiredUpdateAsync(ctx, itemId, update, ct); + return await _actionModule.ApplyWiredUpdateAsync(ctx, itemId, update, ct).ConfigureAwait(false); } catch (Exception ex) { diff --git a/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs b/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs index 652749cc..52217cc1 100644 --- a/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs +++ b/Turbo.Rooms/Grains/RoomGrain.Furni.Wall.cs @@ -14,7 +14,7 @@ public sealed partial class RoomGrain { public async Task AddWallItemAsync(IRoomWallItem item, CancellationToken ct) { - return await _actionModule.AddWallItemAsync(item, ct); + return await _actionModule.AddWallItemAsync(item, ct).ConfigureAwait(false); } public async Task PlaceWallItemAsync( @@ -28,7 +28,7 @@ public async Task PlaceWallItemAsync( CancellationToken ct ) { - return await _actionModule.PlaceWallItemAsync(ctx, item, x, y, z, wallOffset, rot, ct); + return await _actionModule.PlaceWallItemAsync(ctx, item, x, y, z, wallOffset, rot, ct).ConfigureAwait(false); } public async Task MoveWallItemByIdAsync( @@ -51,7 +51,7 @@ CancellationToken ct wallOffset, newRot, ct - ); + ).ConfigureAwait(false); } public async Task RemoveWallItemByIdAsync( @@ -60,7 +60,7 @@ public async Task RemoveWallItemByIdAsync( CancellationToken ct ) { - return await _actionModule.RemoveWallItemByIdAsync(ctx, itemId, ct); + return await _actionModule.RemoveWallItemByIdAsync(ctx, itemId, ct).ConfigureAwait(false); } public async Task UseWallItemByIdAsync( @@ -70,7 +70,7 @@ public async Task UseWallItemByIdAsync( int param = -1 ) { - return await _actionModule.UseWallItemByIdAsync(ctx, itemId, ct, param); + return await _actionModule.UseWallItemByIdAsync(ctx, itemId, ct, param).ConfigureAwait(false); } public async Task ClickWallItemByIdAsync( @@ -80,7 +80,7 @@ public async Task ClickWallItemByIdAsync( int param = -1 ) { - return await _actionModule.ClickWallItemByIdAsync(ctx, itemId, ct, param); + return await _actionModule.ClickWallItemByIdAsync(ctx, itemId, ct, param).ConfigureAwait(false); } public Task GetWallItemSnapshotByIdAsync(