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; }
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; }
bool KMapSettings::initialize(StreamInterface& si) { char buf[64]; XMLDomParser parser; if(!parser.Initialize()) { Log(LOG_ERROR, "error: KMapSettings::initialize, init xml parser"); return false; } XMLElementNode xmlRoot; if(!parser.Parse(si, xmlRoot)) { Log(LOG_ERROR, "error: KMapSettings::initialize, parse xml, %s", parser.GetErrorMsg()); return false; } KMapSetting ms; XMLNodeColl coll = xmlRoot.QueryChildren2("MapSettings/Map"); int n = coll.Size(); for(int i=0; i<n; i++) { ms.clear(); XMLElementNode* mapXml = (XMLElementNode*)coll.GetNode(i); const char* mapName = mapXml->QueryAtt("file")->c_str(); const char* descName = mapXml->QueryAtt("name")->c_str(); ms.m_mapID = mapXml->QueryAtt("id")->Integer(); if(mapXml->QueryAtt("dup")) { ms.m_duplicate = mapXml->QueryAtt("dup")->Integer() ? 1:0; } ms.m_mapName = KBuffer64k::WriteData(mapName, strlen(mapName)+1); ms.m_descName = KBuffer64k::WriteData(descName, strlen(descName)+1); if(mapXml->QueryAtt("EntryPoint.value")) ms.setEntryPoint(0, mapXml->QueryAtt("EntryPoint.value")->Integer()); if(mapXml->QueryAtt("BornPoint.value")) ms.setBornPoint(0, mapXml->QueryAtt("BornPoint.value")->Integer()); if(mapXml->QueryAtt("RelivePoint.value")) ms.setRelivePoint(0, mapXml->QueryAtt("RelivePoint.value")->Integer()); if(mapXml->QueryAtt("ExitPoint.value")) ms.setExitPoint(0, mapXml->QueryAtt("ExitPoint.value")->Integer()); if(mapXml->QueryAtt("ReturnPoint.value")) ms.setReturnPoint(0, mapXml->QueryAtt("ReturnPoint.value")->Integer()); int len = sprintf_k(buf, sizeof(buf), "Map_%d", ms.m_mapID); ms.m_luaTable = KBuffer64k::WriteData(buf, len+1); ms.m_createTimeout = ms.getIntAttr("createTimeout", 2*60); ms.m_idleTimeout = ms.getIntAttr("idleTimeout", ms.m_duplicate?5*60:-1); ms.m_carePlayerEnter = ms.getBoolAttr("carePlayerEnter", false) ? TRUE : FALSE; m_maps[ms.m_mapID] = ms; } return true; }
XMLNodeColl XMLElementNode::QueryChildren2(const char* path) { char cpath[1024]; strcpy_k(cpath, sizeof(cpath), path); char* ss[512]; int n = split(cpath, '/', ss, 512); XMLNodeColl collRst; XMLNodeColl collTmp; collTmp.AddNode(this); int start = 0, end = collTmp.Size(); for(int i=0; i<n; i++) { const char* realPath = ss[i]; for(int k=start; k<end; k++) { XMLDomNode* pNode = collTmp.GetNode(k); XMLElementNode* pElemNode = pNode->ToElementNode(); XMLNodeColl& coll = pElemNode->m_children; for(int j=0; j<coll.Size(); j++) { XMLDomNode* pChildNode = coll.GetNode(j); if(!pChildNode->IsTextNode()) { if(pChildNode->ToElementNode()->m_tagName.icompare(realPath) == 0) { if(i != n-1) { collTmp.AddNode(pChildNode); } else { collRst.AddNode(pChildNode); } } } } } start = end; end = collTmp.Size(); } return collRst; }
bool KWorldSettings::initialize(KMapSettings& mss, StreamInterface& fi) { char buf[128]; XMLDomParser parser; if(!parser.Initialize()) { Log(LOG_ERROR, "error: KWorldSettings::initialize, init xml parser"); return false; } XMLElementNode xmlRoot; if(!parser.Parse(fi, xmlRoot)) { Log(LOG_ERROR, "error: KWorldSettings::initialize, parse xml, %s", parser.GetErrorMsg()); return false; } KWorldSetting ws; XMLNodeColl coll2; int c; XMLNodeColl coll = xmlRoot.QueryChildren2("WorldSettings/World"); int n = coll.Size(); for(int i=0; i<n; i++) { ws.clear(); XMLElementNode* worldXml = (XMLElementNode*)coll.GetNode(i); const char* worldName = worldXml->QueryAtt("name")->c_str(); ws.m_mapID = worldXml->QueryAtt("map")->Integer(); ws.m_mapSetting = mss.getMapSetting(ws.m_mapID); if(!ws.m_mapSetting) { Log(LOG_ERROR, "error: KWorldSettings::initialize, map %d not found", ws.m_mapID); return false; } ws.m_worldType = worldXml->QueryAtt("type")->Integer(); ws.m_worldName = KBuffer64k::WriteData(worldName, strlen(worldName)+1); int len = sprintf_k(buf, sizeof(buf), "WorldMonitor_%d", ws.m_worldType); ws.m_luaTable = KBuffer64k::WriteData(buf, len+1); coll2 = worldXml->QueryChildren2("Monster"); c = coll2.Size(); for(int k=0; k<c; k++) { KWorldSetting::Monster monster; XMLElementNode* elemXml = (XMLElementNode*)coll2.GetNode(k); const char* fileName = elemXml->QueryAtt("value")->c_str(); monster.first = elemXml->QueryAtt("id")->Integer(); monster.second = KBuffer64k::WriteData(fileName, strlen(fileName)+1); ws.m_monsters.push_back(monster); } coll2 = worldXml->QueryChildren2("TreasureCase"); c = coll2.Size(); for(int k=0; k<c; k++) { XMLElementNode* elemXml = (XMLElementNode*)coll2.GetNode(k); const char* fileName = elemXml->QueryAtt("value")->c_str(); ws.m_tcs.push_back(KBuffer64k::WriteData(fileName, strlen(fileName)+1)); } coll2 = worldXml->QueryChildren2("Transimission"); c = coll2.Size(); for(int k=0; k<c; k++) { XMLElementNode* elemXml = (XMLElementNode*)coll2.GetNode(k); const char* fileName = elemXml->QueryAtt("value")->c_str(); ws.m_transes.push_back(KBuffer64k::WriteData(fileName, strlen(fileName)+1)); } coll2 = worldXml->QueryChildren2("Traffic"); c = coll2.Size(); for(int k=0; k<c; k++) { XMLElementNode* elemXml = (XMLElementNode*)coll2.GetNode(k); int trafficRoute = elemXml->QueryAtt("value")->Integer(); ws.m_traffics.push_back(trafficRoute); } //coll2 = worldXml->QueryChildren2("Scene"); c = coll2.Size(); //for(int k=0; k<c; k++) //{ // KWorldSetting::Scene scene; // XMLElementNode* elemXml = (XMLElementNode*)coll2.GetNode(k); // scene.first = elemXml->QueryAtt("x")->Integer(); // scene.second = elemXml->QueryAtt("y")->Integer(); // ws.m_scenes.insert_unique(scene); //} this->_addWorldType(ws); } return true; }