viewing paste Unknown #38095 | C

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
#include "common/hercules.h" /* Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces) */
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "map/clif.h"
#include "map/pc.h"
#include "map/script.h"
 
//----------
#include "common/nullpo.h"
#include "common/sql.h"
//----------
 
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h" /* should always be the last Hercules file included! (if you don't make it last, it'll intentionally break compile time) */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
HPExport struct hplugin_info pinfo = {
    "FluxCP - Cashpoints",    // Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "0.1",       // Plugin version
    HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
};
 
int pc_reg_received_post(int retVal, struct map_session_data *sd)
{
    if(retVal != 1){
        return retVal;
    }
    nullpo_ret(sd);
    char *data;
    int value = -1;
    
    ShowWarning("RUNNING PLUGIN(account_id=%d, char_id=%d).\n", sd->status.account_id, sd->status.char_id); //INFO 
    
    if (SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT `balance` FROM `cp_credits` WHERE `account_id` = '%d'", sd->status.account_id)){
        Sql_ShowDebug(map->mysql_handle);
        
    }
                        
    while (SQL_SUCCESS == SQL->NextRow(map->mysql_handle)) {
        SQL->GetData(map->mysql_handle, 0, &data, NULL); value = atoi(data);
    }
    SQL->FreeResult(map->mysql_handle);
 
    sd->cashPoints = value;
    
    return 1;
}
 
 
int pc_paycash_post(int retVal, struct map_session_data *sd, int price, int points)
{
    if(retVal < 0){
        return retVal;
    }
    ShowWarning("Plugin: Points: %d --- %d :Cashpoints\n",points,sd->cashPoints);
    //ShowWarning("Plugin @ paycash price: %d (account_id=%d, char_id=%d).\n",price, sd->status.account_id, sd->status.char_id); //INFO 
    
    if (SQL_ERROR == SQL->Query(map->mysql_handle, "UPDATE `cp_credits` SET  `balance` = '%d' WHERE `account_id` = '%d'",sd->cashPoints/*-cash*/, sd->status.account_id)){
        Sql_ShowDebug(map->mysql_handle);
    }
                        
    SQL->FreeResult(map->mysql_handle); 
    
    ShowWarning("Plugin: value=%d).\n", sd->cashPoints);        //Result    
    
    return price-points+points;
}
 
HPExport void plugin_init(void) {
    if (SERVER_TYPE == SERVER_TYPE_MAP) {
        addHookPost(pc, reg_received, pc_reg_received_post);
        addHookPost(pc, paycash, pc_paycash_post);
    }
}
 
HPExport void server_online (void) {
    ShowInfo ("'%s' Plugin by Normynator/Hercules. Version '%s'\n",pinfo.name,pinfo.version);
}
 
Viewed 992 times, submitted by Guest.