Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:29:58+00:00 2026-06-07T18:29:58+00:00

This code explains what I want to do: unsigned long g_PlayerIP[MAX_AMOUNT_OF_PLAYERS];//save the IP address

  • 0

This code explains what I want to do:

unsigned long g_PlayerIP[MAX_AMOUNT_OF_PLAYERS];//save the IP address of each player
int g_max_ip = MAX_CONNECTED_FROM_ONE_IP;

PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid)
{
    PlayerLoopList.push_back(playerid);

    char szIP[32];
    GetPlayerIp(playerid,szIP);//get the ip of the player into szIP
    unsigned short explodeIP[4];//declare 4 eight bit variables, to store the exploded ip
    sscanf(szIP, " %d[^.].%d[^.].%d[^.].%d", &explodeIP[0], &explodeIP[1], &explodeIP[2], &explodeIP[3]);//explode ip into 4 pats ranging from 0 to 255
    g_PlayerIP[playerid] = (explodeIP[0] + (explodeIP[1] << 8) + (explodeIP[2] << 16) + (explodeIP[3] << 24));//store the ip as a 32bit integer
    int connected = 0;//variable for counting connected players fron one ip
    for(list <int>::iterator i = PlayerLoopList.begin(); i != PlayerLoopList.end(); ++i)
    {
        if(g_PlayerIP[playerid] == g_PlayerIP[*i])
        {
            ++connected;
        }
    }
    if(connected >= g_max_ip)
    {
        Report(playerid,IP_FLOOD,g_PlayerIP[playerid]);//too many connected from one ip, report it.
    }
    return true;
}

and seeing this part:

    sscanf(szIP, " %d[^.].%d[^.].%d[^.].%d", &explodeIP[0], &explodeIP[1], &explodeIP[2], &explodeIP[3]);//explode ip into 4 pats ranging from 0 to 255
    g_PlayerIP[playerid] = (explodeIP[0] + (explodeIP[1] << 8) + (explodeIP[2] << 16) + (explodeIP[3] << 24));//store the ip as a 32bit integer
    int connected = 0;//variable for counting connected players fron one ip
    for(list <int>::iterator i = PlayerLoopList.begin(); i != PlayerLoopList.end(); ++i)
    {
        if(g_PlayerIP[playerid] == g_PlayerIP[*i])
        {
            ++connected;
        }
    }

makes me a bit, well, questioning me about if it can be done faster, there has to be a superb way in c++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:29:59+00:00Added an answer on June 7, 2026 at 6:29 pm

    Just use std::map. That way you don’t need one for every possible ip, only the ips you’re actually using.

    std::map<int, unsigned int> counts;
    
    counts[playerid]++;
    if (counts[playid] >= g_max_ip){ //Report
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you explain to me the output of this Java code? int a=5,i; i=++a
I found this tutorial that explains what I want to do using html but
hi I have got the following code and I want to close this overlay
Can anyone explain this code to me? Whats the meaning and how to use
Can anyone explain why this code: {% form_theme form _self %} {% block avo_gallery_upload_widget
Can anyone explain why this code with the given routes returns the first route?
This code is not compilable. I can't find why in standard. Can someone explain?
Could you please explain why this code is not syntactically correct? private void addEditor(final
Can anybody explain what does JdClient is in this code: public JdClient client =
Can someone explain to me what the bolded portions of this code are doing?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.