From b71a98f17468c52e99c622c4b1fb3587cb4e16a5 Mon Sep 17 00:00:00 2001
From: BotoX <botox@botox.bz>
Date: Sat, 11 Feb 2017 03:01:25 +0100
Subject: [PATCH] Add GetClientIClient native.

---
 core/smn_player.cpp         | 22 ++++++++++++++++++++++
 plugins/include/clients.inc |  9 +++++++++
 2 files changed, 31 insertions(+)

diff --git a/core/smn_player.cpp b/core/smn_player.cpp
index 95490bc1..56a33fee 100644
--- a/core/smn_player.cpp
+++ b/core/smn_player.cpp
@@ -356,6 +356,27 @@ static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
 	return sp_ftoc(value);
 }
 
+static cell_t sm_GetClientIClient(IPluginContext *pContext, const cell_t *params)
+{
+	int client = params[1];
+
+	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
+	if (!pPlayer)
+	{
+		return pContext->ThrowNativeError("Client index %d is invalid", client);
+	}
+	else if (!pPlayer->IsConnected())
+	{
+		return pContext->ThrowNativeError("Client %d is not connected", client);
+	}
+	else if (pPlayer->IsFakeClient())
+	{
+		return pContext->ThrowNativeError("Client %d is a bot", client);
+	}
+
+	return (cell_t)pPlayer->GetIClient();
+}
+
 static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
 {
 	int client = params[1];
@@ -392,6 +413,7 @@ REGISTER_NATIVES(playernatives)
 	{"GetClientAvgChoke",		GetAvgChoke},
 	{"GetClientAvgData",		GetAvgData},
 	{"GetClientAvgPackets",		GetAvgPackets},
+	{"GetClientIClient",		sm_GetClientIClient },
 	{"RunAdminCacheChecks",		RunAdminCacheChecks},
 	{NULL,						NULL}
 };
diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc
index a61cfa79..e1a2c61c 100644
--- a/plugins/include/clients.inc
+++ b/plugins/include/clients.inc
@@ -741,6 +741,15 @@ native float GetClientAvgData(int client, NetFlow flow);
  */
 native float GetClientAvgPackets(int client, NetFlow flow);
 
+/**
+ * Returns the client's baseserver IClient pointer.
+ *
+ * @param client		Player's index.
+ * @return				IClient address.
+ * @error				Invalid client index, client not connected, or fake client.
+ */
+native Address GetClientIClient(int client);
+
 /**
  * Translates an userid index to the real player index.
  *