IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Boost C++ Discussion :

boost::asio win / linux


Sujet :

Boost C++

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut boost::asio win / linux
    Bonjour sous windows avec boost::asio il me suffit de lancer un petit thread qui contient :

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    while (pRunning)
    {
        pIoService.run();
        Sleep(10);
    }

    sa fonctionne comme il faut, mais linux n'aime pas trop, a moin de lancer manuellement de pIoService.run() dans le thread principale sa ne fonctionne pas ... Quelqun as une idée ?

  2. #2
    Membre chevronné
    Avatar de poukill
    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 155
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 155
    Points : 2 107
    Points
    2 107
    Par défaut
    Je comprends pas trop ton code...
    boost::asio::io_service::run est bloquant. Donc effectivement souvent on le met dans un thread:
    Code Exemple de projet Qt : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    // .h
    class MainWindow
    {
        //
    private:
        boost::asio::io_service			m_io_service;
        boost::asio::io_service::work	m_work_io_service;
        boost::thread					m_asio_thread;
    };
     
    // .cpp
    MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
    :m_io_service(),
    m_work_io_service(m_io_service),
    m_asio_thread(boost::bind(&boost::asio::io_service::run, boost::ref(m_io_service))),
    ...
    {}
     
    MainWindow::~MainWindow()
    {
    	m_io_service.stop();
    	m_asio_thread.join();
    }

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    hummm je vais essayer ton code , le probleme que je rencontre c'est que le run ne fait rien , peut etre qu'il me fait une copie quelque par, enfin je vais voir

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    peut tu m'expliquer a quoi correspond boost::asio::io_service::work ?

  5. #5
    Membre chevronné
    Avatar de poukill
    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 155
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 155
    Points : 2 107
    Points
    2 107
    Par défaut
    Citation Envoyé par hardcpp Voir le message
    hummm je vais essayer ton code , le probleme que je rencontre c'est que le run ne fait rien , peut etre qu'il me fait une copie quelque par, enfin je vais voir
    io_service est non copiable, c'est impossible.

    Citation Envoyé par hardcpp Voir le message
    peut tu m'expliquer a quoi correspond boost::asio::io_service::work ?
    A empecher que io_service::run s'arrête lorsqu'il n'a plus de travail (cf doc). Tu n'en a surement pas besoin. Moi c'est spécial !

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    si x) c'est sa qu'il me faudrait =) et pour l'arreter ?

    EDIT : merci de ton aide sa fonctionne

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    par contre j'ai une assée grande (environ 1,5 seconde : serveur dédié ovh) latence entre les envoie / reception de packet avec linux ...

  8. #8
    Membre chevronné
    Avatar de poukill
    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 155
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 155
    Points : 2 107
    Points
    2 107
    Par défaut
    Citation Envoyé par hardcpp Voir le message
    par contre j'ai une assée grande (environ 1,5 seconde : serveur dédié ovh) latence entre les envoie / reception de packet avec linux ...
    Bigre, c'est beaucoup. Et avec la version Windows tu l'as pas ?

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    sous windows aucun lag :/ je vous montre le code (après c'est peut etre mysql)

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    #include "WorldSocket.hpp"
    #include "Service.hpp"
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <typeinfo>
    #include <stdexcept>
    #include <string.h>
     
    namespace Akhynia { namespace SDK { namespace Network {
     
    	/// Constructor
    	WorldSocket::WorldSocket()
    		:	pHandler(0), pSocket(Base::Service::GetSingleton()->GetIoService()), 
    			pListenSocket(0), pIsConnected(false), pIsServer(false), pListenOnceCheck(false)
    	{
    		Base::Service::GetSingleton()->Init();
    	}
    	/// Destructor
    	WorldSocket::~WorldSocket()
    	{
    		pPacketQueueMutex.lock();
    		while (pPacketQueue.empty() == false)
    			pPacketQueue.pop();
    		pPacketQueueMutex.unlock();
     
    		Disconnect();
     
    		if (pListenSocket != 0)
    		{
    			delete pListenSocket;
    		}
     
    		Base::Service::GetSingleton()->UnInit();
    	}
     
    	// ============================================================================================ //
     
    	/// Connect to a server
    	/// @param _Host : URL of server
    	void WorldSocket::Connect(IpAddress & _Host)
    	{
    		pRemoteHost = _Host;
    		pSocket.async_connect(_Host.GetEndPoint(), boost::bind(&WorldSocket::Async_Connect, this, boost::asio::placeholders::error));		
    	}
    	/// Listen on a port
    	/// @param _Port : Port to listen
    	void WorldSocket::Listen(const int &  _Port)
    	{
    		boost::system::error_code _Error;
     
    		pListenSocket = new boost::asio::ip::tcp::acceptor(Base::Service::GetSingleton()->GetIoService(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), _Port));
     
    		pPendingClient = new WorldSocket();
    		pListenSocket->async_accept(pPendingClient->pSocket, boost::bind(&WorldSocket::Async_Accept, this, boost::asio::placeholders::error));
     
    		pIsServer = true;
    	}
    	/// Disconnect to server
    	void WorldSocket::Disconnect()
    	{
    		if (pIsConnected == true)
    		{
    			pSocket.close();
    		}
    		else if (pIsServer == true)
    		{
    			pListenSocket->close();
    		}
    	}
     
    	// ============================================================================================ //
     
    	/// Send a packet
    	/// @param _Packet : Packet to send
    	void WorldSocket::Send(Packet * _Packet)
    	{
    		std::string								_OutboundHeader;
    		std::string								_OutboundData;
    		std::vector<boost::asio::const_buffer>	_Buffers;
    		std::ostringstream						_HeaderStream;
     
    		_HeaderStream << std::setw(8) << std::hex <<  _Packet->GetDataSize();
    		if (!_HeaderStream || _HeaderStream.str().size() != 8)
    		{
    			return ;
    		}
     
    		_OutboundHeader = _HeaderStream.str();
    		_OutboundData	= _Packet->GetData();
     
    		_Buffers.push_back(boost::asio::buffer(_OutboundHeader));
    		_Buffers.push_back(boost::asio::buffer((void*)_Packet->GetData(), _Packet->GetDataSize()));
     
    		pSocket.async_send(_Buffers, boost::bind(&WorldSocket::Async_Send, this, boost::asio::placeholders::error));
    	}
    	/// Recv a packet
    	/// @return Packet
    	Packet WorldSocket::Receive()
    	{
    		if (pPacketQueue.empty() == true)
    			return Packet();
     
    		pPacketQueueMutex.lock();
    		Packet _Received = pPacketQueue.front();
    		pPacketQueue.pop();
    		pPacketQueueMutex.unlock();
     
    		return _Received;
    	}
    	/// Release a Network packer
    	/// @param _Packet : Packet to release
    	void WorldSocket::ReleasePacket(Packet & _Packet)
    	{
     
    	}
     
    	// ============================================================================================ //
     
    	/// Set the socket handler
    	/// @param Handler : New socket functions handler
    	void WorldSocket::SetSocketHandler(SocketHandler * _Handler)
    	{
    		this->pHandler = _Handler;
    	}
     
    	// ============================================================================================ //
     
    	/// Get the socket handler
    	/// @return The current socket handler
    	SocketHandler * WorldSocket::GetSocketHandler()
    	{
    		return this->pHandler;
    	}
     
    	// ============================================================================================ //
     
    	/// Async connect handle
    	void WorldSocket::Async_Connect(const boost::system::error_code& _Error)
    	{
    		Packet _Tmp;
     
    		if (!_Error)
    		{
    			pIsConnected = true;
     
    			_Tmp << OpCode(OPCODE_CONNECTION_REQUEST_ACCEPTED); 
    			Logger::GetSingleton()->sLog("WorldSocket", "Connection request accepted to : %s:%d", pRemoteHost.GetEndPoint().address().to_string().c_str(), pRemoteHost.GetEndPoint().port());
     
    			if (pHandler)
    				pHandler->SocketHandle_ConnectionRequestAccepted(this);
     
    			StartRecursiveReceive();
    		}
    		else
    		{
    			pIsConnected = false;
     
    			_Tmp << OpCode(OPCODE_CONNECTION_REQUEST_FAILED); 
    			Logger::GetSingleton()->sLog("WorldSocket", "Connection request failed to : %s:%d", pRemoteHost.GetEndPoint().address().to_string().c_str(), pRemoteHost.GetEndPoint().port());	
     
    			if (pHandler)
    				pHandler->SocketHandle_ConnectionRequestFailed(this);	
    		}
    	}
    	/// Async accept handle
    	void WorldSocket::Async_Accept(const boost::system::error_code& _Error)
    	{
    		Packet _Tmp;
     
    		if (!_Error)
    		{
    			if (pListenOnceCheck == false)
    			{
    				Logger::GetSingleton()->sLog("WorldSocket", "Listen start");
     
    				pListenOnceCheck = true;
     
    				if (pHandler)
    					pHandler->SocketHandle_ListenStart(this);
    			}
     
    			Logger::GetSingleton()->sLog("WorldSocket", "New client : %s:%d", pPendingClient->pSocket.remote_endpoint().address().to_string().c_str(), pPendingClient->pSocket.remote_endpoint().port());
     
    			pPendingClient->pIsConnected	= true;
    			pPendingClient->StartRecursiveReceive();
     
    			if (pHandler)
    				pHandler->SocketHandle_NewClient(this, pPendingClient);
    		}
    		else
    		{
    			if (pListenOnceCheck == false)
    			{
    				Logger::GetSingleton()->eLog("WorldSocket", "Listen error");
     
    				pListenOnceCheck = true;
     
    				if (pHandler)
    					pHandler->SocketHandle_ListenError(this);	
    			}
     
    			Logger::GetSingleton()->eLog("WorldSocket", "New client accept failed");
     
    			if (pHandler)
    				pHandler->SocketHandle_NewClientAcceptError(this);
    		}
     
    		pPendingClient = new WorldSocket();
    		pListenSocket->async_accept(pPendingClient->pSocket, boost::bind(&WorldSocket::Async_Accept, this, boost::asio::placeholders::error));
    	}
    	/// Async send handle
    	void WorldSocket::Async_Send(const boost::system::error_code& _Error)
    	{
    		if (_Error)
    		{
    			Logger::GetSingleton()->eLog("WorldSocket", "Send packet failed");
     
    			Disconnect();
     
    			if (pHandler)	
    				pHandler->SocketHandle_ConnectionLostedOrDisconnected(this);
    		}
    	}
    	/// Async receive handle
    	void WorldSocket::Async_Receive(const boost::system::error_code& _Error, size_t _Received)
    	{
    		if (!_Error)
    		{
    			std::istringstream _Is(std::string(pInboundTcpHeader, 8));
    			pInboundTcpSize = 0;
     
    			if (!(_Is >> std::hex >> pInboundTcpSize))
    			{
    				return;
    			}
     
    			pInboundTcpData.resize(pInboundTcpSize);
     
    			boost::asio::async_read(pSocket, boost::asio::buffer(pInboundTcpData), boost::bind(&WorldSocket::Async_ReceiveData, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));			
    		}
    		else
    		{
    			Logger::GetSingleton()->eLog("WorldSocket", "Receive packet failed");
     
    			Disconnect();
     
    			if (pHandler)		
    				pHandler->SocketHandle_ConnectionLostedOrDisconnected(this);
    		}
    	}
    	/// Async receive handle
    	void WorldSocket::Async_ReceiveData(const boost::system::error_code& _Error, size_t _Received)
    	{
    		if (!_Error)
    		{
    			Packet _Packet;
    			_Packet.Append(&pInboundTcpData[0], pInboundTcpData.size());
     
    			pPacketQueueMutex.lock();
    			pPacketQueue.push(_Packet);
    			pPacketQueueMutex.unlock();
     
    			if(pHandler)
    				pHandler->SocketHandle_ReceivePacket(this);	
     
    			if (pIsConnected == true)
    				StartRecursiveReceive();
    		}
    		else
    		{
    			Logger::GetSingleton()->eLog("WorldSocket", "Receive packet failed");
     
    			Disconnect();
     
    			if (pHandler)		
    				pHandler->SocketHandle_ConnectionLostedOrDisconnected(this);
    		}
    	}
     
    	// ============================================================================================ //
     
    	/// Process a internal packet
    	/// @param _Packet : packet to process
    	void WorldSocket::InternalPacket(Packet * _Packet)
    	{
     
    	}
    	/// Loop of async_recv
    	void WorldSocket::StartRecursiveReceive()
    	{
    		if (pIsConnected == true)
    			boost::asio::async_read(pSocket, boost::asio::buffer(pInboundTcpHeader), boost::bind(&WorldSocket::Async_Receive, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
    	}
     
    }	// Network
    }	// SDK
    }	// Akhynia
    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    #include "stdafx.h"
    #include "Session.hpp"
    #include "LogonQuery.hpp"
    #include "ServerOperator.hpp"
     
    namespace Akhynia { namespace Server { namespace Logon {
     
    	/// Constructor
    	Session::Session(Akhynia::SDK::Network::WorldSocket * _Client, Akhynia::SDK::Network::DataBase::SQLDatabase * _Database, Akhynia::Server::Game::Logon::ServerVector	* _ServerList)
    		: pSocket(_Client), pRunning(true), pSessionStatus(SESSION_STATUS_NOT_LOGGED), pLogonMySQL(_Database), pServerList(_ServerList)
    	{
    		this->pSocket->SetSocketHandler(this);
    	}
    	/// Destructor
    	Session::~Session()
    	{
    		delete this->pSocket;
    	}
     
    	// ============================================================================================ //
     
    	/// Add packet to packet queue
    	/// @param _Packet : Packet to add
    	void Session::QueuePacket(Akhynia::SDK::Network::Packet _Packet)
    	{
    		this->pPacketsQueue.push(_Packet);
    	}
    	/// Update the session
    	void Session::Update()
    	{
    		if (pRunning == false)
    			return;
     
    		while (pPacketsQueue.empty() == false)
    		{
    			Akhynia::SDK::Network::Packet _Packet = pPacketsQueue.front();
     
    			Uint16 _OpCode;
    			_Packet >> _OpCode;
     
    			if (_OpCode < Akhynia::OPCODE_COUNT)
    			{
    				OpCodeHandler _OpCodeHandler = OpCodeTable[_OpCode];
     
    				if (_OpCodeHandler.Status <= pSessionStatus)
    					(this->*_OpCodeHandler.Handler)(&_Packet);
    			}
     
    			pPacketsQueue.pop();
    		}
    	}
     
    	// ============================================================================================ //
     
    	/// Get session stat
    	/// @return bool
    	bool Session::Running()
    	{
    		return this->pRunning;
    	}
    	/// Get session stat
    	/// @return bool
    	bool Session::operator()()
    	{
    		return this->pRunning;
    	}
     
    	// ============================================================================================ //
     
    	/// Packet receive
    	/// @param _Sender : Socket sender
    	/// @param _Data   : Packet data
    	void Session::SocketHandle_ReceivePacket(Akhynia::SDK::Network::WorldSocket * _Sender)
    	{
    		this->QueuePacket(_Sender->Receive());
    	}
    	/// Disconnect Notification
    	/// @param _Sender : Socket sender
    	void Session::SocketHandle_ConnectionLostedOrDisconnected(Akhynia::SDK::Network::WorldSocket * _Sender)
    	{
    		this->pRunning = false;
    	}
     
    	// ============================================================================================ //
     
    	/// Unknown opcode
    	/// @param _Packet : Received packet
    	void Session::OpCode_Unknown(Akhynia::SDK::Network::Packet * _Packet)
    	{
     
    	}
    	/// Logon request opcode
    	/// @param _Packet : Received packet
    	void Session::OpCode_LogonRequest(Akhynia::SDK::Network::Packet * _Packet)
    	{
    		Akhynia::SDK::Network::Packet _ToSend;
    		std::string _Login, _Password, _GameVersion;
     
    		(*_Packet) >> _Login;
    		(*_Packet) >> _Password;
    		(*_Packet) >> _GameVersion;
     
    		if (_GameVersion != CLIENT_SERVER_VERSION)
    		{
    			_ToSend << OpCode(SMSG_CLIENT_OLD_VERSION);
    		}
    		else
    		{
    			Akhynia::Server::Game::Logon::LogonQuery _Query(pLogonMySQL);
     
    			Uint16 _OpCode = _Query.Parse(_Login, _Password);
    			_ToSend << _OpCode;
     
    			if (_OpCode == SMSG_LOGON_REQUEST_SUCCESS)
    				pSessionStatus = SESSION_STATUS_LOGGED;
    		}
     
    		pSocket->Send(&_ToSend);
    	}
    	/// Server list request opcode
    	/// @param _Packet : Received packet
    	void Session::OpCode_GetServerList(Akhynia::SDK::Network::Packet * _Packet)
    	{
    		Akhynia::SDK::Network::Packet _ToSend;
    		_ToSend << OpCode(SMSG_GET_SERVER_LIST_REQUEST_DATA);
    		_ToSend << *pServerList;
     
    		pSocket->Send(&_ToSend);
    	}
     
    }	// Logon
    }	// Server
    }	// Akhynia
    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    #include "stdafx.h"
    #include "LogonQuery.hpp"
    #include "../../../OpCode.hpp"
     
    namespace Akhynia { namespace Server { namespace Game { namespace Logon {
     
    	/// Constructor
    	/// @param _DataBase : Database connection
    	LogonQuery::LogonQuery(Akhynia::SDK::Network::DataBase::SQLDatabase * _DataBase)
    		: pDataBase(_DataBase)
    	{
     
    	}
    	/// Destructor
    	LogonQuery::~LogonQuery()
    	{
     
    	}
     
    	// ============================================================================================ //
     
    	/// Execute a logon query
    	/// @param _Login    : Account login
    	/// @param _Password : Sha1 encrypted password
    	/// @return A OpCode
    	Uint16 LogonQuery::Parse(const std::string & _Login, const std::string & _Password)
    	{
    		if (_Login.find("--") != std::string::npos || _Password.find("--") != std::string::npos || _Login.find("'") != std::string::npos || _Password.find("'") != std::string::npos)
    			return false;
     
    		pDataBase->ThreadStart();
    		Akhynia::SDK::Network::DataBase::SQLQuery * _Query = pDataBase->ExecuteRequest(true, "SELECT ID, Banned, Online, Account_Level, Password FROM Account WHERE User='%s'", _Login.c_str());
     
    		Uint16 _Ret = SMSG_LOGON_REQUEST_FAILED;
     
    		if (_Query->QueryNextRow() == true && _Query->QueryGetField("Password")->String() == std::string(_Password))
    		{
    			if (_Query->QueryGetField("Banned")->Int32() == 1)
    				_Ret = SMSG_LOGON_REQUEST_ACCOUNT_BANNED;
    			else if (_Query->QueryGetField("Online")->Int32() == 1)
    				_Ret = SMSG_LOGON_REQUEST_ACCOUNT_USED;
    			else
    			{
    				pLogin			= _Login;
    				pPassword		= _Password;
    				pID				= _Query->QueryGetField("ID")->Int32();
    				pAccount_Level	= _Query->QueryGetField("Account_Level")->Int32();
     
    				_Ret = SMSG_LOGON_REQUEST_SUCCESS;
    			}
    		}
     
    		_Query->Release();
    		pDataBase->ThreadEnd();
     
    		return _Ret;
    	}
     
    }	// Logon
    }	// Game
    }	// Server
    }	// Akhynia

  10. #10
    Membre chevronné
    Avatar de poukill
    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 155
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 155
    Points : 2 107
    Points
    2 107
    Par défaut
    Comme ça, c'est dur à dire...

  11. #11
    Futur Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    J'ai trouver ya longtemps mais j'ai oublier de poster la solution.

    Mon prob c'est que sous linux le sleep il me le prend en seconde, allors que sous windows je l'ai bien en ms ... j'ai du utiliser usleep

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Utilisation de Select [Win/Linux]
    Par granquet dans le forum Réseau
    Réponses: 6
    Dernier message: 28/01/2010, 10h04
  2. Quel langage pour une meilleure portabilité Win/Linux
    Par darkervein dans le forum OpenGL
    Réponses: 3
    Dernier message: 22/04/2005, 14h59
  3. [JFrame] [Win/Linux] Comportement keyPressed/keyReleased
    Par plegat dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 23/11/2004, 18h27
  4. partage de connexion win-linux
    Par ynnotna dans le forum Développement
    Réponses: 2
    Dernier message: 15/07/2003, 15h38
  5. Réseau Win/Linux
    Par ben91 dans le forum Développement
    Réponses: 2
    Dernier message: 08/09/2002, 22h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo