Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) Lof Dev Teams
- // Legend Of Fea Statistics modules
- // Plz check statslof.h for config before trying any hardcoding style.
- //Include all files
- #include "../common/cbasetypes.h"
- #include "../common/timer.h"
- #include "../common/nullpo.h"
- #include "../common/malloc.h"
- #include "../common/showmsg.h"
- #include "../common/strlib.h"
- #include "../common/utils.h"
- #include "../common/ers.h"
- #include "../common/sql.h"
- #include "statslof.h"
- #include "skill.h"
- #include "map.h"
- #include "path.h"
- #include "clif.h"
- #include "pc.h"
- #include "status.h"
- #include "pet.h"
- #include "homunculus.h"
- #include "mercenary.h"
- #include "mob.h"
- #include "npc.h"
- #include "battle.h"
- #include "battleground.h"
- #include "party.h"
- #include "itemdb.h"
- #include "script.h"
- #include "intif.h"
- #include "log.h"
- #include "chrif.h"
- #include "guild.h"
- #include "date.h"
- #include "unit.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <math.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #ifndef WIN32
- #include <unistd.h>
- #else
- #include <winsock2.h>
- #endif
- //Config part (edit as you want on your system)
- static char stats_pathfile[MAX_BUFFER] = "/home/lighta/Assembla/lof_v2/statslof/";
- static int autopath=1; //0-1 this will override stats_pathfile defined
- static char stats_player_skillfile[MAX_BUFFER] = "player_count_skill.txt";
- static char stats_player_killfile[MAX_BUFFER] = "player_count_kill.txt";
- static char stats_player_consofile[MAX_BUFFER] = "player_count_conso.txt";
- static char stats_player_dmgfile[MAX_BUFFER] = "player_count_dmg.txt";
- static char stats_player_healfile[MAX_BUFFER] = "player_count_heal.txt";
- static char stats_guild_skillfile[MAX_BUFFER] = "guild_count_skill.txt";
- static char stats_guild_killfile[MAX_BUFFER] = "guild_count_kill.txt";
- static char stats_data[MAX_BUFFER] = "Stats_Woe_Data";
- static char stats_player_skill_db[MAX_BUFFER] = "Stats_Woe_Skill";
- static char stats_player_kill_db[MAX_BUFFER] = "Stats_Woe_Kill";
- static char stats_player_conso_db[MAX_BUFFER] = "Stats_Woe_Conso";
- static char stats_player_dmg_db[MAX_BUFFER] = "Stats_Woe_Dammage";
- static char stats_player_heal_db[MAX_BUFFER] = "Stats_Woe_Heal";
- static char stats_guild_skill_db[MAX_BUFFER] = "Stats_Woe_GSkill";
- static char stats_guild_kill_db[MAX_BUFFER] = "Stats_Woe_GKill";
- //@TODO prevoir script_agitstart2 (second tab ?)
- //Construction tab and index
- static unsigned int cpt_id_skill=0; //Compteur de char recorded
- static unsigned int cpt_rec_skill=0; //Compteur de skill recorded
- static unsigned int statswoe_skill[MAX_CHAR_ID+2][MAX_SKILL_CNT+1]; //Tab de stats skills players
- static unsigned int cpt_id_conso=0; //Compteur de conso par char recorded
- static unsigned int cpt_rec_conso=0; //Compteur de conso recorded
- static unsigned int statswoe_conso[MAX_CHAR_ID][MAX_CONSO_CNT+1]; //Tab de stats conso players
- static unsigned int cpt_id_dmg=0; //Compteur de dmg par char recorded
- static unsigned int cpt_rec_dmg=0; //Compteur de dmg recorded
- static unsigned int statswoe_dmg[MAX_CHAR_ID][MAX_DMG_DONE+1]; //Tab de stats dmg players
- static unsigned int cpt_id_kill=0; //Compteur de kill par char recorded
- static unsigned int statswoe_kill[MAX_CHAR_ID][MAX_KILL_CNT+1]; //Tab de stats kill players
- static unsigned int cpt_id_heal=0; //Compteur de heal par char recorded
- static unsigned int statswoe_heal[MAX_CHAR_ID][MAX_HEAL_CNT+1]; //Tab de stats heal players
- static unsigned int cpt_id_gskill=0; //Compteur de guild recorded (skill)
- static unsigned int cpt_rec_gskill=0; //Compteur de guildskill recorded
- static unsigned int statswoe_gskill[MAX_GUILD_ID][MAX_GSKILL_CNT+1]; //Tab de stats skills guild
- static unsigned int cpt_id_gkill=0; //Compteur de guild recorded (kill)
- static unsigned int statswoe_gkill[MAX_GUILD_ID][MAX_GKILL_CNT+1]; //Tab de stats skills guild
- static unsigned int idwoe=1; //IDWoe for permanente save table
- static unsigned int enable=0; //Var d'activation des stats
- static unsigned int curdate=0; //Var date courrante
- char query[QUERY_LENGTH]; //Query String
- int cmds=CMDDEF; //Command status result
- //lof_dammagecount statslof_dmgcount[MAX_CHAR_ID]; //Dammage tab.
- int statslof_init() {
- #ifndef WIN32
- char cCurrentPath[MAX_BUFFER];
- cmds=CMDDEF;
- //Path file
- if (autopath==1) {
- getcwd(cCurrentPath, sizeof(cCurrentPath));
- sprintf(stats_pathfile, "%s/statslof/", cCurrentPath);
- }
- #else
- ShowWarning("Windows plateform detected, OS unsuported, map-server may crash");
- #endif
- //ShowWarning("Init done stats_pathfile=%s\n",stats_pathfile);
- return cmds;
- }
- /*
- * Inner fonction d'ajout d'un char dans les stats
- * @Return new index
- */
- int statslof_addchar(int statstype,int index, int idplayers) {
- int ichar=0;
- if(index >= MAX_CHAR_ID) return 0; //Chk Array bound
- ichar=index;
- switch(statstype) {
- case STATSKILL :
- //ShowWarning("Skill : Char not found, index=%d\n",index);
- statswoe_skill[ichar][0]=idplayers; //insert new char id
- cpt_id_skill++; //increment nb char in woe for statskill tab
- break;
- case STATCONSO :
- //ShowWarning("Conso : Char not found, index=%d\n",index);
- statswoe_conso[ichar][0]=idplayers; //insert new char id
- cpt_id_conso++; //increment nb char in woe for statsconso tab
- break;
- case STATDMG :
- //ShowWarning("DmgRec : Char not found, index=%d\n",index);
- statswoe_dmg[ichar][0]=idplayers; //insert new char id
- cpt_id_dmg++; //increment nb char in woe for statsdmg tab
- break;
- case STATDMGDONE :
- //ShowWarning("DmgDone : Char not found, index=%d\n",index);
- statswoe_dmg[ichar][0]=idplayers; //insert new char id
- cpt_id_dmg++; //increment nb char in woe for statsdmg tab
- break;
- case STATKILL :
- //ShowWarning("Kill : Char not found, index=%d\n",index);
- statswoe_kill[ichar][0]=idplayers; //insert new char id
- cpt_id_kill++; //increment nb char in woe for statkill tab
- break;
- case STATHEAL :
- //ShowWarning("Heal : Char not found, index=%d\n",index);
- statswoe_heal[ichar][0]=idplayers; //insert new char id
- cpt_id_heal++; //increment nb char in woe for statkill tab
- break;
- }
- return ichar;
- }
- /*
- * Fonction d'incrementation des skills
- * Appeler à chaque utilisation de skill par player.
- * Mapflag should be used before calling this
- *
- * statswoe_skill[i][j] structure :
- * [x][0]=charid, x=[2;MAX_CHAR_ID]
- * [0][x]=skillid x=[1;MAX_SKILL_CNT]
- * [1][x]=skilltype, x=[1; MAX_SKILL_CNT]
- */
- int statslof_skill_cnt(struct map_session_data *sd, int idplayers, int idskill, int skilltype){
- unsigned int i=0, j=1;
- unsigned int ichar=0, iskill=0; //index for char and skill
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idplayers==0 || idskill==0 || skilltype==0) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=2;i<=cpt_id_skill+2;i++) { //parcours char id
- if(statswoe_skill[i][0] == idplayers) {
- ichar = i; //index char
- break; //optimise
- }
- }
- if (ichar==0) ichar=statslof_addchar(STATSKILL,cpt_id_skill+2, idplayers); //Ajout si rien trouver dans le parcours
- if (ichar==0) return CMDFAIL; //Can't add char
- for(j=1;j<=cpt_rec_skill+1;j++) { //parcous skill id
- if(statswoe_skill[0][j] == idskill) {
- iskill = j; //index skill
- break; //optimise
- }
- }
- if (iskill==0) iskill=statslof_addskill(cpt_rec_skill+1, idskill, skilltype); //Ajout si rien trouver dans le parcours
- if (iskill==0) return CMDFAIL; //Can't add skill
- statswoe_skill[ichar][iskill]++; //insert in tab
- //ShowWarning("Skill added : Char : %d, skill : %d, count : %d\n",statswoe_skill[ichar][0],statswoe_skill[0][iskill],statswoe_skill[ichar][iskill]);
- //statslof_display(sd, STATSKILL);
- }
- return 0;
- }
- /*
- * Inner fonction d'ajout d'un skill dans les stats
- * @Return new index
- */
- int statslof_addskill(int index, int idskill, int skilltype) {
- if (index>=MAX_SKILL_CNT) return 0; //Chk Array bound
- //ShowWarning("Skill not found, index=%d\n",index);
- statswoe_skill[0][index]=idskill; //insert skill id
- statswoe_skill[1][index]=skilltype; //insert skill type
- cpt_rec_skill++; //increment skill_cnt_total
- return index;
- }
- /*
- *Fonction incrementation des consos utilises durant la woe
- *Appel a chaque utilisation d'un conso
- *
- * statswoe_conso[i][j] structure :
- * [x][0]=charid, x=[1;MAX_CHAR_ID]
- * [0][x]=consoid x=[1;MAX_CONSO_CNT]
- */
- int statslof_conso_cnt(struct map_session_data *sd, int idplayers, int idconso) {
- unsigned int i=0, j=1;
- unsigned int ichar=0, iconso=0; //index for char and item
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idplayers==0 || idconso==0) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=0;i<=cpt_id_conso;i++) { //parcours char id
- if(statswoe_conso[i][0] == idplayers) {
- ichar = i; //index char
- break; //optimise
- }
- }
- if (ichar==0) ichar=statslof_addchar(STATCONSO,cpt_id_conso+1, idplayers);//Ajout si rien trouver dans le parcours
- if (ichar==0) return CMDFAIL; //Can't add char
- for(j=1;j<=cpt_rec_conso;j++) { //parcous skill id
- if(statswoe_conso[0][j] == idconso) {
- iconso = j; //index skill
- break; //optimise
- }
- }
- if (iconso==0) iconso=statslof_addconso(cpt_rec_conso+1, idconso); //Ajout si rien trouver dans le parcours
- if (iconso==0) return CMDFAIL; //Can't add conso
- statswoe_conso[ichar][iconso]++; //insert in tab
- //ShowWarning("Conso added, Char : %d, conso : %d, count : %d\n",statswoe_conso[ichar][0],statswoe_conso[0][iconso],statswoe_conso[ichar][iconso]);
- //statslof_display(sd, STATCONSO);
- }
- return 0;
- }
- /*
- * Inner fonction d'ajout d'un item dans les stats
- * @Return new index
- */
- int statslof_addconso(int index, int idconso) {
- if (index>=MAX_CONSO_CNT) return 0;
- //ShowWarning("Conso not found, index=%d\n",index);
- statswoe_conso[0][index]=idconso; //insert conso id
- cpt_rec_conso++; //increment conso_cnt_total
- return index;
- }
- /*
- *Fonction incrementation des consos utilises durant la woe
- *Appel a chaque utilisation d'un conso
- *
- * statswoe_dmg[i][j] structure :
- * [x][0]=charid, x=[1;MAX_CHAR_ID]
- * [0][x]=dmgid x=[1;9]
- */
- int statslof_damage_cnt(struct map_session_data *sd, int idplayers, int idbyplayers,int dammage) {
- unsigned int i=0;
- unsigned int ichar=0; //index for dmg
- unsigned int ichar1=0; //index for dmg
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idplayers==0 || dammage==0) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- //Dammage rec-
- switch (idplayers){
- case 1288 : //emp dmg
- case 1905 : //barri dmg
- case 1907 : //stone1 dmg
- case 1908 : //stone2 dmg
- case 1899 : //sword (guardian SE) dmg
- case 1285 : //archer
- case 1286 : //knight
- case 1287 : break; //solider (guardian FE) dmg NOTHING TO DO DMG REC BY MOB
- default : //player case
- for(i=0;i<=cpt_id_dmg;i++) { //parcours char id
- if(statswoe_dmg[i][0] == idplayers) {
- ichar = i; //index char
- break; //optimise
- }
- }
- if (ichar==0) ichar=statslof_addchar(STATDMG,cpt_id_dmg+1, idplayers);//Ajout si rien trouver dans le parcours
- if (ichar==0) return CMDFAIL; //Can't add char
- if(dammage>statswoe_dmg[ichar][2]) statswoe_dmg[ichar][2]=dammage; //update max dmg receive
- statswoe_dmg[ichar][1]+=dammage; //update dmg tot receive
- break;
- }
- //Dammage done
- for(i=0;i<=cpt_id_dmg;i++) { //parcours char id
- if(statswoe_dmg[i][0] == idbyplayers) {
- ichar1 = i; //index char
- break; //optimise
- }
- }
- if (ichar1==0) ichar1=statslof_addchar(STATDMGDONE,cpt_id_dmg+1, idbyplayers);
- if (ichar1==0) return CMDFAIL; //Can't add char
- switch (idplayers){
- case 1288 : statswoe_dmg[ichar1][5]+=dammage; break; //emp dmg
- case 1905 : statswoe_dmg[ichar1][6]+=dammage; break; //barri dmg
- case 1907 : //stone1 dmg
- case 1908 : statswoe_dmg[ichar1][7]+=dammage; break; //stone2 dmg
- case 1899 : statswoe_dmg[ichar1][8]+=dammage; break; //sword (guardian SE) dmg
- case 1285 : //archer
- case 1286 : //knight
- case 1287 : statswoe_dmg[ichar1][9]+=dammage; break; //solider (guardian FE) dmg
- default : //player case
- if(dammage>statswoe_dmg[ichar1][4]) statswoe_dmg[ichar1][4]=dammage; //update max dmg done
- statswoe_dmg[ichar1][3]+=dammage; //update dmg tot done
- break;
- }
- //statslof_display(sd, STATDMG);
- }
- return 0;
- }
- /*
- *Fonction incrementation des kill fait durant la woe
- *Appel à chaque mort d'un PC ou mob
- * statswoe_kill[i][j] structure :
- * [x][0]=charid, x=[1;MAX_CHAR_ID]
- * [0][x]=killid x=[1;7] death/kill/emp/barri/stone/gse/gfe
- */
- int statslof_kill_cnt(struct map_session_data *sd, int idplayers, int idkill) {
- unsigned int i=0, j=0;
- unsigned int ichar=0, ikill=0; //index for char and kill id
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idplayers==0 || idkill==0) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=0;i<=cpt_id_kill;i++) { //parcours char id
- if(statswoe_kill[i][0] == idplayers) {
- ichar = i; //index char
- break; //optimise
- }
- }
- if (ichar==0) ichar=statslof_addchar(STATKILL,cpt_id_kill+1, idplayers);//Ajout si rien trouver dans le parcours
- if (ichar==0) return CMDFAIL; //Can't add char
- switch(idkill){
- case PLDEATH : statswoe_kill[ichar][1]++; break;//update death player
- case PLKILL : statswoe_kill[ichar][2]++; break; //update kill a player
- case 1288 : statswoe_kill[ichar][3]++; break; //update kill an emperium
- case 1905 : statswoe_kill[ichar][4]++; break; //update kill a barricade
- case 1907 : //update kill a guardian stone1
- case 1908 : statswoe_kill[ichar][5]++; break; //update kill a guardian stone2
- case 1899 : statswoe_kill[ichar][6]++; break; //update kill a sword guardian (se ?)
- case 1285 : //update kill an archer guardian (fe)
- case 1286 : //update kill a knight guardian (fe)
- case 1287 : statswoe_kill[ichar][7]++; break; //update kill a soldier guardian (fe)
- default : return 2; //Error if not in list
- }
- //statslof_display(sd, STATKILL);
- }
- return 0;
- }
- /*
- * Heal done and receive
- * healtype HEAL_REC | HEAL_DONE
- * HEAL_REC effectiveness heal received and recovered
- * HEAL_DONE heal done on target
- *
- * statswoe_kill[i][j] structure :
- * [x][0]=charid, x=[1;MAX_CHAR_ID]
- * [0][x]=healid x=[1;4] (detail on code)
- */
- int statslof_heal_cnt(struct map_session_data *sd, int idplayers, int hp, int healtype) {
- unsigned int i=0, j=1;
- unsigned int ichar=0, iheal=0; //index for char and item
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idplayers==0 || hp==0 || (healtype!=HEAL_DONE && healtype!=HEAL_REC)) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=0;i<=cpt_id_heal;i++) { //parcours char id
- if(statswoe_heal[i][0] == idplayers) {
- ichar = i; //index char
- break; //optimise
- }
- }
- if (ichar==0) ichar=statslof_addchar(STATHEAL,cpt_id_heal+1, idplayers);//Ajout si rien trouver dans le parcours
- if (ichar==0) return CMDFAIL; //Can't add char
- if (healtype == HEAL_DONE){
- statswoe_heal[ichar][1]+=hp; //heal done total
- if (hp > statswoe_heal[ichar][2])
- statswoe_heal[ichar][2]=hp; //heal done max
- } else if (healtype == HEAL_REC){
- statswoe_heal[ichar][3]+=hp; //heal receive total
- if (hp > statswoe_heal[ichar][4])
- statswoe_heal[ichar][4]=hp; //heal receive max
- } else return 1;
- //statslof_display(sd, STATHEAL);
- }
- return 0;
- }
- /*
- * Inner fonction d'ajout d'une guilde dans les stats
- * @Return new index
- */
- int statslof_addguild(int statstype,int index, int idguild) {
- int iguild=0;
- if (index>=MAX_GUILD_ID) return 0; //Chk Array boud
- iguild=index;
- switch(statstype) {
- case STATGSKILL :
- //ShowWarning("Skill : Guild not found, index=%d\n",index);
- cpt_id_gskill++; //increment nb guild in woe for statswoe_gskill tab
- statswoe_gskill[iguild][0]=idguild; //insert new guild id
- break;
- case STATGKILL :
- //ShowWarning("Kill : Guild not found, index=%d\n",index);
- cpt_id_gkill++; //increment nb char in woe for statkill tab
- statswoe_gkill[iguild][0]=idguild; //insert new char id
- break;
- }
- return iguild;
- }
- /*
- *Fonction incrementation des guid skill utilises durant la woe
- *Appel a chaque utilisation d'un guildskill
- *
- * statswoe_gskill[i][j] structure :
- * [x][0]=guildid, x=[1;MAX_CHAR_ID]
- * [0][x]=skillid x=[1;4]
- */
- int statslof_gskill_cnt(struct map_session_data *sd, int idguild, int idskill){
- unsigned int i=0, j=1;
- unsigned int iguild=0, iskill=0; //index for guild and skill
- cmds=CMDDEF;
- //ShowWarning("statslof_gskill_cnt call \n idguild=%d \n idskill=%d\n",idguild,idskill);
- if (sd==NULL) return CMDFAIL; //Security check
- if (idguild==0 || idskill==0 || (idskill!=10010 && idskill!=10011 && idskill!=10012 && idskill!=10013)) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=0;i<=cpt_id_gskill;i++) { //parcours guildid
- if(statswoe_gskill[i][0] == idguild) {
- iguild = i; //index char
- break; //optimise
- }
- }
- if (iguild==0) iguild=statslof_addguild(STATGSKILL,cpt_id_gskill+1, idguild); //Ajout si rien trouver dans le parcours
- if (iguild==0) return CMDFAIL; //Guild can't be added
- for(j=1;j<=cpt_rec_gskill;j++) { //parcous skill id
- if(statswoe_gskill[0][j] == idskill) {
- iskill = j; //index skill
- break; //optimise
- }
- }
- if (iskill==0) iskill=statslof_addgskill(cpt_rec_gskill+1, idskill); //Ajout si rien trouver dans le parcours
- if (iskill==0) return CMDFAIL; //Skill can't be added
- statswoe_gskill[iguild][iskill]++; //insert in tab
- //ShowWarning("Gskill added : Guild=%d, gskill=%d, count=%d\n", statswoe_gskill[iguild][0], statswoe_gskill[0][iskill], statswoe_gskill[iguild][iskill]);
- }
- return cmds;
- }
- /*
- * Inner fonction d'ajout d'un skill dans les stats
- * @Return new index
- */
- int statslof_addgskill(int index, int idskill) {
- if (index>=MAX_GSKILL_CNT) return 0; //Chk Array boud
- //ShowWarning("GSkill %d not found in tab, index=%d\n",idskill,index);
- statswoe_gskill[0][index]=idskill; //insert skill id
- cpt_rec_gskill++; //increment skill_cnt_total
- return index;
- }
- /*
- *Fonction incrementation des kills durant la woe
- *Appel a chaque mort d'un PC ou mob
- *
- * statswoe_gkill[i][j] structure :
- * [x][0]=guildid, x=[1;MAX_CHAR_ID]
- * [0][x]=killid x=[1;7]
- */
- int statslof_gkill_cnt(struct map_session_data *sd, int idguild, int idkill) {
- unsigned int i=0, j=0;
- unsigned int iguild=0, ikill=0; //index for char and kill id
- cmds=CMDDEF;
- if (sd==NULL) return CMDFAIL; //Security check
- if (idguild==0 || idkill==0) return CMDFAIL; //Security check
- //Woe
- if((map[sd->bl.m].flag.gvg_castle)&& enable==1){
- for(i=0;i<=cpt_id_gkill;i++) { //parcours char id
- if(statswoe_gkill[i][0] == idguild) {
- iguild = i; //index char
- break; //optimise
- }
- }
- if (iguild==0) iguild=statslof_addguild(STATGKILL,cpt_id_gkill+1, idguild);//Ajout si rien trouver dans le parcours
- if (iguild==0) return CMDFAIL; //Can't add guild
- switch(idkill){
- case PLDEATH : statswoe_gkill[iguild][1]++; break; //update death player
- case PLKILL : statswoe_gkill[iguild][2]++; break; //update kill a playe
- case 1288 : statswoe_gkill[iguild][3]++; break; //update kill an emperium
- case 1905 : statswoe_gkill[iguild][4]++; break; //update kill a barricade
- case 1907 : //update kill a guardian stone1
- case 1908 : statswoe_gkill[iguild][5]++; break; //update kill a guardian stone2
- case 1899 : statswoe_gkill[iguild][6]++; break; //update kill a sword guardian (se ?)
- case 1285 : //update kill an archer guardian (fe)
- case 1286 : //update kill a knight guardian (fe)
- case 1287 : statswoe_gkill[iguild][7]++; break; //update kill a soldier guardian (fe)
- default : return 2; //Error if not in list
- }
- }
- return 0;
- }
- /*
- * Fonction d'enregistrement en CSV,
- * Appeler periodiquement et a la fin de la woe @TODO
- See Table format in _sql-files/statslof.sql
- */
- int statslof_insert_inCSV() {
- FILE *f;
- int i=0,j=0;
- char file[MAX_BUFFER], st[MAX_BUFFER], blankst[1];
- struct item_data *itemdata;
- cmds=CMDDEF;
- //Insert skill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_skillfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=2;i<cpt_id_skill+2;i++) {
- for(j=1;j<=cpt_rec_skill;j++){
- if(statswoe_skill[i][j] != 0 && statswoe_skill[i][0] != 0) {//fill the table with skill used > 0 count for each charid
- //File format csv
- fprintf(f,"%d,%d,%s,%d,%d\n",idwoe,statswoe_skill[i][0],skill_get_desc(statswoe_skill[0][j]),statswoe_skill[1][j],statswoe_skill[i][j]);
- }
- }
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert gskill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_skillfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_gskill;i++) {
- for(j=1;j<=cpt_rec_gskill;j++){
- if(statswoe_gskill[i][j] != 0) {//fill the table with skill used > 0 count for each charid
- //File format csv
- fprintf(f,"%d,%d,%s,%d\n",idwoe,statswoe_gskill[i][0],skill_get_desc(statswoe_gskill[0][j]),statswoe_gskill[i][j]);
- }
- }
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert conso
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_consofile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_conso;i++) {
- for(j=1;j<=cpt_rec_conso;j++){
- if(statswoe_conso[i][j] != 0) {//fill the table with useitem > 0 count for each charid
- itemdata=itemdb_search(statswoe_conso[0][j]);
- //File format csv
- fprintf(f,"%d,%d,%s,%d\n",idwoe,statswoe_conso[i][0],itemdata->jname,statswoe_conso[i][j]);
- }
- }
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert dmg
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_dmgfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_dmg;i++) {
- if(statswoe_dmg[i][1] != 0 || statswoe_dmg[i][3] != 0 || statswoe_dmg[i][5] != 0 || statswoe_dmg[i][6] != 0 || statswoe_dmg[i][7] != 0 || statswoe_dmg[i][8] != 0 || statswoe_dmg[i][9] != 0 ) {//fill the table with dmg > 0 count for each charid
- //File format csv
- fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",idwoe,statswoe_dmg[i][0],statswoe_dmg[i][1],statswoe_dmg[i][2],statswoe_dmg[i][3],statswoe_dmg[i][4],statswoe_dmg[i][5],statswoe_dmg[i][6],statswoe_dmg[i][7],statswoe_dmg[i][8],statswoe_dmg[i][9]);
- }
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert heal
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_healfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_heal;i++) {
- if(statswoe_heal[i][3] != 0) {//fill the table with heal > 0 count for each charid
- //File format csv
- fprintf(f,"%d,%d,%d,%d,%d,%d\n",idwoe,statswoe_heal[i][0],statswoe_heal[i][1],statswoe_heal[i][2],statswoe_heal[i][3],statswoe_heal[i][4]);
- }
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert kill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_killfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_kill;i++) {
- sprintf(st,"%s",blankst);//reinit
- for(j=1;j<=MAX_KILL_CNT;j++){
- //File format csv
- sprintf(st,"%s,%d",st,statswoe_kill[i][j]); //Ajout champs de kill
- }
- fprintf(f,"%d,%d%s\n",idwoe,statswoe_kill[i][0],st);
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //Insert gkill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_killfile);
- if((f = fopen(file, "w"))==NULL) { //Check if file exist
- ShowError("File %s, can't be create\n", file);
- cmds=CMDFAIL;
- }
- else {
- for(i=1;i<=cpt_id_gkill;i++) {
- sprintf(st,"%s",blankst);//reinit
- for(j=1;j<=MAX_GKILL_CNT;j++){
- //File format csv
- sprintf(st,"%s,%d",st,statswoe_gkill[i][j]); //Ajout champs de gkill
- }
- fprintf(f,"%d,%d%s\n",idwoe,statswoe_gkill[i][0],st);
- }
- fclose(f);
- #ifndef WIN32
- chmod(file, S_IRWXU | S_IRGRP | S_IROTH);
- #endif
- //ShowWarning("File %s was create successfully\n",file);
- }
- //ShowWarning("File creation complete cmds=%d\n",cmds);
- return cmds;
- }
- /*
- * Fonction d'enregistrement dans la BDD
- * Appeler par script_agitend à chaque fin de woe.
- See Table format in _sql-files/statslof.sql
- */
- #ifndef TXT_ONLY
- int statslof_insert_inDB() {
- char file[MAX_BUFFER];
- FILE *f;
- cmds=CMDDEF;
- if (statslof_insert_inCSV()==CMDFAIL) return CMDFAIL; //Update and check files
- //Insert skill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_skillfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_skill_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert gskill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_skillfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_guild_skill_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert conso
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_consofile);
- //ShowWarning("%s\n",file);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_conso_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert dmg
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_dmgfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_dmg_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert kill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_killfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','",file, stats_player_kill_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert heal
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_player_healfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_player_heal_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- //Insert gkill
- sprintf(file,"%s%d/%s", stats_pathfile, curdate, stats_guild_killfile);
- if((f = fopen(file, "r"))==NULL) { //Check if file exist
- ShowError("File %s, doesn't exist\n", file);
- cmds=CMDFAIL;
- }
- else {
- fclose (f);
- sprintf(query,"LOAD DATA INFILE '%s' INTO TABLE %s FIELDS TERMINATED BY ','", file, stats_guild_kill_db);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- else {
- ShowWarning("File %s load in DB\n",file);
- }
- }
- if(cmds==CMDDEF) cmds=CMDOK; //Check if cmd was all success
- //ShowWarning("Insert in DB complete cmds=%d\n",cmds);
- return cmds;
- }
- #endif /* not TXT_ONLY */
- /*
- * Fonction pour Reset les Stats.
- * Preparation pour la newt woe.
- * Effacement uniquement des tableau.
- */
- int statslof_reset() {
- char* data;
- char datefolder[MAX_BUFFER];
- cmds=statslof_init();
- cmds=statslof_clean_tab();
- curdate=statslof_getCurrentDate();
- //ShowWarning("Check point reached; curdate=%d,\n",curdate);
- #ifndef TXT_ONLY
- sprintf(query,"SELECT max(woe_id) as `woe_id` from `%s`;", stats_data);
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- while (SQL_SUCCESS == Sql_NextRow(mmysql_handle)){
- Sql_GetData(mmysql_handle, 0, &data, NULL);
- idwoe=atoi(data);
- }
- #else
- idwoe=0;
- #endif /* not TXT_ONLY *///ShowWarning("Check point reached; idwoe=%d,\n",idwoe);
- sprintf(datefolder,"%s%d",stats_pathfile,curdate);
- #ifndef WIN32
- mode_t process_mask = umask(0);
- if(mkdir(datefolder,S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH)== -1 ) {
- ShowError("Folder can't be created, check files/user permission\n");
- cmds=CMDFAIL; //Quit if can't make folder
- }
- umask(process_mask);
- #endif
- //ShowWarning("New Woe added idwoe=%d, curdate=%d\n",idwoe, curdate);
- if(cmds!=CMDFAIL) cmds=CMDOK; //Check if all cmd was sucess
- return cmds; //@TODO change to check 1st value too
- }
- /*
- * Fonction pour nettoyer les stats.
- * Uniquement celle en mémoire. (tableau)
- */
- int statslof_clean_tab() {
- static unsigned int i=0, j=0, k=0;
- cmds=CMDDEF;
- //Index part
- cpt_id_skill=0;
- cpt_rec_skill=0;
- cpt_id_conso=0;
- cpt_rec_conso=0;
- cpt_id_dmg=0;
- cpt_rec_dmg=0;
- cpt_id_kill=0;
- cpt_id_gkill=0;
- cpt_id_gskill=0;
- cpt_rec_gskill=0;
- for(i=0;i<MAX_CHAR_ID;i++) {
- statswoe_skill[i][0]=0; //Reset cpt_id_skill
- for(j=0;j<MAX_SKILL_CNT;j++) statswoe_skill[i][j]=0; //Reset skillcount
- if(j!=MAX_SKILL_CNT) {
- ShowError ("Error occur in clean killcount\n j=%d | MAX_SKILL_CNT=%d\n",j,MAX_SKILL_CNT);
- cmds=CMDFAIL;
- }
- statswoe_conso[i][0]=0; //Reset cpt_id_conso
- for(j=0;j<MAX_CONSO_CNT;j++) statswoe_conso[i][j]=0; //Reset conso count
- if(j!=MAX_CONSO_CNT) {
- ShowError ("Error occur in clean conso count\n j=%d | MAX_CONSO_CNT=%d\n",j,MAX_CONSO_CNT);
- cmds=CMDFAIL;
- }
- statswoe_dmg[i][0]=0; //Reset cpt_id_dmg
- for (j=0;j<MAX_DMG_DONE;j++) statswoe_dmg[i][j]=0; //Reset dammage count
- if(j!=MAX_DMG_DONE) {
- ShowError ("Error occur in clean dammage count\n j=%d | MAX_DMG_DONE=%d\n",j,MAX_DMG_DONE);
- cmds=CMDFAIL;
- }
- statswoe_kill[i][0]=0; //Reset cpt_id_kill
- for(j=0;j<MAX_KILL_CNT;j++) statswoe_kill[i][j]=0; //Reset killcount
- if(j!=MAX_KILL_CNT) {
- ShowError ("Error occur in clean killcount\n j=%d | MAX_KILL_CNT=%d\n",j,MAX_KILL_CNT);
- cmds=CMDFAIL;
- }
- }
- if(i!=MAX_CHAR_ID) { //Check if all tab erased
- ShowError ("Error occur in clean_tab\n i=%d | MAX_CHAR_ID=%d\n",i,MAX_CHAR_ID);
- cmds=CMDFAIL;
- }
- for(i=0;i<MAX_GUILD_ID;i++) {
- statswoe_gskill[i][0]=0; //Reset cpt_id_gskill
- for(j=0;j<MAX_GSKILL_CNT;j++) statswoe_skill[i][j]=0; //Reset gskillcount
- if(j!=MAX_GSKILL_CNT) {
- ShowError ("Error occur in clean gskillcount\n j=%d | MAX_GSKILL_CNT=%d\n",j,MAX_GSKILL_CNT);
- cmds=CMDFAIL;
- }
- statswoe_gkill[i][0]=0; //Reset cpt_id_gkill
- for(j=0;j<MAX_GKILL_CNT;j++) statswoe_gkill[i][j]=0; //Reset killcount
- if(j!=MAX_GKILL_CNT) {
- ShowError ("Error occur in clean gkillcount\n j=%d | MAX_GKILL_CNT=%d\n",j,MAX_GKILL_CNT);
- cmds=CMDFAIL;
- }
- }
- if(i!=MAX_GUILD_ID) { //Check if all tab erased
- ShowError ("Error occur in clean_tab\n i=%d | MAX_GUILD_ID=%d\n",i,MAX_GUILD_ID);
- cmds=CMDFAIL;
- }
- for (j=0;j<MAX_SKILL_CNT;j++) statswoe_skill[0][j]=0; //Reset cpt_rec_skill
- if(j!=MAX_SKILL_CNT) {
- ShowError ("Error occur in clean cpt_rec_skill\n j=%d | MAX_SKILL_CNT=%d\n",j,MAX_SKILL_CNT);
- cmds=CMDFAIL;
- }
- for (j=0;j<MAX_GSKILL_CNT;j++) statswoe_gskill[0][j]=0; //Reset cpt_rec_gskill
- if(j!=MAX_GSKILL_CNT) {
- ShowError ("Error occur in clean cpt_rec_skill\n j=%d | MAX_GSKILL_CNT=%d\n",j,MAX_GSKILL_CNT);
- cmds=CMDFAIL;
- }
- for (j=0;j<MAX_CONSO_CNT;j++) statswoe_conso[0][j]=0; //Reset cpt_rec_conso
- if(j!=MAX_CONSO_CNT) {
- ShowError ("Error occur in clean cpt_rec_conso\n j=%d | MAX_CONSO_CNT=%d\n",j,MAX_CONSO_CNT);
- cmds=CMDFAIL;
- }
- return cmds;
- }
- /*
- * Fonction pour nettoyer entierement les stats.
- * Appeler par script_agitstart à chaque debut de woe.
- * @TODO parameter so not clean all everytime ?
- */
- int statslof_clean() {
- char query[QUERY_LENGTH];
- cmds=CMDDEF;
- statslof_clean_tab();
- #ifndef TXT_ONLY
- sprintf(query, "TRUNCATE TABLE `%s`", stats_data); //Clean sql table data
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_player_skill_db); //Clean sql table skill (player)
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_guild_skill_db); //Clean sql table gskill (guilde)
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_player_conso_db); //Clean sql table conso
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_player_dmg_db); //Clean sql table dmg
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_player_heal_db); //Clean sql table heal
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`",stats_player_kill_db); //Clean sql table kill (player)
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- sprintf(query, "TRUNCATE TABLE `%s`", stats_guild_kill_db); //Clean sql table gkill (guilde)
- if (SQL_SUCCESS!=Sql_Query(mmysql_handle,query)) {
- Sql_ShowDebug(mmysql_handle);
- cmds=CMDFAIL;
- }
- #endif /* not TXT_ONLY */
- if(cmds!=CMDFAIL) cmds=CMDOK; //Check if all cmd was sucess
- return cmds;
- }
- /*
- * Fonction pour activer les stats.
- * Appeler par script_agitstart à chaque debut de woe.
- */
- int statslof_enable(int typeStat) {
- cmds=CMDDEF; //Commande status
- switch(typeStat) {
- case TYPEWOE : //Enable statsWoe
- if (enable!=1) {
- enable=1; //Activation stats woe
- statslof_init();
- cmds=CMDOK;
- }
- else cmds=CMDFAIL;
- break;
- case TYPERWC : //Enable statsRWC
- if ((enable>>1)!=1) {
- enable|=2; //Activation stats RWC
- cmds=CMDOK;
- }
- else cmds=CMDFAIL;
- break;
- default : cmds=CMDDEF;
- }
- return cmds;
- }
- /*
- * Fonction pour activer les stats.
- * Appeler par script_agitstart à chaque debut de woe.
- */
- int statslof_disable(int typeStat) {
- cmds=CMDDEF; //Commande status
- switch(typeStat) {
- case TYPEWOE:
- if (enable==1) {
- enable=0; //Desactivation stats woe
- cmds=CMDOK;
- }
- else cmds=CMDFAIL;
- break;
- case TYPERWC : //Disable statsRWC
- if ((enable>>1)==1) {
- int tmp=0;
- enable&=tmp<<1; //Desactivation stats RWC
- cmds=CMDOK;
- }
- else cmds=CMDFAIL;
- break;
- default : cmds=CMDDEF;
- }
- return cmds;
- }
- /*
- * Fonction d'affichage des stats.
- * For Test mode purpose ONLY !!
- */
- int statslof_display(struct map_session_data *sd, int statstype){
- unsigned int k=0, l=0;
- char cptcharinfo[CHAT_SIZE_MAX], charinfo[CHAT_SIZE_MAX], cptguildinfo[CHAT_SIZE_MAX], guildinfo[CHAT_SIZE_MAX];
- char cpt_rec_skillinfo[CHAT_SIZE_MAX], skillinfo[CHAT_SIZE_MAX];
- char cpt_rec_consoinfo[CHAT_SIZE_MAX], consoinfo[CHAT_SIZE_MAX];
- char cpt_rec_dmginfo[CHAT_SIZE_MAX], dmginfo[CHAT_SIZE_MAX];
- char killinfo[CHAT_SIZE_MAX], healinfo[CHAT_SIZE_MAX];
- struct item_data *itemdataintab;
- cmds=CMDDEF;
- if (sd==NULL) return 1; //Security check
- switch(statstype){
- case STATSKILL :
- sprintf(cptcharinfo, "Cptchar : %d",cpt_id_skill);
- //ShowWarning("%s\n",cptcharinfo);
- clif_displaymessage(sd->fd,cptcharinfo);
- sprintf(cpt_rec_skillinfo, "Total different skill : %d ",cpt_rec_skill);
- //ShowWarning("%s\n",cpt_rec_skillinfo);
- clif_displaymessage(sd->fd,cpt_rec_skillinfo);
- for(k=2;k<cpt_id_skill+2;k++){
- sprintf(charinfo, "Char Info %d :",statswoe_skill[k][0]);
- //ShowWarning("%s\n",charinfo);
- clif_displaymessage(sd->fd,charinfo);
- for(l=1;l<=cpt_rec_skill;l++) {
- sprintf(skillinfo, "Skill info number :%s count :%d type :%d",skill_get_desc(statswoe_skill[0][l]),statswoe_skill[k][l],statswoe_skill[1][l]);
- //ShowWarning("%s\n",skillinfo);
- clif_displaymessage(sd->fd, skillinfo);
- }
- }
- if ((k==cpt_id_skill-1)&&(l==cpt_rec_skill)) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- //Display conso tab
- case STATCONSO :
- sprintf(cptcharinfo, "Cptchar : %d",cpt_id_conso);
- //ShowWarning("%s\n",cptcharinfo);
- clif_displaymessage(sd->fd,cptcharinfo);
- sprintf(cpt_rec_consoinfo, "Total conso cnt : %d",cpt_rec_conso);
- //ShowWarning("%s\n",cpt_rec_consoinfo);
- clif_displaymessage(sd->fd,cpt_rec_consoinfo);
- for(k=1;k<=cpt_id_conso;k++){
- sprintf(charinfo, "Char Info %d :",statswoe_conso[k][0]);
- //ShowWarning("%s\n",charinfo);
- clif_displaymessage(sd->fd,charinfo);
- for(l=1;l<=cpt_rec_conso;l++) {
- itemdataintab=itemdb_search(statswoe_conso[0][l]);
- sprintf(consoinfo, "Item info :%s count :%d",itemdataintab->jname,statswoe_conso[k][l]);
- //ShowWarning("%s\n",consoinfo);
- clif_displaymessage(sd->fd, consoinfo);
- }
- }
- if ((k==cpt_id_conso)&&(l==cpt_rec_conso)) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- //Display dmg tab
- case STATDMG :
- sprintf(cptcharinfo, "Cptchar : %d",cpt_id_dmg);
- //ShowWarning("%s\n",cptcharinfo);
- clif_displaymessage(sd->fd,cptcharinfo);
- sprintf(cpt_rec_dmginfo, "Total dmg cnt : %d",cpt_rec_dmg);
- //ShowWarning("%s\n",cpt_rec_dmginfo);
- clif_displaymessage(sd->fd,cpt_rec_dmginfo);
- for(k=1;k<=cpt_id_dmg;k++){
- sprintf(charinfo, "Char Info %d : ",statswoe_dmg[k][0]);
- //ShowWarning("%s\n",charinfo);
- clif_displaymessage(sd->fd,charinfo);
- sprintf(dmginfo, "Dammage rec total info :%d",statswoe_dmg[k][1]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage rec max info :%d",statswoe_dmg[k][2]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done total info :%d",statswoe_dmg[k][3]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done max info :%d",statswoe_dmg[k][4]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done emp :%d",statswoe_dmg[k][5]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done barri :%d",statswoe_dmg[k][6]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done stone :%d",statswoe_dmg[k][7]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done guardien SE :%d",statswoe_dmg[k][8]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- sprintf(dmginfo, "Dammage done guardien FE :%d",statswoe_dmg[k][9]);
- //ShowWarning("%s\n",dmginfo);
- clif_displaymessage(sd->fd, dmginfo);
- }
- if (k==cpt_id_dmg) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- //Display kill tab
- case STATKILL :
- sprintf(cptcharinfo, "Cptchar : %d ",cpt_id_kill);
- //ShowWarning("%s\n",cptcharinfo);
- clif_displaymessage(sd->fd,cptcharinfo);
- for(k=1;k<=cpt_id_kill;k++){
- sprintf(charinfo, "Char Info %d : ",statswoe_kill[k][0]);
- //ShowWarning("%s\n",charinfo);
- clif_displaymessage(sd->fd,charinfo);
- sprintf(killinfo, "Kill info number :death count :%d",statswoe_kill[k][1]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :player count :%d",statswoe_kill[k][2]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :emperium count :%d",statswoe_kill[k][3]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :guardian (fe?) count :%d",statswoe_kill[k][4]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :guardian (se?) count :%d",statswoe_kill[k][5]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :barricade count :%d",statswoe_kill[k][6]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :stone guardian count :%d",statswoe_kill[k][7]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- }
- if (k==cpt_id_kill) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- case STATHEAL :
- sprintf(cptcharinfo, "Cptchar : %d ",cpt_id_heal);
- //ShowWarning("%s\n",cptcharinfo);
- clif_displaymessage(sd->fd,cptcharinfo);
- for(k=1;k<=cpt_id_heal;k++){
- sprintf(charinfo, "Char Info %d : ",statswoe_heal[k][0]);
- //ShowWarning("%s\n",charinfo);
- clif_displaymessage(sd->fd,charinfo);
- sprintf(healinfo, "Heal done total info :%d",statswoe_heal[k][1]);
- //ShowWarning("%s\n",healinfo);
- clif_displaymessage(sd->fd, healinfo);
- sprintf(healinfo, "Heal done max info :%d",statswoe_heal[k][2]);
- //ShowWarning("%s\n",healinfo);
- clif_displaymessage(sd->fd, healinfo);
- sprintf(healinfo, "Heal receive total info :%d",statswoe_heal[k][3]);
- //ShowWarning("%s\n",healinfo);
- clif_displaymessage(sd->fd, healinfo);
- sprintf(healinfo, "Heal receive max info :%d",statswoe_heal[k][4]);
- //ShowWarning("%s\n",healinfo);
- clif_displaymessage(sd->fd, healinfo);
- }
- if (k==cpt_id_heal) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- case STATGSKILL :
- sprintf(cptguildinfo, "Cptguild : %d ",cpt_id_gskill);
- //ShowWarning("%s\n",cptguildinfo);
- clif_displaymessage(sd->fd,cptguildinfo);
- sprintf(cpt_rec_skillinfo, "Total different skill : %d ",cpt_rec_gskill);
- //ShowWarning("%s\n",cpt_rec_skillinfo);
- clif_displaymessage(sd->fd,cpt_rec_skillinfo);
- for(k=1;k<=cpt_id_gskill;k++){
- sprintf(guildinfo, "Guild Info %d : ",statswoe_gskill[k][0]);
- //ShowWarning("%s\n",guildinfo);
- clif_displaymessage(sd->fd,guildinfo);
- for(l=1;l<=cpt_rec_gskill;l++) {
- sprintf(guildinfo, "Skill info number :%s count :%d ",skill_get_desc(statswoe_gskill[0][l]),statswoe_gskill[k][l]);
- //ShowWarning("%s\n",guildinfo);
- clif_displaymessage(sd->fd, guildinfo);
- }
- }
- if ((k==cpt_id_gskill)&&(l==cpt_rec_gskill)) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- case STATGKILL :
- sprintf(cptguildinfo, "Cptguild : %d ",cpt_id_gkill);
- //ShowWarning("%s\n",cptguildinfo);
- clif_displaymessage(sd->fd,cptguildinfo);
- for(k=1;k<=cpt_id_gkill;k++){
- sprintf(guildinfo, "Guild Info %d : ",statswoe_gkill[k][0]);
- //ShowWarning("%s\n",guildinfo);
- clif_displaymessage(sd->fd,guildinfo);
- sprintf(killinfo, "Kill info number :death count :%d",statswoe_gkill[k][1]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :player count :%d",statswoe_gkill[k][2]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :emperium count :%d",statswoe_gkill[k][3]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :guardian (fe?) count :%d",statswoe_gkill[k][4]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :guardian (se?) count :%d",statswoe_gkill[k][5]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :barricade count :%d",statswoe_gkill[k][6]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- sprintf(killinfo, "Kill info number :stone guardian count :%d",statswoe_gkill[k][7]);
- //ShowWarning("%s\n",killinfo);
- clif_displaymessage(sd->fd, killinfo);
- }
- //ShowWarning("k=%d, cpt=%d\n",k, cpt_id_gkill);
- if (k==cpt_id_gkill) cmds=CMDOK; //Check if was success
- else cmds=CMDFAIL;
- break;
- default : cmds=CMDDEF;
- }
- return cmds;
- }
- /*
- * Fonction pour simuler le fonctionnement IG
- * Genere des stats alétoire et regarde le fonctionnement de nos methodes
- */
- int statslof_test(struct map_session_data *sd){
- // Oki ca bug un peu bcp xd =)
- int i=0, j=0, tmp=0;
- int idplayer=0, idguild, idskill=0, idconso=0, idkill=0, idbyplayer=0, dammage=0,type=0, heal=0;
- static unsigned int idcharmin=100025, idcharmax=172829, idguildmax=1165;
- static unsigned int idskillmin=1, idskillmax=544;
- static unsigned int idconsomin=500, idconsomax=700;
- static unsigned int dmgmin=10000, dmgmax=300000, healmin=600, healmax=20000;
- static unsigned int idkilltab[10]={1,2,1288,1285,1286,1287,1899,1905,1907,1908};
- static unsigned int gskilltab[4]={10010,10011,10012,10013};
- cmds=CMDDEF;
- if (sd==NULL) return 1; //Security check
- if(statslof_reset()==CMDFAIL) {
- ShowError ("\n Statslof_reset Failed in a Test call\n Test is canceled");
- return CMDFAIL;
- }
- srand ( (unsigned)time ( NULL ) );
- for(i=0;i<=MAX_CHAR_ID+5;i++) {
- idplayer= (rand()%(idcharmax+1-idcharmin)) + idcharmin; //[150000;180000]
- //Skill tests
- for (j=0;j<=MAX_SKILL_CNT+5;j++) {
- idskill=(rand()%(idskillmax+1-idskillmin)) + idskillmin; //[1;544]
- type=rand()%2; //[0;1]
- statslof_skill_cnt(sd, idplayer, idskill,type);
- }
- if (j!=MAX_SKILL_CNT+5) cmds=CMDFAIL;
- //Conso tests
- for (j=0;j<=MAX_CONSO_CNT+5;j++) {
- idconso=(rand()%(idconsomax+1-idconsomin)) + idconsomin; //[500;700]
- statslof_conso_cnt(sd, idplayer, idconso);
- }
- if (j!=MAX_CONSO_CNT+5) cmds=CMDFAIL;
- //Kill tests
- for (j=0;j<=MAX_KILL_CNT+5;j++) {
- tmp=(rand()% 10); //[0;9]
- idkill=idkilltab[tmp];
- statslof_kill_cnt(sd, idplayer, idkill);
- }
- if (j!=MAX_KILL_CNT+5) cmds=CMDFAIL;
- //Dmg tests
- for (j=0;j<=MAX_DMG_DONE+5;j++) {
- dammage=(rand()%(dmgmax+1-dmgmin)) + dmgmin;
- idbyplayer=(rand()%(idcharmax+1-idcharmin)) + idcharmin; //[150000;180000]
- statslof_damage_cnt(sd, idplayer, idbyplayer, dammage);
- }
- if (j!=MAX_DMG_DONE+5) cmds=CMDFAIL;
- //Heal tests
- for (j=0;j<=MAX_DMG_DONE+5;j++) {
- heal=(rand()%(healmax+1-healmin)) + healmin; //[600;20000]
- type=rand()%2; //[0;1]
- statslof_heal_cnt(sd, idplayer, heal, type);
- }
- if (j!=MAX_DMG_DONE+5) cmds=CMDFAIL;
- }
- if (i!=MAX_CHAR_ID+5) cmds=CMDFAIL;
- //ShowWarning("Char simulation complete\n");
- for(i=0; i<=MAX_GUILD_ID+5; i++){
- idguild= (rand()%idguildmax)+1; //[1;1165]
- //Skill tests
- for (j=0;j<=MAX_GSKILL_CNT+5;j++) {
- tmp=(rand()% 4); //[0;3]
- idskill=gskilltab[tmp];
- statslof_gskill_cnt(sd, idguild, idskill);
- }
- if (j!=MAX_GSKILL_CNT+5) cmds=CMDFAIL;
- //Kill tests
- for (j=0;j<=MAX_GKILL_CNT+5;j++) {
- tmp=(rand()% 10); //[0;9]
- idkill=idkilltab[tmp];
- statslof_gkill_cnt(sd, idguild, idkill);
- }
- if (j!=MAX_GKILL_CNT+5) cmds=CMDFAIL;
- }
- if (i!=MAX_GUILD_ID+5) cmds=CMDFAIL;
- //ShowWarning("Guild simulation complete\n");
- #ifndef TXT_ONLY
- tmp=statslof_insert_inDB();
- #endif /* not TXT_ONLY */
- if (tmp!=CMDOK) cmds=CMDFAIL;
- //ShowWarning("Full simulation complete\n");
- if(cmds==CMDDEF) cmds=CMDOK;
- return cmds;
- }
- // getCurrentTime()
- // returns int in this format hhmmss
- int statslof_getCurrentTime(){
- time_t rawtime;
- struct tm * timeinfo;
- int rtime=0,h=0,m=0,s=0;
- time ( &rawtime );
- timeinfo = localtime ( &rawtime );
- mktime ( timeinfo );
- #ifndef WIN32
- h = timeinfo->tm_hour*pow(10,4);
- m = timeinfo->tm_min*pow(10,2);
- s = timeinfo->tm_sec;
- rtime = h+m+s;
- #endif
- return rtime;
- }
- // getCurrentDate()
- // returns int in this format yyyymmdd
- //@TODO adapt format for SQL yyyy-mm-dd should be better.
- int statslof_getCurrentDate(){
- time_t rawtime;
- struct tm * timeinfo;
- int rtime=0,y=0,m=0,d=0;
- time ( &rawtime );
- timeinfo = localtime ( &rawtime );
- mktime ( timeinfo );
- #ifndef WIN32
- y = (timeinfo->tm_year+1900)*pow(10,4);
- m = (timeinfo->tm_mon+1)*pow(10,2);
- d = timeinfo->tm_mday;
- rtime = y+m+d;
- #endif
- return rtime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement