Split ip
#1

Hi guys

Ive been trying this so much that i worked myself into a corner, was hoping you can help me out here.

I need to split a ip
123.123.123.123
However, i want it to be split this way:
123.123*


Any thoughts?
Reply
#2

pawn Код:
public OnPlayerConnect(playerid)
{
    RangeBan(playerid);
    return 1;
 }
pawn Код:
stock RangeBan(playerid)
{
    new pos, string[32];
    GetPlayerIp(playerid, string, 16);
    pos = strfind(string, ".", false, 0);
    pos = strfind(string, ".", false, pos + 1);
    strmid(string, string, 0, pos + 1, 16);
    format(string, 32, "banip %s*.*", string);
    return SendRconCommand(string);
}

//or
stock RangeBan(playerid)
{
    new string[32], CurrentIP[4];
    GetPlayerIp(playerid, string, 16);
    sscanf(string, "p<.>dddd", CurrentIP[0], CurrentIP[1], CurrentIP[2], CurrentIP[3]);

    format(string, sizeof(string), "banip %i.%i.*.*", CurrentIP[0], CurrentIP[1]);
    return SendRconCommand(string);
}
Reply
#3

RangeBan it's not recommended
Reply
#4

This then?

pawn Код:
public OnPlayerConnect(playerid)
{
    new string[30];
    format(string, sizeof(string), "Splitted IP: %s", splitip(playerid));
    printf(string);
}
pawn Код:
stock splitip(playerid)
{
    new pos, string[32];
    GetPlayerIp(playerid, string, 16);
    pos = strfind(string, ".", false, 0);
    pos = strfind(string, ".", false, pos + 1);
    strmid(string, string, 0, pos + 1, 16);
    format(string, 32, "%s*", string);
    return string;
}
output
Код:
[14:40:37] Splitted IP: 192.168.*
Reply
#5

Thank you that seemed to work

And yes, it is for a rangeban system that i now got working.
The point is to whitelist certain player names if a innocent guy is caught in a rangeban, it now works.

Once again, thank you for ur help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)