好多新内容
This commit is contained in:
@@ -1377,6 +1377,7 @@ namespace GameServer.Client
|
||||
data["display_name"]?.ToString(),
|
||||
data["avatar_url"]?.ToString());
|
||||
}
|
||||
Enqueue(() => ApplyHonorUpdate(data));
|
||||
_socialConnectedTcs?.TrySetResult(true);
|
||||
return;
|
||||
case "unread_count":
|
||||
@@ -1454,6 +1455,11 @@ namespace GameServer.Client
|
||||
Enqueue(() => ApplyPresenceUpdate(presence));
|
||||
return;
|
||||
}
|
||||
case "honor_updated":
|
||||
{
|
||||
Enqueue(() => ApplyHonorUpdate(data));
|
||||
return;
|
||||
}
|
||||
case "presence_updated":
|
||||
return;
|
||||
case "friend_removed":
|
||||
@@ -2126,13 +2132,169 @@ namespace GameServer.Client
|
||||
|
||||
entry.friend_name = NetworkManager.ResolveDisplayName(presence.display_name, presence.steam_id, false);
|
||||
entry.friend_avatar = NetworkManager.ResolveAvatarUrl(presence.avatar_url, presence.steam_id);
|
||||
entry.player_title_id = presence.player_title_id ?? string.Empty;
|
||||
entry.player_title = presence.player_title ?? string.Empty;
|
||||
entry.online = !string.Equals(presence.status, "OFFLINE", StringComparison.OrdinalIgnoreCase);
|
||||
entry.status = presence.status;
|
||||
|
||||
UpsertFriend(entry);
|
||||
ApplyTitleUpdate(presence.steam_id, entry.player_title_id, entry.player_title);
|
||||
OnFriendsListChanged?.Invoke(GetFriendsSnapshot());
|
||||
}
|
||||
|
||||
private void ApplyHonorUpdate(JObject data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string steamId = data["steam_id"]?.ToString();
|
||||
if (string.IsNullOrWhiteSpace(steamId))
|
||||
{
|
||||
steamId = NetworkManager.Instance != null ? NetworkManager.Instance.SteamId : string.Empty;
|
||||
}
|
||||
|
||||
JObject primaryHonor = data["primary_honor"] as JObject;
|
||||
string titleId = primaryHonor?["honor_key"]?.ToString() ?? data["player_title_id"]?.ToString() ?? string.Empty;
|
||||
string title = primaryHonor?["honor_name"]?.ToString() ?? data["player_title"]?.ToString() ?? string.Empty;
|
||||
ApplyTitleUpdate(steamId, titleId, title);
|
||||
}
|
||||
|
||||
private void ApplyTitleUpdate(string steamId, string titleId, string title)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(steamId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string safeTitleId = titleId ?? string.Empty;
|
||||
string safeTitle = title ?? string.Empty;
|
||||
bool roomChanged = ApplyTitleToCurrentRoom(steamId, safeTitleId, safeTitle);
|
||||
bool friendsChanged = ApplyTitleToFriends(steamId, safeTitleId, safeTitle);
|
||||
bool roomChatChanged = ApplyTitleToMessages(_roomChatMessages, steamId, safeTitleId, safeTitle);
|
||||
bool worldChatChanged = ApplyTitleToMessages(_worldChatMessages, steamId, safeTitleId, safeTitle);
|
||||
bool privateChatChanged = false;
|
||||
|
||||
foreach (List<ArenaRoomChatMessage> messages in _privateChatMessages.Values)
|
||||
{
|
||||
privateChatChanged |= ApplyTitleToMessages(messages, steamId, safeTitleId, safeTitle);
|
||||
}
|
||||
|
||||
if (roomChanged)
|
||||
{
|
||||
OnRoomSnapshotChanged?.Invoke(CurrentRoom);
|
||||
}
|
||||
|
||||
if (friendsChanged)
|
||||
{
|
||||
OnFriendsListChanged?.Invoke(GetFriendsSnapshot());
|
||||
}
|
||||
|
||||
if (roomChatChanged)
|
||||
{
|
||||
OnRoomChatMessagesChanged?.Invoke(GetRoomChatMessages());
|
||||
}
|
||||
|
||||
if (worldChatChanged)
|
||||
{
|
||||
OnWorldChatMessagesChanged?.Invoke(GetWorldChatMessages());
|
||||
}
|
||||
|
||||
if (privateChatChanged)
|
||||
{
|
||||
foreach (string partnerId in _privateChatMessages.Keys.ToList())
|
||||
{
|
||||
OnPrivateChatMessagesChanged?.Invoke(partnerId, GetPrivateChatMessages(partnerId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool ApplyTitleToCurrentRoom(string steamId, string titleId, string title)
|
||||
{
|
||||
if (CurrentRoom == null || CurrentRoom.participants == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
foreach (ArenaRoomParticipant participant in CurrentRoom.participants)
|
||||
{
|
||||
if (participant == null || !string.Equals(participant.steam_id, steamId, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.Equals(participant.player_title_id ?? string.Empty, titleId, StringComparison.Ordinal))
|
||||
{
|
||||
participant.player_title_id = titleId;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!string.Equals(participant.player_title ?? string.Empty, title, StringComparison.Ordinal))
|
||||
{
|
||||
participant.player_title = title;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private bool ApplyTitleToFriends(string steamId, string titleId, string title)
|
||||
{
|
||||
if (!_friends.TryGetValue(steamId, out SocialFriendEntry friend) || friend == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
if (!string.Equals(friend.player_title_id ?? string.Empty, titleId, StringComparison.Ordinal))
|
||||
{
|
||||
friend.player_title_id = titleId;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!string.Equals(friend.player_title ?? string.Empty, title, StringComparison.Ordinal))
|
||||
{
|
||||
friend.player_title = title;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static bool ApplyTitleToMessages(IEnumerable<ArenaRoomChatMessage> messages, string steamId, string titleId, string title)
|
||||
{
|
||||
if (messages == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
foreach (ArenaRoomChatMessage message in messages)
|
||||
{
|
||||
if (message == null || !string.Equals(GetChatMessageSteamId(message), steamId, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.Equals(message.player_title_id ?? string.Empty, titleId, StringComparison.Ordinal))
|
||||
{
|
||||
message.player_title_id = titleId;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!string.Equals(message.player_title ?? string.Empty, title, StringComparison.Ordinal))
|
||||
{
|
||||
message.player_title = title;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void RemoveFriend(string steamId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(steamId))
|
||||
@@ -2947,6 +3109,16 @@ namespace GameServer.Client
|
||||
participant.avatar_url = existing.avatar_url;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(participant.player_title_id))
|
||||
{
|
||||
participant.player_title_id = existing.player_title_id;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(participant.player_title))
|
||||
{
|
||||
participant.player_title = existing.player_title;
|
||||
}
|
||||
|
||||
if (participant.join_order <= 0)
|
||||
{
|
||||
participant.join_order = existing.join_order;
|
||||
|
||||
@@ -107,6 +107,22 @@ namespace GameServer.Client
|
||||
[JsonProperty("total_plays")] public int total_plays;
|
||||
[JsonProperty("actime")] public string actime;
|
||||
[JsonProperty("u_reg_id")] public int u_reg_id;
|
||||
[JsonProperty("player_title_id")] public string player_title_id;
|
||||
[JsonProperty("player_title")] public string player_title;
|
||||
[JsonProperty("primary_honor")] public HonorData primary_honor;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class HonorData
|
||||
{
|
||||
[JsonProperty("id")] public int id;
|
||||
[JsonProperty("honor_key")] public string honor_key;
|
||||
[JsonProperty("honor_name")] public string honor_name;
|
||||
[JsonProperty("honor_desc")] public string honor_desc;
|
||||
[JsonProperty("honor_tier")] public string honor_tier;
|
||||
[JsonProperty("granted_by")] public string granted_by;
|
||||
[JsonProperty("granted_at")] public string granted_at;
|
||||
[JsonProperty("expires_at")] public string expires_at;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -285,6 +301,8 @@ namespace GameServer.Client
|
||||
[JsonProperty("uid")] public int uid;
|
||||
[JsonProperty("display_name")] public string display_name;
|
||||
[JsonProperty("avatar_url")] public string avatar_url;
|
||||
[JsonProperty("player_title_id")] public string player_title_id;
|
||||
[JsonProperty("player_title")] public string player_title;
|
||||
[JsonProperty("is_host")] public bool is_host;
|
||||
[JsonProperty("is_ready")] public bool is_ready;
|
||||
[JsonProperty("join_order")] public int join_order;
|
||||
@@ -337,6 +355,7 @@ namespace GameServer.Client
|
||||
[JsonProperty("receiver_id")] public string receiver_id;
|
||||
[JsonProperty("uid")] public int uid;
|
||||
[JsonProperty("display_name")] public string display_name;
|
||||
[JsonProperty("player_title_id")] public string player_title_id;
|
||||
[JsonProperty("player_title")] public string player_title;
|
||||
[JsonProperty("avatar_url")] public string avatar_url;
|
||||
[JsonProperty("content")] public string content;
|
||||
@@ -371,6 +390,8 @@ namespace GameServer.Client
|
||||
[JsonProperty("uid")] public int uid;
|
||||
[JsonProperty("friend_name")] public string friend_name;
|
||||
[JsonProperty("friend_avatar")] public string friend_avatar;
|
||||
[JsonProperty("player_title_id")] public string player_title_id;
|
||||
[JsonProperty("player_title")] public string player_title;
|
||||
[JsonProperty("online")] public bool online;
|
||||
[JsonProperty("status")] public string status;
|
||||
[JsonProperty("since")] public string since;
|
||||
@@ -476,6 +497,8 @@ namespace GameServer.Client
|
||||
[JsonProperty("uid")] public int uid;
|
||||
[JsonProperty("display_name")] public string display_name;
|
||||
[JsonProperty("avatar_url")] public string avatar_url;
|
||||
[JsonProperty("player_title_id")] public string player_title_id;
|
||||
[JsonProperty("player_title")] public string player_title;
|
||||
[JsonProperty("status")] public string status;
|
||||
}
|
||||
|
||||
|
||||
@@ -366,6 +366,7 @@ public class NetworkManager : MonoBehaviour
|
||||
}
|
||||
|
||||
ProfileData data = await GetJson<ProfileData>(BuildApiUrl($"/api/profile/{targetSteamId}"), CancellationToken.None);
|
||||
NormalizeProfileTitle(data);
|
||||
CacheIdentity(targetSteamId, data != null ? data.display_name : null, data != null ? data.avatar_url : null);
|
||||
return data;
|
||||
}
|
||||
@@ -439,11 +440,35 @@ public class NetworkManager : MonoBehaviour
|
||||
}
|
||||
|
||||
ProfileData data = await GetJson<ProfileData>(BuildApiUrl($"/api/players/uid/{uid}"), CancellationToken.None);
|
||||
NormalizeProfileTitle(data);
|
||||
string identitySteamId = data != null ? data.steam_id : null;
|
||||
CacheIdentity(identitySteamId, data != null ? data.display_name : null, data != null ? data.avatar_url : null);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static void NormalizeProfileTitle(ProfileData data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.primary_honor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(data.player_title_id))
|
||||
{
|
||||
data.player_title_id = data.primary_honor.honor_key;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(data.player_title))
|
||||
{
|
||||
data.player_title = data.primary_honor.honor_name;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SteamFriendsImportResponse> ImportSteamFriends(IEnumerable<string> steamFriends)
|
||||
{
|
||||
if (OnlineModeSettings.IsLocalOnlyMode)
|
||||
|
||||
Reference in New Issue
Block a user