PSM_Agent

03/23/2026 08:14 GM Wifo#1
Hello everyone,

I’ve created this GitHub repository [Only registered and activated users can see links. Click Here To Register...] to share open‑source work.
This space will include meaningful developments, experiments, and other projects that I want to make available to the community.

My goal is to document progress, share code, and provide resources that others may find useful or inspiring.


SecureTech CLR Command Procedure
This project provides a SQL Server CLR stored procedure that acts as a secure bridge between SQL Server and the Shaiya game server.

It enables administrators to send server commands directly from SQL while enforcing strict validation, logging, and security controls.

Environment
Windows
Visual Studio 2026
.NET Framework 4.8.1
C#


AgentProcedures.cs
*Entry point for SQL Server.

Exposes RunServiceCommand as a SQL CLR procedure
Receives parameters from SQL
Calls CommandExecutor
Sends output back via SqlPipe

CommandExecutor.cs
*Core execution logic.

Validates the command via CommandRules
Enforces rate limits via RequestThrottle
Builds the packet via PacketFactory
Sends it to ps_game via socket
Logs the result via ActivityLogger
Uses centralized constants (BufferSize, Host, Port) from ServiceConfig

CommandRules.cs
*Ensures commands are safe.

Checks format and length
Requires that all commands start with /
Throws exceptions for invalid input
Uses ServiceConfig.MaxCommandLength for length validation

ActivityLogger.cs
*Handles logging of command attempts.

Appends success or error entries to the log file
Records timestamp, service, command, and error message
Uses ServiceConfig.LogFilePath for centralized log location

PacketFactory.cs
*Constructs the binary packet to send to ps_game.

Uses fixed header size and marker from ServiceConfig
Combines header, service name, and command text
Produces correct byte structure

RequestThrottle.cs
*Prevents flooding.

Reads the last log entry timestamp from ServiceConfig.LogFilePath
Blocks if a new command is issued within ServiceConfig.MinIntervalSeconds

SocketHelper.cs
*Handles socket communication.

Connects to ServiceConfig.Host:ServiceConfig.Port
Sends packet data
Receives server response

ServiceConfig.cs
*Centralized configuration.

Host, Port, HeaderSize, HeaderMarker
MaxCommandLength
BufferSize
LogFilePath (combines directory + filename)
MinIntervalSeconds

ErrorHandler.cs
*Standardized error formatting.

Produces consistent error strings for logging and SQL output

Utilities.cs
*Helper methods.

Timestamp formatting
String checks and other small utilities

03/23/2026 11:39 [DEV]Elessar#2
Why are you reposting topics from 10 years ago?
[Only registered and activated users can see links. Click Here To Register...]
03/23/2026 20:51 GM Wifo#3
Quote:
Originally Posted by [DEV]Elessar View Post
Why are you reposting topics from 10 years ago?
[Only registered and activated users can see links. Click Here To Register...]
I didn’t repost the topic because my release was described as open source, while Betalfa’s topic focused only on DLLs and databases. I replicated the other functions so that the scripts and procedures from other developers would still work. Developers can also change the @cmmd and @servicename values to help prevent SQL Server hacking. In addition, I included built‑in security features in my release.
03/24/2026 11:45 [DEV]Elessar#4
That topic already has source code? :thinking:
03/24/2026 21:58 GM Wifo#5
I’ve organized the context and attached the
Quote:
PSM_Agent.rar
so you can download them directly here. If you notice any problems, please leave a comment so I can fix them. Thank you!