I need to ban player, i have idea to get player ip, and create list with banned players, if list contain player ip his get disconnected, but i idk how to get player ip, have only client id, in documentation i find nothing, in google too, do something know way to get player ip?
#if UNITY_SERVER || UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
public class BanManager : MonoBehaviour
{
public static BanManager main;
public List<string> bannedIps;
public void Awake()
{
main = this;
}
public void Start()
{
NetworkManager.Singleton.ConnectionApprovalCallback = ApprovalConnectionForBanCheck;
}
public static void BanPlayerIp(ulong clientId)
{
main.bannedIps.Add("127.0.0.1"); // i idk how to get ip, then this i add local ip
NetworkManager.Singleton.DisconnectClient(clientId);
}
private void ApprovalConnectionForBanCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
{
string cachedIp = "127.0.0.1"; // i idk how to get ip, for example just use local ip
bool approved = true;
foreach (string s in bannedIps)
{
if(s == cachedIp)
{
approved = false;
}
}
response.Approved = approved;
response.Pending = false;
}
}
#endif
I believe most players in the world connect via a dynamic IP address which means they can easily get another address and you potentially ban someone else.
Yes, most player uses dynamic IP address, but dynamic ip address donāt changes every day, heās changes every 7-14 days (i idk how days, but approximately is 7-14 days), itās have temporarly effeciency
Netcode by default donāt provide player auth id, i need manually provide from client in rpc, but i include decompile my game, cheater, when decompile game and change it, can replace idās, generate always new random or replace manually it, all information provided in rpc can be replaced, if cheater cannot overrides methodās i can just push bytes from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography (DWORD parametr āMachineGuidā) and ban it by hardware, but, iām earler say, cheater can replace values, values provide by unity netcode and donāt get aviablity replaced are ip and clientId (get changing by re-join on the server), but i provide playerId, not for ban, this exist for getting saves, i can delete saves, but if cheater replace all variables, i have only playerId with his saves and ip (ip iām need to got, i already idk how to get it), you can say āUse Il2CPPā, but with il2cpp cheater can override methods with harmony or something of that, i idk how its works in Il2CPP, but iām sure, bypasses exists
Generally speaking if a solution doesnāt solve the problem it is a less than optimal solution. You are describing a case where you want to ban an annoying player and he only has to be smart enough to get a new IP address or use a VPN.
Cheaters often uses free vpn, free vpn with restrictions, such a āTemporarly testing using for 24 hoursā or ā10 GB Free Vpn, Next GBās Payā, heās create new accounts, this creating can be for a long time, for change ip addres, such a pull out and insert the internet cable, this can use lot of time, player often is lazy, his like just change player id and player, and, maybe cheater donāt install vpn? Maybe his toooo lazy to install it, cheater can be stupid and donāt know about vpn, or donāt remember it, ip banning uses on most games, and, i just need to get ip, all solutions contains alternatives solutions or unprofitability reply like āPlayer Can Use Vpnā or āIp often dynamic and itās changeā, i just need valid replyās
That was Evil-Otaku It might be useful to have the IP passed in on client approval for those not wanting to use an authentication service. Is there a good reason for not including it?
I mean if i connect this unity service, i donāt get from NetworkClient, OnClientConnected callback args or something of that, i need to provide it manually from rpc, but, cheaters with harmony or something of that can override methods, he can rewrite method to send fake player id, but cheater cannot rewrite clientId, getted from ServerRpcParams or OnClientConnected callback args, in UNet i can get player ip without providing ip from rpc by same player
I invented method, heās stupid, but itās work, and something different unsuitable for me, i use additionally other network library (Mirror), and first connect player to mirror server. When player connect to mirror server, i get ip (I know how to get ip from mirror) and reject connection to netcode (main) server, you can say āCheater can rewrite method and directly connect to netcode serverā, but, i create ātoken listā, contain 25 random number from 1 to 9 converted to string, if player connect to mirror server, token create, add to token list, provide to player by rpc sending and send to netcode server, netcode server add this token to token list too, if player connect to netcode server, before spawning player need provide token by rpc, when token provided, netcode server search this token in list, if token doesnāt finded, netcode server just kicking player, else netcode server spawn player, i change thread status with āresolvedā (i answered myself lol)
That sounds like a painful workaround, it might be worth creating a feature request on the NGO github for visibility on the client IP. Maybe first we can trouble @simon-lemay-unity and ask if he thinks itās something that realistically would be added to the NGO Unity Transport wrapper.
It would indeed make a great feature request for the Unity Transport wrapper. The low level transport package already exposes this information so it would be pretty easy to expose it through the NGO wrapper.