A lightweight, high-performance TCP server designed for handling software licensing, user authentication, and remote configuration management. Built with .NET (C#), it utilizes a command pattern architecture, SQLite for data persistence, and Serilog for robust logging.
- TCP Socket Communication: Fast, raw socket communication using
TcpListener. - Asynchronous Architecture: Fully async/await implementation for handling multiple concurrent clients.
- Authentication System:
- Key-based login.
- HWID Locking: Binds a license key to a specific hardware ID.
- Subscription expiration checks.
- Ban system.
- Role-Based Access Control: Decorator-based permission system (
AdminOnlyAttribute) to separate Admin and User commands. - Remote Configuration: Users can store and retrieve JSON configurations associated with their license.
- Extensible Command Pattern: Easily add new commands by implementing the
ICommandinterface. - Data Persistence: Uses Entity Framework Core with SQLite.
- Language: C# (.NET 10.0 recommended)
- ORM: Entity Framework Core
- Database: SQLite (
licenseServer.db) - Logging: Serilog (Console & File)
- .NET SDK installed.
- Clone the repository:
git clone https://github.com/larkliy/TcpLicenseServer.git
- Navigate to the project directory:
cd TcpLicenseServer/TcpLicenseServer - Build the project:
dotnet build
- Run the server:
The server will automatically create the
dotnet run
licenseServer.dbdatabase file on the first run.
The server communicates via text-based commands over TCP on port 8080.
Format: COMMAND arg1 arg2 ...
To access any functionality, the client must first log in.
- Command:
LOGIN [LicenseKey] [HWID] - Example:
LOGIN admin-secret-key MyCpuId123
Available to all authenticated users.
| Command | Arguments | Description |
|---|---|---|
CONFIGCREATE |
[Name] [JSON content] |
Saves a new configuration string. |
GETCONFIG |
[Name] |
Retrieves a specific configuration. |
GETCONFIGS |
None | Lists all configurations owned by the user. |
Available only if the user has the Admin role.
| Command | Arguments | Description |
|---|---|---|
USERCREATE |
[Key] [Role] [SubEndDate] |
Creates a new user. Default role is "User". |
USERBANUNBAN |
[Key] |
Toggles the ban status of a user. |
USERHWIDUPDATE |
[Key] [NewHWID] |
Resets or updates a user's HWID binding. |
USERSUBSCRIPTIONDATEUPDATE |
[Key] [DateTime] |
Extends or reduces a subscription. |
USERINFO |
[Key] |
Returns full JSON details about a user. |
GETALLUSERS |
[Page] [Size] |
Lists all users (paginated). |
GETALLCONFIGS |
[Page] [Size] |
Lists all configs on the server. |
- Commands/: Contains logic for all executable commands.
- Decorators/: Handles middleware logic like
AuthGuardandCheckOnAdmin. - Data/: EF Core DbContext and database configuration.
- Models/: Database entities (
User,Config) and session models. - MainServer.cs: Handles the TCP listener and client acceptance loop.
- CommandFactory.cs: Uses Reflection to dynamically register commands.
This server is currently a prototype.
Pull requests and contributions are welcome!
This project is open-source. Feel free to modify and distribute it as needed.