Also-Known-As [MySQL]
#1

So I was trying to create a Also-Known-As system using MySQL, I am not quite sure if I should use a threaded or non-threaded query on this especially I am using them both for commands and OnPlayerConnect.

OnPlayerConnect
PHP Code:
    new Cacheresultcountrows;
    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `accounts` WHERE `IP` = '%s'"PlayerInfo[playerid][p_newIP]);
    
result mysql_query(mysqlquery);
    
cache_get_row_count(rows);
    for(new 
0rowsi++) {
        new 
aka_ip[16];
        
cache_get_value_name(i"IP"aka_ip);
        if(
IpMatch(aka_ipPlayerInfo[playerid][p_newIP])) {
            
count ++;
        }
    }
    if(
count) {
        
format(querysizeof(query), "[Warning] "white"%s may have connected before to the server with a different name. (/aka %d)"GetName(playerid), playerid);
        foreach(
Playeri) if(PlayerInfo[i][p_Admin] >= 1) {
            
SendClientMessage(iCOLOR_REDquery);
        }
        
printf("[Warning] %s may have connected before to the server with a different name. (/aka %d)"GetName(playerid), playerid);
    }
    
cache_delete(result); 
/aka
PHP Code:
CMD:aka(playeridparams[])
{
    if(!
PlayerInfo[playerid][p_Logged]) return SendClientMessage(playerid0xFFFFFFFF">> "red"You are not logged in.");
    if(
PlayerInfo[playerid][p_Admin] < && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid0xFFFFFFFF">> "red"You are not an administrator to use this command.");
    new 
idCacheresultaka_names[5][MAX_PLAYER_NAME], countrowsquery[128], string[135];
    if(
sscanf(params"u"id)) return SendClientMessage(playeridCOLOR_RED"Usage: "white"/aka [playerid]");
    if(
id == INVALID_PLAYER_ID) return SendClientMessage(playerid0xFFFFFFFF">> "red"Player not connected.");
    if(
PlayerInfo[playerid][p_Admin] < PlayerInfo[id][p_Admin]) return SendClientMessage(playerid0xFFFFFFFF">> "red"You cannot use this command on higher admin.");
    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `accounts` WHERE `IP` = '%s'"PlayerInfo[id][p_newIP]);
    
result mysql_query(mysqlquery);
    
cache_get_row_count(rows);
    for(new 
0rowsi++) {
        new 
aka_ip[16];
        
cache_get_value_name(i"IP"aka_ip);
        if(
IpMatch(aka_ipPlayerInfo[id][p_newIP])) {
            if(
count sizeof(aka_names)) {
                
cache_get_value_name(i"NAME"aka_names[i]);
            }
            
count ++;
        }
    }
    
    
format(stringsizeof(string), ">> "green"%s is also known as... (IP: %s)"GetName(id), PlayerInfo[id][p_newIP]);
    
SendClientMessage(playeridCOLOR_GREENstring);
    
format(stringsizeof(string), "%s"aka_names[0]);
    for (new 
1= ((count sizeof (aka_names)) ? (sizeof (aka_names)) : (count)); ji++)
    {
        if (
== (1))
        {
            if (
count sizeof (aka_names))
                
format(stringsizeof(string), "%s, %s and %d more."stringaka_names[i], (count j));
            else
                
format(stringsizeof(string), "%s and %s."stringaka_names[i]);
        } else {
              
format(stringsizeof(string), "%s, %s"stringaka_names[i]);
        }
    }
    
    if(!
count) {
        
format(stringsizeof(string), "This player has no other names used in the server.");
    }
    
SendClientMessage(playeridCOLOR_GREYstring);
    
cache_delete(result);
    return 
1;

Based off from Gammix's /aka, I tried doing a version of my own and so far it works great (performance-wise? *shrugs*)
Reply


Messages In This Thread
Also-Known-As [MySQL] - by JaKe Elite - 23.01.2019, 14:22
Re: Also-Known-As [MySQL] - by Calisthenics - 23.01.2019, 15:39
Re: Also-Known-As [MySQL] - by Logic_ - 23.01.2019, 17:54

Forum Jump:


Users browsing this thread: 2 Guest(s)