示例#1
0
BOOL KServerSetting::InitializeDatabaseSettings( const char* xmlCfgFile )
{
	XMLElementNode m_xmlSetting;

	XMLDomParser parser;
	parser.Initialize("GB2312");

	KInputFileStream fi;
	if(!fi.Open(xmlCfgFile))
	{
		return FALSE;
	}
	if(!parser.Parse(fi, m_xmlSetting))
	{
		Log(LOG_FATAL, "Error %s" , parser.GetErrorMsg());
		return FALSE;
	}

	XMLNodeColl coll;
	coll = m_xmlSetting.QueryChildren("DatabaseSettings/Database");
	for(int i=0; i < coll.Size(); i++)
	{
		XMLElementNode* pXml = (XMLElementNode*)coll.GetNode(i);
		int type	= (int)pXml->QueryAtt("Type")->Integer();
		m_DBSettings[type].Addr		= pXml->QueryAtt("IP")->c_str();
		m_DBSettings[type].Port		= pXml->QueryAtt("Port")->Integer();
		m_DBSettings[type].DBName		= pXml->QueryAtt("DBName")->c_str();
		m_DBSettings[type].DBUser		= pXml->QueryAtt("DBUser")->c_str();
		m_DBSettings[type].DBPassword	= pXml->QueryAtt("DBPassword")->c_str();
		m_DBSettings[type].CharSet		= pXml->QueryAtt("DBChatSet")->c_str();
	}

	return TRUE;
}
示例#2
0
bool KOutgoingMessage::save()
{
	string_512 fullpath = this->buildMessageFullPath();
	if(fullpath.empty()) return true;

	KOutputFileStream fo;
	if(!fo.OpenForce(fullpath.c_str(), "w+"))
	{
		Log(LOG_ERROR, "error: open '%s'", fullpath.c_str());
		return false;
	}
	
	KInputFileStream fi;
	if(!fi.Open(m_messageFile.c_str(), "rb"))
	{
		Log(LOG_ERROR, "error: open '%s'", m_messageFile.c_str());
		return false;
	}

	char buf[1024]; int n;
	while(n = fi.ReadData(buf, sizeof(buf)), n > 0) fo.WriteData(buf, n);
	fi.Close(); fo.Close();

	if(!m_messageFile.empty() && m_isTmpFile)
		System::File::KFileUtil::deleteFile(m_messageFile.c_str());
	
	return saveMessageToDB(this);
}
示例#3
0
BOOL KServerSetting::InitializeServerSettings( const char* xmlCfgFile )
{
	XMLElementNode m_xmlSetting;

	XMLDomParser parser;
	parser.Initialize("GB2312");

	KInputFileStream fi;
	if(!fi.Open(xmlCfgFile))
	{
		return FALSE;
	}
	if(!parser.Parse(fi, m_xmlSetting))
	{
		Log(LOG_FATAL, "Error %s" , parser.GetErrorMsg());
		return FALSE;
	}

	XMLNodeColl coll;
	coll = m_xmlSetting.QueryChildren("ServerSettings/Server");
	for(int i=0; i < coll.Size(); i++)
	{
		XMLElementNode* pXml = (XMLElementNode*)coll.GetNode(i);
		int type	= (int)pXml->QueryAtt("Type")->Integer();
		m_ServerSettings[type].ID			= pXml->QueryAtt("ID")->Integer();
		m_ServerSettings[type].Name			= pXml->QueryAtt("Name")->c_str();
		m_ServerSettings[type].PrivateAddr	= pXml->QueryAtt("PrivateIP")->c_str();
		m_ServerSettings[type].PrivatePort	= pXml->QueryAtt("PrivatePort")->Integer();
		m_ServerSettings[type].PublicAddr	= pXml->QueryAtt("PublicIP")->c_str();
		m_ServerSettings[type].PublicPort	= pXml->QueryAtt("PublicPort")->Integer();
		m_ServerSettings[type].LogLevel		= pXml->QueryAtt("LogLevel")->Integer();

		switch(type)
		{
		case enum_SSI_LoginServer:
		case enum_SSI_CharacterServer:
		case enum_SSI_WorldServer:
		case enum_SSI_GameServer:
		case enum_SSI_ChatServer:
			{
				m_ServerSettings[type].MaxPlayer = (int)pXml->QueryAtt("MaxPlayer")->Integer();
			};
		}

		switch(type)
		{
		case enum_SSI_LoginServer:
		case enum_SSI_CharacterServer:
		case enum_SSI_MailServer:
			{
				m_ServerSettings[type].MaxDBLink = (int)pXml->QueryAtt("MaxDBLink")->Integer();
			}
			break;
		}			
	}

	return TRUE;
}
示例#4
0
bool KMapSettings::initialize(const char* fileName)
{
	KInputFileStream fi;
	if(!fi.Open(fileName))
	{
		Log(LOG_ERROR, "error: KMapSettings::initialize(%s), open.", fileName);
		return false;
	}
	return this->initialize(fi);
}
示例#5
0
void FS_LoadAvatar::execute()
{
	string_512 filepath = m_target->buildAvatarFilePath(m_target->m_avatar.c_str());
	KInputFileStream fi;
	if(!fi.Open(filepath.c_str(), "rb"))
	{
		m_result = GetLastError();
		Log(LOG_ERROR, "error: open '%s', %s", filepath.c_str(), strerror_r2(m_result).c_str());
		m_result = JgErrorCode::err_OpenFile;
		return;
	}

	int n; char buf[1024];
	while(n = fi.ReadData(buf, sizeof(buf)), n > 0)
		m_avatarData.WriteData(buf, n);

	return;
}
示例#6
0
bool KMapDataManager::openMap(const char* mapName)
{
	KMapData* mapData = this->getMapData(mapName);
	if(mapData) return true;

	JG_C::KString<512> filepath = this->_getFilePath(mapName);

	KInputFileStream fi;
	if(!fi.Open(filepath.c_str()))
		return false;

	KMapData mdt;
	if(!mdt.initialize(fi))
		return false;

	MapDesc mapDesc;
	mapDesc.mapName = KBuffer64k::WriteData(mapName, strlen(mapName)+1);
	mapDesc.mapData = mdt;
	m_mapByName[mapDesc.mapName] = mapDesc;

	return true;
}