Skip to content

feat(api): Add GetClientIP method to keep track of connected clients. - #4

Merged
Rushaway merged 4 commits into
srcdslab:masterfrom
Dolly132:dolly-3
Aug 1, 2026
Merged

feat(api): Add GetClientIP method to keep track of connected clients.#4
Rushaway merged 4 commits into
srcdslab:masterfrom
Dolly132:dolly-3

Conversation

@Dolly132

Copy link
Copy Markdown

For security reasons, it is mandatory to check who is trying to connect to the socket server
therefore, I added a new method to identify the ip of the client that connects to the server.
Should help in blocking traffic coming from non-whitelisted ips (Used in SMJSONAPI plugin)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds client IP tracking to the AsyncSocket SourceMod extension so plugins can identify the remote peer (primarily for server-accepted connections) and apply allow/deny logic (e.g., whitelisting).

Changes:

  • Added m_pClientIP to CAsyncSocketContext and pClientIP to CSocketConnect, including cleanup/free logic.
  • Captured the peer IP on new inbound connections (uv_tcp_getpeername + uv_ip*_name) and propagated it onto the created socket context.
  • Exposed a new SourcePawn native AsyncSocket.GetClientIP() and added it to the .inc methodmap.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/extension.h Extends the connect-queue payload to carry a client IP pointer.
src/extension.cpp Captures peer IP on accept, stores it on socket contexts, adds AsyncSocket.GetClientIP native, and frees stored IPs on teardown.
src/context.h Adds m_pClientIP to the socket context.
src/context.cpp Initializes and frees m_pClientIP in the context lifecycle.
package/addons/sourcemod/scripting/include/AsyncSocket.inc Adds GetClientIP() to the SourcePawn-facing API surface.
Comments suppressed due to low confidence (1)

src/extension.cpp:140

  • Indentation here uses spaces instead of the tab indentation used elsewhere in this file, and the braces are misaligned with the surrounding style.
			if (pConnect->pClientIP)
            {
                pConnect->pSocketContext->m_pClientIP = pConnect->pClientIP;
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/extension.cpp
Comment thread src/extension.cpp
Comment thread src/extension.cpp Outdated
Comment thread package/addons/sourcemod/scripting/include/AsyncSocket.inc
Dolly132 and others added 2 commits July 28, 2026 17:05
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Rushaway
Rushaway merged commit 5984a05 into srcdslab:master Aug 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants