int NFCLoginNet_ServerModule::OnSocketClientEvent( const int nSockIndex, const NF_NET_EVENT eEvent, NFINet* pNet ) { if (eEvent & NF_NET_EVENT_EOF) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_EOF", "Connection closed", __FUNCTION__, __LINE__); OnClientDisconnect(nSockIndex); } else if (eEvent & NF_NET_EVENT_ERROR) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_ERROR", "Got an error on the connection", __FUNCTION__, __LINE__); OnClientDisconnect(nSockIndex); } else if (eEvent & NF_NET_EVENT_TIMEOUT) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_TIMEOUT", "read timeout", __FUNCTION__, __LINE__); OnClientDisconnect(nSockIndex); } else if (eEvent == NF_NET_EVENT_CONNECTED) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_CONNECTED", "connectioned success", __FUNCTION__, __LINE__); OnClientConnected(nSockIndex); } return 0; }
bool HelloWorld4ActorModule::AfterInit() { //初始化完毕 std::cout << "Hello, world4, AfterInit, ThreadID: " << std::this_thread::get_id() << std::endl; m_pKernelModule = dynamic_cast<NFIKernelModule*>(pPluginManager->FindModule("NFCKernelModule")); m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); //////////////////////////////////////同步///////////////////////////////////////////////////////////////////// m_pEventProcessModule->AddAsyncEventCallBack(NFIDENTID(), 2222, this, &HelloWorld4ActorModule::OnASyncEvent, &HelloWorld4ActorModule::OnSyncEvent); for (int i = 0; i < 20; ++i) { m_pEventProcessModule->DoEvent(NFIDENTID(), 2222, NFCDataList() << boost::lexical_cast<std::string>(i), false); } std::cout << "End Test Actor, ThreadID: " << std::this_thread::get_id() << std::endl; /////////////////////////////////////////////////////////////////////////////////////////////////////////// return true; }
bool NFCLoginNet_ServerModule::AfterInit() { m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pKernelModule = dynamic_cast<NFIKernelModule*>(pPluginManager->FindModule("NFCKernelModule")); m_pLoginLogicModule = dynamic_cast<NFILoginLogicModule*>(pPluginManager->FindModule("NFCLoginLogicModule")); m_pLogModule = dynamic_cast<NFILogModule*>(pPluginManager->FindModule("NFCLogModule")); m_pLogicClassModule = dynamic_cast<NFILogicClassModule*>(pPluginManager->FindModule("NFCLogicClassModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); m_pLoginToMasterModule = dynamic_cast<NFILoginToMasterModule*>(pPluginManager->FindModule("NFCLoginToMasterModule")); m_pUUIDModule = dynamic_cast<NFIUUIDModule*>(pPluginManager->FindModule("NFCUUIDModule")); assert(NULL != m_pEventProcessModule); assert(NULL != m_pKernelModule); assert(NULL != m_pLoginLogicModule); assert(NULL != m_pLogModule); assert(NULL != m_pLogicClassModule); assert(NULL != m_pElementInfoModule); assert(NULL != m_pLoginToMasterModule); assert(NULL != m_pUUIDModule); m_pEventProcessModule->AddEventCallBack(NFIDENTID(), NFED_ON_CLIENT_LOGIN_RESULTS, this, &NFCLoginNet_ServerModule::OnLoginResultsEvent); m_pEventProcessModule->AddEventCallBack(NFIDENTID(), NFED_ON_CLIENT_SELECT_SERVER_RESULTS, this, &NFCLoginNet_ServerModule::OnSelectWorldResultsEvent); 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_LOGIN && 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"); m_pUUIDModule->SetIdentID(nServerID); Initialization(NFIMsgHead::NF_Head::NF_HEAD_LENGTH, this, &NFCLoginNet_ServerModule::OnReciveClientPack, &NFCLoginNet_ServerModule::OnSocketClientEvent, nMaxConnect, nPort, nCpus); } } } return true; }
const NFIDENTID NFCWorldGuildDataModule::CreateGuild(const NFIDENTID& xPlayeID, const std::string& strName, const std::string& strRoleName, const int nLevel, const int nJob , const int nDonation , const int nVIP, const int nOffLine /*= 1*/, const int nPower/* = NFMsg::GUILD_POWER_TYPE_PRESIDENT*/) { bool bExit = false; if (!m_pClusterSQLModule->Exists(mstrGuildNameTalble, strName, bExit)) { return NFIDENTID(); } if (bExit) { return NFIDENTID(); } const NFIDENTID xGuidID = m_pUUIDModule->CreateGUID(); //Guild std::vector<std::string> vGuildFieldVec; std::vector<std::string> vGuildValueVec; vGuildFieldVec.push_back("Name"); vGuildValueVec.push_back(strName); vGuildFieldVec.push_back("GuildLevel"); vGuildValueVec.push_back("1"); vGuildFieldVec.push_back("PresidentID"); vGuildValueVec.push_back(xPlayeID.ToString()); vGuildFieldVec.push_back("PresidentName"); vGuildValueVec.push_back(strRoleName); vGuildFieldVec.push_back("GuildMemeberMaxCount"); vGuildValueVec.push_back("200"); if (!m_pClusterSQLModule->Updata(mstrGuildTalble, xGuidID.ToString(), vGuildFieldVec, vGuildValueVec)) { return NFIDENTID(); } //Name std::vector<std::string> vFieldVec; std::vector<std::string> vValueVec; vFieldVec.push_back("GuildID"); vValueVec.push_back(xGuidID.ToString()); m_pClusterSQLModule->Updata(mstrGuildNameTalble, strName, vFieldVec, vValueVec); return xGuidID; }
NFIDENTID NFCProperty::GetObject() const { if (!m_pTData.get()) { return NFIDENTID(); } if (TDATA_OBJECT == m_pTData->nType) { return boost::get<NFIDENTID>(m_pTData->variantData); } return NFIDENTID(); }
int NFCGameServerToWorldModule::OnSocketEvent( const int nSockIndex, const NF_NET_EVENT eEvent ) { if (eEvent == NF_NET_EVENT_CONNECTED) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_CONNECTED", "Connected success", __FUNCTION__, __LINE__); OnClientConnected(nSockIndex); } else { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, nSockIndex), "NF_NET_EVENT_EOF", "Connection closed or Got an error!", __FUNCTION__, __LINE__); OnClientDisconnect(nSockIndex); } return 0; }
int NFCNPCRefreshModule::OnDeadDestroyHeart( const NFIDENTID& self, const std::string& strHeartBeat, const float fTime, const int nCount) { //and create new object const std::string& strClassName = m_pKernelModule->GetPropertyString( self, "ClassName" ); const std::string& strSeedID = m_pKernelModule->GetPropertyString( self, "NPCConfigID" ); const std::string& strConfigID = m_pKernelModule->GetPropertyString( self, "ConfigID" ); int nContainerID = m_pKernelModule->GetPropertyInt( self, "SceneID" ); int nGroupID = m_pKernelModule->GetPropertyInt( self, "GroupID" ); //m_pSceneProcessModule->ClearAll( nContainerID, nGroupID, strSeendID ); float fSeedX = m_pKernelModule->GetPropertyFloat( self, "X" ); float fSeedY = m_pKernelModule->GetPropertyFloat( self, "Y" ); float fSeedZ = m_pKernelModule->GetPropertyFloat( self, "Z" ); m_pKernelModule->DestroyObject( self ); NFCDataList arg; arg << "X" << fSeedX; arg << "Y" << fSeedY; arg << "Z" << fSeedZ; arg << "SeedID" << strSeedID; m_pKernelModule->CreateObject( NFIDENTID(), nContainerID, nGroupID, strClassName, strConfigID, arg ); return 0; }
bool NFCSceneProcessModule::CreateContinerObject( const int nContainerID, const int nGroupID, const std::string& strFileName, const std::string& strSeedID ) { NF_SHARE_PTR<NFMapEx<std::string, SceneGroupResource>> pSceneResource = mtSceneResourceConfig.GetElement( nContainerID ); if ( pSceneResource.get() ) { NF_SHARE_PTR<SceneGroupResource> pGroupResource = pSceneResource->GetElement( strFileName ); if ( pSceneResource.get() ) { NF_SHARE_PTR<NFMapEx<std::string, SceneSeedResource>> pResourceList = pGroupResource->xSceneGroupResource.GetElement( "NPC" ); if ( pResourceList.get() ) { NF_SHARE_PTR<SceneSeedResource> pResourceObject = pResourceList->GetElement( strSeedID ); if ( pResourceObject.get() ) { const std::string& strClassName = m_pElementInfoModule->GetPropertyString(pResourceObject->strConfigID, "ClassName"); NFCDataList arg; arg << "X" << pResourceObject->fSeedX; arg << "Y" << pResourceObject->fSeedY; arg << "Z" << pResourceObject->fSeedZ; arg << "SeedID" << strSeedID; m_pKernelModule->CreateObject( NFIDENTID(), nContainerID, nGroupID, strClassName, pResourceObject->strConfigID, arg ); } } } } return true; }
int NFCWorldNet_ServerModule::OnGameServerRegisteredProcess(const NFIPacket& msg) { NFIDENTID nPlayerID; NFMsg::ServerInfoReportList xMsg; if (!RecivePB(msg, xMsg, nPlayerID)) { return 0; } for (int i = 0; i < xMsg.server_list_size(); ++i) { NFMsg::ServerInfoReport* pData = xMsg.mutable_server_list(i); NF_SHARE_PTR<ServerData> pServerData = mGameMap.GetElement(pData->server_id()); if (!pServerData.get()) { pServerData = NF_SHARE_PTR<ServerData>(NF_NEW ServerData()); mGameMap.AddElement(pData->server_id(), pServerData); } pServerData->nFD = msg.GetFd(); *(pServerData->pData) = *pData; m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, pData->server_id()), pData->server_name(), "GameServerRegistered"); } SynGameToProxy(); return 0; }
const NFIDENTID NFCGridModule::OnObjectLeave(const NFIDENTID& self, const int& sceneID, const NFIDENTID& lastGrid) { OnMoveOut(self, lastGrid, lastGrid); return NFIDENTID(); }
void NFCGameServerToWorldModule::UnRegister() { NF_SHARE_PTR<NFILogicClass> xLogicClass = m_pLogicClassModule->GetElement("GameServer"); if (xLogicClass.get()) { NFList<std::string>& xNameList = xLogicClass->GetConfigNameList(); std::string strConfigName; if (xNameList.Get(0, strConfigName)) { const int nServerID = m_pElementInfoModule->GetPropertyInt(strConfigName, "ServerID"); 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"); NFMsg::ServerInfoReportList xMsg; NFMsg::ServerInfoReport* pData = xMsg.add_server_list(); pData->set_server_id(nServerID); pData->set_server_name(strName); pData->set_server_cur_count(0); pData->set_server_ip(strIP); pData->set_server_port(nPort); pData->set_server_max_online(nMaxConnect); pData->set_server_state(NFMsg::EST_MAINTEN); SendMsgPB(NFMsg::EGameMsgID::EGMI_GTW_GAME_UNREGISTERED, xMsg, GetNet()->FD()); m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, pData->server_id()), pData->server_name(), "UnRegister"); } } }
const NFIDENTID NFCGridModule::ComputerGridID(const int nX, const int nY, const int nZ) { int nGridXIndex = nX / nGridWidth; int nGridZIndex = nZ / nGridWidth; return NFIDENTID(nGridXIndex, nGridZIndex); }
int NFCLoginNet_ServerModule::OnSelectWorldProcess( const NFIPacket& msg ) { NFIDENTID nPlayerID; NFMsg::ReqConnectWorld xMsg; if (!RecivePB(msg, xMsg, nPlayerID)) { return 0; } NetObject* pNetObject = GetNet()->GetNetObject(msg.GetFd()); if (!pNetObject) { return 0; } //没登录过 if (pNetObject->GetConnectKeyState() <= 0) { return 0; } NFCDataList val; val << xMsg.world_id() << pNetObject->GetClientID() << pPluginManager->AppID() << pNetObject->GetAccount(); m_pEventProcessModule->DoEvent(NFIDENTID(), NFED_ON_CLIENT_SELECT_SERVER, val); return 0; }
int NFCLoginLogicModule::OnLoginEvent(const NFIDENTID& object, const int nEventID, const NFIDataList& var) { if (3 != var.GetCount() || !var.TypeEx(TDATA_TYPE::TDATA_OBJECT, TDATA_TYPE::TDATA_STRING, TDATA_TYPE::TDATA_STRING, TDATA_TYPE::TDATA_UNKNOWN)) { return -1; } ////////////////////////////////////////////////////////////////////////// const NFIDENTID xIdent = var.Object(0); const std::string& strAccount = var.String(1); const std::string& strPassword = var.String(2); int64_t nState = -1; std::vector<std::string> xFieldVec; std::vector<std::string> xValueVec; xFieldVec.push_back("Password"); if (m_pClusterSqlModule->Query("AccountInfo", strAccount, xFieldVec, xValueVec) && xFieldVec.size() == xValueVec.size() && strPassword == xValueVec[0]) { //µÇ¼³É¹¦ nState = 0; } NFCDataList valEventInfo; valEventInfo << nState << xIdent << strAccount; m_pEventProcessModule->DoEvent(NFIDENTID(), NFED_ON_CLIENT_LOGIN_RESULTS, valEventInfo); return 0; }
bool HelloWorld3Module::AfterInit() { //初始化完毕 std::cout << "Hello, world3, AfterInit" << std::endl; m_pKernelModule = dynamic_cast<NFIKernelModule*>(pPluginManager->FindModule("NFCKernelModule")); m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); //创建容器,所有的对象均需在容器中 m_pKernelModule->CreateContainer(1, ""); m_pEventProcessModule->AddClassCallBack("Player", this, &HelloWorld3Module::OnClassCallBackEvent); //创建对象,挂类回调和属性回调,然后事件处理对象 NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->CreateObject(NFIDENTID(0, 10), 1, 0, "Player", "", NFCDataList()); if (!pObject.get()) { return false; } pObject->GetPropertyManager()->AddProperty(pObject->Self(), "Hello", TDATA_STRING, true, true, true, true, 0, ""); pObject->GetPropertyManager()->AddProperty(pObject->Self(), "World", TDATA_INT, true, true, true, true, 0, ""); pObject->AddPropertyCallBack("Hello", this, &HelloWorld3Module::OnPropertyStrCallBackEvent); pObject->AddPropertyCallBack("World", this, &HelloWorld3Module::OnPropertyCallBackEvent); pObject->SetPropertyString("Hello", "hello,World"); pObject->SetPropertyInt("World", 1111); m_pEventProcessModule->DoEvent(pObject->Self(), 11111111, NFCDataList() << int(100) << "200"); return true; }
bool HelloWorld5Module::AfterInit() { //初始化完毕 std::cout << "Hello, world5, AfterInit, ThreadID: " << std::this_thread::get_id() << std::endl; m_pKernelModule = dynamic_cast<NFIKernelModule*>(pPluginManager->FindModule("NFCKernelModule")); m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); /////////////////////////////////////////////////////////////////////////////////////////////////////////// //int nActorID = m_pEventProcessModule->AddActorEventCallBack<NFCTestComponent, HelloWorld5Module>(this, &HelloWorld5Module::OnSyncEvent); int nActorID = m_pEventProcessModule->AddActorEventCallBack<NFCTestComponent>(this, &HelloWorld5Module::OnSyncEvent); for (int i = 0; i < 20; ++i) { m_pEventProcessModule->SendActorMsg(nActorID, 555, NFIDENTID(), boost::lexical_cast<std::string>(i)); } std::cout << "End Test Actor, ThreadID: " << std::this_thread::get_id() << std::endl; /////////////////////////////////////////////////////////////////////////////////////////////////////////// return true; }
NFIDENTID NFCObject::GetRecordObject(const std::string& strRecordName, const int nRow, const std::string& strColTag) { NF_SHARE_PTR<NFIRecord> pRecord = GetRecordManager()->GetElement(strRecordName); if (pRecord.get()) { return pRecord->GetObject(nRow, strColTag); } return NFIDENTID(); }
NFIDENTID NFCObject::GetPropertyObject(const std::string& strPropertyName) { NF_SHARE_PTR<NFIProperty> pProperty = GetPropertyManager()->GetElement(strPropertyName); if (pProperty.get()) { return pProperty->GetObject(); } return NFIDENTID(); }
NFCProperty::NFCProperty() { mbPublic = false; mbPrivate = false; mbSave = false; mSelf = NFIDENTID(); eType = TDATA_UNKNOWN; msPropertyName = ""; }
NFIDENTID NFCWorldGuildModule::CreateGuild( const NFIDENTID& self, const std::string& strName, const std::string& strRoleName, const int nLevel, const int nJob , const int nDonation , const int nVIP) { if (strName.empty()) { return NFIDENTID(); } bool bExit = false; if (!m_pWorldGuildDataModule->ExitGuild(self, strName, bExit)) { return NFIDENTID(); } if (bExit) { return NFIDENTID(); } return m_pWorldGuildDataModule->CreateGuild(self, strName, strRoleName, nLevel, nJob, nDonation, nVIP); }
bool NFCWorldToMasterModule::AfterInit() { m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pWorldLogicModule = dynamic_cast<NFIWorldLogicModule*>(pPluginManager->FindModule("NFCWorldLogicModule")); m_pLogicClassModule = dynamic_cast<NFILogicClassModule*>(pPluginManager->FindModule("NFCLogicClassModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); m_pLogModule = dynamic_cast<NFILogModule*>(pPluginManager->FindModule("NFCLogModule")); assert(NULL != m_pEventProcessModule); assert(NULL != m_pWorldLogicModule); assert(NULL != m_pLogicClassModule); assert(NULL != m_pElementInfoModule); assert(NULL != m_pLogModule); m_pEventProcessModule->AddEventCallBack(NFIDENTID(), NFED_ON_CLIENT_SELECT_SERVER_RESULTS, this, &NFCWorldToMasterModule::OnSelectServerResultsEvent); NFIClusterClientModule::Bind(this, &NFCWorldToMasterModule::OnReciveMSPack, &NFCWorldToMasterModule::OnSocketMSEvent); 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) { 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"); ServerData xServerData; xServerData.nGameID = nServerID; xServerData.eServerType = (NF_SERVER_TYPE)nServerType; xServerData.strIP = strIP; xServerData.nPort = nPort; xServerData.strName = strName; xServerData.eState = NFMsg::EServerState::EST_NARMAL; NFIClusterClientModule::AddServer(xServerData); } } } return true; }
int NFCGameServerToWorldModule::OnAckLeaveGuildProcess( const NFIPacket& msg ) { NFIDENTID nPlayerID; NFMsg::ReqAckLeaveGuild xData; if (!NFINetModule::RecivePB(msg, xData, nPlayerID)) { return 0; } m_pKernelModule->SetPropertyObject(nPlayerID, "GuildID", NFIDENTID()); m_pGameServerNet_ServerModule->SendMsgPBToGate(msg.GetMsgHead()->GetMsgID(), xData, nPlayerID); return 0; }
int NFCLoginNet_ServerModule::OnLoginResultsEvent(const NFIDENTID& object, const int nEventID, const NFIDataList& var) { if (3 != var.GetCount() || !var.TypeEx(TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_OBJECT, TDATA_TYPE::TDATA_STRING, TDATA_TYPE::TDATA_UNKNOWN)) { return -1; } const int nState = var.Int(0); const NFIDENTID xIdent = var.Object(1); const std::string& strAccount = var.String(2); NF_SHARE_PTR<int> xFD = mxClientIdent.GetElement(xIdent); if (xFD) { if (0 != nState) { //此帐号密码错误或者被封号 //登录失败 NFMsg::AckEventResult xMsg; xMsg.set_event_code(NFMsg::EGEC_ACCOUNTPWD_INVALID); SendMsgPB(NFMsg::EGameMsgID::EGMI_ACK_LOGIN, xMsg, *xFD); return 0; } NetObject* pNetObject = GetNet()->GetNetObject(*xFD); if (pNetObject) { //记录他登录过 pNetObject->SetConnectKeyState(1); pNetObject->SetAccount(strAccount); } //把服务器列表广播下去 NFMsg::AckEventResult xData; xData.set_event_code(NFMsg::EGEC_ACCOUNT_SUCCESS); SendMsgPB(NFMsg::EGameMsgID::EGMI_ACK_LOGIN, xData, *xFD); //SynWorldToClient(unAddress); m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, *xFD), "Login successed :", strAccount.c_str()); } return 0; }
int NFCWorldToMasterModule::OnKickClientProcess(const NFIPacket& msg) { NFIDENTID nPlayerID; NFMsg::ReqKickFromWorld xMsg; if (!NFINetModule::RecivePB(msg, xMsg, nPlayerID)) { return 0; } //T人,下线 NFCDataList var; var << xMsg.world_id() << xMsg.account(); m_pEventProcessModule->DoEvent(NFIDENTID(), NFED_ON_KICK_FROM_SERVER, var); return 0; }
int NFCWorldToMasterModule::OnSelectServerProcess(const NFIPacket& msg) { NFIDENTID nPlayerID; NFMsg::ReqConnectWorld xMsg; if (!NFINetModule::RecivePB(msg, xMsg, nPlayerID)) { return 0; } NFCDataList var; var << xMsg.world_id() << NFINetModule::PBToNF(xMsg.sender()) << xMsg.login_id() << xMsg.account(); m_pEventProcessModule->DoEvent(NFIDENTID(), NFED_ON_CLIENT_SELECT_SERVER, var); return 0; }
const NFIDENTID NFCGridModule::OnObjectMove(const NFIDENTID& self, const int& sceneID, const NFIDENTID& lastGrid, const int nX, const int nY, const int nZ) { if (sceneID != mSceneID) { return NFIDENTID(); } const NFIDENTID& currGrid = ComputerGridID(nX, nY, nZ); if (currGrid == lastGrid) { return lastGrid; } OnMoveOut(self, currGrid, lastGrid); OnMoveIn(self, currGrid, lastGrid); return currGrid; }
int NFCWorldNet_ServerModule::OnGameServerUnRegisteredProcess(const NFIPacket& msg) { NFIDENTID nPlayerID; NFMsg::ServerInfoReportList xMsg; if (!RecivePB(msg, xMsg, nPlayerID)) { return 0; } for (int i = 0; i < xMsg.server_list_size(); ++i) { NFMsg::ServerInfoReport* pData = xMsg.mutable_server_list(i); mGameMap.RemoveElement(pData->server_id()); m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, pData->server_id()), pData->server_name(), "GameServerRegistered"); } return 0; }
void NFCGameServerToWorldModule::Register(NFINet* pNet) { //成功就注册 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_GAME && 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"); NFMsg::ServerInfoReportList xMsg; NFMsg::ServerInfoReport* pData = xMsg.add_server_list(); pData->set_server_id(nServerID); pData->set_server_name(strName); pData->set_server_cur_count(0); pData->set_server_ip(strIP); pData->set_server_port(nPort); pData->set_server_max_online(nMaxConnect); pData->set_server_state(NFMsg::EST_NARMAL); pData->set_server_type(nServerType); NF_SHARE_PTR<ServerData> pServerData = GetServerNetInfo(pNet); if (pServerData) { int nTargetID = pServerData->nGameID; SendToServerByPB(nTargetID, NFMsg::EGameMsgID::EGMI_GTW_GAME_REGISTERED, xMsg); m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, NFIDENTID(0, pData->server_id()), pData->server_name(), "Register"); } } } } }
int NFCWorldNet_ServerModule::OnSelectServerEvent(const NFIDENTID& object, const int nEventID, const NFIDataList& var) { if (4 != var.GetCount() || !var.TypeEx(TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_STRING, TDATA_TYPE::TDATA_UNKNOWN)) { return 0; } const int nWorldID = var.Int(0); const int nSenderAddress = var.Int(1); const int nLoginID = var.Int(2); const std::string& strAccount = var.String(3); ////////////////////////////////////////////////////////////////////////// if (InThisWorld(strAccount)) { return 0; } NF_SHARE_PTR<ServerData> pServerData = mProxyMap.First(); if (pServerData.get()) { NFMsg::AckConnectWorldResult xData; xData.set_world_id(nWorldID); xData.set_sender_ip(nSenderAddress); xData.set_login_id(nLoginID); xData.set_account(strAccount); xData.set_world_ip(pServerData->pData->server_ip()); xData.set_world_port(pServerData->pData->server_port()); xData.set_world_key(strAccount); SendMsgPB(NFMsg::EGMI_ACK_CONNECT_WORLD, xData, pServerData->nFD); //结果 NFCDataList varResult; varResult << nWorldID << nSenderAddress << nLoginID << strAccount << pServerData->pData->server_ip() << pServerData->pData->server_port() << strAccount; m_pEventProcessModule->DoEvent(NFIDENTID(), NFED_ON_CLIENT_SELECT_SERVER_RESULTS, varResult); } return 0; }
bool NFCLoginLogicModule::AfterInit() { ////////////////////////////////////////////////////////////////////////// m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pClusterSqlModule = dynamic_cast<NFIClusterModule*>(pPluginManager->FindModule("NFCMysqlClusterModule")); assert(NULL != m_pEventProcessModule); assert(NULL != m_pClusterSqlModule); ////////////////////////////////////////////////////////////////////////// // register event calback m_pEventProcessModule->AddEventCallBack(NFIDENTID(), NFED_ON_CLIENT_LOGIN, this, &NFCLoginLogicModule::OnLoginEvent); return true; }