int CWorldMgrD::CreateCellInNewSpace(T_VECTOR_OBJECT* p) { if(p->size() != 4) { return -1; } CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); uint16_t etype = VOBJECT_GET_U16((*p)[1]); #ifdef __USE_MSGPACK charArrayDummy *d = (charArrayDummy*)VOBJECT_GET_BLOB((*p)[2]); #else const char* pszParams = VOBJECT_GET_STR((*p)[2]); #endif charArrayDummy& props = *((charArrayDummy*)((*p)[3]->vv.p)); uint16_t nCellappId = ChooseACellApp(etype); CMailBox* mb = GetServerMailbox(nCellappId); if(mb) { #ifdef __USE_MSGPACK mb->RpcCall(GetRpcUtil(), MSGID_CELLAPP_CREATE_CELL_IN_NEW_SPACE, emb, etype, *d, props); #else mb->RpcCall(GetRpcUtil(), MSGID_CELLAPP_CREATE_CELL_IN_NEW_SPACE, emb, etype, pszParams, props); #endif } return 0; }
int CWorldOther::RegisterGlobally(T_VECTOR_OBJECT* p) { //printf("rrrr,%d\n", p->size()); if(p->size() != 2) { return -1; } const char* szName = VOBJECT_GET_STR((*p)[0]); CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[1]); LogDebug("CWorldOther::RegisterGlobally", "szName=%s;m_nServerMailboxId=%d;m_nEntityType=%d;m_nEntityId=%d", szName, emb.m_nServerMailboxId, emb.m_nEntityType, emb.m_nEntityId); //printf("rrrr2222, %s, %d \n", szName, ref); bool bRet = false; map<string, CEntityMailbox*>::iterator iter = m_globalBases.lower_bound(szName); if(iter != m_globalBases.end() && iter->first.compare(szName) == 0) { //existed! } else { //add new bRet = true; CEntityMailbox* pe = new CEntityMailbox; pe->m_nServerMailboxId = emb.m_nServerMailboxId; pe->m_nEntityType = emb.m_nEntityType; pe->m_nEntityId = emb.m_nEntityId; m_globalBases.insert(iter, make_pair(szName, pe)); } return 0; }
int CWorldDbmgr::UpdateEntity(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 3) { return -1; } CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); TDBID dbid = VOBJECT_GET_U64((*p)[1]); SEntityPropFromPluto* p2 = (SEntityPropFromPluto*)((*p)[2]->vv.p); const string& strEntityName = GetDefParser().GetTypeName(p2->etype); //string strSql; //db.make_update_sql(strEntityName, p2->data, dbid, strSql); //string strSql2; //db.make_create_sql(strEntityName, strSql2); //cout << strSql2 << endl; string strErr; int nRet = db.UpdateEntity(strEntityName, p2->data, dbid, strErr); if(nRet != 0) { if(nRet == -4) { LogWarning("UpdateEntity_err", "entity no change"); return 0; } else { LogWarning("UpdateEntity_err", "%s", strErr.c_str()); } //cout << strErr << endl; return -2; } // //通知db结果 // CEpollServer* s = this->GetServer(); // CMailBox* mb = s->GetServerMailbox(emb.m_nServerMailboxId); // if(mb) // { //#ifdef _WIN32 // mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref); //#else // CRpcUtil& rpc = GetRpcUtil(); // CPluto* u = new CPluto; // rpc.Encode(*u, MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref); // u->SetMailbox(mb); // g_pluto_sendlist.PushPluto(u); //#endif // } return 0; }
int CWorldDbmgr::InsertDB(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 3) { return -1; } CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); int32_t ref = VOBJECT_GET_I32((*p)[1]); SEntityPropFromPluto* p2 = (SEntityPropFromPluto*)((*p)[2]->vv.p); const string& strEntityName = GetDefParser().GetTypeName(p2->etype); //string strSql; //db.make_insert_sql(strEntityName, p2->data, strSql); //cout << strSql << endl; //string strSql2; //db.make_create_sql(strEntityName, strSql2); //cout << strSql2 << endl; //LogWarning("insert to db", "emb ref strEntityName = %s", strEntityName.c_str()); string strErr; TDBID newid = db.InsertEntity(strEntityName, p2->data, strErr); if(newid == 0) { LogWarning("InsertDB_err", "newid=0;err=%s", strErr.c_str()); //cout << strErr << endl; //return -2; } //通知db结果 CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(emb.m_nServerMailboxId); if(mb) { #ifdef _WIN32 mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref, strErr.c_str()); #else CRpcUtil& rpc = GetRpcUtil(); CPluto* u = new CPluto; rpc.Encode(*u, MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref, strErr.c_str()); u->SetMailbox(mb); LogDebug("CDbOper::InsertDB", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); #endif } return 0; }
//发到cell的entity rpc调用 T_VECTOR_OBJECT* CRpcUtil::DecodeCellEntityRpc(CPluto& u) { //特殊处理 T_VECTOR_OBJECT* ll = new T_VECTOR_OBJECT; VOBJECT* v = new VOBJECT; u.FillVObject(V_ENTITYMB, *v); ll->push_back(v); if(u.GetDecodeErrIdx() > 0) { return ll; } CEntityMailbox& mb = VOBJECT_GET_EMB(v); //取funcid v = new VOBJECT; u.FillVObject(V_UINT16, *v); ll->push_back(v); if(u.GetDecodeErrIdx() > 0) { return ll; } int32_t nFuncId = (int32_t)VOBJECT_GET_U16(v); const SEntityDef* pDef = GetWorld()->GetDefParser().GetEntityDefByType(mb.m_nEntityType); if(pDef) { const string& strFunc = pDef->m_cellMethodsMap.GetStrByInt(nFuncId); map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_cellMethods.find(strFunc); if(iter11 != pDef->m_cellMethods.end()) { _SEntityDefMethods* pMethods = iter11->second; list<VTYPE>& refs = pMethods->m_argsType; list<VTYPE>::const_iterator iter2 = refs.begin(); for(; iter2 != refs.end(); ++iter2) { VOBJECT* v = new VOBJECT; u.FillVObject(*iter2, *v); ll->push_back(v); if(u.GetDecodeErrIdx() > 0) { break; } } return ll; } } ClearTListObject(ll); return NULL; }
int CWorldDbmgr::UpdateEntityToRedis(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 3) { return -1; } CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); TDBID dbid = VOBJECT_GET_U64((*p)[1]); SEntityPropFromPluto* p2 = (SEntityPropFromPluto*)((*p)[2]->vv.p); const string& strEntityName = GetDefParser().GetTypeName(p2->etype); string strErr; db.UpdateEntityToRedis(strEntityName, p2->data, dbid, strErr); return 0; }
int CWorldDbmgr::RedisHashLoad(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 3) { return -1; } const CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); const string& strAttri = VOBJECT_GET_SSTR((*p)[1]); const string& strKey = VOBJECT_GET_SSTR((*p)[2]); //查找该key的值 string strValue; db.RedisHashLoad(strKey, strValue); //回调 SyncRpcCall(g_pluto_sendlist, emb.m_nServerMailboxId, MSGID_BASEAPP_ON_REDIS_HASH_LOAD, emb, strAttri, strValue); return 0; }
int CWorldMgrD::RegisterGlobally(T_VECTOR_OBJECT* p) { //printf("rrrr,%d\n", p->size()); if(p->size() != 3) { return -1; } CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); const char* szName = VOBJECT_GET_STR((*p)[1]); int32_t ref = VOBJECT_GET_I32((*p)[2]); //printf("rrrr2222, %s, %d \n", szName, ref); bool bRet = false; map<string, CEntityMailbox*>::iterator iter = m_globalBases.lower_bound(szName); if(iter != m_globalBases.end() && iter->first.compare(szName) == 0) { //existed! } else { //add new bRet = true; CEntityMailbox* pe = new CEntityMailbox; pe->m_nServerMailboxId = emb.m_nServerMailboxId; pe->m_nEntityType = emb.m_nEntityType; pe->m_nEntityId = emb.m_nEntityId; m_globalBases.insert(iter, make_pair(szName, pe)); } //如果注册成功,同步给所有的baseapp CEpollServer* s = this->GetServer(); if(bRet) { vector<CMailBox*>& mbs = s->GetAllServerMbs(); vector<CMailBox*>::iterator iter = mbs.begin(); for(; iter != mbs.end(); ++iter) { CMailBox* basemb = *iter; if(basemb && basemb->GetServerMbType() == SERVER_BASEAPP) { basemb->RpcCall(GetRpcUtil(),MSGID_BASEAPP_ADD_GLOBALBASE, szName, emb); } if (basemb && basemb->GetServerMbType() == SERVER_LOG) { LogDebug("mogo::CWorldMgrD::RegisterGlobally", "szName=%s;", szName); //通知logapp,哪一个base进程拥有哪一个globalbase basemb->RpcCall(GetRpcUtil(), MSGID_OTHER_ADD_GLOBALBASE, szName, emb); } } } //通知注册结果 CMailBox* mb = s->GetServerMailbox(emb.m_nServerMailboxId); if(mb) { mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_REGISTERGLOBALLY_CALLBACK, emb, (uint8_t)bRet, ref); } return 0; }