You've already forked CC-Framework.BriskGameServer
389 lines
15 KiB
C#
389 lines
15 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
internal static class BriskModelMapper
|
|
{
|
|
public static BriskLoginResult ToLoginResult(Dictionary<string, object> data)
|
|
{
|
|
var profileData = BriskValueReader.GetDictionary(data, "profile");
|
|
return new BriskLoginResult
|
|
{
|
|
AccessToken = BriskValueReader.GetString(data, "access_token"),
|
|
ExpiresIn = BriskValueReader.GetInt(data, "expires_in"),
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
|
LoginProvider = BriskValueReader.GetString(profileData, "login_provider"),
|
|
LoginUserId = BriskValueReader.GetString(profileData, "login_user_id"),
|
|
IsNewPlayer = BriskValueReader.GetBool(data, "is_new_player"),
|
|
Profile = ToProfile(profileData)
|
|
};
|
|
}
|
|
|
|
public static BriskBootstrapResult ToBootstrapResult(Dictionary<string, object> data)
|
|
{
|
|
return new BriskBootstrapResult
|
|
{
|
|
ProjectName = BriskValueReader.GetString(data, "project_name"),
|
|
ServerTime = BriskValueReader.GetString(data, "server_time"),
|
|
MaintenanceMode = BriskValueReader.GetBool(data, "maintenance_mode"),
|
|
MaintenanceMessage = BriskValueReader.GetString(data, "maintenance_message"),
|
|
MinClientVersion = BriskValueReader.GetString(data, "min_client_version"),
|
|
FeatureFlags = BriskValueReader.GetDictionary(data, "feature_flags") ?? new Dictionary<string, object>(),
|
|
DynamicConfig = BriskValueReader.GetDictionary(data, "dynamic_config") ?? new Dictionary<string, object>()
|
|
};
|
|
}
|
|
|
|
public static BriskConfigCurrent ToConfigCurrent(Dictionary<string, object> data)
|
|
{
|
|
return new BriskConfigCurrent
|
|
{
|
|
FeatureFlags = BriskValueReader.GetDictionary(data, "feature_flags") ?? new Dictionary<string, object>(),
|
|
DynamicConfig = BriskValueReader.GetDictionary(data, "dynamic_config") ?? new Dictionary<string, object>()
|
|
};
|
|
}
|
|
|
|
public static BriskPlayerMe ToPlayerMe(Dictionary<string, object> data)
|
|
{
|
|
return new BriskPlayerMe
|
|
{
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
|
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
|
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
|
ProfileJson = BriskValueReader.GetDictionary(data, "profile_json")
|
|
};
|
|
}
|
|
|
|
public static BriskProfile ToProfile(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskProfile
|
|
{
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
|
ProfileJson = BriskValueReader.GetDictionary(data, "profile_json")
|
|
};
|
|
}
|
|
|
|
public static BriskLeaderboardEntry ToLeaderboardEntry(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskLeaderboardEntry
|
|
{
|
|
Rank = BriskValueReader.GetInt(data, "rank"),
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
|
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
|
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
|
Score = BriskValueReader.GetLong(data, "score"),
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url")
|
|
};
|
|
}
|
|
|
|
public static BriskLeaderboardPlayerRank ToLeaderboardPlayerRank(Dictionary<string, object> data)
|
|
{
|
|
var entry = ToLeaderboardEntry(data);
|
|
if (entry == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskLeaderboardPlayerRank
|
|
{
|
|
Rank = entry.Rank,
|
|
Score = entry.Score,
|
|
PlayerId = entry.PlayerId,
|
|
ProjectAccountId = entry.ProjectAccountId,
|
|
LoginProvider = entry.LoginProvider,
|
|
LoginUserId = entry.LoginUserId,
|
|
Nickname = entry.Nickname,
|
|
AvatarUrl = entry.AvatarUrl
|
|
};
|
|
}
|
|
|
|
public static BriskRankSeasonInfo ToRankSeasonInfo(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskRankSeasonInfo
|
|
{
|
|
SeasonId = BriskValueReader.GetString(data, "season_id") ?? BriskValueReader.GetString(data, "id"),
|
|
Name = BriskValueReader.GetString(data, "name"),
|
|
StartAt = BriskValueReader.GetString(data, "start_at"),
|
|
EndAt = BriskValueReader.GetString(data, "end_at")
|
|
};
|
|
}
|
|
|
|
public static List<BriskLeaderboardEntry> ToLeaderboardEntries(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToLeaderboardEntry(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static List<BriskRankSeasonInfo> ToRankSeasonInfos(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToRankSeasonInfo(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static BriskAnnouncementItem ToAnnouncementItem(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskAnnouncementItem
|
|
{
|
|
Id = BriskValueReader.GetLong(data, "id"),
|
|
Title = BriskValueReader.GetString(data, "title"),
|
|
Content = BriskValueReader.GetString(data, "content"),
|
|
ContentType = BriskValueReader.GetString(data, "content_type"),
|
|
StartAt = BriskValueReader.GetString(data, "start_at"),
|
|
EndAt = BriskValueReader.GetString(data, "end_at"),
|
|
IsRead = BriskValueReader.GetBool(data, "is_read")
|
|
};
|
|
}
|
|
|
|
public static List<BriskAnnouncementItem> ToAnnouncementItems(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToAnnouncementItem(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static BriskArchiveSlot ToArchiveSlot(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskArchiveSlot
|
|
{
|
|
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
|
Version = BriskValueReader.GetInt(data, "version"),
|
|
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static BriskArchiveMeta ToArchiveMeta(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskArchiveMeta
|
|
{
|
|
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
|
Version = BriskValueReader.GetInt(data, "version"),
|
|
Checksum = BriskValueReader.GetString(data, "checksum"),
|
|
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static BriskArchiveUploadResult ToArchiveUploadResult(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskArchiveUploadResult
|
|
{
|
|
SlotNo = BriskValueReader.GetInt(data, "slot_no"),
|
|
Version = BriskValueReader.GetInt(data, "version"),
|
|
SizeBytes = BriskValueReader.GetLong(data, "size_bytes"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static List<BriskArchiveSlot> ToArchiveSlots(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToArchiveSlot(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static BriskSpaceView ToSpaceView(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceView
|
|
{
|
|
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
|
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
|
ContentExists = BriskValueReader.GetBool(data, "content_exists"),
|
|
ContentVersion = BriskValueReader.GetLong(data, "content_version"),
|
|
ContentType = BriskValueReader.GetString(data, "content_type"),
|
|
ContentSizeBytes = BriskValueReader.GetLong(data, "content_size_bytes"),
|
|
ContentChecksum = BriskValueReader.GetString(data, "content_checksum"),
|
|
LikeCount = BriskValueReader.GetLong(data, "like_count"),
|
|
VisitCount = BriskValueReader.GetLong(data, "visit_count"),
|
|
LikedByMe = BriskValueReader.GetBool(data, "liked_by_me"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static BriskSpaceStats ToSpaceStats(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceStats
|
|
{
|
|
ProjectAccountId = BriskValueReader.GetString(data, "project_account_id"),
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
LoginProvider = BriskValueReader.GetString(data, "login_provider"),
|
|
LoginUserId = BriskValueReader.GetString(data, "login_user_id"),
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
|
ContentExists = BriskValueReader.GetBool(data, "content_exists"),
|
|
ContentVersion = BriskValueReader.GetLong(data, "content_version"),
|
|
ContentType = BriskValueReader.GetString(data, "content_type"),
|
|
ContentSizeBytes = BriskValueReader.GetLong(data, "content_size_bytes"),
|
|
ContentChecksum = BriskValueReader.GetString(data, "content_checksum"),
|
|
LikeCount = BriskValueReader.GetLong(data, "like_count"),
|
|
VisitCount = BriskValueReader.GetLong(data, "visit_count"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static BriskSpaceContentUpdateResult ToSpaceContentUpdateResult(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceContentUpdateResult
|
|
{
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
ContentVersion = BriskValueReader.GetLong(data, "content_version"),
|
|
ContentType = BriskValueReader.GetString(data, "content_type"),
|
|
ContentSizeBytes = BriskValueReader.GetLong(data, "content_size_bytes"),
|
|
ContentChecksum = BriskValueReader.GetString(data, "content_checksum"),
|
|
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
|
|
};
|
|
}
|
|
|
|
public static BriskSpaceLikeResult ToSpaceLikeResult(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceLikeResult
|
|
{
|
|
Liked = BriskValueReader.GetBool(data, "liked"),
|
|
LikeCount = BriskValueReader.GetLong(data, "like_count")
|
|
};
|
|
}
|
|
|
|
public static BriskSpaceVisit ToSpaceVisit(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceVisit
|
|
{
|
|
VisitorPlayerId = BriskValueReader.GetString(data, "visitor_player_id") ?? BriskValueReader.GetString(data, "player_id"),
|
|
VisitorLoginProvider = BriskValueReader.GetString(data, "visitor_login_provider") ?? BriskValueReader.GetString(data, "login_provider"),
|
|
VisitorLoginUserId = BriskValueReader.GetString(data, "visitor_login_user_id") ?? BriskValueReader.GetString(data, "login_user_id"),
|
|
VisitorNickname = BriskValueReader.GetString(data, "visitor_nickname") ?? BriskValueReader.GetString(data, "nickname"),
|
|
VisitorAvatarUrl = BriskValueReader.GetString(data, "visitor_avatar_url") ?? BriskValueReader.GetString(data, "avatar_url"),
|
|
VisitedAt = BriskValueReader.GetString(data, "visited_at")
|
|
};
|
|
}
|
|
|
|
public static List<BriskSpaceVisit> ToSpaceVisits(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToSpaceVisit(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static BriskSpaceLikeItem ToSpaceLikeItem(Dictionary<string, object> data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BriskSpaceLikeItem
|
|
{
|
|
PlayerId = BriskValueReader.GetString(data, "player_id"),
|
|
Nickname = BriskValueReader.GetString(data, "nickname"),
|
|
AvatarUrl = BriskValueReader.GetString(data, "avatar_url"),
|
|
CreatedAt = BriskValueReader.GetString(data, "created_at")
|
|
};
|
|
}
|
|
|
|
public static List<BriskSpaceLikeItem> ToSpaceLikeItems(object data)
|
|
{
|
|
return ExtractList(data)
|
|
.Select(item => ToSpaceLikeItem(item as Dictionary<string, object>))
|
|
.Where(item => item != null)
|
|
.ToList();
|
|
}
|
|
|
|
public static Dictionary<string, object> ExtractObject(object data)
|
|
{
|
|
return data as Dictionary<string, object>;
|
|
}
|
|
|
|
private static List<object> ExtractList(object data)
|
|
{
|
|
if (data is List<object> list)
|
|
{
|
|
return list;
|
|
}
|
|
|
|
if (data is Dictionary<string, object> dictionary)
|
|
{
|
|
return BriskValueReader.GetList(dictionary, "items")
|
|
?? BriskValueReader.GetList(dictionary, "list")
|
|
?? BriskValueReader.GetList(dictionary, "records")
|
|
?? new List<object>();
|
|
}
|
|
|
|
return new List<object>();
|
|
}
|
|
}
|