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