1 (edited by DoctorTee 2014-05-25 20:07:47)

Topic: Error when compile utown mod

Hi all

I downloaded the uTown mod, and I'm modifing it.

I'm trying to modify the TeeWorlds Server to use a MySQL BDDR for the accounts in a City Mod.

But, when I've modified the file accounts.cpp, I've got a lot of errors, and I don't know how to resolve them.

Errors :

src/game/server/city/account.cpp: In member function ‘void CAccount::Login(char*, char*)’:
src/game/server/city/account.cpp:98:60: error: request for member ‘Username’ in ‘"SELECT * FROM account WHERE nickname = "’, which is of non-class type ‘const char [40]’
         request="SELECT * FROM account WHERE nickname = ". Username;
           src/game/server/city/account.cpp:113:20: erreur: cannot convert ‘MYSQL_ROW {aka char**}’ to ‘char*’ in assignment
             row[i] = mysql_fetch_row(result);
                    ^
src/game/server/city/account.cpp:118:20: erreur: incompatible types in assignment of ‘char*’ to ‘char [32]’
         AccUsername=row[0];
                    ^
src/game/server/city/account.cpp:119:20: erreur: incompatible types in assignment of ‘char*’ to ‘char [32]’
         AccPassword=row[1];
                    ^
src/game/server/city/account.cpp:120:16: erreur: incompatible types in assignment of ‘char*’ to ‘char [32]’
         AccRcon=row[2];
                ^
src/game/server/city/account.cpp:121:20: erreur: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
         AccID=row[3];
                    ^
                                                 ^

Code :

void CAccount::Login(char *Username, char *Password)
{
    char aBuf[125];
    MYSQL mysql;
    mysql_init(&mysql);
    mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    if(m_pPlayer->m_AccData.m_UserID)
    {
        dbg_msg("account", "Account login failed ('%s' - Already logged in)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Already logged in");
        return;
    }
    else if(strlen(Username) > 15 || !strlen(Username))
    {
        str_format(aBuf, sizeof(aBuf), "Username too %s", strlen(Username)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(strlen(Password) > 15 || !strlen(Password))
    {
        str_format(aBuf, sizeof(aBuf), "Password too %s!", strlen(Password)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(!Exists(Username))
    {
        dbg_msg("account", "Account login failed ('%s' - Missing)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "This account does not exist.");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Please register first. (/register <user> <pass>)");
        return;
    }

    char AccUsername[32];
    char AccPassword[32];
    char AccRcon[32];
    int AccID;

    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))
    {
        char request[100];
        request="SELECT * FROM account WHERE nickname = ". Username;
        mysql_query(&mysql, request);
        MYSQL_RES *result = NULL;
        MYSQL_ROW row;

        result = mysql_store_result(&mysql);
        num_champs = mysql_num_fields(result);

        while (i<num_champs)
        {
            row[i] = mysql_fetch_row(result)
            i++;
        }

        AccUsername=row[0];
        AccPassword=row[1];
        AccRcon=row[2];
        AccID=row[3];

        mysql_free_result(result);

        mysql_close(&mysql);
    }
    else
    {
        printf("An error as occured when tried to connect to the DB!");
    }

This is a part of the code, because the rest is not linked.

I'm not an expert in C++, so if it's a stupid error, be lenient please.

Can you help me ?

--
Doctor tee, newbie in modding for Teeworlds

2

Re: Error when compile utown mod

You can't copy arrays just with =.
You should try and learn more C++ before going in and tweaking the Teeworlds code.

Not Luck, Just Magic.

3 (edited by DoctorTee 2014-05-24 18:22:54)

Re: Error when compile utown mod

That's not the problem, I'll solve it soon .

The problem is the error about the var Username.

And, if you want to know, i'm not a newbie in programmation : I've already coded in C, PHP, Python...

EDIT : I've modified the code, for solve the problem (I've copyied a code, and I've lost some lines in road ^^' ).

--
Doctor tee, newbie in modding for Teeworlds

4

Re: Error when compile utown mod

Hello DoctorTee,

for copying char-arrays you could use str_format(...) or str_copy(...). Take a look into system.h to get the needed parameters.

In general, before assigning a variable of a different type you should cast it to the needed type and also in some cases you need to use pointer(*), references(&) or something else...


DoctorTee wrote:
        char request[100];
        request="SELECT * FROM account WHERE nickname = ". Username;
       

you can only use a = for char arrays on declaration:

char aText[] = "foo";
char aText2[100] = "bar";

the . Username is supposed to be a concatenation in PHP-style i guess
use the str_format function for that stuff

Greetings Pikotee

#yemDX is a known troll

5 (edited by DoctorTee 2014-05-26 18:15:57)

Re: Error when compile utown mod

Thank you a lot.

I'll try it tomorrow, And say if it works...

I solved the problem...

char request[100]="SELECT * FROM account WHERE nickname = ";
strcat(request, Username);

And it works now !

Please don't lock the topic, if I have some other problems. (And sorry for my horrible english, I'm french ^^ )

=================================

EDIT

Now, when I compile, I have these errors :

objs/game/server/city/account.o: dans la fonction « CAccount::Exists(char const*) »:
account.cpp:(.text+0x33): référence indéfinie vers « mysql_init »
account.cpp:(.text+0x4b): référence indéfinie vers « mysql_options »
account.cpp:(.text+0x8b): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x113): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x11b): référence indéfinie vers « mysql_use_result »
objs/game/server/city/account.o: dans la fonction « CAccount::Login(char*, char*) »:
account.cpp:(.text+0x173): référence indéfinie vers « mysql_init »
account.cpp:(.text+0x18b): référence indéfinie vers « mysql_options »
account.cpp:(.text+0x32c): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x3d1): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x3d9): référence indéfinie vers « mysql_store_result »
account.cpp:(.text+0x3e7): référence indéfinie vers « mysql_num_fields »
account.cpp:(.text+0x3f3): référence indéfinie vers « mysql_fetch_row »
account.cpp:(.text+0x4a3): référence indéfinie vers « mysql_free_result »
account.cpp:(.text+0x4ab): référence indéfinie vers « mysql_close »
account.cpp:(.text+0x5d2): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x67b): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x683): référence indéfinie vers « mysql_store_result »
account.cpp:(.text+0x691): référence indéfinie vers « mysql_num_fields »
account.cpp:(.text+0x6a1): référence indéfinie vers « mysql_fetch_row »
account.cpp:(.text+0x925): référence indéfinie vers « mysql_free_result »
account.cpp:(.text+0x92d): référence indéfinie vers « mysql_close »
objs/game/server/city/account.o: dans la fonction « CAccount::Register(char*, char*) »:
account.cpp:(.text+0xb1c): référence indéfinie vers « mysql_init »
account.cpp:(.text+0xb34): référence indéfinie vers « mysql_options »
account.cpp:(.text+0xd1d): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0xe45): référence indéfinie vers « mysql_query »
account.cpp:(.text+0xe4d): référence indéfinie vers « mysql_store_result »
account.cpp:(.text+0xe5d): référence indéfinie vers « mysql_free_result »
account.cpp:(.text+0xe65): référence indéfinie vers « mysql_close »
objs/game/server/city/account.o: dans la fonction « CAccount::Apply() »:
account.cpp:(.text+0xffc): référence indéfinie vers « mysql_init »
account.cpp:(.text+0x1014): référence indéfinie vers « mysql_options »
account.cpp:(.text+0x1054): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x192f): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x1937): référence indéfinie vers « mysql_store_result »
account.cpp:(.text+0x193f): référence indéfinie vers « mysql_free_result »
account.cpp:(.text+0x1947): référence indéfinie vers « mysql_close »
objs/game/server/city/account.o: dans la fonction « CAccount::Delete() »:
account.cpp:(.text+0x1b6b): référence indéfinie vers « mysql_init »
account.cpp:(.text+0x1b83): référence indéfinie vers « mysql_options »
account.cpp:(.text+0x1bdb): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x1caa): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x1cb2): référence indéfinie vers « mysql_close »
objs/game/server/city/account.o: dans la fonction « CAccount::NewUsername(char*) »:
account.cpp:(.text+0x1e73): référence indéfinie vers « mysql_init »
account.cpp:(.text+0x1e8b): référence indéfinie vers « mysql_options »
account.cpp:(.text+0x1f64): référence indéfinie vers « mysql_real_connect »
account.cpp:(.text+0x20ae): référence indéfinie vers « mysql_query »
account.cpp:(.text+0x20b6): référence indéfinie vers « mysql_close »
collect2: erreur: ld a retourné 1 code d'état d'exécution
bam: 'teeworlds_srv' error 256

I know, it's because the MySQL librairies are not linked in the compiler, but I don't know how to add them...

How can I solve that ?

--
Doctor tee, newbie in modding for Teeworlds

6

Re: Error when compile utown mod

DoctorTee wrote:
char request[100]="SELECT * FROM account WHERE nickname = ";
strcat(request, Username);

That code is dangerous, it opens up SQL injections (it might not be so bad because nicknames are limited), but think about what happens when the nick name is `1;DROP account` (you get the idea).

7

Re: Error when compile utown mod

heinrich5991 wrote:
DoctorTee wrote:
char request[100]="SELECT * FROM account WHERE nickname = ";
strcat(request, Username);

That code is dangerous, it opens up SQL injections (it might not be so bad because nicknames are limited), but think about what happens when the nick name is `1;DROP account` (you get the idea).

http://xkcd.com/327/

8

Re: Error when compile utown mod

Thx, but help me to solve my problem please

--
Doctor tee, newbie in modding for Teeworlds

9

Re: Error when compile utown mod

Look in bam.lua and search for sth like
'settings.link.libs:Add("somelib")'

Add a new lib to the correct settings (probably to server_settings, but you can also add it to settings).
Replace 'somelib' with your library name

10

Re: Error when compile utown mod

Thank you a lot... I'll try it tommorow.

For the MySQL request, I'll create a censure function for all the SQL keywords, and some other...

--
Doctor tee, newbie in modding for Teeworlds

11

Re: Error when compile utown mod

@Zgokee: that's my fav "comic"^^

@DoctorTee: don't write own functions to avoid vulnerabilities, use existing ones on the internet to avoid also coding mistakes

#yemDX is a known troll

12

Re: Error when compile utown mod

If you want...

Now, I'm searching on a good city map to prepare my city map and a correct config for the server

--
Doctor tee, newbie in modding for Teeworlds

13 (edited by Neox 2014-05-28 00:19:05)

Re: Error when compile utown mod

@DoctorTee: Pikotee is the coder of that mod, he also had published a map with it, just go and take it wink (well afaik he published a map)

while(!Success())
    TryAgain();
Try until you succeed.

14 (edited by 2014-05-31 20:11:49)

Re: Error when compile utown mod

I know neox, but where is the map, I haven't found it...

==
EDIT : I've found a map, but I still have problems with the mod...

It compiles, no error/warnings, but It don't works correctly...

When I try to connect to an account which is created, I've this error, always :

[account]: Account login failed ('PSEUDO' - already in use (local))

I don't know how it works, but the file ++UserID++.acc is empty, and I'm alone on my local server, because nobody can connect to it...

It's no usefull to say me :
"Learn C++ and learn how to use this code"

Thanks ^^


==

Little up...


==

An other little up...

Thanks ^^

--
Doctor tee, newbie in modding for Teeworlds

15

Re: Error when compile utown mod

I doubt that we can help you without the relevent source code.

16 (edited by DoctorTee 2014-06-05 20:15:49)

Re: Error when compile utown mod

I can give you my source code (The account.cpp), but you're going to yell on me...

This is a draft code, so it's not very... clean

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com.                */

#include <string.h>
#include <iostream>
#include <fstream>
#include <engine/config.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "account.h"
using namespace std;
//#include "game/server/gamecontext.h"
// Pour l'API MySQL
#include <mysql/mysql.h> //Ne pas l'oublier...

#if defined(CONF_FAMILY_UNIX)
    #include <sys/types.h>
    #include <fcntl.h>
    #include <unistd.h>
#endif

//A changer bien sur
#define MYSQL_HOST "localhost" //server
#define MYSQL_DB "{BD}" //nom de la BD
#define MYSQL_LOGIN "{LOGIN}" //login de connexion a la BD
#define MYSQL_PASSWD "{PASSWORD}" //mot de passe

CAccount::CAccount(CPlayer *pPlayer, CGameContext *pGameServer)
{
   m_pPlayer = pPlayer;
   m_pGameServer = pGameServer;
}

/*
#ifndef GAME_VERSION_H
#define GAME_VERSION_H
#ifndef NON_HASED_VERSION
#include "generated/nethash.cpp"
#define GAME_VERSION "0.6.1"
#define GAME_NETVERSION "0.6 626fce9a778df4d4" //the std game version
#endif
#endif
*/

void CAccount::Login(char *Username, char *Password)
{
    char aBuf[125];
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    if(m_pPlayer->m_AccData.m_UserID)
    {
        dbg_msg("account", "Account login failed ('%s' - Already logged in)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Already logged in");
        return;
    }
    else if(strlen(Username) > 15 || !strlen(Username))
    {
        str_format(aBuf, sizeof(aBuf), "Username too %s", strlen(Username)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(strlen(Password) > 15 || !strlen(Password))
    {
        str_format(aBuf, sizeof(aBuf), "Password too %s!", strlen(Password)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(!Exists(Username))
    {
        dbg_msg("account", "Account login failed ('%s' - Missing)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "This account does not exist.");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Please register first. (/register <user> <pass>)");
        dbg_msg("test", "test");
        return;
    }
dbg_msg("test", "test2");
    //str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", Username);

    char AccUsername[32];
    char AccPassword[32];
    char AccRcon[32];
    int AccID=-1;

dbg_msg("test", "test3");

    //FILE *Accfile;
    //Accfile = fopen(aBuf, "r");
    //fscanf(Accfile, "%s\n%s\n%s\n%d", AccUsername, AccPassword, AccRcon, &AccID);
    //fclose(Accfile);

    /********************/
    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
    {
    dbg_msg("test", "test4");
        //Requête qui sélectionne tout dans ma table account avec le nickname correspondant
        char request[200]="SELECT nickname, passwd, rcon, id FROM account WHERE nickname = \"";
        strcat(request, Username);
        strcat(request, "\"");
        dbg_msg("test", "REQUETE = %s", &request);
        mysql_query(&mysql, request);
        dbg_msg("test", "test5");
        //Déclaration des objets
        MYSQL_RES *result = NULL;
        MYSQL_ROW row;
        unsigned int i = 0;
        //unsigned int num_champs = 0;
        char *contenu[50];
        char IDtxt[5];
        int IDbddr=-1;
        dbg_msg("test", "test6");
        //On met le jeu de résultat dans le pointeur result
        result = mysql_store_result(&mysql);
        //dbg_msg("test", "test6_2");
        //num_champs = mysql_num_fields(result);
        //dbg_msg("test", "num_champs = %d", num_champs);
        //row = mysql_fetch_row(result);
        dbg_msg("test", "test7");
        //while (i<=num_champs)
        //i++;
        while ((row = mysql_fetch_row(result)))
        {
            dbg_msg("test", "test7_2");
            //row = mysql_fetch_row(result);
            //contenu[0]=row[0];
            /*if (i==4)
            {
                dbg_msg("test", "test8");
                strcat(IDtxt, row[i]);
                IDbddr=atoi(IDtxt);
            }
            else
            {
                dbg_msg("test", "test8_2_%d", i);
                strcat(contenu[i], row);
            }
            i++;*/
            for(i = 0; i <= 4; i++)
            {
                if (i==4)
                {
                    dbg_msg("test", "test8");
                    strcat(IDtxt, row[i]);
                    IDbddr=atoi(IDtxt);
                }
                else
                {
                    dbg_msg("test", "test8_2_%d", i);
                    dbg_msg("test", "row = %s", row[i]);
                    contenu[i] = row[i];
                    dbg_msg("test", "test8_2_2_%d", i);
                }
               //On ecrit toutes les valeurs
               //printf("[%.*s] ", (int) lengths[i], row[i] ? row[i] : "NULL");
            }
        }
        dbg_msg("test", "test9");
        //On fait une boucle pour avoir la valeur de chaque champs
        strcat(AccUsername, contenu[1]);
        dbg_msg("test", "test10");
        strcat(AccPassword, contenu[2]);
        dbg_msg("test", "test11");
        strcat(AccRcon, contenu[3]);
        dbg_msg("test", "test12");
        AccID = IDbddr;
        dbg_msg("test", "test13");
        //Libération du jeu de résultat
        mysql_free_result(result);
        dbg_msg("test", "test14");
        //Fermeture de MySQL
        mysql_close(&mysql);
        dbg_msg("test", "test15");
    }
    else
    {
      //printf("An error as occured when tried to connect to the DB!");
    }
    /********************/

    for(int i = 0; i < MAX_SERVER; i++)
    {
        for(int j = 0; j < MAX_CLIENTS; j++)
        {
            if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->m_AccData.m_UserID == AccID)
            {
                dbg_msg("account", "Account login failed ('%s' - already in use (local))", Username);
                GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Account already in use");
                return;
            }

            if(!GameServer()->m_aaExtIDs[i][j])
                continue;

            if(AccID == GameServer()->m_aaExtIDs[i][j])
            {
                dbg_msg("account", "Account login failed ('%s' - already in use (extern))", Username);
                GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Account already in use");
                return;
            }
        }
    }

    if(strcmp(Username, AccUsername))
    {
        dbg_msg("account", "Account login failed ('%s' - Wrong username)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Wrong username or password");
        return;
    }

    if(strcmp(Password, AccPassword))
    {
        dbg_msg("account", "Account login failed ('%s' - Wrong password)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Wrong username or password");
        return;
    }

    //FILE *Accfile;
    //Accfile = fopen(aBuf, "r");
    //fscanf(Accfile, "%s\n%s\n%s\n%d", AccUsername, AccPassword, AccRcon, &AccID);
    //fclose(Accfile);

    //Accfile = fopen(aBuf, "r");
    /****************/
    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
    {
        //Requête qui sélectionne tout dans ma table account avec le nickname correspondant
        char request[100]="SELECT * FROM account WHERE nickname = ";
        strcat(request, Username);
        mysql_query(&mysql, request);
        //Déclaration des objets
        MYSQL_RES *result = NULL;
        MYSQL_ROW row;
        unsigned int i = 0;
        unsigned int num_champs = 0;
        char *contenu[5];
        char valuetxt[5];
        int temp=-1;
        int valuebddr[40];

        //On met le jeu de résultat dans le pointeur result
        result = mysql_store_result(&mysql);
        num_champs = mysql_num_fields(result);
        row = mysql_fetch_row(result);

        while (i<=num_champs)
        {
            //row = mysql_fetch_row(result);
            //contenu[0]=row[0];
            if (i<4)
            {
                strcat(contenu[i], row[i]);
            }
            else
            {
                strcat(valuetxt, row[i]);
                temp=atoi(valuetxt);
                valuebddr[i]=temp;
            }
            i++;
        }

    /****************/

        //On fait une boucle pour avoir la valeur de chaque champs
        /*strcat(AccUsername, contenu[0]);
        strcat(AccPassword, contenu[1]);
        strcat(AccRcon, contenu[2]);
        AccID = IDbddr;*/

    /***********************/

        //On récupère les valeurs de chaque champ
        strcat(m_pPlayer->m_AccData.m_Username, contenu[0]);
        strcat(m_pPlayer->m_AccData.m_Password, contenu[1]);
        strcat(m_pPlayer->m_AccData.m_RconPassword, contenu[2]);
        m_pPlayer->m_AccData.m_UserID=valuebddr[3];

        m_pPlayer->m_AccData.m_HouseID=valuebddr[4];
         m_pPlayer->m_AccData.m_Money=valuebddr[5];
        m_pPlayer->m_AccData.m_Health=valuebddr[6];
        m_pPlayer->m_AccData.m_Armor=valuebddr[7];
        m_pPlayer->m_Score=valuebddr[8];

        m_pPlayer->m_AccData.m_Donor=valuebddr[9];
        m_pPlayer->m_AccData.m_VIP=valuebddr[10];
        m_pPlayer->m_AccData.m_Arrested=valuebddr[11];

        m_pPlayer->m_AccData.m_AllWeapons=valuebddr[12];
        m_pPlayer->m_AccData.m_HealthRegen=valuebddr[13];
        m_pPlayer->m_AccData.m_InfinityAmmo=valuebddr[14];
        m_pPlayer->m_AccData.m_InfinityJumps=valuebddr[15];
        m_pPlayer->m_AccData.m_FastReload=valuebddr[16];
        m_pPlayer->m_AccData.m_NoSelfDMG=valuebddr[17];

        m_pPlayer->m_AccData.m_GrenadeSpread=valuebddr[18];
        m_pPlayer->m_AccData.m_GrenadeBounce=valuebddr[19];
        m_pPlayer->m_AccData.m_GrenadeMine=valuebddr[20];

        m_pPlayer->m_AccData.m_ShotgunSpread=valuebddr[21];
        m_pPlayer->m_AccData.m_ShotgunExplode=valuebddr[22];
        m_pPlayer->m_AccData.m_ShotgunStars=valuebddr[23];

        m_pPlayer->m_AccData.m_RifleSpread=valuebddr[24];
        m_pPlayer->m_AccData.m_RifleSwap=valuebddr[25];
        m_pPlayer->m_AccData.m_RiflePlasma=valuebddr[26];

        m_pPlayer->m_AccData.m_GunSpread=valuebddr[27];
        m_pPlayer->m_AccData.m_GunExplode=valuebddr[28];
        m_pPlayer->m_AccData.m_GunFreeze=valuebddr[29];

        m_pPlayer->m_AccData.m_HammerWalls=valuebddr[30];
        m_pPlayer->m_AccData.m_HammerShot=valuebddr[31];
        m_pPlayer->m_AccData.m_HammerKill=valuebddr[32];

        m_pPlayer->m_AccData.m_NinjaPermanent=valuebddr[33];
        m_pPlayer->m_AccData.m_NinjaStart=valuebddr[34];
        m_pPlayer->m_AccData.m_NinjaSwitch=valuebddr[35];

        m_pPlayer->m_AccData.m_Level=valuebddr[36];
        m_pPlayer->m_AccData.m_ExpPoints=valuebddr[37];
        //}
        //Libération du jeu de résultat
        mysql_free_result(result);

        //Fermeture de MySQL
        mysql_close(&mysql);
    }
    else
    {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
    }
/****************/
    /*fscanf(Accfile, "%s\n%s\n%s\n%d\n\n\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d",
        m_pPlayer->m_AccData.m_Username, // Done
        m_pPlayer->m_AccData.m_Password, // Done
        m_pPlayer->m_AccData.m_RconPassword,
        &m_pPlayer->m_AccData.m_UserID, // Done

        &m_pPlayer->m_AccData.m_HouseID,
         &m_pPlayer->m_AccData.m_Money, // Done
        &m_pPlayer->m_AccData.m_Health, // Done
        &m_pPlayer->m_AccData.m_Armor, // Done
        &m_pPlayer->m_Score, // Done

        &m_pPlayer->m_AccData.m_Donor,
        &m_pPlayer->m_AccData.m_VIP, // Done
        &m_pPlayer->m_AccData.m_Arrested, // Done

        &m_pPlayer->m_AccData.m_AllWeapons, // Done
        &m_pPlayer->m_AccData.m_HealthRegen, // Done
        &m_pPlayer->m_AccData.m_InfinityAmmo, // Done
        &m_pPlayer->m_AccData.m_InfinityJumps, // Done
        &m_pPlayer->m_AccData.m_FastReload, // Done
        &m_pPlayer->m_AccData.m_NoSelfDMG, // Done

        &m_pPlayer->m_AccData.m_GrenadeSpread, // Done
        &m_pPlayer->m_AccData.m_GrenadeBounce, // Done
        &m_pPlayer->m_AccData.m_GrenadeMine,

        &m_pPlayer->m_AccData.m_ShotgunSpread, // Done
        &m_pPlayer->m_AccData.m_ShotgunExplode, // Done
        &m_pPlayer->m_AccData.m_ShotgunStars,

        &m_pPlayer->m_AccData.m_RifleSpread, // Done
        &m_pPlayer->m_AccData.m_RifleSwap, // Done
        &m_pPlayer->m_AccData.m_RiflePlasma, // Done

        &m_pPlayer->m_AccData.m_GunSpread, // Done
        &m_pPlayer->m_AccData.m_GunExplode, // Done
        &m_pPlayer->m_AccData.m_GunFreeze, // Done

        &m_pPlayer->m_AccData.m_HammerWalls, // Done
        &m_pPlayer->m_AccData.m_HammerShot, // Done
        &m_pPlayer->m_AccData.m_HammerKill, // Done

        &m_pPlayer->m_AccData.m_NinjaPermanent, // Done
        &m_pPlayer->m_AccData.m_NinjaStart, // Done
        &m_pPlayer->m_AccData.m_NinjaSwitch, // Done

        &m_pPlayer->m_AccData.m_Level,
        &m_pPlayer->m_AccData.m_ExpPoints);

    fclose(Accfile);*/

    CCharacter *pOwner = GameServer()->GetPlayerChar(m_pPlayer->GetCID());

    if(pOwner)
    {
        if(pOwner->IsAlive())
            pOwner->Die(m_pPlayer->GetCID(), WEAPON_GAME);
    }

    if(m_pPlayer->GetTeam() == TEAM_SPECTATORS)
        m_pPlayer->SetTeam(TEAM_RED);

    dbg_msg("account", "Account login sucessful ('%s')", Username);
    GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Login succesful");


    if(str_comp(m_pPlayer->m_AccData.m_RconPassword,g_Config.m_SvRconModPassword) == 0)
        GameServer()->Server()->SetRconlvl(m_pPlayer->GetCID(),1);

    else if(str_comp(m_pPlayer->m_AccData.m_RconPassword,g_Config.m_SvRconPassword) == 0)
        GameServer()->Server()->SetRconlvl(m_pPlayer->GetCID(),2);


}

void CAccount::Register(char *Username, char *Password)
{
    char aBuf[125];
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    if(m_pPlayer->m_AccData.m_UserID)
    {
        dbg_msg("account", "Account registration failed ('%s' - Logged in)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Already logged in");
        return;
    }
    if(strlen(Username) > 15 || !strlen(Username))
    {
        str_format(aBuf, sizeof(aBuf), "Username too %s", strlen(Username)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(strlen(Password) > 15 || !strlen(Password))
    {
        str_format(aBuf, sizeof(aBuf), "Password too %s!", strlen(Password)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }
    else if(Exists(Username))
    {
        dbg_msg("account", "Account registration failed ('%s' - Already exists)", Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Account already exists.");
        return;
    }

    #if defined(CONF_FAMILY_UNIX)
    char Filter[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_";
    // "äöü<>|!§$%&/()=?`´*'#+~«»¢“”æßðđŋħjĸł˝;,·^°@ł€¶ŧ←↓→øþ\\";
    char *p = strpbrk(Username, Filter);
    if(!p)
    {
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Don't use invalid chars for username!");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "A - Z, a - z, 0 - 9, . - _");
        return;
    }

    if(mkdir("accounts", mode_t S_IRWXU || S_IRWXG | S_IROTH | S_IXOTH))
        dbg_msg("account", "Account folder created!");
    #endif

    //str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", Username);

    /*FILE *Accfile;
    Accfile = fopen(aBuf, "a+");*/

/****************/
    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
    {
        //Requête qui ajoute une ligne avec comme valeurs le pseudo et le mdp dans la table account
        char request[100]="INSERT INTO account (nickname, passwd) VALUES (\"";
        strcat(request, Username);
        strcat(request, "\", \"");
        strcat(request, Password);
        strcat(request, "\")");
        mysql_query(&mysql, request);
        //Déclaration des objets
        MYSQL_RES *result = NULL;

        //On met le jeu de résultat dans le pointeur result
        /*result = mysql_store_result(&mysql);
        if (!result)
        {
            dbg_msg("ERROR", "Error : can't create account");
        }*/

        //}
        //Libération du jeu de résultat
        mysql_free_result(result);

        //Fermeture de MySQL
        mysql_close(&mysql);
    }
    else
    {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
    }
    /****************/


    /*str_format(aBuf, sizeof(aBuf), "%s\n%s\n%s\n%d\n\n\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d",
        Username,
        Password,
        "0",
        NextID(),

        m_pPlayer->m_AccData.m_HouseID,
        m_pPlayer->m_AccData.m_Money,
        m_pPlayer->m_AccData.m_Health<10?10:m_pPlayer->m_AccData.m_Health,
        m_pPlayer->m_AccData.m_Armor<10?10:m_pPlayer->m_AccData.m_Armor,
        m_pPlayer->m_Score<0?0:m_pPlayer->m_Score,

        m_pPlayer->m_AccData.m_Donor,
        m_pPlayer->m_AccData.m_VIP,
        m_pPlayer->m_AccData.m_Arrested,

        m_pPlayer->m_AccData.m_AllWeapons,
        m_pPlayer->m_AccData.m_HealthRegen,
        m_pPlayer->m_AccData.m_InfinityAmmo,
        m_pPlayer->m_AccData.m_InfinityJumps,
        m_pPlayer->m_AccData.m_FastReload,
        m_pPlayer->m_AccData.m_NoSelfDMG,

        m_pPlayer->m_AccData.m_GrenadeSpread,
        m_pPlayer->m_AccData.m_GrenadeBounce,
        m_pPlayer->m_AccData.m_GrenadeMine,

        m_pPlayer->m_AccData.m_ShotgunSpread,
        m_pPlayer->m_AccData.m_ShotgunExplode,
        m_pPlayer->m_AccData.m_ShotgunStars,

        m_pPlayer->m_AccData.m_RifleSpread,
        m_pPlayer->m_AccData.m_RifleSwap,
        m_pPlayer->m_AccData.m_RiflePlasma,

        m_pPlayer->m_AccData.m_GunSpread,
        m_pPlayer->m_AccData.m_GunExplode,
        m_pPlayer->m_AccData.m_GunFreeze,

        m_pPlayer->m_AccData.m_HammerWalls,
        m_pPlayer->m_AccData.m_HammerShot,
        m_pPlayer->m_AccData.m_HammerKill,

        m_pPlayer->m_AccData.m_NinjaPermanent,
        m_pPlayer->m_AccData.m_NinjaStart,
        m_pPlayer->m_AccData.m_NinjaSwitch,

        m_pPlayer->m_AccData.m_Level,
        m_pPlayer->m_AccData.m_ExpPoints);

    fputs(aBuf, Accfile);
    fclose(Accfile);*/

    dbg_msg("account", "Registration succesful ('%s')", Username);
    str_format(aBuf, sizeof(aBuf), "Registration succesful - ('/login %s %s'): ", Username, Password);
    GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
    Login(Username, Password);
}
bool CAccount::Exists(const char *Username)
{
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    /*char aBuf[128];
    /str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", Username);
    if(FILE *Accfile = fopen(aBuf, "r"))
    {
        fclose(Accfile);
        return true;
    }
    return false;*/
    /****************/
    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
    {
        //Requête qui sélectionne tout dans la table account avec le nickname correspondant
        char request[100]="SELECT * FROM account WHERE nickname = ";
        strcat(request, Username);
        mysql_query(&mysql, request);
        //Déclaration des objets
        MYSQL_RES *result = NULL;

        //On met le jeu de résultat dans le pointeur result
        result = mysql_use_result(&mysql);
        if (result == 0 || result == NULL)
        {
            return true;
        }
        else
        {
            return false;
        }

        //}
        //Libération du jeu de résultat
        mysql_free_result(result);

        //Fermeture de MySQL
        mysql_close(&mysql);
    }
    else
    {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
    }
    return true;
/****************/
}

void CAccount::Apply()
{
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    /*
    char aBuf[512];
    str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", m_pPlayer->m_AccData.m_Username);
    std::remove(aBuf);
    FILE *Accfile;
    Accfile = fopen(aBuf,"a+");

    str_format(aBuf, sizeof(aBuf), "%s\n%s\n%s\n%d\n\n\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n\n%d\n%d\n%d\n%d\n%d",
        m_pPlayer->m_AccData.m_Username,
        m_pPlayer->m_AccData.m_Password,
        m_pPlayer->m_AccData.m_RconPassword,
        m_pPlayer->m_AccData.m_UserID,

        m_pPlayer->m_AccData.m_HouseID,
        m_pPlayer->m_AccData.m_Money,
        m_pPlayer->m_AccData.m_Health,
        m_pPlayer->m_AccData.m_Armor,
        m_pPlayer->m_Score,

        m_pPlayer->m_AccData.m_Donor,
        m_pPlayer->m_AccData.m_VIP,
        m_pPlayer->m_AccData.m_Arrested,

        m_pPlayer->m_AccData.m_AllWeapons,
        m_pPlayer->m_AccData.m_HealthRegen,
        m_pPlayer->m_AccData.m_InfinityAmmo,
        m_pPlayer->m_AccData.m_InfinityJumps,
        m_pPlayer->m_AccData.m_FastReload,
        m_pPlayer->m_AccData.m_NoSelfDMG,

        m_pPlayer->m_AccData.m_GrenadeSpread,
        m_pPlayer->m_AccData.m_GrenadeBounce,
        m_pPlayer->m_AccData.m_GrenadeMine,

        m_pPlayer->m_AccData.m_ShotgunSpread,
        m_pPlayer->m_AccData.m_ShotgunExplode,
        m_pPlayer->m_AccData.m_ShotgunStars,

        m_pPlayer->m_AccData.m_RifleSpread,
        m_pPlayer->m_AccData.m_RifleSwap,
        m_pPlayer->m_AccData.m_RiflePlasma,

        m_pPlayer->m_AccData.m_GunSpread,
        m_pPlayer->m_AccData.m_GunExplode,
        m_pPlayer->m_AccData.m_GunFreeze,

        m_pPlayer->m_AccData.m_HammerWalls,
        m_pPlayer->m_AccData.m_HammerShot,
        m_pPlayer->m_AccData.m_HammerKill,

        m_pPlayer->m_AccData.m_NinjaPermanent,
        m_pPlayer->m_AccData.m_NinjaStart,
        m_pPlayer->m_AccData.m_NinjaSwitch,

        m_pPlayer->m_AccData.m_Level,
        m_pPlayer->m_AccData.m_ExpPoints);

    fputs(aBuf, Accfile);
    fclose(Accfile);*/
    /****************/
    if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
    {
        //Requête qui enregistre les données dans la BDDR
        char temp[20];
        char request[250]="INSERT INTO account VALUES VALUES (";
        strcat(request, m_pPlayer->m_AccData.m_Username);
        strcat(request, ",");
        strcat(request, m_pPlayer->m_AccData.m_Password);
        strcat(request, ",");
        strcat(request, m_pPlayer->m_AccData.m_RconPassword);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_UserID);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HouseID);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Money);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Health);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Armor);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_Score);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Donor);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_VIP);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Arrested);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_AllWeapons);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HealthRegen);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_InfinityAmmo);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_InfinityJumps);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_FastReload);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NoSelfDMG);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeBounce);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeMine);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunExplode);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunStars);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RifleSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RifleSwap);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RiflePlasma);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunExplode);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunFreeze);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerWalls);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerShot);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerKill);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaPermanent);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaStart);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaSwitch);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Level);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ExpPoints);
        strcat(request, temp);
        strcat(request, ");");

        mysql_query(&mysql, request);
        //Déclaration des objets
        MYSQL_RES *result = NULL;

        //On met le jeu de résultat dans le pointeur result
        result = mysql_store_result(&mysql);

        //}
        //Libération du jeu de résultat
        mysql_free_result(result);

        //Fermeture de MySQL
        mysql_close(&mysql);
    }
    else
    {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
    }
/****************/
}

void CAccount::Reset()
{
    str_copy(m_pPlayer->m_AccData.m_Username, "", 32);
    str_copy(m_pPlayer->m_AccData.m_Password, "", 32);
    str_copy(m_pPlayer->m_AccData.m_RconPassword, "", 32);
    m_pPlayer->m_AccData.m_UserID = 0;

    m_pPlayer->m_AccData.m_HouseID = 0;
    m_pPlayer->m_AccData.m_Money = 0;
    m_pPlayer->m_AccData.m_Health = 10;
    m_pPlayer->m_AccData.m_Armor = 10;
    m_pPlayer->m_Score = 0;

    m_pPlayer->m_AccData.m_Donor = 0;
    m_pPlayer->m_AccData.m_VIP = 0;
    m_pPlayer->m_AccData.m_Arrested = 0;

    m_pPlayer->m_AccData.m_AllWeapons = 0;
    m_pPlayer->m_AccData.m_HealthRegen = 0;
    m_pPlayer->m_AccData.m_InfinityAmmo = 0;
    m_pPlayer->m_AccData.m_InfinityJumps = 0;
    m_pPlayer->m_AccData.m_FastReload = 0;
    m_pPlayer->m_AccData.m_NoSelfDMG = 0;

    m_pPlayer->m_AccData.m_GrenadeSpread = 0;
    m_pPlayer->m_AccData.m_GrenadeBounce = 0;
    m_pPlayer->m_AccData.m_GrenadeMine = 0;

    m_pPlayer->m_AccData.m_ShotgunSpread = 0;
    m_pPlayer->m_AccData.m_ShotgunExplode = 0;
    m_pPlayer->m_AccData.m_ShotgunStars = 0;

    m_pPlayer->m_AccData.m_RifleSpread = 0;
    m_pPlayer->m_AccData.m_RifleSwap = 0;
    m_pPlayer->m_AccData.m_RiflePlasma = 0;

    m_pPlayer->m_AccData.m_GunSpread = 0;
    m_pPlayer->m_AccData.m_GunExplode = 0;
    m_pPlayer->m_AccData.m_GunFreeze = 0;

    m_pPlayer->m_AccData.m_HammerWalls = 0;
    m_pPlayer->m_AccData.m_HammerShot = 0;
    m_pPlayer->m_AccData.m_HammerKill = 0;

    m_pPlayer->m_AccData.m_NinjaPermanent = 0;
    m_pPlayer->m_AccData.m_NinjaStart = 0;
    m_pPlayer->m_AccData.m_NinjaSwitch = 0;

    m_pPlayer->m_AccData.m_Level = 1;
    m_pPlayer->m_AccData.m_ExpPoints = 0;

}

void CAccount::Delete()
{
    //char aBuf[128];
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    if(m_pPlayer->m_AccData.m_UserID)
    {
        Reset();
        /*str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", m_pPlayer->m_AccData.m_Username);
        std::remove(aBuf);
        */
            /****************/
        if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME BDDR
        {
            //Requête qui supprimme une ligne dans la table account avec l'ID donné
            char temp[20];
            char request[100]="DELETE FROM account WHERE `id` = \"";
            sprintf(temp, "%d", m_pPlayer->m_AccData.m_UserID);
            strcat(request, temp);
            strcat(request, "\";");
            mysql_query(&mysql, request);

            //Fermeture de MySQL
            mysql_close(&mysql);
        }
        else
        {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
        }
        /****************/
        dbg_msg("account", "Account deleted ('%s')", m_pPlayer->m_AccData.m_Username);
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Account deleted!");
    }
    else
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Please, login to delete your account");
}

void CAccount::NewPassword(char *NewPassword)
{
    char aBuf[128];
    if(!m_pPlayer->m_AccData.m_UserID)
    {
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Please, login to change the password");
        return;
    }
    if(strlen(NewPassword) > 15 || !strlen(NewPassword))
    {
        str_format(aBuf, sizeof(aBuf), "Password too %s!", strlen(NewPassword)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }

    str_copy(m_pPlayer->m_AccData.m_Password, NewPassword, 32);
    Apply();


    dbg_msg("account", "Password changed - ('%s')", m_pPlayer->m_AccData.m_Username);
    GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Password successfully changed!");
}

void CAccount::NewUsername(char *NewUsername)
{
    char aBuf[128];
    MYSQL mysql;
    mysql_init(&mysql);
    //mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"option");
    if(!m_pPlayer->m_AccData.m_UserID)
    {
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Please, login to change the username");
        return;
    }
    if(strlen(NewUsername) > 15 || !strlen(NewUsername))
    {
        str_format(aBuf, sizeof(aBuf), "Username too %s!", strlen(NewUsername)?"long":"short");
        GameServer()->SendChatTarget(m_pPlayer->GetCID(), aBuf);
        return;
    }

    /*str_format(aBuf, sizeof(aBuf), "accounts/+%s.acc", m_pPlayer->m_AccData.m_Username);
    std::rename(aBuf, NewUsername);*/
    /****************/
        if(mysql_real_connect(&mysql,MYSQL_HOST,MYSQL_LOGIN,MYSQL_PASSWD,MYSQL_DB,0,NULL,0))//FIXME : BDDR
        {
            //Requête qui met à jour une ligne dans la table account avec l'ID donné
            char request[100]="UPDATE account SET account.username=";
            char temp[20];
            //sprintf(temp, "%d", m_pPlayer->m_AccData.m_Username);
            strcat(request, m_pPlayer->m_AccData.m_Username);
            strcat(request, " WHERE accounts.id=");
            sprintf(temp, "%d", m_pPlayer->m_AccData.m_UserID);
            strcat(request, temp);
            strcat(request, ";");

            mysql_query(&mysql, request);

            //Fermeture de MySQL
            mysql_close(&mysql);
        }
        else
        {
      //printf("Une erreur s'est produite lors de la connexion à la BDD!");
        }
    /****************/

    str_copy(m_pPlayer->m_AccData.m_Username, NewUsername, 32);
    Apply();


    dbg_msg("account", "Username changed - ('%s')", m_pPlayer->m_AccData.m_Username);
    GameServer()->SendChatTarget(m_pPlayer->GetCID(), "Username successfully changed!");
}

int CAccount::NextID()
{
    FILE *Accfile;
    int UserID = 1;
    char aBuf[32];
    char AccUserID[32];

    str_copy(AccUserID, "accounts/++UserIDs++.acc", sizeof(AccUserID));//TODO : Vérifier s'il est encore actif...

    if(Exists("+UserIDs++"))
    {
        Accfile = fopen(AccUserID, "r");
        fscanf(Accfile, "%d", &UserID);
        fclose(Accfile);

        std::remove(AccUserID);

        Accfile = fopen(AccUserID, "a+");
        str_format(aBuf, sizeof(aBuf), "%d", UserID+1);
        fputs(aBuf, Accfile);
        fclose(Accfile);

        return UserID+1;
    }
    else
    {
        Accfile = fopen(AccUserID, "a+");
        str_format(aBuf, sizeof(aBuf), "%d", UserID);
        fputs(aBuf, Accfile);
        fclose(Accfile);
    }

    return 1;
}

I'm french, so there's some french sentences...
And the dbg_msg("test", "test2"); were for debug the server, because of some problems when launched it...

Be forgiving with me please, I'm not an expert ...

And I haven't modified correctly the rest of the code, it's only the login part which I'm debugging

=================

Up

--
Doctor tee, newbie in modding for Teeworlds

17

Re: Error when compile utown mod

You can't just post your code and expect someone to magically fix it.

Btw, what the..

strcat(request, m_pPlayer->m_AccData.m_Username);
        strcat(request, ",");
        strcat(request, m_pPlayer->m_AccData.m_Password);
        strcat(request, ",");
        strcat(request, m_pPlayer->m_AccData.m_RconPassword);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_UserID);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HouseID);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Money);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Health);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Armor);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_Score);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Donor);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_VIP);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Arrested);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_AllWeapons);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HealthRegen);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_InfinityAmmo);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_InfinityJumps);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_FastReload);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NoSelfDMG);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeBounce);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GrenadeMine);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunExplode);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ShotgunStars);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RifleSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RifleSwap);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_RiflePlasma);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunSpread);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunExplode);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_GunFreeze);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerWalls);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerShot);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_HammerKill);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaPermanent);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaStart);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_NinjaSwitch);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_Level);
        strcat(request, temp);
        strcat(request, ",");
        sprintf(temp, "%d", m_pPlayer->m_AccData.m_ExpPoints);
        strcat(request, temp);
        strcat(request, ");");

Use an array and a for loop, that's really ugly.

Not Luck, Just Magic.

18

Re: Error when compile utown mod

@DoctorTee: contact me in skype and i'll try my best to help you, cause i think i know the bugs and the code better than other. (name: georg96a) smile

#yemDX is a known troll

19

Re: Error when compile utown mod

Pikotee : Please add me.
Dune : I know that's ugly, but it's a draft, that's I sayed, so it's not the definitive code...

--
Doctor tee, newbie in modding for Teeworlds