check for maximum connections per IP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dani klas
    New Member
    • Feb 2012
    • 1

    check for maximum connections per IP

    const char *GetParsedIP(co nst char *ipadd)
    {
    // code by Dan Pop, http://bytes.com/forum/thread212174.ht ml
    unsigned b1, b2, b3, b4, port = 0;
    unsigned char c;
    int rc;
    static char ipge[20];

    if(!Q_strncmp(i padd,"localhost ",strlen("local host")))
    return "localhost" ;

    rc = sscanf(ipadd, "%3u.%3u.%3u.%3 u:%u%c", &b1, &b2, &b3, &b4, &port, &c);
    if (rc < 4 || rc > 5)
    return NULL;
    if ( (b1 | b2 | b3 | b4) > 255 || port > 65535)
    return NULL;
    if (strspn(ipadd, "0123456789 .:") < strlen(ipadd))
    return NULL;
    sprintf(ipge, "%u.%u.%u.% u", b1, b2, b3, b4);
    return ipge;
    }
    if(count == 0 ){//== 0
    return "Missing IP in userinfo.";
    } else if(count > 1){
    return "Too many IP fields in userinfo";
    } else {
    if (GetParsedIP(In fo_ValueForKey( userinfo, "ip")) == NULL)
    return "Malformed IP in userinfo.";
    }
    count = 0;
    // quad: check for maximum connections per IP
    // based on reyalp's combinedfixes.l ua and Invaderzim's patch
    // (prevents fakeplayers DOS http://aluigi.altervis ta.org/fakep.htm )
    conn_per_ip = 1;
    // value = Info_ValueForKe y (userinfo, "ip"); // Dens: value is already the ip
    Q_strncpyz(ip, GetParsedIP(val ue), sizeof(ip));
    for (i=0; i<level.numConn ectedClients; i++) {
    clientNum2 = level.sortedCli ents[i];
    if(clientNum == clientNum2) continue;
    if(isBot || g_entities[clientNum2].r.svFlags & SVF_BOT) continue; // IGNORE BOTS
    trap_GetUserinf o(clientNum2,
    userinfo2,
    sizeof(userinfo 2));
    value = Info_ValueForKe y (userinfo2, "ip");
    Q_strncpyz(ip2, GetParsedIP(val ue), sizeof(ip2));
    if (strcmp(ip, ip2)==0) {
    conn_per_ip++;
    }
    }
    if (conn_per_ip > g_maxIPconnecti ons.integer) {
    G_LogPrintf("Rt CW: Possible DoS attack, rejecting client from %s "
    "(%d connections already)\n", ip, g_maxIPconnecti ons.integer);
    return "Too many connections from your IP.";
    }

    Hi

    I found the code on assambla site and i put in wolf rtcw source but when i connect to server and server is in warmup i get this meassage Q_strncpyz: NULL src
    also when server goes to next map Q_strncpyz: NULL src
    i search in web but the answers there i found didnt help
    i hope here is somebody who can help me
Working...