int CWorldDbmgr::SelectAccount(T_VECTOR_OBJECT* p, CDbOper& db) { #if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW if(p->size() != 3) #else if(p->size() != 4) #endif { return -1; } uint16_t nServerId = VOBJECT_GET_U16((*p)[0]); int32_t nFd = VOBJECT_GET_I32((*p)[1]); const char* s1 = VOBJECT_GET_STR((*p)[2]); #if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW #else const char* s2 = VOBJECT_GET_STR((*p)[3]); #endif CPluto* u = new CPluto; string strErr; #if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW if(db.SelectAccount(nFd, s1, *u, strErr) != 0) #else if(db.SelectAccount(nFd, s1, s2, *u, strErr) != 0) #endif { delete u; //cout << strErr << endl; LogWarning("SelectAccount_err", "%s", strErr.c_str()); return -2; } //通知db结果 CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(nServerId); if(mb) { #ifdef _WIN32 mb->RpcCall(*u); #else u->SetMailbox(mb); LogDebug("CWorldDbmgr::SelectAccount", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); #endif } else { delete u; LogWarning("SelectAccount_err", "no mb!"); return -3; } return 0; }
int CWorldMgrD::CreateBaseFromDbByName(T_VECTOR_OBJECT* p) { if(p->size() < 3) { return -1; } uint8_t createFlag = VOBJECT_GET_U8((*p)[0]); const char* pszEntityType = VOBJECT_GET_STR((*p)[1]); const char* pszKey = VOBJECT_GET_STR((*p)[2]); uint16_t nBaseappId; if(p->size() > 3) { //指定了baseapp nBaseappId = VOBJECT_GET_U16((*p)[3]); } else { //未指定baseapp,选择一个 nBaseappId = ChooseABaseApp(pszEntityType); } #ifdef __TEST_LOGIN CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(nBaseappId); if (mb) { TENTITYID nOtherEntityId = 0; CPluto* u = new CPluto; (*u).Encode(MSGID_BASEAPP_LOOKUP_ENTITY_CALLBACK); (*u) << (uint64_t)0 << this->GetNextEntityId()<< createFlag << pszKey << nOtherEntityId; (*u) << this->GetDefParser().GetTypeId(pszEntityType); TDBID dbid2 = 0; (*u).ReplaceField(PLUTO_FILED_BEGIN_POS, dbid2); (*u) << EndPluto; u->SetMailbox(mb); LogDebug("CWorldMgrD::CreateBaseFromDbByName", "u.GenLen()=%d", u.GetLen()); mb->PushPluto(u); } #else CMailBox* mb = GetServerMailbox(SERVER_DBMGR); if(mb) { mb->RpcCall(GetRpcUtil(), MSGID_DBMGR_CREATEBASE_FROM_NAME, nBaseappId, createFlag, pszEntityType, pszKey); } #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; }
int CWorldDbmgr::TableExcute(T_VECTOR_OBJECT* p, CDbOper& db) { if (p->size() != 3) { LogError("CWorldDbmgr::TableInsert", "p->size()=%d", p->size()); return -1; } uint16_t nBaseappId = VOBJECT_GET_U16((*p)[0]); const string& strSql = VOBJECT_GET_SSTR((*p)[1]); uint32_t ref = VOBJECT_GET_U32((*p)[2]); //LogDebug("CWorldDbmgr::TableExcute", "nBaseappId=%d;ref=%d;strSql=%s", // nBaseappId, ref, strSql.c_str()); string strErr; uint8_t ret = db.TableExcute(strSql, strErr); if(ret != 0) { LogWarning("ExcuteDB_err", "ret=%d;err=%s", ret, strErr.c_str()); } //ref == 0 无返回 if (ref == 0) { return 0; } //通知db结果 CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(nBaseappId); if(mb) { #ifdef _WIN32 mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_TABLE_EXCUTE_CALLBACK, ref, ret ); #else CRpcUtil& rpc = GetRpcUtil(); CPluto* u = new CPluto; rpc.Encode(*u, MSGID_BASEAPP_TABLE_EXCUTE_CALLBACK, ref, ret); u->SetMailbox(mb); LogDebug("CDbOper::InsertDB", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); #endif } return 0; }
//根据dbid查找entity int CWorldDbmgr::LookupEntityByDbId(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 4) { return -1; } uint8_t nServerId = VOBJECT_GET_U8((*p)[0]); const char* szEntityName = VOBJECT_GET_STR((*p)[1]); TDBID dbid = VOBJECT_GET_U64((*p)[2]); int32_t ref = VOBJECT_GET_I32((*p)[3]); CPluto* u = new CPluto; string strErr; if(db.LookupEntityByDbId(szEntityName, dbid, ref, *u, strErr) != 0) { delete u; //cout << strErr << endl; LogWarning("LookupEntityByDbId_err", "%s", strErr.c_str()); return -2; } //通知db结果 CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(nServerId); if(mb) { #ifdef _WIN32 mb->RpcCall(*u); #else u->SetMailbox(mb); LogDebug("CWorldDbmgr::LookupEntityByDbId", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); #endif } else { LogWarning("CWorldDbmgr::LookupEntityByDbId", "u.GenLen()=%d", u->GetLen()); delete u; } return 0; }
int CWorldDbmgr::DestroyAccountCache(T_VECTOR_OBJECT* p) { if(p->size() != 2) { LogError("CWorldDbmgr::DestroyAccountCache", "p->size()=%d", p->size()); return -1; } //const CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]); const string& strKey = VOBJECT_GET_SSTR((*p)[0]); const string& strEntityType = VOBJECT_GET_SSTR((*p)[1]); //const int32_t ref = VOBJECT_GET_I32((*p)[3]); //先查找该key相关的entity是否已经创建出来了 SEntityLookup* pLookup = LookupEntityInfo(strKey, strEntityType); if(pLookup != NULL) { //LogDebug("CWorldDbmgr::DestroyAccountCache", "entity exists;strKey=%s;eid=%d;baseapp=%d", strKey.c_str(), pLookup->eid, pLookup->sid); CMailBox* mb = GetServerMailbox(pLookup->sid); if(mb) { CPluto* u = new CPluto; u->Encode(MSGID_BASEAPP_DEL_ACCOUNT_CACHE_CALLBACK); (*u) << pLookup->eid << EndPluto; u->SetMailbox(mb); //LogDebug("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen()); DeleteEntityInfo(strKey, strEntityType); g_pluto_sendlist.PushPluto(u); return 0; } } LogError("CWorldDbmgr::DestroyAccountCache", "pLookup is not exists.strKey = %s, strEntityType = %s ",strKey.c_str(), strEntityType.c_str()); return -1; //DeleteEntityInfo(strKey, strEntityType); //回调 //RpcCall(emb.m_nServerMailboxId, MSGID_BASEAPP_DEL_ACCOUNT_CACHE_CALLBACK, emb); //return 0; }
int CWorldDbmgr::LookupEntityByName(T_VECTOR_OBJECT* p, CDbOper& db) { if(p->size() != 4) { return -1; } uint16_t nBaseappId = VOBJECT_GET_U16((*p)[0]); uint8_t nCreateFlag = VOBJECT_GET_U8((*p)[1]); const char* pszEntityName = VOBJECT_GET_STR((*p)[2]); const char* pszKey = VOBJECT_GET_STR((*p)[3]); const string& strKey(pszKey); //先查找该key相关的entity是否已经创建出来了 SEntityLookup* pLookup = LookupEntityInfo(strKey, pszEntityName); if(pLookup != NULL) { //LogInfo("CWorldDbmgr::LookEntityByName", "entity exists;key=%s;eid=%d;baseapp=%d", \ // pszKey, pLookup->eid, pLookup->sid); CMailBox* mb = GetServerMailbox(pLookup->sid); if(mb) { CPluto* u = new CPluto; u->Encode(MSGID_BASEAPP_ENTITY_MULTILOGIN); (*u) << pLookup->eid << EndPluto; u->SetMailbox(mb); //LogDebug("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); } return 0; } TENTITYID new_eid = MyGetNextEntityId(); CPluto* u = new CPluto; string strErr; if(db.LookupEntityByName(nCreateFlag, pszEntityName, strKey, new_eid, *u, nBaseappId, strErr) != 0) { delete u; //cout << strErr << endl; LogWarning("LookEntityByName_err", "%s", strErr.c_str()); return -2; } //add for lookup CreateNewEntityToLookup(strKey, pszEntityName, new_eid, nBaseappId); //通知db结果 CEpollServer* s = this->GetServer(); CMailBox* mb = s->GetServerMailbox(nBaseappId); if(mb) { #ifdef _WIN32 mb->RpcCall(*u); #else u->SetMailbox(mb); LogDebug("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen()); g_pluto_sendlist.PushPluto(u); #endif } else { LogWarning("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen()); delete u; } return 0; }
int CWorldOther::SdkServerVerify(T_VECTOR_OBJECT* p, CPluto& u) { #if 0 //注释掉老代码 if (p->size() != 4) { return -1; } 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(); if (NULL == pmb) { return -1; } CPluto* duplicate = new CPluto(u.GetBuff(), u.GetMaxLen()); duplicate->SetMailbox(pmb); int ret = threadpool_add_job(g_threadpool, ThreadJob_SdkServerVerify, (void*)(duplicate)); if (ret != 0) { //直接返回服务器繁忙,请稍后再试 //printf("服务器繁忙,请稍后再试!\n"); //std::cout << "服务器繁忙,请稍后再试!" << endl; LogWarning("CWorldOther::SdkServerVerify", "threadpool list is full."); CPluto* u2 = new CPluto; u2->Encode(MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK); (*u2)<< int32_t(-2) << nFd << strAccount << strPlatId << EndPluto; g_pluto_sendlist.PushPluto(u2); //不适合多线程发送 //pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, -2, nFd, strAccount, strPlatId); } return 0; #endif if (p->size() != 4) { return -1; } 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(); pluto_msgid_t msg_id = u.GetMsgId();; string resp = ""; int ret = GetUrl_new(url.c_str(), resp); if (ret != CURLE_OK) { LogWarning("CWorldOther::SdkServerVerify", "%s ret = %d", strAccount.c_str(), ret); //todo:faild. SyncRpcCall(g_pluto_sendlist, SERVER_LOGINAPP, MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId); 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); } SyncRpcCall(g_pluto_sendlist, SERVER_LOGINAPP, MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId); return 0; }