FriendRequestToken
A class in Root.Township, the global namespace.
A player's friend token: hand it to another player and, if both sides report the handover within 2 seconds, the server sends a friend request through the API. Not saved.
- Listed in Global namespace: E to H
- Inherits or implements
ActionItem - Nested types
FriendshipSyncResult
Constructors
| Member | What it is |
|---|---|
FriendRequestToken() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
16 private and internal fields
| Member | What it is |
|---|---|
private PositionEvent alreadyFriendsEffect | Effect played when the players were already friends. |
private IAnalyticsService analyticsService | Analytics service used to log friend requests. |
private PositionEvent deniedFriendshipEffect | Effect played when the request did not result in a friendship. |
private HoverPickup hoverPickup | Hover component the token returns to when let go. |
private static readonly Logger logger | NLog logger for this class. |
private int maxNameLength | Serialized name length limit. Not used in this code. |
private TextRenderer[] nameRenderers | Text renderers that show the owner's name. |
private PositionEvent newFriendshipEffect | Effect played when a new friendship is made. |
private int otherTokenId | User ID of the other player in the current handover, or -1. |
private Pickup pickup | The token's pickup. |
private bool receivedOwnerToken | Server: true once the owner's side of the handover has arrived. |
private float releaseTimeout | Owner client: time until which a grab by someone else counts as a handover, or -1. |
private MethodSyncStruct<int> syncFriendshipRequest | Method sync for handover reports. Note it uses the syncFriendshipRequestEffect message type. |
private MethodSyncStruct<int> syncFriendshipRequestEffect | Method sync for the result effect. Note it uses the syncFriendshipRequest message type. |
private Timeline.IEntry timelineEntry | Pending timeout call. |
private const float TimeoutTime | Handover window in seconds (2). |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the request and effect sync messages. |
void Inject(IAnalyticsService analyticsService) | VContainer injection of the analytics service. |
14 private and internal methods
| Member | What it is |
|---|---|
private async void AddFriend() | Server: checks the API for an existing friendship, sends a friend request if needed, updates both players' friend lists and syncs the result effect. |
private void Awake() | Stops the pickup saving and hooks its filter, grab and release events; clients also update the name on owner change. |
private void CallFriendshipEvent(Player player, Player friend, FriendshipInfo friendship) | Adds the other player to a player's FriendshipManager from the API's friendship info. |
private void Filter(Interactor interactor, Interactable interactable, ref bool result) | Lets the local player grab the token only if they own it or the owner is holding it. |
private void Grabbed(Interactable interactable, Interactor interactor) | When a non-owner takes it, both the taker's client and the owner's client (if released in the last 2 seconds) send the handover to the server. |
private void Hover(Interactable interactable, Interactor interactor) | On release, puts the token back on its hover point; for the owner, starts the 2 second handover window. |
private void OnDestroy() | Cancels the pending timeout. |
private void RunEffects(FriendRequestToken.FriendshipSyncResult friendshipSyncResult) | Client: plays the new friend, already friends or denied effect at the token. |
private void SyncFriendRequestForPlayer(int friendID) | Server: handles the owner's report; adds the friend if the other side already reported, else remembers it. |
private void SyncFriendRequestForTokenOwner(IPlayer player) | Server: handles the taker's report; adds the friend if the owner already reported, else remembers the taker. |
private void SyncFriendshipRequest(IPlayer player, Stream stream, int friendID) | Server: reads a handover report, starts the timeout on the first one and routes it by sender. |
private void SyncFriendshipRequestEffect(IPlayer player, Stream stream, int friendshipResultIndex) | Client: reads the result, plays its effect and marks the player as a friend on success. |
private void TimeoutFade() | Server: clears a half-finished handover after 2 seconds and fades the token out. |
private void UpdateName(IPlayer owner) | Client: writes the owner's username on the name renderers and adds them to materialize. |