This commit is contained in:
skidfire
2026-09-06 19:59:27 -04:00
parent 55d8e11a5d
commit fe3468c65d
247 changed files with 338183 additions and 0 deletions
+126
View File
@@ -0,0 +1,126 @@
using Vanadium.Classes.DBs;
using Vanadium.Controllers;
using Newtonsoft.Json;
namespace Vanadium.Hubs
{
public static class ApiHub
{
public static async Task GetFriendsList(long playerId)
{
try
{
var friends = FriendsDB.GetRelationships(playerId);
var message = JsonConvert.SerializeObject(new
{
target = "FriendsListResult",
data = friends
});
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error getting friends list: {ex.Message}");
}
}
public static async Task GetRelationships(long playerId)
{
try
{
var player = PlayerDB.Players.FindById(playerId);
var relationships = player?.Player?.Relationships ?? new();
var message = JsonConvert.SerializeObject(new
{
target = "RelationshipsResult",
data = relationships
});
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error getting relationships: {ex.Message}");
}
}
public static async Task SubscribeFriendUpdates(long playerId)
{
try
{
var response = JsonConvert.SerializeObject(new
{
type = 3,
result = (object?)null
});
await NotificationsController.SendToPlayer(playerId, response);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error subscribing to friend updates: {ex.Message}");
}
}
public static async Task SubscribeRelationshipUpdates(long playerId)
{
try
{
var response = JsonConvert.SerializeObject(new
{
type = 3,
result = (object?)null
});
await NotificationsController.SendToPlayer(playerId, response);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error subscribing to relationship updates: {ex.Message}");
}
}
public static async Task NotifyFriendRequest(long playerId, long fromPlayerId, string fromPlayerName)
{
try
{
var message = JsonConvert.SerializeObject(new
{
type = "friendRequest",
from = fromPlayerId,
fromName = fromPlayerName,
timestamp = DateTime.UtcNow
});
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error notifying friend request: {ex.Message}");
}
}
public static async Task NotifyRelationshipChanged(long playerId, long targetPlayerId, string relationshipType, string action)
{
try
{
var message = JsonConvert.SerializeObject(new
{
type = "relationshipChanged",
targetId = targetPlayerId,
relationshipType = relationshipType,
action = action,
timestamp = DateTime.UtcNow
});
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[ApiHub] Error notifying relationship change: {ex.Message}");
}
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.SignalR;
namespace Vanadium.Hubs
{
public abstract class AuthenticatedHub : Hub
{
protected long PlayerId
{
get
{
var raw = Context.UserIdentifier;
if (raw == null || !long.TryParse(raw, out var id))
throw new HubException("Unauthorized");
return id;
}
}
public override async Task OnConnectedAsync()
{
if (Context.UserIdentifier == null)
{
Context.Abort();
return;
}
await Groups.AddToGroupAsync(Context.ConnectionId, $"player:{PlayerId}");
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, $"player:{PlayerId}");
await base.OnDisconnectedAsync(exception);
}
}
}
+47
View File
@@ -0,0 +1,47 @@
using Vanadium.Controllers;
using Newtonsoft.Json;
namespace Vanadium.Hubs
{
public static class DiscordBotHub
{
public static async Task BroadcastBotEvent(string eventType, object payload)
{
try
{
var message = JsonConvert.SerializeObject(new
{
type = "botEvent",
eventType = eventType,
data = payload,
timestamp = DateTime.UtcNow
});
await NotificationsController.SendToAll(message);
}
catch (Exception ex)
{
Console.WriteLine($"[DiscordBotHub] Error broadcasting bot event: {ex.Message}");
}
}
public static async Task BroadcastBotMessage(string message)
{
try
{
var json = JsonConvert.SerializeObject(new
{
type = "botMessage",
message = message,
timestamp = DateTime.UtcNow
});
await NotificationsController.SendToAll(json);
}
catch (Exception ex)
{
Console.WriteLine($"[DiscordBotHub] Error broadcasting bot message: {ex.Message}");
}
}
}
}
+64
View File
@@ -0,0 +1,64 @@
using Vanadium.Classes.WebSocket;
using Vanadium.Controllers;
using Newtonsoft.Json;
namespace Vanadium.Hubs
{
public static class MatchHub
{
public static async Task BroadcastMatchUpdate(long matchId, object update)
{
try
{
var message = JsonConvert.SerializeObject(new WebsocketEvents.Response
{
Id = "MatchUpdate",
Msg = update
});
await NotificationsController.SendToAll(message);
}
catch (Exception ex)
{
Console.WriteLine($"[MatchHub] Error broadcasting match update: {ex.Message}");
}
}
public static async Task BroadcastPlayerHeartbeat(long playerId, object heartbeatData)
{
try
{
var message = JsonConvert.SerializeObject(new WebsocketEvents.Response
{
Id = "PresenceUpdate",
Msg = heartbeatData
});
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[MatchHub] Error broadcasting heartbeat: {ex.Message}");
}
}
public static async Task NotifyPlayerDisconnected(long matchId, long playerId)
{
try
{
var message = JsonConvert.SerializeObject(new
{
type = "playerDisconnected",
playerId = playerId,
matchId = matchId
});
await NotificationsController.SendToAll(message);
}
catch (Exception ex)
{
Console.WriteLine($"[MatchHub] Error notifying player disconnect: {ex.Message}");
}
}
}
}
+61
View File
@@ -0,0 +1,61 @@
namespace Vanadium.Hubs
{
public static class NotiEventTypes
{
public const string AccountUpdate = "AccountUpdate";
public const string SelfAccountUpdate = "SelfAccountUpdate";
public const string AnnouncementUpdate = "AnnouncementUpdate";
public const string AnnouncementDelete = "AnnouncementDelete";
public const string GiftManualConsumed = "gift.manualconsumed";
public const string ServerMaintenance = "ServerMaintenance";
public const string N30 = "30";
public const string N31 = "31";
public const string N32 = "32";
public const string ChatMessageReceived = "ChatMessageReceived";
public const string PlayerLeftChat = "PlayerLeftChat";
public const string ClubMembershipUpdate = "ClubMembershipUpdate";
public const string CreatorClubSubscriptionUpdate = "CreatorClubSubscriptionUpdate";
public const string CommerceSubscriptionUpdate = "CommerceSubscriptionUpdate";
public const string CommunityBoardUpdate = "CommunityBoardUpdate";
public const string N96 = "96";
public const string N70 = "70";
public const string N71 = "71";
public const string WebsiteInventionPurchase = "WebsiteInventionPurchase";
public const string RoomInstanceUpdate = "RoomInstanceUpdate";
public const string PresenceUpdate = "PresenceUpdate";
public const string GoToFailure = "GoToFailure";
public const string N2 = "2";
public const int ilovefemboys = 2;
public const string N3 = "3";
public const string AppVersionUpdate = "AppVersionUpdate";
public const string N80 = "80";
public const string N81 = "81";
public const string N82 = "82";
public const string N83 = "83";
public const string N84 = "84";
public const string N22 = "22";
public const string ModerationUnkick = "ModerationUnkick";
public const string N23 = "23";
public const string PlayerProgressionLevelUpdate = "PlayerProgressionLevelUpdate";
public const string N1 = "1";
public const string ReputationUpdate = "ReputationUpdate";
public const string RoomUpdate = "RoomUpdate";
public const string PhotonAccessToken = "PhotonAccessToken";
public const string N60 = "60";
public const string N62 = "62";
public const string N61 = "61";
public const string RoomCommentDeleted = "RoomCommentDeleted";
public const string N120 = "120";
public const string N121 = "121";
public const string RewardSelectionReceived = "RewardSelectionReceived";
public const string RoomCurrencyCreated = "RoomCurrencyCreated";
public const string RoomCurrencyModified = "RoomCurrencyModified";
public const string RoomCurrencyDeleted = "RoomCurrencyDeleted";
public const string InfluencerSupportedUpdate = "InfluencerSupportedUpdate";
public const string ProgressionEventsRecordUpdate = "ProgressionEventsRecordUpdate";
public const string PlayerCustomAvatarItemModerated = "PlayerCustomAvatarItemModerated";
public const string RrsPushToDevice = "rrs.pushtodevice";
public const string KeepsakeInstanceAdded = "KeepsakeInstanceAdded";
public const string KeepsakeInstanceRemoved = "KeepsakeInstanceRemoved";
}
}
+50
View File
@@ -0,0 +1,50 @@
using Vanadium.Classes.WebSocket;
using Newtonsoft.Json;
using Vanadium.Controllers;
namespace Vanadium.Hubs
{
public static class NotificationHub
{
public static async Task SubscribeToPlayers()
{
await Task.CompletedTask;
}
public static async Task SubscribeToRooms()
{
await Task.CompletedTask;
}
public static async Task SubscribeToEvents()
{
await Task.CompletedTask;
}
public static async Task SendNotificationToPlayer(long playerId, object notification)
{
try
{
var message = JsonConvert.SerializeObject(notification);
await NotificationsController.SendToPlayer(playerId, message);
}
catch (Exception ex)
{
Console.WriteLine($"[NotificationHub] Error sending notification: {ex.Message}");
}
}
public static async Task SendNotificationToAll(object notification)
{
try
{
var message = JsonConvert.SerializeObject(notification);
await NotificationsController.SendToAll(message);
}
catch (Exception ex)
{
Console.WriteLine($"[NotificationHub] Error broadcasting notification: {ex.Message}");
}
}
}
}
+63
View File
@@ -0,0 +1,63 @@
using Vanadium.Classes.WebSocket;
using Vanadium.Controllers;
using Newtonsoft.Json;
using static Vanadium.Classes.DBs.DBClasses.RoomDBClasses;
namespace Vanadium.Hubs
{
public static class RoomHub
{
public static async Task BroadcastRoomUpdate(long roomId, object update)
{
try
{
var message = JsonConvert.SerializeObject(new WebsocketEvents.Response
{
Id = "RoomUpdate",
Msg = update
});
await NotificationsController.SendToAll(message);
}
catch (Exception ex)
{
Console.WriteLine($"[RoomHub] Error broadcasting room update: {ex.Message}");
}
}
public static async Task NotifyRoomOwners(Room room, object message)
{
try
{
var json = JsonConvert.SerializeObject(message);
await NotificationsController.SendToPlayer(room.CreatorAccountId, json);
if (room.Roles != null)
{
foreach (var role in room.Roles.Where(r => r.Role == Role.CoOwner || r.Role == Role.Creator))
{
await NotificationsController.SendToPlayer(role.AccountId, json);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"[RoomHub] Error notifying room owners: {ex.Message}");
}
}
public static async Task NotifyRoomSubscribers(long roomId, object message)
{
try
{
var json = JsonConvert.SerializeObject(message);
await NotificationsController.SendToAll(json);
}
catch (Exception ex)
{
Console.WriteLine($"[RoomHub] Error notifying room subscribers: {ex.Message}");
}
}
}
}
+293
View File
@@ -0,0 +1,293 @@
using Vanadium.Classes.DBs;
using Vanadium.Hubs;
using static Vanadium.Classes.DBs.DBClasses.PlayerDBClasses;
namespace Vanadium.Classes.WebSocket
{
public class WebsocketEvents
{
public class Response
{
public string? Id { get; set; }
public object? Msg { get; set; }
}
public static Response CreatePlayerUpdatedAccountResponse(long playerId)
{
var account = PlayerDB.GetAccountMe(playerId);
return new Response
{
Id = "PlayerUpdatedAccount",
Msg = account
};
}
public static Response CreateClubMembershipUpdateResponse(long clubMemberId, long accountId, long clubId, int membershipType, DateTime createdAt, int invitedMembershipType = 0)
{
return new Response
{
Id = NotiEventTypes.ClubMembershipUpdate,
Msg = new
{
ClubMemberId = clubMemberId,
AccountId = accountId,
ClubId = clubId,
MembershipType = membershipType,
CreatedAt = createdAt,
InvitedMembershipType = invitedMembershipType
}
};
}
public static Response CreateCreatorClubSubscriptionUpdateResponse(long creatorAccountId, long clubId, int membershipType)
{
return new Response
{
Id = NotiEventTypes.CreatorClubSubscriptionUpdate,
Msg = new
{
creatorAccountId = creatorAccountId,
clubId = clubId,
membershipType = membershipType
}
};
}
public static Response CreateSubResponse(ulong playerId, int membershipType)
{
return new Response
{
Id = ((int)ResponseResults.SubscriptionUpdateProfile).ToString(),
Msg = new Sub
{
creatorAccountId = playerId,
clubId = 1,
membershipType = membershipType
}
};
}
public static Response CreateLevelUpdateResponse(long playerId, int level, int xp)
{
return new Response
{
Id = "PlayerProgressionLevelUpdate",
Msg = new
{
PlayerId = playerId,
Level = level,
XP = xp
}
};
}
public static Response CreateReputationUpdateResponse(long playerId)
{
var player = PlayerDB.GetCurrentPlayer(playerId);
var rep = player?.Player?.Reputation ?? new Reputation();
bool isDev = player?.PlayerRoles?.Contains(PlayerRoles.Developer) ?? false;
return new Response
{
Id = "ReputationUpdate",
Msg = new
{
AccountId = playerId,
rep.IsCheerful,
rep.Noteriety,
rep.SelectedCheer,
rep.CheerCredit,
rep.CheerGeneral,
rep.CheerHelpful,
rep.CheerCreative,
rep.CheerGreatHost,
rep.CheerSportsman,
rep.SubscriberCount,
SubscribedCount = rep.SubscribedCount,
RecRoomDeveloper = isDev
}
};
}
public static Response CreateMessageResponse(MessageData messageData, long forPlayerId)
{
return new Response
{
Id = "2",
Msg = new
{
messageData.Id,
messageData.Type,
messageData.Data,
messageData.RoomId,
messageData.PlayerEventId,
ForPlayerId = forPlayerId
}
};
}
public static Response CreateLogoutResponse()
{
return new Response
{
Id = ((int)ResponseResults.Logout).ToString(),
Msg = new { }
};
}
public static Response CreateBanResponse(ModerationBlockDetails block)
{
return new Response
{
Id = ((int)ResponseResults.ModerationKick).ToString(),
Msg = block
};
}
public static Response CreateRelationshipChangedResponse(long targetPlayerId, int relationshipType)
{
return new Response
{
Id = ((int)ResponseResults.RelationshipChanged).ToString(),
Msg = new
{
PlayerId = targetPlayerId,
RelationshipType = relationshipType
}
};
}
public static Response CreateWSEventString(string id, object obj)
{
return new Response
{
Id = id,
Msg = obj
};
}
/*public static Response CreateWSEventId(int id, object obj)
{
return new
{
Id = id,
Msg = obj
};
}*/
public enum NotificationType
{
ALL = -1,
NONE = 0,
Games = 1,
FriendRequests = 2,
FriendStatusOnline = 4,
Cheers = 8,
Rooms = 16,
Subscriptions = 32,
PlayerEvents = 64,
Clubs = 128,
CreatorFeedback = 256,
RoomNotifications = 512,
Deprecated = 1073741824,
NoOptOut = -2147483648
}
public enum ResponseResults // got both from february 2024 decomp :fire:
{
RelationshipChanged = 1,
MessageReceived,
MessageDeleted,
PresenceHeartbeatResponse,
RefreshLogin,
Logout,
SubscriptionUpdateProfile = 11,
SubscriptionUpdatePresence,
SubscriptionUpdateGameSession,
SubscriptionUpdateRoom = 15,
SubscriptionUpdateRoomPlaylist,
ModerationQuitGame = 20,
ModerationUpdateRequired,
ModerationKick,
ModerationKickAttemptFailed,
ModerationRoomBan,
ServerMaintenance = 25,
GiftPackageReceived = 30,
GiftPackageReceivedImmediate,
GiftPackageRewardSelectionReceived,
ProfileJuniorStatusUpdate = 40,
RelationshipsInvalid = 50,
StorefrontBalanceAdd = 60,
StorefrontBalanceUpdate,
StorefrontBalancePurchase,
ConsumableMappingAdded = 70,
ConsumableMappingRemoved,
PlayerEventCreated = 80,
PlayerEventUpdated,
PlayerEventDeleted,
PlayerEventResponseChanged,
PlayerEventResponseDeleted,
PlayerEventStateChanged,
ChatMessageReceived = 90,
CommunityBoardUpdate = 95,
CommunityBoardAnnouncementUpdate,
InventionModerationStateChanged = 100,
FreeGiftButtonItemsAdded = 110,
LocalRoomKeyCreated = 120,
LocalRoomKeyDeleted
}
public enum WebsocketMessageType
{
DEPRECATED_GameInvite,
GameInviteDeclined,
GameJoinFailed,
DEPRECATED_PartyActivitySwitch,
FriendInvite,
VoteToKick,
GameInviteV2,
PartyActivitySwitchV2,
PartyInvite,
RequestGameInvite = 10,
RequestGameInviteDeclined,
FriendStatusOnline = 20,
TextMessage = 30,
FriendRequestAccepted = 40,
FriendCodeUsed,
PlayerCheer = 50,
PlayerCheerAnonymous,
RoomCoOwnerAdded = 60,
RoomCoOwnerRemoved,
RoomCoOwnerInvited,
RoomTranslationCompleted,
RoomModerationCompleted,
CreatorPublishedNewRoom = 70,
PlayerAttendingEvent = 80,
PlayerEventInvitation,
DEPRECATED_GroupInvitation = 90,
DEPRECATED_PlayerJoinedGroup,
CoachMessage = 100,
NewRoomComments = 110,
FriendIntroduction = 130,
ClubMemberInvited = 200,
ClubModeratorInvited,
ClubCoownerInvited,
RoomEarningsDistributionCoOwnerAdded = 210,
RoomEarningsDistributionCoOwnerRemoved,
RoomEarningsDistributionPercentageUpdated,
ModerationActionApplied = 300,
VirtualClubAnnouncementRoomPublished = 100000,
VirtualClubAnnouncementInventionPublished,
VirtualClubAnnouncementGeneric,
VirtualClubAnnouncementPlayerEventPublished,
VirtualClubAnnouncementClub,
VirtualClubAnnouncementPlayer,
VirtualClubAnnouncementCode,
VirtualClubAnnouncementPhoto,
VirtualRoomNotification,
VirtualBroadcastingRequest,
VirtualLeagueAssignment,
VirtualPartyUpRequest
}
}
}