{"id":16204496,"url":"https://github.com/jasonxudeveloper/daserver","last_synced_at":"2025-03-19T07:31:18.714Z","repository":{"id":108806781,"uuid":"590945876","full_name":"JasonXuDeveloper/DaServer","owner":"JasonXuDeveloper","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-30T03:56:41.000Z","size":77,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T16:40:45.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JasonXuDeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-19T15:27:52.000Z","updated_at":"2024-10-14T06:23:27.000Z","dependencies_parsed_at":"2023-07-15T20:16:09.864Z","dependency_job_id":null,"html_url":"https://github.com/JasonXuDeveloper/DaServer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FDaServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FDaServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FDaServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JasonXuDeveloper%2FDaServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JasonXuDeveloper","download_url":"https://codeload.github.com/JasonXuDeveloper/DaServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976644,"owners_count":20377695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:58:26.877Z","updated_at":"2025-03-19T07:31:18.709Z","avatar_url":"https://github.com/JasonXuDeveloper.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DaServer\n\nA developing dotnet(C#) RPC server.\n\n\n\n## Architecture\n### Shared Architecture Diagram - Everything but Network\n```mermaid\n---\ntitle: Shared Architecture Diagram - Everything but Network\n---\nclassDiagram\n    class ComponentRole{\n        \u003c\u003cenumeration\u003e\u003e\n        LowLevel = 0\n        HighLevle = 1\n    }\n    class Component{\n        +ComponentHolder Owner\n        *ComponentRole Role =\u003e ComponentRole.HighLevel;\n        *int TimeInterval =\u003e 10;\n        +long LastExecuteTime = 0;\n        +Create() *Task\n        +Destroy() *Task\n        +Update(long currentMs) *Task\n    }\n    ComponentRole \u003c-- Component\n    class ComponentHolder{\n        +readonly List~Component~ Components\n        -readonly ConcurrentDictionary~Type,Component~ _cache\n        +AddComponent[T]() T?, where T: Component\n        +GetComponent[T]() T?, where T: Component\n        +RemoveComponent[T]() void, where T: Component\n        +RemoveAllComponents() void\n    }\n    ComponentHolder \u003c-- Component\n    class Entity{\n        +long Id\n        -Timer _timer\n        +long StartMs\n        +Enable()\n        +Disable()\n        +Update()\n    }\n    ComponentHolder --\u003e Entity\n    Entity  --\u003e Component : Invoke Update with Current UTC Time\n    class RemoteCall{\n        +int MsgId\n        +int RequestId\n        -byte[]? MessageData\n        +IMessage? MessageObj\n    }\n    class IMessage{\n        \u003c\u003cinterface\u003e\u003e\n        +int .attr Id\n    }\n    class MsgId{\n        +int Error = -1\n        +int Void = 0\n        ...\n    }\n    MessageFactory --\u003e IMessage\n    MessageFactory --\u003e RemoteCall \n    MessageFactory \u003c--\u003e MsgId\n    IMessage \u003c--\u003e MsgId\n    MsgId \u003c--\u003e RemoteCall\n    IMessage \u003c--\u003eRemoteCall\n    class MessageFactory{\n        -ConcurrentDictionary~Type,int~ MsgIdCache\n        -ConcurrentDictionary~int,Type~ IdMsgCache\n        +.cctor() MessageFactory\n        +Reload()$\n        +LoadMsgTypes()$\n        +GetMsgType(int id)$ Type?\n        +GetMsgId(Type type)$ int?\n        +ToRemoteCallMessage~T~(int requestId, T val)$ byte[], where T: IMessage\n        +GetRemoteCall(ReadOnlySequence~byte~ data)$ RemoteCall\n        +GetRemoteCall(scoped Span~byte~ bytes)$ RemoteCall\n    }\n```\n### Shared Architecture Diagram - Network\n```mermaid\n---\ntitle: Shared Architecture Diagram - Network\n---\nclassDiagram\n    class TcpClient{\n        +Action? OnConnected\n        +Action~ReadOnlySequence~byte~~?OnReceived\n        +Action~string~? OnClose\n        +IPAddress Ip\n        +int Port \n        +Socket Socket\n        -Pipe _pipe\n        -bool _isDispose\n        -int _bufferSize = 10 * 1024;\n        +.ctor(string ip, int port) TcpClient\n        -.ctor(Socket socket) TcpClient\n        +Connect()\n        -Start()\n        -SetSocket()\n        -FillPipeAsync(Socket socket, PipeWriter writer) Task\n        -ReadPipeAsync(PipeReader reader) Task\n        -TryParsePacket(ref ReadOnlySequence~byte~ buffer, out ReadOnlySequence~byte~ packet) bool\n        +Send(Span~byte~ buffer)\n        +SendAsync(Memory~byte~ buffer) ValueTask\n        +Close(string msg)\n    }\n    class TcpServer{\n        +IPEndPoint Ip\n        -Socket _listener\n        -bool _disposed\n        -ConcurrentDictionary~ulong,TcpClient~ _clients\n        -ConcurrentQueue~TcpClient~ _clientsToStart\n        +Action~uint~? OnConnect\n        +Action~uint,ReadOnlySequence~byte~~? OnMessage\n        +Action~uint,string~? OnDisconnect;\n        +bool IsRunning\n        -uint _curId\n        +.ctor(string ip, int port) TcpServer\n        +Start()\n        -CheckStatus()\n        -StartClients()\n        -AcceptAsync()\n        -GetClient(uint id) TcpClient?\n        +ClientOnline(uint id) bool\n        +KickClient(uint id)\n        +SendToClient(uint id, Span~byte~ message)\n        +SendToClientAsync(uint id, Memory~byte~ message) ValueTask\n        +Dispose()\n        #Dispose(bool dispose)\n    }\n    TcpClient \u003c-- TcpServer\n    TcpServer \u003c-- Session\n    class Session{\n        +uint Id\n        +bool Connected\n        -TcpServer Server\n        +.ctor(uint id, TcpServer server) Session\n        +Dispose()\n        +Send(Span~byte~ data)\n        +SendAsync(Memory~byte~ data) Task\n        +End()\n    }\n    note for Session \"Session holds the TcpServer instance\\nand sends the client id to it to process\\ndifferent jobs\"\n```\n### Server Architecture Diagram\n```mermaid\n---\ntitle: Server Architecture Diagram\n---\nclassDiagram\n    class IRequestBase{\n        \u003c\u003cinterface\u003e\u003e\n        OnRequest(Actor actor, IMessage request) Task~IMessage?~\n    }\n    note for IRequestBase \"IRequestBase is IRequest in C# impl\"\n    class IRequest~TActor,TRequest,TResponse~{\n        \u003c\u003cinterface\u003e\u003e\n        where TActor : Actor\n        where TRequest : IMessage\n        where TResponse : IMessage\n        OnRequest(Actor actor, IMessage request) Task~IMessage?~\n    }\n    IRequestBase --\u003e IRequest~TActor,TRequest,TResponse~\n    IRequest~TActor,TRequest,TResponse~ --\u003e Request~TActor,TRequest,TResponse~\n    class Request~TActor,TRequest,TResponse~{\n        where TActor : Actor\n        where TRequest : IMessage\n        where TResponse : IMessage\n        +OnRequest(TActor actor, TRequest request)* Task~TResponse?~\n    }\n    class RequestFactory{\n        +ConcurrentDictionary\u003cint, IRequest\u003e Requests\n        .cctor()$ RequestFactory\n        Reload()$\n        LoadRequests()$\n        GetRequest(int msgId)$ IRequest?\n    }\n    Request --\u003e RequestFactory\n    class ComponentHolder{\n        From Shared\n    }\n    class Entity{\n        From Shared\n    }\n    class Component{\n        From Shared\n    }\n    class TcpServer{\n        From Shared\n    }\n    class Session{\n        From Shared\n    }\n    class RemoteCall{\n        From Shared\n    }\n    class TcpComponent{\n        +ComponentRole Role =\u003e ComponentRole.LowLevel\n        -TcpServer _server\n        -ConcurrentDictionary~uint,Session~ _sessions\n        -ConcurrentQueue~[uint-sessionId,RemoteCall-call]~ _queue\n        +Action~uint~? OnClientConnected\n        +Action~uint,string~? OnClientDisconnected\n        +Action~uint,ReadOnlySequence~byte~~? OnClientDataReceived\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n    }\n    class RemoteCallComponent{\n        +ComponentRole Role =\u003e ComponentRole.LowLevel\n        -ConcurrentQueue~[Session-session,RemoteCall-call]~ _requestQueue\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n        +AddRequest(Session session, RemoteCall call)\n    }\n    class ActorSystemComponent{\n        +ComponentRole Role =\u003e ComponentRole.LowLevel\n        +ConcurrentDictionary~Session,Actor~ Actors\n        +ConcurrentDictionary~long,Actor~ ActorsFromId\n        +List~Actor~ ActorList\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n    }\n    class RequestComponent{\n        +ComponentRole Role =\u003e ComponentRole.LowLevel\n        -ConcurrentQueue~RemoteCall~ _requests\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n        +AddRequest(RemoteCall call)\n    }\n    class SessionComponent{\n        +ComponentRole Role =\u003e ComponentRole.LowLevel\n        +int TimeInterval =\u003e 1000\n        -ChangeSession(Session newSession)\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n    }\n    class Actor{\n        +long Id\n        +Entity OwnerEntity\n        +ActorSystemComponent ActorSystem\n        +Session Session\n        +long StartMs\n        +long OnlineMs\n        +.ctor(Entity ownerEntity, Session session) Actor\n        +Destroy()\n        +Send[T](T? val) Task, where T : IMessage\n        +Respond\u003cT\u003e(int requestId, T? val) Task, where T : IMessage\n    }\n    class ActorComponent{\n        +ComponentRole Role =\u003e ComponentRole.HighLevel\n        +Actor Actor\n        +List~Actor~ ActorList\n        +Create() Task\n        +Destroy() Task\n        +Update(long currentMs) Task\n    }\n    class Program{\n    +Main(string[] args)$\n    }\n    note for Program \"Host the server\"\n    Program --\u003e Entity\n    TcpServer \u003c-- TcpComponent\n    Session \u003c-- RemoteCallComponent\n    RemoteCall \u003c-- RemoteCallComponent\n    Session --\u003e Actor\n    ComponentHolder --\u003e Actor\n    TcpComponent --\u003e RemoteCallComponent\n    RemoteCallComponent --\u003e ActorSystemComponent\n    ComponentHolder --\u003e Entity\n    Entity --\u003e Component\n    Component --\u003e TcpComponent\n    Component --\u003e RemoteCallComponent\n    Component --\u003e ActorSystemComponent\n    Actor --\u003e ActorComponent\n    Actor --\u003e ActorSystemComponent\n    ActorComponent --\u003e ActorSystemComponent\n    ActorComponent \u003c-- RequestComponent\n    ActorComponent \u003c-- SessionComponent\n    RequestComponent --\u003e RequestFactory\n```\n\n\u003e Todo: Client Architecture","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonxudeveloper%2Fdaserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonxudeveloper%2Fdaserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonxudeveloper%2Fdaserver/lists"}