Commit cfe163f4 authored by wcb's avatar wcb
Browse files

fixed #13

Showing with 74 additions and 12 deletions
+74 -12
#include <univ/univ.h>
#include <univ/log.h>
#include "dbproc.h"
#include <mysql/mysql.h>
#include "structs.h"
using namespace Sloong;
using namespace Sloong::Universal;
CDBProc::CDBProc()
......@@ -14,9 +14,10 @@ CDBProc::~CDBProc()
mysql_close(&m_MySql);
}
void Sloong::CDBProc::Connect(string ip, string user, string passwd, string db, int port)
void Sloong::CDBProc::Connect(MySQLConnectInfo* info)
{
mysql_real_connect(&m_MySql, ip.c_str(), user.c_str(), passwd.c_str(), db.c_str(), port, NULL, 0);
mysql_real_connect(&m_MySql, info->Address.c_str(), info->User.c_str(),
info->Password.c_str(), info->Database.c_str(), info->Port, NULL, 0);
mysql_set_character_set(&m_MySql, "utf8");
}
......
......@@ -4,13 +4,14 @@
#include <mysql/mysql.h>
namespace Sloong
{
struct MySQLConnectInfo;
class CDBProc
{
public:
CDBProc();
virtual ~CDBProc();
void Connect(string ip, string user, string passwd, string db, int port);
void Connect(MySQLConnectInfo* info);
int Modify(string sqlCmd);
int Query(string sqlCmd, vector<string>& vRes);
......
......@@ -61,11 +61,11 @@ CGlobalFunction::~CGlobalFunction()
SAFE_DELETE_ARR(m_pReloadTagList);
}
void Sloong::CGlobalFunction::Initialize( CLog* plog )
void Sloong::CGlobalFunction::Initialize( CLog* plog, MySQLConnectInfo* info)
{
m_pLog = plog;
// connect to db
m_pDBProc->Connect("localhost","root","sloong","sloong",0);
m_pDBProc->Connect(info);
}
......
......@@ -18,13 +18,14 @@ namespace Sloong
using namespace Universal;
class CUtility;
class CDBProc;
struct MySQLConnectInfo;
class CGlobalFunction
{
public:
CGlobalFunction();
~CGlobalFunction();
void Initialize(CLog* plog);
void Initialize(CLog* plog,MySQLConnectInfo* info);
void InitLua(CLua* pLua);
protected:
CUtility * m_pUtility;
......
......@@ -22,12 +22,12 @@ CMsgProc::~CMsgProc()
SAFE_DELETE(m_pGFunc);
}
void CMsgProc::Initialize(CLog *pLog, string scriptFolder)
void CMsgProc::Initialize(CLog *pLog, string scriptFolder, MySQLConnectInfo* info)
{
m_pLog = pLog;
m_strScriptFolder = scriptFolder;
m_pGFunc->Initialize(m_pLog);
m_pGFunc->Initialize(m_pLog,info);
}
void CMsgProc::InitLua(CLua* pLua, string path)
......
......@@ -11,12 +11,13 @@ namespace Sloong
{
using namespace Universal;
class CGlobalFunction;
struct MySQLConnectInfo;
class CMsgProc
{
public:
CMsgProc();
~CMsgProc();
void Initialize(CLog* pLog, string scriptFolder);
void Initialize(CLog* pLog, string scriptFolder, MySQLConnectInfo* info);
int MsgProcess( int id, CLuaPacket* pUInfo, string& msg, string&res, char*& pBuf);
int NewThreadInit();
void InitLua(CLua* pLua, string folder);
......
......@@ -7,6 +7,14 @@ using namespace Sloong;
using namespace Sloong::Universal;
CServerConfig::CServerConfig()
{
// DB init
m_oConnectInfo.Port = 3306;
m_oConnectInfo.Address = "localhost";
m_oConnectInfo.User = "root";
m_oConnectInfo.Password = "sloong";
m_oConnectInfo.Database = "sloong";
// Server init
m_nPort = 9009;
m_bDebug = true;
m_strLogPath = "./log.log";
......@@ -39,6 +47,29 @@ bool CServerConfig::LoadConfigFile(string path)
int nRes;
string strRes;
bool bRes;
// load connect info
nRes = g_key_file_get_integer(conf, "MySQL", "Port", &err);
if (!err)
m_oConnectInfo.Port = nRes;
g_clear_error(&err);
strRes = g_key_file_get_string(conf, "MySQL", "Address", &err);
if (!err)
m_oConnectInfo.Address = strRes;
g_clear_error(&err);
strRes = g_key_file_get_string(conf, "MySQL", "User", &err);
if (!err)
m_oConnectInfo.User = strRes;
g_clear_error(&err);
strRes = g_key_file_get_string(conf, "MySQL", "Password", &err);
if (!err)
m_oConnectInfo.Password = strRes;
g_clear_error(&err);
strRes = g_key_file_get_string(conf, "MySQL", "Database", &err);
if (!err)
m_oConnectInfo.Database = strRes;
g_clear_error(&err);
nRes = g_key_file_get_integer(conf, "Server", "Port", &err);
if ( !err)
m_nPort = nRes;
......
......@@ -2,6 +2,7 @@
#define SERVERCONFIG_H
#include <string>
#include "structs.h"
using namespace std;
namespace Sloong
{
......@@ -13,6 +14,9 @@ namespace Sloong
bool LoadConfigFile(string path);
// DB config
MySQLConnectInfo m_oConnectInfo;
// Server config
int m_nPort;
string m_strLogPath;
......
......@@ -85,6 +85,7 @@
<ClInclude Include="progressbar.h" />
<ClInclude Include="serverconfig.h" />
<ClInclude Include="sockinfo.h" />
<ClInclude Include="structs.h" />
<ClInclude Include="userv.h" />
<ClInclude Include="utility.h" />
<ClInclude Include="version.h" />
......
......@@ -87,6 +87,9 @@
<ClInclude Include="CmdProcess.h">
<Filter>Header files</Filter>
</ClInclude>
<ClInclude Include="structs.h">
<Filter>Header files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="epollex.cpp">
......
#ifndef STRUCTS_H
#define STRUCTS_H
#include "main.h"
namespace Sloong
{
struct MySQLConnectInfo
{
string Address;
int Port;
string User;
string Password;
string Database;
};
}
#endif // !STRUCTS_H
......@@ -50,7 +50,7 @@ void SloongWallUS::Initialize(CServerConfig* config)
m_pLog->SetWorkInterval(config->m_nSleepInterval);
m_pEpoll->Initialize(m_pLog,config->m_nPort,config->m_nEPoolThreadQuantity,config->m_nPriorityLevel, config->m_bEnableSwiftNumberSup, config->m_bEnableMD5Check);
m_pEpoll->SetSEM(&m_oSem);
m_pMsgProc->Initialize(m_pLog,config->m_strScriptFolder);
m_pMsgProc->Initialize(m_pLog,config->m_strScriptFolder,&config->m_oConnectInfo);
}
void SloongWallUS::Run()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment