int CTimerdWorld::FromRpcCall(CPluto& u) { pluto_msgid_t msg_id = u.GetMsgId(); if(!CheckClientRpc(u)) { LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } T_VECTOR_OBJECT* p = m_rpc.Decode(u); if(p == NULL) { LogWarning("from_rpc_call", "rpc decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); LogWarning("from_rpc_call", "rpc decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } int nRet = -1; switch(msg_id) { case MSGID_ALLAPP_SHUTDOWN_SERVER: { nRet = ShutdownServer(p); break; } default: { LogWarning("from_rpc_call", "unknown msgid:%d\n", msg_id); } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); 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::FromRpcCall(CPluto& u, CDbOper& db) { //printf("CWorldDbmgr::from_rpc_call\n"); //print_hex_pluto(u); pluto_msgid_t msg_id = -1; T_VECTOR_OBJECT* p = NULL; //这一段要加锁(2012/02/15改为不加锁) { //CMutexGuard _g(m_rpcMutex); msg_id = u.GetMsgId(); if(!CheckClientRpc(u)) { LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } p = m_rpc.Decode(u); if(p == NULL) { LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); //PrintHexPluto(u); LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } } //这一段不用加锁 int nRet = -1; switch(msg_id) { case MSGID_DBMGR_INSERT_ENTITY: { nRet = InsertDB(p, db); break; } case MSGID_DBMGR_SELECT_ENTITY: { nRet = LookupEntityByDbId(p, db); break; } case MSGID_DBMGR_UPDATE_ENTITY: { nRet = UpdateEntity(p, db); break; } case MSGID_DBMGR_UPDATE_ENTITY_REDIS: { nRet = UpdateEntityToRedis(p, db); break; } case MSGID_DBMGR_SELECT_ACCOUNT: { nRet = SelectAccount(p, db); break; } case MSGID_DBMGR_RAW_MODIFY_NORESP: { nRet = QueryModifyNoResp(p, db); break; } case MSGID_DBMGR_CREATEBASE_FROM_NAME: { nRet = LookupEntityByName(p, db); break; } case MSGID_DBMGR_LOAD_ALL_AVATAR: { nRet = LoadAllAvatars(p, db); break; } case MSGID_DBMGR_LOAD_ENTITIES_OF_TYPE: { nRet = LoadEntitiesOfType(p, db); break; } case MSGID_DBMGR_SHUTDOWN_SERVER: { nRet = ShutdownServer(p); break; } case MSGID_DBMGR_REDIS_HASH_LOAD: { nRet = RedisHashLoad(p, db); break; } case MSGID_DBMGR_REDIS_HASH_SET: { nRet = RedisHashSet(p, db); break; } case MSGID_DBMGR_REDIS_HASH_DEL: { nRet = RedisHashDel(p, db); break; } case MSGID_DBMGR_DEL_ACCOUNT_CACHE: { nRet = DestroyAccountCache(p); break; } case MSGID_DBMGR_UPDATE_ITEMS: { nRet = UpdateArrayItemsToDb(p, db); break; } case MSGID_DBMGR_LOADING_ITEMS: { nRet = LoadingArrayItemsToInventory(p, db); break; } case MSGID_DBMGR_INCREMENTAL_UPDATE_ITEMS: { nRet = IncremantalUpdateItems(p, db); break; } case MSGID_DBMGR_TABLE_SELECT: { nRet = TableSelect(p, db); break; } case MSGID_DBMGR_UPDATE_BATCH: { nRet = TableUpdateBatch(p, db); break; } case MSGID_DBMGR_TABLE_INSERT: { nRet = TableInsert(p, db); break; } case MSGID_DBMGR_TABLE_EXCUTE: { nRet = TableExcute(p, db); break; } case MSGID_DBMGR_TABLE2_SELECT: { nRet = Table2Select(p, db); break; } case MSGID_DBMGR_TABLE2_INSERT: { nRet = Table2Insert(p, db); break; } case MSGID_DBMGR_TABLE2_EXCUTE: { nRet = Table2Excute(p, db); break; } default: { break; } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); return 0; }
int CWorldMgrD::FromRpcCall(CPluto& u) { //PrintHexPluto(u); pluto_msgid_t msg_id = u.GetMsgId(); #ifndef __TEST_LOGIN if(!CheckClientRpc(u)) { LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } #endif // !__TEST_LOGIN T_VECTOR_OBJECT* p = m_rpc.Decode(u); if(p == NULL) { LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } int nRet = -1; switch(msg_id) { case MSGID_BASEAPPMGR_REGISTERGLOBALLY: { LogInfo("CWorldMgrD::FromRpcCall() MSGID_BASEAPPMGR_REGISTERGLOBALLY", ""); nRet = RegisterGlobally(p); break; } case MSGID_BASEAPPMGR_CREATEBASE_FROM_NAME_ANYWHERE: { nRet = CreateBaseFromDbByName(p); break; } case MSGID_BASEAPPMGR_CREATEBASE_FROM_NAME: { nRet = CreateBaseFromDbByName(p); break; } case MSGID_BASEAPPMGR_CREATE_CELL_IN_NEW_SPACE: { nRet = CreateCellInNewSpace(p); break; } case MSGID_BASEAPPMGR_CREATEBASE_ANYWHERE: { nRet = CreateBaseAnywhere(p); break; } case MSGID_BASEAPPMGR_SHUTDOWN_SERVERS: { nRet = ShutdownAllServers(p, u); break; } case MSGID_BASEAPPMGR_ON_SERVER_SHUTDOWN: { nRet = OnServerShutdown(p); break; } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); return 0; }
void* ThreadJob_SdkServerVerify(void* arg) { CPluto& u = *((CPluto*)arg); pluto_msgid_t msg_id = u.GetMsgId();; T_VECTOR_OBJECT* p = NULL; CMailBox* pmb = u.GetMailbox(); if(!pmb) { //如果没有mb,是从本进程发来的包 delete &u; return (void*)-1; } uint8_t authz = pmb->GetAuthz(); if(authz != MAILBOX_CLIENT_TRUSTED) { LogWarning("ThreadJob_SdkServerVerify", "invalid rpcall error.unknown msgid:%d\n", msg_id); delete &u; return (void*)-1; } p = g_worldOther.GetRpcUtil().Decode(u); if(p == NULL) { LogWarning("ThreadJob_SdkServerVerify", "rpc Decode error.unknown msgid:%d\n", msg_id); delete &u; return (void*)-2; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); //PrintHexPluto(u); LogWarning("ThreadJob_SdkServerVerify", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); delete &u; return (void*)-3; } if (p->size() != 4) { delete &u; return (void*)-4; } string& url = VOBJECT_GET_SSTR((*p)[0]); int32_t nFd = VOBJECT_GET_I32((*p)[1]); string& strAccount = VOBJECT_GET_SSTR((*p)[2]); string& strPlatId = VOBJECT_GET_SSTR((*p)[3]); //CMailBox* pmb = u.GetMailbox(); string resp = ""; int ret = GetUrl(url.c_str(), resp); if (ret != CURLE_OK) { LogWarning("CWorldOther::SdkServerVerify", "%s ret = %d", strAccount.c_str(), ret); //todo:faild. pmb->RpcCall(g_worldOther.GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId); delete &u; return 0; } Trim(resp); cJSON* json = cJSON_Parse(resp.c_str()); cJSON* childJs = cJSON_GetObjectItem(json, "code"); int rst = cJSON_GetObjectItem(json, "code")->valueint; if (rst == 1) { //succeed. if (strAccount.c_str() != cJSON_GetObjectItem(json, "msg")->valuestring) { ret = 0; } else { LogWarning("CWorldOther::SdkServerVerify", "strAccount[%s] msg[%s]", strAccount.c_str(), cJSON_GetObjectItem(json, "msg")->valuestring); ret = 1; //pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, int32_t(1), nFd, strAccount, strPlatId); } } else { //failed. LogWarning("CWorldOther::SdkServerVerify", "strAccount[%s] rst[%d]", strAccount.c_str(), rst); ret = -1; //pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, -1, nFd, strAccount, strPlatId); } pmb->RpcCall(g_worldOther.GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId); delete &u; return (void*)0; }
T_VECTOR_OBJECT* CRpcUtil::DecodeBroadcastClientRpc(CPluto& u) { u.Decode(); T_VECTOR_OBJECT* ll = new T_VECTOR_OBJECT; TENTITYTYPE iType = 0; u >> iType; if(u.GetDecodeErrIdx() > 0) { return ll; } uint16_t nFuncId = 0; u >> nFuncId; if(u.GetDecodeErrIdx() > 0) { return ll; } //CWorldBase& the_world = GetWorldbase(); CWorldBase *pstCWorldBase = dynamic_cast<CWorldBase *>(GetWorld()); if (pstCWorldBase==NULL) { return ll; } const SEntityDef* pDef = pstCWorldBase->GetDefParser().GetEntityDefByType(iType); if(pDef == NULL) { return ll; } const string& strFunc = pDef->m_clientMethodsMap.GetStrByInt(nFuncId); map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_clientMethods.find(strFunc); if(iter11 != pDef->m_clientMethods.end()) { _SEntityDefMethods* pMethods = iter11->second; VOBJECT* v = new VOBJECT; v->vt = V_UINT16; v->vv.u16 = iType; ll->push_back(v); v = new VOBJECT; v->vt = V_STR; v->vv.s = new string(strFunc); ll->push_back(v); list<VTYPE>& refs = pMethods->m_argsType; list<VTYPE>::const_iterator iter2 = refs.begin(); for(; iter2 != refs.end(); ++iter2) { v = new VOBJECT; u.FillVObject(*iter2, *v); ll->push_back(v); if(u.GetDecodeErrIdx() > 0) { return ll; } } return ll; } ClearTListObject(ll); }
//发到base的来自client的entity rpc调用 T_VECTOR_OBJECT* CRpcUtil::DecodeBaseClientRpc(CPluto& u) { CMailBox* mb = u.GetMailbox(); if(mb == NULL) { return NULL; } int fd = mb->GetFd(); //CWorldBase& the_world = GetWorldbase(); CWorldBase *pstCWorldBase = dynamic_cast<CWorldBase *>(GetWorld()); if (pstCWorldBase==NULL) { LogError("CRpcUtil::DecodeBaseClientRpc", "pstCWorldBase is null."); return NULL; } //CEntityBase* pBase = the_world.GetEntityByFd(fd); CEntityBase* pBase = pstCWorldBase->GetEntityByFd(fd); if(pBase == NULL) { return NULL; } #ifdef __PLUTO_ORDER //校验rpc包的顺序 uint16_t PlutoOrder = sz_to_uint16((unsigned char*)u.GetRecvBuff() + MSGLEN_HEAD); uint16_t EntityPlutoOrder = pBase->GetPlutoOrder(); //LogDebug("CRpcUtil::DecodeBaseClientRpc", "PlutoOrder=%d;EntityPlutoOrder=%d", PlutoOrder, EntityPlutoOrder); #endif //const SEntityDef* pDef = the_world.GetDefParser().GetEntityDefByType(pBase->GetEntityType()); const SEntityDef* pDef = pstCWorldBase->GetDefParser().GetEntityDefByType(pBase->GetEntityType()); if(pDef == NULL) { return NULL; } T_VECTOR_OBJECT* ll = new T_VECTOR_OBJECT; VOBJECT* v = new VOBJECT; v->vt = V_ENTITY_POINTER; v->vv.p = pBase; ll->push_back(v); uint16_t nFuncId = 0; u >> nFuncId; if(u.GetDecodeErrIdx() > 0) { return ll; } const string& strFunc = pDef->m_baseMethodsMap.GetStrByInt(nFuncId); map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_baseMethods.find(strFunc); if(iter11 != pDef->m_baseMethods.end()) { _SEntityDefMethods* pMethods = iter11->second; if(pMethods->m_bExposed) { v = new VOBJECT; v->vt = V_STR; v->vv.s = new string(strFunc); ll->push_back(v); 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) { return ll; } } return ll; } //else 该方法不能由客户端调用 } ClearTListObject(ll); return NULL; }
//in parent class , this method has a pure virtual access limited int CWorldLogin::FromRpcCall(CPluto& u) { //printf("CWorldLogin::from_rpc_call\n"); //printf("handle pluto in FromRpcCall()! : start!\n"); pluto_msgid_t msg_id = u.GetMsgId(); //printf("message id : %d\n", msg_id); if(!CheckClientRpc(u)) { LogWarning("FromRpcCall", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } T_VECTOR_OBJECT* p = m_rpc.Decode(u); if(p == NULL) { LogWarning("FromRpcCall", "rpc decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); LogWarning("FromRpcCall", "rpc decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } printf("MSGID_LOGINAPP_MODIFY_LOGIN_FLAG:%d\n", MSGID_LOGINAPP_MODIFY_LOGIN_FLAG); int nRet = -1; switch(msg_id) { case MSGID_LOGINAPP_LOGIN: { AddClientFdToVObjectList(u.GetMailbox()->GetFd(), p); nRet = AccountLogin(p); break; } case MSGID_LOGINAPP_SELECT_ACCOUNT_CALLBACK: { nRet = SelectAccountCallback(p); break; } case MSGID_LOGINAPP_NOTIFY_CLIENT_TO_ATTACH: { nRet = NotifyClientToAttach(p); break; } case MSGID_LOGINAPP_MODIFY_LOGIN_FLAG: { nRet = ModifyLoginFlag(p); break; } case MSGID_ALLAPP_SHUTDOWN_SERVER://103 { nRet = ShutdownServer(p); break; } default: { LogWarning("CWorldLogin::from_rpc_call", "unknown msgid:%d\n", msg_id); break; } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); //printf("handle pluto in FromRpcCall()! : end!\n"); return 0; }
int CWorldOther::FromRpcCall(CPluto& u, CDbOper& db) { //printf("CWorldOther::from_rpc_call\n"); //print_hex_pluto(u); pluto_msgid_t msg_id = -1; T_VECTOR_OBJECT* p = NULL; //这一段要加锁(2012/02/15改为不加锁) { //CMutexGuard _g(m_rpcMutex); msg_id = u.GetMsgId(); if(!CheckClientRpc(u)) { LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id); return -1; } p = m_rpc.Decode(u); if(p == NULL) { LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id); return -1; } if(u.GetDecodeErrIdx() > 0) { ClearTListObject(p); //PrintHexPluto(u); LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx()); return -2; } } //这一段不用加锁 int nRet = -1; switch(msg_id) { case MSGID_LOG_INSERT: { nRet = InsertDB(p, db); break; } case MSGID_OTHER_HTTP_REQ: { nRet = ReqUrl(p); break; } case MSGID_ALLAPP_SHUTDOWN_SERVER: { nRet = ShutdownServer(p); break; } case MSGID_OTHER_ADD_GLOBALBASE: { nRet = RegisterGlobally(p); break; } case MSGID_OTHER_YUNYING_API: { nRet = SupportApi(p, u.GetMailbox(), db); break; } case MSGID_OTHER_CLIENT_RESPONSE: { nRet = Response2Browser(p); PrintHexPluto(u); break; } //case MSGID_OTHER_LOGIN_VERIFY: //{ // //todo:verify // nRet = SdkServerVerify(p, u); // break; //} // case MSGID_OTHER_PLAT_API: // { // nRet = PlatApi(p, u.GetMailbox(), db); // break; // } default: { LogWarning("from_rpc_call", "rpc unkown msg_id = %d\n", msg_id, nRet); break; } } if(nRet != 0) { LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet); } ClearTListObject(p); return 0; }