-
Notifications
You must be signed in to change notification settings - Fork 36
Impersonation #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tabascq
wants to merge
4
commits into
PuzzleServer:main
Choose a base branch
from
tabascq:user/tabascq/Impersonation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Impersonation #1287
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,78 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace ServerCore.ModelBases | ||
| { | ||
| public enum EventRole | ||
| public class EventRole | ||
| { | ||
| // TODO: Expand to add impersonateplayer, when there is an advantage to doing so. | ||
| // Current sticking point is whether the perf of sync is such that we can turn it on for single player pregame. | ||
| // If sync is off for single payer puzzles, there's not much to see. | ||
|
|
||
| public EventRoleType Type { get; private set; } | ||
| public int ImpersonationId { get; private set; } | ||
| public bool IsImpersonating => Type == EventRoleType.impersonateteam; | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| if (!(obj is EventRole)) return false; | ||
| return this == (obj as EventRole); | ||
| } | ||
|
|
||
| public static bool operator ==(EventRole left, EventRole right) | ||
| { | ||
| if (Object.ReferenceEquals(left, null)) return Object.ReferenceEquals(right, null); | ||
| return !Object.ReferenceEquals(right, null) && left.Type == right.Type && left.ImpersonationId == right.ImpersonationId; | ||
| } | ||
|
|
||
| public static bool operator !=(EventRole left, EventRole right) | ||
| { | ||
| return !(left == right); | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return (IsImpersonating) ? $"{Type}-{ImpersonationId}" : Type.ToString(); | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| // revisit if we ever get more than 200M teams or players lol | ||
| Debug.Assert((1 << 3) > (int)Type); | ||
| return (ImpersonationId << 3) + (int)Type; | ||
| } | ||
|
|
||
| public static EventRole Parse(string s) | ||
| { | ||
| if (string.IsNullOrEmpty(s)) return null; | ||
| s = s.ToLower(); | ||
|
|
||
| if (s.StartsWith("impersonateteam-")) | ||
| { | ||
| bool parse = int.TryParse(s.Substring("impersonateteam-".Length), out int id); | ||
| if (!parse) | ||
| { | ||
| return new EventRole() { Type = EventRoleType.play }; | ||
| } | ||
| return new EventRole() { Type = EventRoleType.impersonateteam, ImpersonationId = id }; | ||
| } | ||
| else | ||
| { | ||
| EventRoleType type = Enum.IsDefined(typeof(EventRoleType), s) ? Enum.Parse<EventRoleType>(s): EventRoleType.play; | ||
| return new EventRole() { Type = type }; | ||
| } | ||
| } | ||
|
|
||
| public static EventRole admin = new EventRole() { Type = EventRoleType.admin }; | ||
| public static EventRole author = new EventRole() { Type = EventRoleType.author }; | ||
| public static EventRole play = new EventRole() { Type = EventRoleType.play }; | ||
| } | ||
|
|
||
| public enum EventRoleType | ||
| { | ||
| admin = 1, | ||
| author, | ||
| play | ||
| play, | ||
| impersonateteam | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.