This is the public copy of the guide: it holds no value of any server. The panel (dash.) shows the same guide with your server's game ports, and the kit's files with their SHA-256.

Argus Shield integration: server kit 4, client kit 3.

Integrate Argus Shield into this Metin2 source, the server and the client. You are done when both build with the define ENABLE_ARGUS_PROTECT on and with it off, the checks at the end pass, and you have written the report.

How it works: the game client loads ArgusProtect.dll, gives it the name of each server and connects to the loopback endpoint it returns. The game server takes game traffic only from the listed Shield nodes, and reads the player's address from a header the node writes first.

Rules you never break:
- Never add a fallback to a direct connection: no retry on the server's address, no "if the DLL is missing, connect as before", no resolving the name. A failure ends in a message. The fallback is the leak.
- Never write the server's address into a client file, a comment, a log line, a commit message or your report.
- Never open, print, copy into the chat, hash, re-encode or commit argusprotect.key: it is moved as a file. The same for any credential you meet, such as CONFIG passwords.
- Never touch code outside the places below: no reformatting, no renames. Every added line of logic sits inside #ifdef ENABLE_ARGUS_PROTECT; with the define off the build is the one from before.
- Never weaken a rule to make something work: no connection accepted without a valid header, no skipped node list, no longer deadline, no firewall rule opened wider.
- Never run anything on a live server, change a firewall, restart a core or push a patch to players. You edit the source and build; the owner deploys.
- Never invent an API: the only functions are those of the two files of each side. If a step does not fit the source, stop and say where.
- A value written as <...> (a port, a node) is the owner's to fill in from dash.: never guess one.
- Never commit or push unless the owner says so, and never with the key or the DLL in the commit.
- Before the first edit, compute the SHA-256 of each of the four source files you were given and compare each with the value the owner reads from the build's file list on dash. If one differs, or the owner has no value to give, stop.
- Before the first edit, list where each edit will go and wait for the owner's confirmation. Stop and ask when a place is not found, is found more than once, or already holds another proxy or protection.

The files you are given: argus_protect.h, argus_protect.cpp for the server, next to desc.cpp; ArgusProtect.h, ArgusProtect.cpp for the client, in EterLib. Do not change them.

# Server code

Copy argus_protect.h and argus_protect.cpp next to desc.cpp. Apply steps 1-5 exactly, each inside #ifdef ENABLE_ARGUS_PROTECT (the two #include lines outside it); where a Find line differs, place the edit where the code does the same thing and say so. Do not change the two files, do not add any other check, byte, comment or fallback, and do not remove any line of the game. Then read the six points of Check in your source against this source and report what you found for each, changing nothing for them without asking.

Step 1. common/CommonDefines.h: the switch

Add next to the other defines:

```
#define ENABLE_ARGUS_PROTECT
```

`argus_protect.cpp` does not compile without `ENABLE_NEWSTUFF`, or with `__IMPROVED_HANDSHAKE_PROCESS__` or `ENABLE_ADMIN_PAGE` defined: each of them judges a connection by an address that behind Shield is the node's.

Step 2. game/config.cpp: the CONFIG lines

Below the `#include` lines at the top:

```
#include "argus_protect.h"
```

In `__LoadDefaultConfigFile`, find `while (fgets(buf, 256, fp))` and add as the first lines of its body:

```
#ifdef ENABLE_ARGUS_PROTECT
		if (ArgusProtect::ReadConfigLine(buf))
			continue;
#endif
```

In `config_init`, find `if (g_setQuestObjectDir.empty())` and add above it:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::ApplyConfig();
#endif
```

The first edit goes before `parse_token`, which would cut the value after the colon. The second goes after every line has been read.

Step 3. game/desc.h: the connection's state

Below the `#include` lines at the top:

```
#include "argus_protect.h"
```

Find `int			ProcessInput();` and add above it:

```
#ifdef ENABLE_ARGUS_PROTECT
		void				SetArgusKind(argus_origin_kind eKind)	{ m_eArgusKind = eKind; }
		argus_origin_kind	GetArgusKind() const					{ return m_eArgusKind; }
		bool				IsAwaitingArgusHeader() const			{ return m_pkArgusHeaderEvent != NULL; }
		bool				BeginArgusSession(DWORD dwHandshake);
		bool				ReadArgusHeader(bool bDeadline);
#endif
```

Find `LPEVENT			m_pkPingEvent;` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
		argus_origin_kind	m_eArgusKind;
		LPEVENT				m_pkArgusHeaderEvent;
#endif
```

Every file that uses a `DESC` includes `desc.h`, so the next two steps need no include of their own.

Step 4. game/desc.cpp: silence until the header

In `DESC::Initialize`, find `m_pkDisconnectEvent = NULL;` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	m_eArgusKind = ARGUS_ORIGIN_ACCEPT_PLAIN;
	m_pkArgusHeaderEvent = NULL;
#endif
```

In `DESC::Destroy`, find `event_cancel(&m_pkDisconnectEvent);` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	event_cancel(&m_pkArgusHeaderEvent);
#endif
```

In `EVENTFUNC(ping_event)`, find `LPDESC desc = info->desc;` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	if (desc->IsAwaitingArgusHeader())
		return ping_event_second_cycle;
#endif
```

In `DESC::Setup`, find `SetPhase(PHASE_HANDSHAKE);` and add above it:

```
#ifdef ENABLE_ARGUS_PROTECT
	if (BeginArgusSession(_handshake))
		return true;
#endif
```

In `DESC::ProcessInput`, find `buffer_write_proceed(m_lpInputBuffer, bytes_read);` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	if (IsAwaitingArgusHeader() && !ReadArgusHeader(false))
		return 0;
#endif
```

Step 5. game/desc_manager.cpp: who may connect

In `DESC_MANAGER::AcceptDesc`, replace `if (g_bAuthServer)` with:

```
#ifdef ENABLE_ARGUS_PROTECT
	const argus_origin_kind eArgusKind = ArgusProtect::ClassifyPeer(peer.sin_addr);
	if (eArgusKind == ARGUS_ORIGIN_ACCEPT_REFUSE)
	{
		socket_close(desc);
		return NULL;
	}

	if (g_bAuthServer && eArgusKind != ARGUS_ORIGIN_ACCEPT_HEADER)
#else
	if (g_bAuthServer)
#endif
```

Find `newd = M2_NEW DESC;` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	newd->SetArgusKind(eArgusKind);
#endif
```

The ban check is skipped for a node, whose address is the node's: the player's address is checked once the header is read.

# Check in your source

- Every packet that carries a core's address goes through `g_stProxyIP`: the warp of `CHARACTER::WarpSet` and of a channel switch, the character list of `DESC::SendLoginSuccessPacket` (in the copy that is sent), the new character of `input_db.cpp`, and both branches of `GetServerLocation`. A site of your own that builds a warp or a character's entry gets the form below, right before the packet is sent.
- Nothing else decides at accept by the peer's address: `ClassifyPeer` is the one check.
- Every limit and ban of your source's own (a per-address limiter, a flood guard, a ban list) reads the player's address, which the kit puts into `m_SockAddr`, `m_wPort` and `m_stHost` of the `DESC` after the header. Never the socket's peer: behind Shield that is the node, and a limiter that reads it bans a node and every player on it. Check this before the first player comes through Shield.
- Nothing writes to a connection on a timer before its header.
- Nothing reads the input buffer before the hook: `ReadArgusHeader` is the first reader of a node's bytes.
- The game's admin page is not compiled. A source that compiles its branch under no define puts it inside `#ifndef ENABLE_ARGUS_PROTECT`.

```
#ifdef ENABLE_ARGUS_PROTECT
	if (!g_stProxyIP.empty())
		p.lAddr = inet_addr(g_stProxyIP.c_str());
#endif
```

# CONFIG

In the `CONFIG` of every core, auth included, exactly as written, in lower case. A bad line stops the core at start with its reason. After a change, restart each core: it reads the file once.

```
argus_proxy: true
argus_edge: <node-ip>
argus_edge: <node-ip>
```

Leave each node as <node-ip>: the owner fills the lines in by hand.

# Client code

Copy ArgusProtect.h and ArgusProtect.cpp into EterLib. If the source holds an earlier Argus kit (ArgusProtectClient.h, ArgusProtectClient.cpp, argus_game.h, calls to KeepLastStatus, HasRefusal or TakeRefusal, netGetArgusStatus, a block in root/introLogin.py, ARGUS_PROTECT_MESSAGE_* in the locale files), remove all of it first. Apply steps 1-7 exactly, each inside #ifdef ENABLE_ARGUS_PROTECT (the #include lines outside it). List every place the client reaches the server's own address outside CNetworkStream::Connect and put it, with the code that holds the address, under #ifndef ENABLE_ARGUS_PROTECT. Do not edit any Python or locale file.

Step 1. UserInterface/Locale_inc.h: the switch

Add next to the other defines:

```
#define ENABLE_ARGUS_PROTECT
```

Step 2. EterLib/NetStream.h: the stream keeps its connection object

Find `#include "NetAddress.h"` and add below it:

```
#include "ArgusProtect.h"
```

In `CNetworkStream`, find `virtual void OnDisconnect();` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
		ArgusProtect::Conn m_kArgusConn;
#endif
```

It is protected, not private: step 7 reads it. One `Conn` belongs to one stream and is never shared, copied or reset.

Step 3. EterLib/NetStream.cpp: every connection goes through one place

As the first lines of `CNetworkStream::Connect(const char* c_szAddr, int port, int limitSec)`:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::Target kTarget;
	if (!ArgusProtect::Resolve(m_kArgusConn, c_szAddr, port, kTarget))
	{
		Clear();
		OnConnectFailure();
		return false;
	}

	c_szAddr = kTarget.host;
	port = kTarget.port;
#endif
```

As the first lines of `CNetworkStream::Connect(DWORD dwAddr, int port, int limitSec)`:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::Target kTarget;
	CNetworkAddress kNetAddr;
	if (!ArgusProtect::ResolvePacket(m_kArgusConn, dwAddr, port, kTarget) || !kNetAddr.Set(kTarget.host, kTarget.port))
	{
		Clear();
		OnConnectFailure();
		return false;
	}

	return Connect(kNetAddr);
#else
```

Below `return Connect(szAddr, port, limitSec);`, the last line of that function:

```
#endif
```

Step 4. EterLib/NetAddress.cpp: a name is refused here too

Find `#include "NetAddress.h"` and add below it:

```
#include "ArgusProtect.h"
```

Wrap the whole body of the method that calls `gethostbyname`, the only one:

```
bool CNetworkAddress::SetDNS(const char* c_szHostName)
{
#ifdef ENABLE_ARGUS_PROTECT
	return false;
#else
	// ... the original body, the one that calls gethostbyname ...
#endif
}
```

Without the include this file does not see the define and the door stays open. Return nothing if the method returns void.

Step 5. UserInterface/PythonNetworkStream.cpp: the guild mark server and the channel status checker

In `CPythonNetworkStream::SetMarkServer`, replace `m_kMarkAuth.m_kNetAddr.Set(c_szAddr, uPort);` with:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::Conn kConn;
	ArgusProtect::Target kTarget;
	m_kMarkAuth.m_kNetAddr.Clear();
	if (ArgusProtect::ResolveMark(kConn, c_szAddr, uPort, kTarget))
		m_kMarkAuth.m_kNetAddr.Set(kTarget.host, kTarget.port);
#else
	m_kMarkAuth.m_kNetAddr.Set(c_szAddr, uPort);
#endif
```

In `UserInterface/ServerStateChecker.cpp`: In `CServerStateChecker::Request`, replace `if (!m_kStream.Connect(m_lstChannel.begin()->c_szAddr, m_lstChannel.begin()->uPort))` with:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::Conn kConn;
	ArgusProtect::Target kTarget;
	CNetworkAddress kAddr;
	if (!ArgusProtect::ResolveStatus(kConn, m_lstChannel.begin()->c_szAddr, m_lstChannel.begin()->uPort, kTarget) ||
		!kAddr.Set(kTarget.host, kTarget.port) || !m_kStream.Connect(kAddr))
#else
	if (!m_kStream.Connect(m_lstChannel.begin()->c_szAddr, m_lstChannel.begin()->uPort))
#endif
```

The block under the `if` stays as it is. Ask the status when the player picks a server, never on a timer.

Step 6. UserInterface/UserInterface.cpp: start, or do not start

In `WinMain`, find `Main(hInstance, lpCmdLine);` and add above it:

```
#ifdef ENABLE_ARGUS_PROTECT
	if (!ArgusProtect::Start())
		return 0;
#endif
```

Find `Main(hInstance, lpCmdLine);` and add below it:

```
#ifdef ENABLE_ARGUS_PROTECT
	ArgusProtect::Stop();
#endif
```

A call the client makes to the server's own address beside the game goes under `#ifndef ENABLE_ARGUS_PROTECT`, with the code and the constant that hold the address.

Step 7. UserInterface/AccountConnector.cpp: close a refused login

In `CAccountConnector::OnRemoteDisconnect`, find `__OfflineState_Set();` and add above it:

```
#ifdef ENABLE_ARGUS_PROTECT
	if (ArgusProtect::WasRefused(m_kArgusConn) && m_poHandler)
		PyCallClassMemberFunc(m_poHandler, "OnConnectFailure", Py_BuildValue("()"));
#endif
```

Without it the login window's "connecting" popup would wait forever after a refusal.

# The server list

- Every server is a name, never an address. The name is a label for ArgusProtect.dll: it is sent nowhere and never resolved.
- The default label is `play.argusprotect.invalid`: copy it as it is for every server of the list. It hides nothing, since the host name the DLL connects to and Cloudflare's addresses are visible on the wire anyway; it reads clearly, and no resolver ever answers it.
- The name ends in `.invalid`, which no resolver ever answers. Never a DNS name, and never one that points at your server: an old client would resolve it and connect.
- The ports are the game's own, the ones of the cores.
- A client carries one key, so it reaches the servers of one Argus server only. Servers under two licences need two clients.
- Every other address of the server in the client goes: the auth and guild mark servers, the channel status checker, a web or patch URL on the same machine, a hard-coded call.

```
SRV1 = {
    "name": "My server",
    "host": "play.argusprotect.invalid",  # a label for ArgusProtect.dll, never resolved
    "auth1": 30001,
    "ch1": 30003,
}
```

The game ports of this server: <game-ports>.

# Checks

- Both sides build with the define on, and again with it off.
- With the define off, nothing you added is outside an #ifdef: review every hunk.
- A search of the client tree for any dotted-quad text finds none of the server's. Report only the count and the files, never the address.
- No call in the client resolves a host name on the paths you changed.

# The owner's steps, not yours

- The firewall of the server and the one in front of it.
- The leak test from outside.
- Shipping the DLL and the key with the patcher.
- The checks before a release, including the address-0 check.

# Report

List the files you changed, each edit with its file and line and why you chose that place, what you did not do and why, and the owner's steps that remain.
