Skip to content

Commit

Permalink
update to API 5, consolidate hubs into one
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanley Dimant committed Jul 13, 2022
1 parent 4a83a7d commit a416521
Show file tree
Hide file tree
Showing 21 changed files with 910 additions and 421 deletions.
96 changes: 39 additions & 57 deletions MareSynchronosServer/MareSynchronos.API/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,51 @@

namespace MareSynchronos.API
{
public class API
public class Api
{
public const int Version = 4;
}

public class FilesHubAPI
{
public const string Path = "/files";
public const int Version = 5;
public const string Path = "/mare";

public const string SendAbortUpload = "AbortUpload";
public const string InvokeSendFiles = "SendFiles";
public const string InvokeIsUploadFinished = "IsUploadFinished";
public const string SendUploadFileStreamAsync = "UploadFileStreamAsync";
public const string InvokeGetFileSize = "GetFileSize";
public const string StreamDownloadFileAsync = "StreamDownloadFileAsync";
public const string SendDeleteAllFiles = "DeleteAllFiles";
}
public const string SendFileAbortUpload = "AbortUpload";
public const string InvokeFileSendFiles = "SendFiles";
public const string InvokeFileIsUploadFinished = "IsUploadFinished";
public const string SendFileUploadFileStreamAsync = "UploadFileStreamAsync";
public const string InvokeFileGetFileSize = "GetFileSize";
public const string StreamFileDownloadFileAsync = "StreamDownloadFileAsync";
public const string SendFileDeleteAllFiles = "DeleteAllFiles";

public class ConnectionHubAPI
{
public const string Path = "/heartbeat";
public const string InvokeHeartbeat = "Heartbeat";
public const string InvokeGetSystemInfo = "GetSystemInfo";
public const string OnUpdateSystemInfo = "OnUpdateSystemInfo";
}

public class AdminHubAPI
{
public const string Path = "/admin";

public const string InvokeGetOnlineUsers = "GetOnlineUsers";
public const string InvokeGetBannedUsers = "GetBannedUsers";
public const string SendUpdateOrAddBannedUser = "UpdateOrAddBannedUser";
public const string SendDeleteBannedUser = "DeleteBannedUser";
public const string InvokeGetForbiddenFiles = "GetForbiddenFiles";
public const string SendUpdateOrAddForbiddenFile = "UpdateOrAddForbiddenFile";
public const string SendDeleteForbiddenFile = "DeleteForbiddenFile";
public const string SendChangeModeratorStatus = "ChangeModeratorStatus";

public const string OnForcedReconnect = "ForcedReconnect";
public const string OnUpdateOrAddBannedUser = "UpdateOrAddBannedUser";
public const string OnDeleteBannedUser = "DeleteBannedUser";
public const string OnUpdateOrAddForbiddenFile = "UpdateOrAddForbiddenFile";
public const string OnDeleteForbiddenFile = "DeleteForbiddenFile";
}

public class UserHubAPI
{
public const string Path = "/user";

public const string InvokeGetOnlineUsers = "GetOnlineUsers";
public const string InvokeRegister = "Register";
public const string InvokePushCharacterDataToVisibleClients = "PushCharacterDataToVisibleClients";
public const string InvokeGetOnlineCharacters = "GetOnlineCharacters";
public const string SendPairedClientAddition = "SendPairedClientAddition";
public const string SendPairedClientRemoval = "SendPairedClientRemoval";
public const string SendPairedClientPauseChange = "SendPairedClientPauseChange";
public const string InvokeGetPairedClients = "GetPairedClients";
public const string SendDeleteAccount = "DeleteAccount";

public const string OnUpdateClientPairs = "UpdateClientPairs";
public const string OnReceiveCharacterData = "ReceiveCharacterData";
public const string OnRemoveOnlinePairedPlayer = "RemoveOnlinePairedPlayer";
public const string OnAddOnlinePairedPlayer = "AddOnlinePairedPlayer";
public const string InvokeAdminGetOnlineUsers = "AdminGetOnlineUsers";
public const string InvokeAdminGetBannedUsers = "GetBannedUsers";
public const string SendAdminUpdateOrAddBannedUser = "UpdateOrAddBannedUser";
public const string SendAdminDeleteBannedUser = "DeleteBannedUser";
public const string InvokeAdminGetForbiddenFiles = "GetForbiddenFiles";
public const string SendAdminUpdateOrAddForbiddenFile = "UpdateOrAddForbiddenFile";
public const string SendAdminDeleteForbiddenFile = "DeleteForbiddenFile";
public const string SendAdminChangeModeratorStatus = "ChangeModeratorStatus";

public const string OnAdminForcedReconnect = "OnForcedReconnect";
public const string OnAdminUpdateOrAddBannedUser = "OnUpdateOrAddBannedUser";
public const string OnAdminDeleteBannedUser = "OnDeleteBannedUser";
public const string OnAdminUpdateOrAddForbiddenFile = "OnUpdateOrAddForbiddenFile";
public const string OnAdminDeleteForbiddenFile = "OnDeleteForbiddenFile";

public const string InvokeUserGetOnlineUsers = "GetOnlineUsers";
public const string InvokeUserRegister = "Register";
public const string InvokeUserPushCharacterDataToVisibleClients = "PushCharacterDataToVisibleClients";
public const string InvokeUserGetOnlineCharacters = "GetOnlineCharacters";
public const string SendUserPairedClientAddition = "SendPairedClientAddition";
public const string SendUserPairedClientRemoval = "SendPairedClientRemoval";
public const string SendUserPairedClientPauseChange = "SendPairedClientPauseChange";
public const string InvokeUserGetPairedClients = "GetPairedClients";
public const string SendUserDeleteAccount = "DeleteAccount";

public const string OnUserUpdateClientPairs = "UpdateClientPairs";
public const string OnUserReceiveCharacterData = "ReceiveCharacterData";
public const string OnUserRemoveOnlinePairedPlayer = "RemoveOnlinePairedPlayer";
public const string OnUserAddOnlinePairedPlayer = "AddOnlinePairedPlayer";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -32,7 +30,8 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()

using var sha256 = SHA256.Create();
var hashedHeader = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(authHeader))).Replace("-", "");
var uid = (await _mareDbContext.Users.AsNoTracking().FirstOrDefaultAsync(m => m.SecretKey == hashedHeader))?.UID;
var uid = (await _mareDbContext.Auth.Include("User").AsNoTracking()
.FirstOrDefaultAsync(m => m.HashedKey == hashedHeader))?.UserUID;

if (uid == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections.Generic;
using MareSynchronos.API;
using MareSynchronosServer.Models;
using MareSynchronosServer.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace MareSynchronosServer.Data
{
Expand All @@ -17,12 +14,16 @@ public MareDbContext(DbContextOptions<MareDbContext> options) : base(options)
public DbSet<ClientPair> ClientPairs { get; set; }
public DbSet<ForbiddenUploadEntry> ForbiddenUploadEntries { get; set; }
public DbSet<Banned> BannedUsers { get; set; }
public DbSet<Auth> Auth { get; set; }


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Auth>().ToTable("Auth");
modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<User>().HasIndex(c => c.CharacterIdentification);
modelBuilder.Entity<FileCache>().ToTable("FileCaches");
modelBuilder.Entity<FileCache>().HasIndex(c => c.UploaderUID);
modelBuilder.Entity<ClientPair>().ToTable("ClientPairs");
modelBuilder.Entity<ClientPair>().HasKey(u => new { u.UserUID, u.OtherUserUID });
modelBuilder.Entity<ClientPair>().HasIndex(c => c.UserUID);
Expand Down
51 changes: 0 additions & 51 deletions MareSynchronosServer/MareSynchronosServer/Hubs/BaseHub.cs

This file was deleted.

62 changes: 0 additions & 62 deletions MareSynchronosServer/MareSynchronosServer/Hubs/ConnectionHub.cs

This file was deleted.

Loading

0 comments on commit a416521

Please sign in to comment.