Property "controller" in "NetworkIdentity"#252
Conversation
📝 WalkthroughWalkthroughAdds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs`:
- Line 320: Change the controller property to return a non-nullable PlayerID by
updating its return type from PlayerID? to PlayerID and return owner ??
PlayerID.Server so callers never get a nullable; update the property signature
named "controller" and ensure it references the existing "owner" field and
"PlayerID.Server" constant using the null-coalescing operator.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 436c0f52-c303-4e9d-84f5-f6a66fe9f04c
📒 Files selected for processing (1)
Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs
…ity.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
This isn't fully correct; owner can also be disconnected with the persistent rules. So the most correct would be to check if |
…nectedOwner and ownerHasAuthority).
There was a problem hiding this comment.
♻️ Duplicate comments (1)
Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs (1)
292-299:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winReturn a non-nullable
PlayerIDfromGetController.On Line 292, the method is typed as nullable, but current branches always resolve to a concrete controller. Keeping
PlayerID?preserves unnecessary null handling for callers and weakens the convenience API this PR introduces.🔧 Proposed fix
-public PlayerID? GetController(bool ownerHasAuthority) +public PlayerID GetController(bool ownerHasAuthority) { if (!ownerHasAuthority) return PlayerID.Server; if (!hasConnectedOwner) return PlayerID.Server; - return owner; + return owner.Value; }#!/bin/bash # Verify the signature and inspect call sites for nullable handling/casts. ast-grep --pattern $'public PlayerID? GetController(bool ownerHasAuthority) { $$$ }' rg -n -C2 --type=cs '\bGetController\s*\('🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs` around lines 292 - 299, The method GetController currently returns a nullable PlayerID but all code paths return a concrete PlayerID (using PlayerID.Server or owner); change the signature from PlayerID? to PlayerID and update any call sites if they expect null; specifically edit the public PlayerID? GetController(bool ownerHasAuthority) to public PlayerID GetController(bool ownerHasAuthority), keep the existing branches that return PlayerID.Server when !ownerHasAuthority or !hasConnectedOwner and return owner otherwise, and search for usages of GetController to remove any unnecessary null-checks/casts introduced by the nullable signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs`:
- Around line 292-299: The method GetController currently returns a nullable
PlayerID but all code paths return a concrete PlayerID (using PlayerID.Server or
owner); change the signature from PlayerID? to PlayerID and update any call
sites if they expect null; specifically edit the public PlayerID?
GetController(bool ownerHasAuthority) to public PlayerID GetController(bool
ownerHasAuthority), keep the existing branches that return PlayerID.Server when
!ownerHasAuthority or !hasConnectedOwner and return owner otherwise, and search
for usages of GetController to remove any unnecessary null-checks/casts
introduced by the nullable signature.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5049cd12-6ba1-4608-a9e3-6154e75b6d96
📒 Files selected for processing (1)
Assets/PurrNet/Runtime/Components/NetworkIdentity/NetworkIdentity.cs
Minor update to the
NetworkIdentitycomponent: a new property,controlleradded to provide a convenient way to determine the owner, defaulting toPlayerID.Serverif there is no explicit owner.Use case:
It avoids checking if the owner is null and getting the Server instead.
Summary by CodeRabbit