init
This commit is contained in:
78
Gateway/gateway/config/ws_gate_config.cc
Normal file
78
Gateway/gateway/config/ws_gate_config.cc
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "StdAfx.h"
|
||||
#include "ws_gate_config.h"
|
||||
|
||||
const char WsGateConfig::ConfigFileName[] = ("GateWay.txt");
|
||||
|
||||
WsGateConfig::WsGateConfig(){
|
||||
}
|
||||
|
||||
|
||||
WsGateConfig::~WsGateConfig() {
|
||||
|
||||
}
|
||||
|
||||
void WsGateConfig::showError(const char* err) {
|
||||
SetErrDesc(err);
|
||||
RefString s = ("[Config Error]");
|
||||
s += err;
|
||||
throw s;
|
||||
}
|
||||
|
||||
bool WsGateConfig::loadServerConfig(GateServer * gate_srv)
|
||||
{
|
||||
using namespace stream;
|
||||
|
||||
MemoryStream ms(NULL);
|
||||
|
||||
try {
|
||||
if (ms.loadFromFile(ConfigFileName) <= 0) {
|
||||
showError("unable to load config from file GateWay.txt");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setScript((const char*)ms.getMemory())) {
|
||||
showError("parse config script failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (openGlobalTable("GateServer")) {
|
||||
if (enumTableFirst()) {
|
||||
char str[32];
|
||||
GameClientMgr* gcmgr = NULL;
|
||||
do {
|
||||
if (openFieldTable("LocalService")) {
|
||||
|
||||
getFieldStringBuffer(("ServerName"), str, sizeof(str));
|
||||
gcmgr = gate_srv->AddGameClientMgr(str);
|
||||
|
||||
getFieldStringBuffer(("Address"), str, sizeof(str));
|
||||
gcmgr->SetServiceHost(str);
|
||||
|
||||
int port = getFieldInt("Port");
|
||||
gcmgr->SetServicePort(port);
|
||||
gcmgr->SetMaxSession(getFieldInt("MaxSession"));
|
||||
|
||||
closeTable();
|
||||
}
|
||||
|
||||
if (gcmgr && openFieldTable("BackServer")) {
|
||||
getFieldStringBuffer(("Host"), str, sizeof(str));
|
||||
int port = getFieldInt("Port");
|
||||
|
||||
gcmgr->InitGameWorldClient(str, port);
|
||||
closeTable();
|
||||
}
|
||||
|
||||
} while (enumTableNext());
|
||||
}
|
||||
|
||||
closeTable();
|
||||
}
|
||||
} catch (RefString& s) {
|
||||
OutputMsg(rmNormal, s.rawStr());
|
||||
} catch (...) {
|
||||
MSG_ERR("unexpected error on load config");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
18
Gateway/gateway/config/ws_gate_config.h
Normal file
18
Gateway/gateway/config/ws_gate_config.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
class BaseLuaConfig;
|
||||
|
||||
class WsGateConfig :
|
||||
public BaseLuaConfig {
|
||||
public:
|
||||
WsGateConfig();
|
||||
~WsGateConfig();
|
||||
static const char ConfigFileName[]; //定义配置文件名称
|
||||
|
||||
//加载并读取服务器服务配置
|
||||
bool loadServerConfig(GateServer *gate_srv);
|
||||
|
||||
protected:
|
||||
void showError(const char* err);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user