Advertisement
S4T3K

GPCI Basics

Mar 14th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.18 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. native gpci (playerid, serial [], len);
  5.  
  6. new gpci_joueur[128], MySQL, requete[1024];
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     MySQL = mysql_connect("localhost", "root", "votre_base_de_donnees", "");
  11.     return 1;
  12. }
  13.  
  14. public OnPlayerConnect(playerid)
  15. {
  16.     gpci(playerid, gpci_joueur, sizeof(gpci_joueur));
  17.     format(requete, 1024, "SELECT * FROM Banlist WHERE gpci='%s'", gpci_joueur);
  18.     mysql_tquery(MySQL, requete);
  19.     mysql_store_result();
  20.     if(mysql_num_rows() > 0)
  21.     {
  22.         SendClientMessage(playerid, -1, "{FF0000}[Erreur]{FFFFFF} Vous êtes banni.");
  23.         Kick(playerid);
  24.     }
  25.     else return SendClientMessage(playerid, -1, " {013FD1}[Acceuil]{FFFFFF} Bienvenue sur le serveur !");
  26.     return 1;
  27. }
  28.  
  29. BanGPCI(playerid, adminname[], raison[])
  30. {
  31.     new heures, minutes, secondes, jour, mois, annee;
  32.     gettime(heures, minutes, secondes);
  33.     getdate(annee, mois, jour);
  34.     gpci(playerid, gpci_joueur, sizeof(gpci_joueur));
  35.     format(requete, 1024, "INSERT INTO Banlist VALUES (NULL, '%s', '%s', '%d-%d-%d %d:%d:%d', '%s');", gpci_joueur, adminname, annee, mois, jour, heures, minutes, secondes, raison);
  36.     mysql_tquery(MySQL, requete);
  37.     Kick(playerid);
  38. }
  39.  
  40. strtok(const string[], &index, const seperator[] = " ")
  41. {
  42.     const size = 30;
  43.     new idx = strfind(string, seperator, false, index), result[size];
  44.     if(idx == -1)
  45.     {
  46.         if((idx = strlen(string)) > index)
  47.             strmid(result, string, index, idx, size),index = idx;
  48.     }
  49.     else if(idx > (index + size - 1))
  50.         strmid(result, string, index, (idx = index + size - 1), size), index = idx;
  51.     else strmid(result, string, index, idx, size), index = idx + 1;
  52.     return result;
  53. }
  54.  
  55. stock isNumeric(const string[])
  56. {
  57.   new length=strlen(string);
  58.   if (length==0) return false;
  59.   for (new i = 0; i < length; i++)
  60.     {
  61.       if (
  62.             (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
  63.              || (string[i]=='-' && i!=0)                                             // A '-' but not at first.
  64.              || (string[i]=='+' && i!=0)                                             // A '+' but not at first.
  65.          ) return false;
  66.     }
  67.   if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  68.   return true;
  69. }
  70.  
  71. #define RETURN_USER_FAILURE -1
  72. #define RETURN_USER_MULTIPLE -2
  73.  
  74. stock ReturnUser(text[])
  75. {
  76.     new pos = 0;
  77.     new userid = RETURN_USER_FAILURE;
  78.        
  79.     while(text[pos] < 0x21) { // Strip out leading spaces
  80.         if(text[pos] == 0) return RETURN_USER_FAILURE; // No passed text
  81.         pos++;
  82.     }
  83.        
  84.     if(isNumeric(text[pos])) { // Check whole passed string
  85.         userid = strval(text[pos]);
  86.         if(userid >=0 && userid < MAX_PLAYERS)
  87.         {
  88.             if(IsPlayerConnected(userid)) return userid;
  89.             return RETURN_USER_FAILURE;
  90.         }
  91.     }
  92.    
  93.     // They entered [part of] a name or the id search failed (check names just incase)
  94.     new len = strlen(text[pos]);
  95.     new count = 0;
  96.     new name[MAX_PLAYER_NAME+1];
  97.    
  98.     for(new i = 0; i < MAX_PLAYERS; i++)
  99.     {
  100.         if(IsPlayerConnected(i))
  101.         {
  102.             GetPlayerName(i, name, sizeof(name));
  103.             if(strcmp(name, text[pos], true, len) == 0) // Check segment of name
  104.             {
  105.                 if(len == strlen(name)) { // Exact match
  106.                     return i;
  107.                 }
  108.                 else { // Partial match
  109.                     count++;
  110.                     userid = i;
  111.                 }
  112.             }
  113.         }
  114.     }
  115.    
  116.     if(!count) return RETURN_USER_FAILURE;
  117.     if(count > 1) return RETURN_USER_MULTIPLE;
  118.    
  119.     return userid;
  120. }
  121.  
  122. public OnPlayerCommandText(playerid, cmdtext[])
  123. {
  124.     if(strcmp(cmdtext, "/bangpci", true) == 0)
  125.     {
  126.         new tmp[36], idx;
  127.         strtok(cmdtext, idx);
  128.         if(!strlen(tmp))
  129.         {
  130.             SendClientMessage(playerid, -1, "{33CCFF}USAGE:{FFFFFF} /bangpci {D15401}[ID du joueur] [Raison]");
  131.             return 1;
  132.         }
  133.         new joueur = ReturnUser(tmp);
  134.         if(!IsPlayerConnected(joueur))
  135.         {
  136.             SendClientMessage(playerid, -1, "{FF0000}[Erreur]{FFFFFF} Ce joueur n'est pas connecté !");
  137.             return 1;
  138.         }
  139.         new raison[126];
  140.         raison = strtok(cmdtext, idx);
  141.         if(!strlen(raison))
  142.         {
  143.             SendClientMessage(playerid, -1, "{33CCFF}USAGE:{FFFFFF} /bangpci [ID du joueur] {D15401}[Raison]");
  144.             return 1;
  145.         }
  146.         new adminname[MAX_PLAYER_NAME+1];
  147.         GetPlayerName(playerid, adminname, MAX_PLAYER_NAME+1);
  148.         BanGPCI(joueur, adminname, raison);
  149.         return 1;
  150.     }
  151.     return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement