bool NFCPluginManager::LoadPluginConfig() { rapidxml::file<> fdoc("Plugin.xml"); rapidxml::xml_document<> doc; doc.parse<0>(fdoc.data()); rapidxml::xml_node<>* pRoot = doc.first_node(); for (rapidxml::xml_node<>* pPluginNode = pRoot->first_node("Plugin"); pPluginNode; pPluginNode = pPluginNode->next_sibling("Plugin")) { const char* strPluginName = pPluginNode->first_attribute("Name")->value(); const char* strMain = pPluginNode->first_attribute("Main")->value(); mPluginNameMap.insert(PluginNameMap::value_type(strPluginName, true)); } rapidxml::xml_node<>* pPluginAppNode = pRoot->first_node("APPID"); if (!pPluginAppNode) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } const char* strAppID = pPluginAppNode->first_attribute("Name")->value(); if (!strAppID) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } if (!NF_StrTo(strAppID, mnAppID)) { NFASSERT(0, "App ID Convert Error", __FILE__, __FUNCTION__); return false; } rapidxml::xml_node<>* pPluginConfigPathNode = pRoot->first_node("ConfigPath"); if (!pPluginConfigPathNode) { NFASSERT(0, "There are no ConfigPath", __FILE__, __FUNCTION__); return false; } if (NULL == pPluginConfigPathNode->first_attribute("Name")) { NFASSERT(0, "There are no ConfigPath.Name", __FILE__, __FUNCTION__); return false; } mstrConfigPath = pPluginConfigPathNode->first_attribute("Name")->value(); return true; }
bool NFCClassModule::AddPropertys(rapidxml::xml_node<>* pPropertyRootNode, NF_SHARE_PTR<NFIClass> pClass) { for (rapidxml::xml_node<>* pPropertyNode = pPropertyRootNode->first_node(); pPropertyNode; pPropertyNode = pPropertyNode->next_sibling()) { if (pPropertyNode) { const char* strPropertyName = pPropertyNode->first_attribute("Id")->value(); if (pClass->GetPropertyManager()->GetElement(strPropertyName)) { //error NFASSERT(0, strPropertyName, __FILE__, __FUNCTION__); continue; } const char* pstrType = pPropertyNode->first_attribute("Type")->value(); const char* pstrPublic = pPropertyNode->first_attribute("Public")->value(); const char* pstrPrivate = pPropertyNode->first_attribute("Private")->value(); const char* pstrSave = pPropertyNode->first_attribute("Save")->value(); const char* pstrCache = pPropertyNode->first_attribute("Cache")->value(); const char* pstrRef = pPropertyNode->first_attribute("Ref")->value(); const char* pstrUpload = pPropertyNode->first_attribute("Upload")->value(); bool bPublic = lexical_cast<bool>(pstrPublic); bool bPrivate = lexical_cast<bool>(pstrPrivate); bool bSave = lexical_cast<bool>(pstrSave); bool bCache = lexical_cast<bool>(pstrCache); bool bRef = lexical_cast<bool>(pstrRef); bool bUpload = lexical_cast<bool>(pstrUpload); NFData varProperty; if (TDATA_UNKNOWN == ComputerType(pstrType, varProperty)) { //std::cout << "error:" << pClass->GetTypeName() << " " << pClass->GetInstancePath() << ": " << strPropertyName << " type error!!!" << std::endl; NFASSERT(0, strPropertyName, __FILE__, __FUNCTION__); } //printf( " Property:%s[%s]\n", pstrPropertyName, pstrType ); NF_SHARE_PTR<NFIProperty> xProperty = pClass->GetPropertyManager()->AddProperty(NFGUID(), strPropertyName, varProperty.GetType()); xProperty->SetPublic(bPublic); xProperty->SetPrivate(bPrivate); xProperty->SetSave(bSave); xProperty->SetCache(bCache); xProperty->SetRef(bRef); xProperty->SetUpload(bUpload); } } return true; }
bool NFCClassModule::AddComponents(rapidxml::xml_node<>* pComponentRootNode, NF_SHARE_PTR<NFIClass> pClass) { for (rapidxml::xml_node<>* pComponentNode = pComponentRootNode->first_node(); pComponentNode; pComponentNode = pComponentNode->next_sibling()) { if (pComponentNode) { const char* strComponentName = pComponentNode->first_attribute("Name")->value(); const char* strLanguage = pComponentNode->first_attribute("Language")->value(); const char* strEnable = pComponentNode->first_attribute("Enable")->value(); bool bEnable = lexical_cast<bool>(strEnable); if (bEnable) { if (pClass->GetComponentManager()->GetElement(strComponentName)) { //error NFASSERT(0, strComponentName, __FILE__, __FUNCTION__); continue; } NF_SHARE_PTR<NFIComponent> xComponent(NF_NEW NFIComponent(NFGUID(), strComponentName)); pClass->GetComponentManager()->AddComponent(strComponentName, xComponent); } } } return true; }
bool NFCWorldNet_ServerModule::AfterInit() { m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_PTWG_PROXY_REGISTERED, this, &NFCWorldNet_ServerModule::OnProxyServerRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_PTWG_PROXY_UNREGISTERED, this, &NFCWorldNet_ServerModule::OnProxyServerUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_PTWG_PROXY_REFRESH, this, &NFCWorldNet_ServerModule::OnRefreshProxyServerInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_GTW_GAME_REGISTERED, this, &NFCWorldNet_ServerModule::OnGameServerRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_GTW_GAME_UNREGISTERED, this, &NFCWorldNet_ServerModule::OnGameServerUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_GTW_GAME_REFRESH, this, &NFCWorldNet_ServerModule::OnRefreshGameServerInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_DTW_DB_REGISTERED, this, &NFCWorldNet_ServerModule::OnDBServerRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_DTW_DB_UNREGISTERED, this, &NFCWorldNet_ServerModule::OnDBServerUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_DTW_DB_REFRESH, this, &NFCWorldNet_ServerModule::OnRefreshDBServerInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_ACK_ONLINE_NOTIFY, this, &NFCWorldNet_ServerModule::OnOnlineProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_ACK_OFFLINE_NOTIFY, this, &NFCWorldNet_ServerModule::OnOfflineProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_STS_SERVER_REPORT, this, &NFCWorldNet_ServerModule::OnTransmitServerReport); if (!m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQSWICHSERVER, this, &NFCWorldNet_ServerModule::OnReqSwitchServer)) { return false; } if (!m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_ACKSWICHSERVER, this, &NFCWorldNet_ServerModule::OnAckSwitchServer)) { return false; } m_pNetModule->AddEventCallBack(this, &NFCWorldNet_ServerModule::OnSocketEvent); m_pNetModule->ExpandBufferSize(); NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement(NFrame::Server::ThisName()); if (xLogicClass) { const std::vector<std::string>& strIdList = xLogicClass->GetIDList(); for (int i = 0; i < strIdList.size(); ++i) { const std::string& strId = strIdList[i]; const int nServerType = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Type()); const int nServerID = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::ServerID()); if (nServerType == NF_SERVER_TYPES::NF_ST_WORLD && pPluginManager->GetAppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Port()); const int nMaxConnect = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::MaxOnline()); const int nCpus = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::CpuCount()); //const std::string& strName = m_pElementModule->GetPropertyString(strId, NFrame::Server::Name()); //const std::string& strIP = m_pElementModule->GetPropertyString(strId, NFrame::Server::IP()); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } return true; }
bool NFCProxyServerNet_ServerModule::AfterInit() { m_pKernelModule = pPluginManager->FindModule<NFIKernelModule>(); m_pLogicClassModule = pPluginManager->FindModule<NFILogicClassModule>(); m_pProxyToWorldModule = pPluginManager->FindModule<NFIProxyServerToWorldModule>(); m_pLogModule = pPluginManager->FindModule<NFILogModule>(); m_pElementModule = pPluginManager->FindModule<NFIElementModule>(); m_pUUIDModule = pPluginManager->FindModule<NFIUUIDModule>(); m_pProxyServerToGameModule = pPluginManager->FindModule<NFIProxyServerToGameModule>(); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CONNECT_KEY, this, &NFCProxyServerNet_ServerModule::OnConnectKeyProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_WORLD_LIST, this, &NFCProxyServerNet_ServerModule::OnReqServerListProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_SELECT_SERVER, this, &NFCProxyServerNet_ServerModule::OnSelectServerProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_ROLE_LIST, this, &NFCProxyServerNet_ServerModule::OnReqRoleListProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CREATE_ROLE, this, &NFCProxyServerNet_ServerModule::OnReqCreateRoleProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_DELETE_ROLE, this, &NFCProxyServerNet_ServerModule::OnReqDelRoleProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_ENTER_GAME, this, &NFCProxyServerNet_ServerModule::OnReqEnterGameServer); m_pNetModule->AddReceiveCallBack(this, &NFCProxyServerNet_ServerModule::OnOtherMessage); m_pNetModule->AddEventCallBack(this, &NFCProxyServerNet_ServerModule::OnSocketClientEvent); NF_SHARE_PTR<NFILogicClass> xLogicClass = m_pLogicClassModule->GetElement("Server"); if (xLogicClass.get()) { NFList<std::string>& xNameList = xLogicClass->GetConfigNameList(); std::string strConfigName; for (bool bRet = xNameList.First(strConfigName); bRet; bRet = xNameList.Next(strConfigName)) { const int nServerType = m_pElementModule->GetPropertyInt(strConfigName, "Type"); const int nServerID = m_pElementModule->GetPropertyInt(strConfigName, "ServerID"); if (nServerType == NF_SERVER_TYPES::NF_ST_PROXY && pPluginManager->AppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt(strConfigName, "Port"); const int nMaxConnect = m_pElementModule->GetPropertyInt(strConfigName, "MaxOnline"); const int nCpus = m_pElementModule->GetPropertyInt(strConfigName, "CpuCount"); const std::string& strName = m_pElementModule->GetPropertyString(strConfigName, "Name"); const std::string& strIP = m_pElementModule->GetPropertyString(strConfigName, "IP"); m_pUUIDModule->SetIdentID(nServerID); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } return true; }
bool NFCMasterNet_ServerModule::AfterInit() { m_pKernelModule = pPluginManager->FindModule<NFIKernelModule>(); m_pLogModule = pPluginManager->FindModule<NFILogModule>(); m_pClassModule = pPluginManager->FindModule<NFIClassModule>(); m_pElementModule = pPluginManager->FindModule<NFIElementModule>(); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_STS_HEART_BEAT, this, &NFCMasterNet_ServerModule::OnHeartBeat); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_MTL_WORLD_REGISTERED, this, &NFCMasterNet_ServerModule::OnWorldRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_MTL_WORLD_UNREGISTERED, this, &NFCMasterNet_ServerModule::OnWorldUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_MTL_WORLD_REFRESH, this, &NFCMasterNet_ServerModule::OnRefreshWorldInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_REGISTERED, this, &NFCMasterNet_ServerModule::OnLoginRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_UNREGISTERED, this, &NFCMasterNet_ServerModule::OnLoginUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_REFRESH, this, &NFCMasterNet_ServerModule::OnRefreshLoginInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CONNECT_WORLD, this, &NFCMasterNet_ServerModule::OnSelectWorldProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_ACK_CONNECT_WORLD, this, &NFCMasterNet_ServerModule::OnSelectServerResultProcess); m_pNetModule->AddReceiveCallBack(this, &NFCMasterNet_ServerModule::InvalidMessage); m_pNetModule->AddEventCallBack(this, &NFCMasterNet_ServerModule::OnSocketEvent); NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement("Server"); if (xLogicClass.get()) { NFList<std::string>& xNameList = xLogicClass->GetConfigNameList(); std::string strConfigName; for (bool bRet = xNameList.First(strConfigName); bRet; bRet = xNameList.Next(strConfigName)) { const int nServerType = m_pElementModule->GetPropertyInt(strConfigName, "Type"); const int nServerID = m_pElementModule->GetPropertyInt(strConfigName, "ServerID"); if (nServerType == NF_SERVER_TYPES::NF_ST_MASTER && pPluginManager->AppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt(strConfigName, "Port"); const int nMaxConnect = m_pElementModule->GetPropertyInt(strConfigName, "MaxOnline"); const int nCpus = m_pElementModule->GetPropertyInt(strConfigName, "CpuCount"); const std::string& strName = m_pElementModule->GetPropertyString(strConfigName, "Name"); const std::string& strIP = m_pElementModule->GetPropertyString(strConfigName, "IP"); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } return true; }
bool NFCLoginNet_ServerModule::AfterInit() { m_pKernelModule = pPluginManager->FindModule<NFIKernelModule>(); m_pLoginLogicModule = pPluginManager->FindModule<NFILoginLogicModule>(); m_pLogModule = pPluginManager->FindModule<NFILogModule>(); m_pLogicClassModule = pPluginManager->FindModule<NFILogicClassModule>(); m_pElementModule = pPluginManager->FindModule<NFIElementModule>(); m_pLoginToMasterModule = pPluginManager->FindModule<NFILoginToMasterModule>(); m_pUUIDModule = pPluginManager->FindModule<NFIUUIDModule>(); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_STS_HEART_BEAT, this, &NFCLoginNet_ServerModule::OnHeartBeat); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_LOGIN, this, &NFCLoginNet_ServerModule::OnLoginProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_LOGOUT, this, &NFCLoginNet_ServerModule::OnLogOut); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CONNECT_WORLD, this, &NFCLoginNet_ServerModule::OnSelectWorldProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_WORLD_LIST, this, &NFCLoginNet_ServerModule::OnViewWorldProcess); m_pNetModule->AddReceiveCallBack(this, &NFCLoginNet_ServerModule::InvalidMessage); m_pNetModule->AddEventCallBack(this, &NFCLoginNet_ServerModule::OnSocketClientEvent); NF_SHARE_PTR<NFILogicClass> xLogicClass = m_pLogicClassModule->GetElement("Server"); if (xLogicClass.get()) { NFList<std::string>& xNameList = xLogicClass->GetConfigNameList(); std::string strConfigName; for (bool bRet = xNameList.First(strConfigName); bRet; bRet = xNameList.Next(strConfigName)) { const int nServerType = m_pElementModule->GetPropertyInt(strConfigName, "Type"); const int nServerID = m_pElementModule->GetPropertyInt(strConfigName, "ServerID"); if (nServerType == NF_SERVER_TYPES::NF_ST_LOGIN && pPluginManager->AppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt(strConfigName, "Port"); const int nMaxConnect = m_pElementModule->GetPropertyInt(strConfigName, "MaxOnline"); const int nCpus = m_pElementModule->GetPropertyInt(strConfigName, "CpuCount"); m_pUUIDModule->SetIdentID(nServerID); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } return true; }
bool NFDBNet_ServerModule::AfterInit() { InitAllHomeScene(); m_pNetModule->AddEventCallBack(this, &NFDBNet_ServerModule::OnSocketEvent); m_pNetModule->ExpandBufferSize(); NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement(NFrame::Server::ThisName()); if (xLogicClass) { const std::vector<std::string>& strIdList = xLogicClass->GetIDList(); for (int i = 0; i < strIdList.size(); ++i) { const std::string& strId = strIdList[i]; const int nServerType = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Type()); const int nServerID = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::ServerID()); if (nServerType == NF_SERVER_TYPES::NF_ST_DB && pPluginManager->GetAppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Port()); const int nMaxConnect = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::MaxOnline()); const int nCpus = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::CpuCount()); //const std::string& strName = m_pElementModule->GetPropertyString(strId, NFrame::Server::ID()); //const std::string& strIP = m_pElementModule->GetPropertyString(strId, NFrame::Server::IP()); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_ROLE_LIST, this, &NFDBNet_ServerModule::OnRequireRoleListProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CREATE_ROLE, this, &NFDBNet_ServerModule::OnCreateRoleGameProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_DELETE_ROLE, this, &NFDBNet_ServerModule::OnDeleteRoleGameProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_LOAD_ROLE_DATA, this, &NFDBNet_ServerModule::OnLoadRoleDataProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_SAVE_ROLE_DATA, this, &NFDBNet_ServerModule::OnSaveRoleDataProcess); return true; }
void NFCPlayerLogic::RequireEnterGameServer(int nRoleIndex) { if(nRoleIndex >= m_RoleList.size()) { NFASSERT(0, "out of range", __FILE__, __FUNCTION__); return ; } NFMsg::ReqEnterGameServer xMsg; xMsg.set_account(g_pLoginLogic->GetAccount()); xMsg.set_game_id(g_pLoginLogic->GetServerID()); xMsg.set_name(m_RoleList[nRoleIndex].noob_name()); *xMsg.mutable_id() = m_RoleList[nRoleIndex].id(); m_nRoleIndex = nRoleIndex; m_RoleGuid = NFINetModule::PBToNF(m_RoleList[nRoleIndex].id()); g_pNetLogic->SendToServerByPB(NFMsg::EGameMsgID::EGMI_REQ_ENTER_GAME, xMsg); }
bool NFCMasterNet_ServerModule::AfterInit() { m_pKernelModule = pPluginManager->FindModule<NFIKernelModule>("NFCKernelModule"); m_pLogModule = pPluginManager->FindModule<NFILogModule>("NFCLogModule"); m_pLogicClassModule = pPluginManager->FindModule<NFILogicClassModule>("NFCLogicClassModule"); m_pElementInfoModule = pPluginManager->FindModule<NFIElementInfoModule>("NFCElementInfoModule"); assert(NULL != m_pKernelModule); assert(NULL != m_pLogModule); assert(NULL != m_pLogicClassModule); assert(NULL != m_pElementInfoModule); NF_SHARE_PTR<NFILogicClass> xLogicClass = m_pLogicClassModule->GetElement("Server"); if (xLogicClass.get()) { NFList<std::string>& xNameList = xLogicClass->GetConfigNameList(); std::string strConfigName; for (bool bRet = xNameList.First(strConfigName); bRet; bRet = xNameList.Next(strConfigName)) { const int nServerType = m_pElementInfoModule->GetPropertyInt(strConfigName, "Type"); const int nServerID = m_pElementInfoModule->GetPropertyInt(strConfigName, "ServerID"); if (nServerType == NF_SERVER_TYPES::NF_ST_MASTER && pPluginManager->AppID() == nServerID) { const int nPort = m_pElementInfoModule->GetPropertyInt(strConfigName, "Port"); const int nMaxConnect = m_pElementInfoModule->GetPropertyInt(strConfigName, "MaxOnline"); const int nCpus = m_pElementInfoModule->GetPropertyInt(strConfigName, "CpuCount"); const std::string& strName = m_pElementInfoModule->GetPropertyString(strConfigName, "Name"); const std::string& strIP = m_pElementInfoModule->GetPropertyString(strConfigName, "IP"); int nRet = Initialization(this, &NFCMasterNet_ServerModule::OnRecivePack, &NFCMasterNet_ServerModule::OnSocketEvent, nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } } } } return true; }
bool NFCElementModule::CheckRef() { NF_SHARE_PTR<NFIClass> pLogicClass = m_pClassModule->First(); while (pLogicClass) { NF_SHARE_PTR<NFIPropertyManager> pClassPropertyManager = pLogicClass->GetPropertyManager(); if (pClassPropertyManager) { NF_SHARE_PTR<NFIProperty> pProperty = pClassPropertyManager->First(); while (pProperty) { //if one property is ref,check every config if (pProperty->GetRef()) { NFList<std::string>& strIdList = pLogicClass->GetIdList(); std::string strId; for (bool bRet = strIdList.First(strId); bRet; bRet = strIdList.Next(strId)) { const std::string& strRefValue= this->GetPropertyString(strId, pProperty->GetKey()); if (!this->GetElement(strRefValue)) { std::string msg; msg.append("check ref failed id: ").append(strRefValue).append(" in ").append(pLogicClass->GetClassName()); NFASSERT(nRet, msg.c_str(), __FILE__, __FUNCTION__); exit(0); } } } pProperty = pClassPropertyManager->Next(); } } ////////////////////////////////////////////////////////////////////////// pLogicClass = m_pClassModule->Next(); } return false; }
bool NFCElementInfoModule::Load(rapidxml::xml_node<>* attrNode, NF_SHARE_PTR<NFILogicClass> pLogicClass) { //attrNode is the node of a object std::string strConfigID = attrNode->first_attribute("ID")->value(); if (strConfigID.empty()) { NFASSERT(0, strConfigID, __FILE__, __FUNCTION__); return false; } if (ExistElement(strConfigID)) { NFASSERT(0, strConfigID, __FILE__, __FUNCTION__); return false; } NF_SHARE_PTR<ElementConfigInfo> pElementInfo(NF_NEW ElementConfigInfo()); AddElement(strConfigID, pElementInfo); //can find all configid by class name pLogicClass->AddConfigName(strConfigID); //ElementConfigInfo* pElementInfo = CreateElement( strConfigID, pElementInfo ); NF_SHARE_PTR<NFIPropertyManager> pElementPropertyManager = pElementInfo->GetPropertyManager(); NF_SHARE_PTR<NFIRecordManager> pElementRecordManager = pElementInfo->GetRecordManager(); //1.add property //2.set the default value of them NF_SHARE_PTR<NFIPropertyManager> pClassPropertyManager = pLogicClass->GetPropertyManager(); NF_SHARE_PTR<NFIRecordManager> pClassRecordManager = pLogicClass->GetRecordManager(); if (pClassPropertyManager.get() && pClassRecordManager.get()) { NF_SHARE_PTR<NFIProperty> pProperty = pClassPropertyManager->First(); while (pProperty.get()) { pElementPropertyManager->AddProperty(NFGUID(), pProperty); pProperty = pClassPropertyManager->Next(); } NF_SHARE_PTR<NFIRecord> pRecord = pClassRecordManager->First(); while (pRecord.get()) { pElementRecordManager->AddRecord(NFGUID(), pRecord->GetName(), pRecord->GetInitData(), pRecord->GetKeyState(), pRecord->GetInitDesc(), pRecord->GetTag(), pRecord->GetRelatedRecord(), pRecord->GetRows(), pRecord->GetPublic(), pRecord->GetPrivate(), pRecord->GetSave(), pRecord->GetView(), pRecord->GetIndex()); pRecord = pClassRecordManager->Next(); } } //3.set the config value to them //const char* pstrConfigID = attrNode->first_attribute( "ID" ); for (rapidxml::xml_attribute<>* pAttribute = attrNode->first_attribute(); pAttribute; pAttribute = pAttribute->next_attribute()) { const char* pstrConfigName = pAttribute->name(); const char* pstrConfigValue = pAttribute->value(); //printf( "%s : %s\n", pstrConfigName, pstrConfigValue ); NF_SHARE_PTR<NFIProperty> temProperty = pElementPropertyManager->GetElement(pstrConfigName); if (!temProperty) { continue; } NFIDataList::TData var; TDATA_TYPE eType = temProperty->GetType(); switch (eType) { case TDATA_INT: { if (!LegalNumber(pstrConfigValue)) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetInt(lexical_cast<NFINT64>(pstrConfigValue)); } break; case TDATA_FLOAT: { if (strlen(pstrConfigValue) <= 0) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetFloat((double)atof(pstrConfigValue)); } break; case TDATA_STRING: var.SetString(pstrConfigValue); break; case TDATA_OBJECT: { if (strlen(pstrConfigValue) <= 0) { NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); } var.SetObject(NFGUID()); } break; default: NFASSERT(0, temProperty->GetKey(), __FILE__, __FUNCTION__); break; } pElementPropertyManager->SetProperty(pstrConfigName, var); } NFIDataList::TData xData; xData.SetString(pLogicClass->GetClassName()); pElementPropertyManager->SetProperty("ClassName", xData); return true; }
bool NFCMasterNet_ServerModule::AfterInit() { m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_STS_HEART_BEAT, this, &NFCMasterNet_ServerModule::OnHeartBeat); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_WTM_WORLD_REGISTERED, this, &NFCMasterNet_ServerModule::OnWorldRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_WTM_WORLD_UNREGISTERED, this, &NFCMasterNet_ServerModule::OnWorldUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_WTM_WORLD_REFRESH, this, &NFCMasterNet_ServerModule::OnRefreshWorldInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_REGISTERED, this, &NFCMasterNet_ServerModule::OnLoginRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_UNREGISTERED, this, &NFCMasterNet_ServerModule::OnLoginUnRegisteredProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_LTM_LOGIN_REFRESH, this, &NFCMasterNet_ServerModule::OnRefreshLoginInfoProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_REQ_CONNECT_WORLD, this, &NFCMasterNet_ServerModule::OnSelectWorldProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_ACK_CONNECT_WORLD, this, &NFCMasterNet_ServerModule::OnSelectServerResultProcess); m_pNetModule->AddReceiveCallBack(NFMsg::EGMI_STS_SERVER_REPORT, this, &NFCMasterNet_ServerModule::OnServerReport); m_pNetModule->AddReceiveCallBack(this, &NFCMasterNet_ServerModule::InvalidMessage); m_pNetModule->AddEventCallBack(this, &NFCMasterNet_ServerModule::OnSocketEvent); m_pNetModule->ExpandBufferSize(); NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement(NFrame::Server::ThisName()); if (xLogicClass) { const std::vector<std::string>& strIdList = xLogicClass->GetIDList(); for (int i = 0; i < strIdList.size(); ++i) { const std::string& strId = strIdList[i]; const int nServerType = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Type()); const int nServerID = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::ServerID()); if (nServerType == NF_SERVER_TYPES::NF_ST_MASTER && pPluginManager->GetAppID() == nServerID) { const int nPort = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Port()); const int nMaxConnect = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::MaxOnline()); const int nCpus = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::CpuCount()); const std::string& strName = m_pElementModule->GetPropertyString(strId, NFrame::Server::Name()); const std::string& strIP = m_pElementModule->GetPropertyString(strId, NFrame::Server::IP()); int nRet = m_pNetModule->Initialization(nMaxConnect, nPort, nCpus); if (nRet < 0) { std::ostringstream strLog; strLog << "Cannot init server net, Port = " << nPort; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(nRet, "Cannot init server net", __FILE__, __FUNCTION__); exit(0); } NFMsg::ServerInfoReport reqMsg; reqMsg.set_server_id(nServerID); reqMsg.set_server_name(strName); reqMsg.set_server_cur_count(0); reqMsg.set_server_ip(strIP); reqMsg.set_server_port(nPort); reqMsg.set_server_max_online(nMaxConnect); reqMsg.set_server_state(NFMsg::EST_NARMAL); reqMsg.set_server_type(nServerType); auto pServerData = NF_SHARE_PTR<ServerData>(NF_NEW ServerData()); *(pServerData->pData) = reqMsg; mMasterMap.AddElement(nServerID, pServerData); } } } return true; }
bool NFCPluginManager::LoadPluginConfig() { std::string strContent; GetFileContent(mstrConfigName, strContent); rapidxml::xml_document<> xDoc; xDoc.parse<0>((char*)strContent.c_str()); rapidxml::xml_node<>* pRoot = xDoc.first_node(); rapidxml::xml_node<>* pAppNameNode = pRoot->first_node(mstrAppName.c_str()); if (!pAppNameNode) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } for (rapidxml::xml_node<>* pPluginNode = pAppNameNode->first_node("Plugin"); pPluginNode; pPluginNode = pPluginNode->next_sibling("Plugin")) { const char* strPluginName = pPluginNode->first_attribute("Name")->value(); mPluginNameMap.insert(PluginNameMap::value_type(strPluginName, true)); } /* rapidxml::xml_node<>* pPluginAppNode = pAppNameNode->first_node("APPID"); if (!pPluginAppNode) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } const char* strAppID = pPluginAppNode->first_attribute("Name")->value(); if (!strAppID) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } if (!NF_StrTo(strAppID, mnAppID)) { NFASSERT(0, "App ID Convert Error", __FILE__, __FUNCTION__); return false; } */ rapidxml::xml_node<>* pPluginConfigPathNode = pAppNameNode->first_node("ConfigPath"); if (!pPluginConfigPathNode) { NFASSERT(0, "There are no ConfigPath", __FILE__, __FUNCTION__); return false; } if (NULL == pPluginConfigPathNode->first_attribute("Name")) { NFASSERT(0, "There are no ConfigPath.Name", __FILE__, __FUNCTION__); return false; } mstrConfigPath = pPluginConfigPathNode->first_attribute("Name")->value(); return true; }
bool NFCClassModule::AddRecords(rapidxml::xml_node<>* pRecordRootNode, NF_SHARE_PTR<NFIClass> pClass) { for (rapidxml::xml_node<>* pRecordNode = pRecordRootNode->first_node(); pRecordNode; pRecordNode = pRecordNode->next_sibling()) { if (pRecordNode) { const char* pstrRecordName = pRecordNode->first_attribute("Id")->value(); if (pClass->GetRecordManager()->GetElement(pstrRecordName)) { //error //file << pClass->mstrType << ":" << pstrRecordName << std::endl; //assert(0); NFASSERT(0, pstrRecordName, __FILE__, __FUNCTION__); continue; } const char* pstrRow = pRecordNode->first_attribute("Row")->value(); const char* pstrCol = pRecordNode->first_attribute("Col")->value(); const char* pstrPublic = pRecordNode->first_attribute("Public")->value(); const char* pstrPrivate = pRecordNode->first_attribute("Private")->value(); const char* pstrSave = pRecordNode->first_attribute("Save")->value(); const char* pstrCache = pRecordNode->first_attribute("Cache")->value(); const char* pstrUpload = pRecordNode->first_attribute("Upload")->value(); std::string strView; if (pRecordNode->first_attribute("View") != NULL) { strView = pRecordNode->first_attribute("View")->value(); } bool bPublic = lexical_cast<bool>(pstrPublic); bool bPrivate = lexical_cast<bool>(pstrPrivate); bool bSave = lexical_cast<bool>(pstrSave); bool bCache = lexical_cast<bool>(pstrCache); bool bUpload = lexical_cast<bool>(pstrUpload); NF_SHARE_PTR<NFDataList> recordVar(NF_NEW NFDataList()); NF_SHARE_PTR<NFDataList> recordTag(NF_NEW NFDataList()); for (rapidxml::xml_node<>* recordColNode = pRecordNode->first_node(); recordColNode; recordColNode = recordColNode->next_sibling()) { //const char* pstrColName = recordColNode->first_attribute( "Id" )->value(); NFData TData; const char* pstrColType = recordColNode->first_attribute("Type")->value(); if (TDATA_UNKNOWN == ComputerType(pstrColType, TData)) { //assert(0); NFASSERT(0, pstrRecordName, __FILE__, __FUNCTION__); } recordVar->Append(TData); ////////////////////////////////////////////////////////////////////////// if (recordColNode->first_attribute("Tag") != NULL) { const char* pstrTag = recordColNode->first_attribute("Tag")->value(); recordTag->Add(pstrTag); } else { recordTag->Add(""); } } NF_SHARE_PTR<NFIRecord> xRecord = pClass->GetRecordManager()->AddRecord(NFGUID(), pstrRecordName, recordVar, recordTag, atoi(pstrRow)); xRecord->SetPublic(bPublic); xRecord->SetPrivate(bPrivate); xRecord->SetSave(bSave); xRecord->SetCache(bCache); xRecord->SetUpload(bUpload); } } return true; }
bool NFCProperty::DeSerialization() { bool bRet = false; const TDATA_TYPE eType = GetType(); if (eType == TDATA_STRING && nullptr != mxData && !mxData->IsNullValue()) { NFCDataList xDataList; const std::string& strData = mxData->GetString(); xDataList.Split(strData.c_str(), ";"); if (xDataList.GetCount() <= 0) { return bRet; } NFCDataList xTemDataList; xTemDataList.Split(xDataList.String(0).c_str(), ","); const int nSubDataLength = xTemDataList.GetCount(); if (xDataList.GetCount() == 1 && nSubDataLength == 1) { //most of property value only one value return bRet; } if (nullptr == mxEmbeddedList) { mxEmbeddedList = NF_SHARE_PTR<NFList<std::string>>(NF_NEW NFList<std::string>()); } else { mxEmbeddedList->ClearAll(); } for (int i = 0; i < xDataList.GetCount(); ++i) { if (xDataList.String(i).empty()) { NFASSERT(0, strData, __FILE__, __FUNCTION__); } mxEmbeddedList->Add(xDataList.String(i)); } //////////////////////////////////////// if (nSubDataLength < 2 || nSubDataLength > 2) { return bRet; } if (nullptr == mxEmbeddedMap) { mxEmbeddedMap = NF_SHARE_PTR<NFMapEx<std::string, std::string>>(NF_NEW NFMapEx<std::string, std::string>()); } else { mxEmbeddedMap->ClearAll(); } for (int i = 0; i < xDataList.GetCount(); ++i) { NFCDataList xTemDataList; const std::string& strTemData = xDataList.String(i); xTemDataList.Split(strTemData.c_str(), ","); { if (xTemDataList.GetCount() != nSubDataLength) { NFASSERT(0, strTemData, __FILE__, __FUNCTION__); } const std::string& strKey = xTemDataList.String(0); const std::string& strValue = xTemDataList.String(1); if (strKey.empty() || strValue.empty()) { NFASSERT(0, strTemData, __FILE__, __FUNCTION__); } mxEmbeddedMap->AddElement(strKey, NF_SHARE_PTR<std::string>(NF_NEW std::string(strValue))); } } bRet = true; } return bRet; }
bool NFCProxyServerToWorldModule::AfterInit() { m_pNetClientModule->AddReceiveCallBack(NF_SERVER_TYPES::NF_ST_WORLD, NFMsg::EGMI_ACK_CONNECT_WORLD, this, &NFCProxyServerToWorldModule::OnSelectServerResultProcess); m_pNetClientModule->AddReceiveCallBack(NF_SERVER_TYPES::NF_ST_WORLD, NFMsg::EGMI_STS_NET_INFO, this, &NFCProxyServerToWorldModule::OnServerInfoProcess); m_pNetClientModule->AddReceiveCallBack(NF_SERVER_TYPES::NF_ST_WORLD, this, &NFCProxyServerToWorldModule::OnOtherMessage); m_pNetClientModule->AddEventCallBack(NF_SERVER_TYPES::NF_ST_WORLD, this, &NFCProxyServerToWorldModule::OnSocketWSEvent); m_pNetClientModule->ExpandBufferSize(); NF_SHARE_PTR<NFIClass> xLogicClass = m_pClassModule->GetElement(NFrame::Server::ThisName()); if (xLogicClass) { const std::vector<std::string>& strIdList = xLogicClass->GetIDList(); const int nCurAppID = pPluginManager->GetAppID(); std::vector<std::string>::const_iterator itr = std::find_if(strIdList.begin(), strIdList.end(), [&](const std::string& strConfigId) { return nCurAppID == m_pElementModule->GetPropertyInt32(strConfigId, NFrame::Server::ServerID()); }); if (strIdList.end() == itr) { std::ostringstream strLog; strLog << "Cannot find current server, AppID = " << nCurAppID; m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, NULL_OBJECT, strLog, __FUNCTION__, __LINE__); NFASSERT(-1, "Cannot find current server", __FILE__, __FUNCTION__); exit(0); } const int nCurArea = m_pElementModule->GetPropertyInt32(*itr, NFrame::Server::Area()); for (int i = 0; i < strIdList.size(); ++i) { const std::string& strId = strIdList[i]; const int nServerType = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Type()); const int nServerID = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::ServerID()); const int nServerArea = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Area()); if (nServerType == NF_SERVER_TYPES::NF_ST_WORLD && nCurArea == nServerArea) { const int nPort = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::Port()); const int nMaxConnect = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::MaxOnline()); const int nCpus = m_pElementModule->GetPropertyInt32(strId, NFrame::Server::CpuCount()); const std::string& strName = m_pElementModule->GetPropertyString(strId, NFrame::Server::Name()); const std::string& strIP = m_pElementModule->GetPropertyString(strId, NFrame::Server::IP()); ConnectData xServerData; xServerData.nGameID = nServerID; xServerData.eServerType = (NF_SERVER_TYPES)nServerType; xServerData.strIP = strIP; xServerData.nPort = nPort; xServerData.strName = strName; m_pNetClientModule->AddServer(xServerData); } } } return true; }