Changeset 95

User picture

Author: Nairod

(2009/02/27 12:18) About 3 years ago

Le serveur se connecte à MySQL par la librairie mysql++

Affected files

Updated Serveur/Database.cpp Download diff

9495
2
2
3
Database::Database() : Moteur()
3
Database::Database() : Moteur()
4
{
4
{
5
    // constructeur
5
    _conn = mysqlpp::Connection(false);
6
}
6
}
7
7
8
8
9
bool Database::connect(std::string host, std::string base, 
9
bool Database::connect(std::string host, std::string base, 
10
						std::string user, std::string mdp)
10
						std::string user, std::string mdp)
11
{
11
{
12
	return true;
12
  	if (_conn.connect(base.c_str(), host.c_str(), user.c_str(), mdp.c_str()))
13
    {
14
    	std::cout << "Mysql : reussie" << std::endl;
15
    	return true;	
16
    }
17
    std::cout << "Mysql : échouée -> " << _conn.error() << std::endl;
18
	return false;
13
}
19
}

Updated Serveur/Database.hpp Download diff

9495
17
    	std::string _bdd_base;
17
    	std::string _bdd_base;
18
    	std::string _bdd_user;
18
    	std::string _bdd_user;
19
    	std::string _bdd_mdp;
19
    	std::string _bdd_mdp;
20
    	mysqlpp::Connection _conn;
20
    	
21
    	
21
    private:
22
    private:
22
};
23
};

Updated Serveur/Makefile Download diff

9495
8
OUT := Asimo
8
OUT := Asimo
9
9
10
all :
10
all :
11
	LC_ALL=C g++ -o $(OUT) $(LIB_LIB).so $(FILES) $(SFML) $(SQL) 
11
	LC_ALL=C g++ -o $(OUT) $(LIB_LIB).so $(FILES) $(SFML) $(SQL)
12
	
12
	
13
static :
13
static :
14
	LC_ALL=C g++ -o $(OUT) $(LIB_LIB).a $(FILES) $(SFML)
14
	LC_ALL=C g++ -o $(OUT) $(LIB_LIB).a $(FILES) $(SFML)

Updated Serveur/Reseau.hpp Download diff

9495
1
#ifndef RESEAU_H
1
#ifndef RESEAU_H
2
#define RESEAU_H
2
#define RESEAU_H
3
3
4
#include "SFML/Network.hpp"
5
#include "../Lib/include/Coord.hpp"
6
#include <iostream>
4
#include <iostream>
7
#include <vector>
5
#include <vector>
8
#include <stdarg.h>
6
#include <SFML/Network.hpp>
7
#include "../Lib/include/Coord.hpp"
8
#include "Database.hpp"
9
9
10
class Reseau // à adapter à Moteur
10
class Reseau // à adapter à Moteur
11
{
11
{
...
...
15
        void envoyer(std::string id, std::string message);
15
        void envoyer(std::string id, std::string message);
16
        Coord coord(std::string id); // chercher pos de id avec Database
16
        Coord coord(std::string id); // chercher pos de id avec Database
17
        void envoyerCurrent(std::string id, std::string message, std::vector<Coord> pos);
17
        void envoyerCurrent(std::string id, std::string message, std::vector<Coord> pos);
18
        
19
        void setBase(Database *base) {_base = base;}
20
        Database* getBase() {return _base;}
18
21
19
    protected:
22
    protected:
23
    	Database *_base;
24
    	
20
        int _port;
25
        int _port;
21
26
22
        // recevoir
27
        // recevoir

Updated Serveur/Serveur.cpp Download diff

9495
2
2
3
Serveur::Serveur()
3
Serveur::Serveur()
4
{
4
{
5
    // constructeur
5
	_base.connect("localhost","base","asimo","pass");
6
    _reseau.setBase(&_base);
6
}
7
}
7
8
8
void Serveur::run()
9
void Serveur::run()

Updated Serveur/Serveur.hpp Download diff

9495
2
#define SERVEUR_H
2
#define SERVEUR_H
3
3
4
#include "Reseau.hpp"
4
#include "Reseau.hpp"
5
#include "Database.hpp"
5
6
6
class Serveur
7
class Serveur
7
{
8
{
...
...
10
        void run();
11
        void run();
11
12
12
    protected:
13
    protected:
13
        Reseau _reseau;
14
        Reseau _reseau;
15
        Database _base;
14
16
15
    private:
17
    private:
16
};
18
};