viewing paste Unknown #12696 | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
//Child of int atcommand_accountinfo
void account_info(const int fd, struct map_session_data *sd, int account_id)
{
    char userid[NAME_LENGTH], user_pass[NAME_LENGTH], email[40], last_ip[20], lastlogin[30];
    short level = -1;
    char *data;
    int logincount = 0,state = 0;
    
    if ( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `userid`, `user_pass`, `email`, `last_ip`, `level`, `lastlogin`, `logincount`, `state` FROM `login` WHERE `account_id` = '%d'", account_id) )
        clif_displaymessage(fd, "[Driver Error] : Query Error. (connection seems crappy :/) Tell the admin.");
    else if ( Sql_NumRows(mmysql_handle) == 0 )
        clif_displaymessage(fd, "Account Not Found");
    else
    {
        Sql_NextRow(mmysql_handle);
        Sql_GetData(mmysql_handle, 0, &data, NULL); safestrncpy(userid, data, sizeof(userid));
        Sql_GetData(mmysql_handle, 1, &data, NULL); safestrncpy(user_pass, data, sizeof(user_pass));
        Sql_GetData(mmysql_handle, 2, &data, NULL); safestrncpy(email, data, sizeof(email));
        Sql_GetData(mmysql_handle, 3, &data, NULL); safestrncpy(last_ip, data, sizeof(last_ip));
        Sql_GetData(mmysql_handle, 4, &data, NULL); level = atoi(data);
        Sql_GetData(mmysql_handle, 5, &data, NULL); safestrncpy(lastlogin, data, sizeof(lastlogin));
        Sql_GetData(mmysql_handle, 6, &data, NULL); logincount = atoi(data);
        Sql_GetData(mmysql_handle, 7, &data, NULL); state = atoi(data);
    }
    
    Sql_FreeResult(mmysql_handle);
    
    if (level == -1)
        return;
    
    sprintf(atcmd_output, "-- Account %d --", account_id);
    clif_displaymessage(fd, atcmd_output);
    sprintf(atcmd_output, "User: %s | GM Level: %d | State: %d", userid, level, state);
    clif_displaymessage(fd, atcmd_output);
    if (pc_isGM(sd) >= 98)
    {
        sprintf(atcmd_output, "Password: %s.", user_pass);
        clif_displaymessage(fd, atcmd_output);
    }
    
    sprintf(atcmd_output, "Account e-mail: %s.", email);
    clif_displaymessage(fd, atcmd_output);
    sprintf(atcmd_output, "Last IP: %s (%s)", last_ip, geoip_getcountry(str2ip(last_ip)));
    clif_displaymessage(fd, atcmd_output);
    sprintf(atcmd_output, "This user has logged %d times, the last time were at %s.", logincount, lastlogin);
    clif_displaymessage(fd, atcmd_output);
    
    clif_displaymessage(fd, "-- Character Details --");
    
    if ( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `char_id`, `name`, `char_num`, `class`, `base_level`, `job_level`, `online` FROM `char` WHERE `account_id` = '%d' ORDER BY `char_num`", account_id) )
        clif_displaymessage(fd, "Character Query Error. Show it to the Admin.");
    else if ( Sql_NumRows(mmysql_handle) == 0 )
        clif_displaymessage(fd, "This account doesnt have characters.");
    else
    {
        while ( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
        {
            int char_id, class_;
            short char_num, base_level, job_level, online;
            char name[NAME_LENGTH];
            
            Sql_GetData(mmysql_handle, 0, &data, NULL); char_id = atoi(data);
            Sql_GetData(mmysql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
            Sql_GetData(mmysql_handle, 2, &data, NULL); char_num = atoi(data);
            Sql_GetData(mmysql_handle, 3, &data, NULL); class_ = atoi(data);
            Sql_GetData(mmysql_handle, 4, &data, NULL); base_level = atoi(data);
            Sql_GetData(mmysql_handle, 5, &data, NULL); job_level = atoi(data);
            Sql_GetData(mmysql_handle, 6, &data, NULL); online = atoi(data);
            
            sprintf(atcmd_output, "[Slot/CID: %d/%d] %s | %s | Level: %d/%d | %s", char_num, char_id, name, job_name(class_), base_level, job_level, online?"On":"Off");
            clif_displaymessage(fd, atcmd_output);
        }
    }
    
    Sql_FreeResult(mmysql_handle);
    
    return;
}
 
//Syntax: <account_id>/<char_name>
//Result: If using account id and id exists return information about user account, if using char name and more than one result found lists all found results.
int atcommand_accountinfo(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
    int account_id = 0;
    char *data;
    
    nullpo_retr(-1, sd);
    
    if (!message || !*message || strlen(message)>NAME_LENGTH ) {
        clif_displaymessage(fd, "(usage: @accinfo/@accountinfo <account_id/char name>).");
        return -1;
    }
    
    account_id = atoi(message);
    
    if (account_id < START_ACCOUNT_NUM)
    {
        if ( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `char` WHERE `name` like '%s' limit 10", message) )
        {
            clif_displaymessage(fd, "Query Error on accountinfo function.");
            Sql_FreeResult(mmysql_handle);
            return -1;
        }
        else if ( Sql_NumRows(mmysql_handle) == 0 )
        {
            clif_displaymessage(fd, "Invalid Account ID/Char Name");
            Sql_FreeResult(mmysql_handle);
            return -1;
        }
        else
        {
            if (Sql_NumRows(mmysql_handle) == 1) {
                Sql_NextRow(mmysql_handle);
                Sql_GetData(mmysql_handle, 0, &data, NULL); account_id = atoi(data);
                Sql_FreeResult(mmysql_handle);
            }
            else
            {
                sprintf(atcmd_output, "Your Query Returned the following %d results, please be more specific...", (int)Sql_NumRows(mmysql_handle));
                clif_displaymessage(fd, atcmd_output);
                while ( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
                {
                    int class_;
                    short base_level, job_level, online;
                    char name[NAME_LENGTH];
                    
                    Sql_GetData(mmysql_handle, 0, &data, NULL); account_id = atoi(data);
                    Sql_GetData(mmysql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
                    Sql_GetData(mmysql_handle, 2, &data, NULL); class_ = atoi(data);
                    Sql_GetData(mmysql_handle, 3, &data, NULL); base_level = atoi(data);
                    Sql_GetData(mmysql_handle, 4, &data, NULL); job_level = atoi(data);
                    Sql_GetData(mmysql_handle, 5, &data, NULL); online = atoi(data);
                    
                    sprintf(atcmd_output, "[ACID: %d] %s | %s | Level: %d/%d | %s", account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline");
                    clif_displaymessage(fd, atcmd_output);
                }
                Sql_FreeResult(mmysql_handle);
                return -1;
            }
        }
    }
    account_info(fd, sd, account_id);
    return 0;
}
 
Viewed 815 times, submitted by Guest.