Advertisement
Sasuke_Uchiha

Aka

Aug 31st, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.49 KB | None | 0 0
  1. stock LoadPlayerAka(playerid,id=1,name[]="none")
  2. {
  3.     new mysqlquery[124];
  4.     mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "SELECT ip,username FROM aka WHERE username = '%e' OR ip = '%e'", PlayerInfo[playerid][pUserName], PlayerInfo[playerid][pIP]);
  5.     print(mysqlquery);
  6.     if(id == 1) return mysql_pquery(g_SQL, mysqlquery,"OnAkaLoad", "d", playerid);
  7.     else if(id == 2) return mysql_pquery(g_SQL, mysqlquery,"GetPlayerIPs", "ds", playerid,name); //using this to load aka for even offline players
  8.     return 1;
  9. }
  10. forward OnAkaLoad(playerid); //forward
  11. public OnAkaLoad(playerid) // public
  12. {
  13.     new mysqlquery[124], //storing mysql format
  14.         name[MAX_PLAYER_NAME], // storing the name in row
  15.         ip[16], //storing the ip in row
  16.         namerow=-1, // will store where the name was found
  17.         iprow=-1; // will store where the ip was found
  18.     for(new i, j = cache_get_row_count(g_SQL); i < j; i++) // loop through all the rows that were found
  19.     {
  20.         cache_get_field_content(i, "username", name, g_SQL, MAX_PLAYER_NAME); // this will get the username from the current row
  21.         cache_get_field_content(i, "ip", ip, g_SQL, MAX_PLAYER_NAME); //this will get the ip from the current row
  22.         printf("Got row %d with name %s",i,name); // just for my own testing
  23.         if(strcmp(name,PlayerInfo[playerid][pUserName]) == 0) // the will match if the name from that field matches player name
  24.         {
  25.             printf("Name Matched in row %d with name %s",i,name); // just for my own testing
  26.             namerow=i; // will store player name row
  27.         }
  28.         if(strcmp(ip,PlayerInfo[playerid][pIP]) == 0) //this will match if the ip from player matches the one in row
  29.         {
  30.             printf("IP Matched in row %d with name %s",i,name); // just for my own testing
  31.             iprow=i; // will store player ip row
  32.         }
  33.         if(namerow == iprow) // this will check if the player name row and ip row are same
  34.         {
  35.             break; // as they are same no need to do anything further
  36.         }
  37.        
  38.     }
  39.     if(namerow == -1) // will check if any row with that name was founded or not
  40.     {
  41.         mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
  42.         print(mysqlquery);
  43.         mysql_pquery(g_SQL,mysqlquery); //no row with that name so inserting the aka
  44.     }
  45.     else if(iprow == -1) //will check if any row with that ip was founded or not
  46.     {
  47.         mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
  48.         print(mysqlquery);
  49.         mysql_pquery(g_SQL,mysqlquery); // no row with this ip inserting the aka
  50.     }
  51.     else if(namerow != iprow) // will check if this ip was also stored for the name we are checking
  52.     {
  53.         mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
  54.         print(mysqlquery);
  55.         mysql_pquery(g_SQL,mysqlquery); // updating the aka.
  56.     }
  57.     return 1;
  58. }
  59. forward GetPlayerIPs(playerid,TargetName[]);
  60. public GetPlayerIPs(playerid,TargetName[])
  61. {
  62.     new string[124],name[MAX_PLAYER_NAME],ip[16];
  63.     format(string,sizeof(string),""ORANGE"%s "ADMIN"IPs : "ORANGE"",TargetName);
  64.     for(new i, j = cache_get_row_count(g_SQL); i < j; i++)
  65.     {
  66.         cache_get_field_content(i, "username", name, g_SQL, MAX_PLAYER_NAME);
  67.         if(strcmp(name,TargetName) == 0)
  68.         {
  69.             cache_get_field_content(i, "ip", ip, g_SQL, MAX_PLAYER_NAME);
  70.             format(string,sizeof(string),"%s%s | ",string,ip);
  71.         }
  72.     }
  73.     SendClientMessage(playerid,COLOR_ADMIN,string);
  74.     return 1;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement