void nsVolume::UpdateMountLock(bool aMountLocked) { MOZ_ASSERT(NS_IsMainThread()); if (aMountLocked == mMountLocked) { return; } // The locked/unlocked state changed. Tell IOThread about it. mMountLocked = aMountLocked; LogState(); XRE_GetIOMessageLoop()->PostTask( FROM_HERE, NewRunnableFunction(Volume::UpdateMountLock, NS_LossyConvertUTF16toASCII(Name()), MountGeneration(), aMountLocked)); }
bool ClassAdLog::TruncLog() { MyString tmp_log_filename; int new_log_fd; FILE *new_log_fp; dprintf(D_ALWAYS,"About to rotate ClassAd log %s\n",logFilename()); if(!SaveHistoricalLogs()) { dprintf(D_ALWAYS,"Skipping log rotation, because saving of historical log failed for %s.\n",logFilename()); return false; } tmp_log_filename.sprintf( "%s.tmp", logFilename()); new_log_fd = safe_open_wrapper_follow(tmp_log_filename.Value(), O_RDWR | O_CREAT | O_LARGEFILE, 0600); if (new_log_fd < 0) { dprintf(D_ALWAYS, "failed to rotate log: safe_open_wrapper(%s) returns %d\n", tmp_log_filename.Value(), new_log_fd); return false; } new_log_fp = fdopen(new_log_fd, "r+"); if (new_log_fp == NULL) { dprintf(D_ALWAYS, "failed to rotate log: fdopen(%s) returns NULL\n", tmp_log_filename.Value()); return false; } // Now it is time to move courageously into the future. historical_sequence_number++; LogState(new_log_fp); fclose(log_fp); log_fp = NULL; fclose(new_log_fp); // avoid sharing violation on move if (rotate_file(tmp_log_filename.Value(), logFilename()) < 0) { dprintf(D_ALWAYS, "failed to rotate job queue log!\n"); // Beat a hasty retreat into the past. historical_sequence_number--; int log_fd = safe_open_wrapper_follow(logFilename(), O_RDWR | O_APPEND | O_LARGEFILE, 0600); if (log_fd < 0) { EXCEPT("failed to reopen log %s, errno = %d after failing to rotate log.",logFilename(),errno); } log_fp = fdopen(log_fd, "a+"); if (log_fp == NULL) { EXCEPT("failed to refdopen log %s, errno = %d after failing to rotate log.",logFilename(),errno); } return false; } int log_fd = safe_open_wrapper_follow(logFilename(), O_RDWR | O_APPEND | O_LARGEFILE, 0600); if (log_fd < 0) { EXCEPT( "failed to open log in append mode: " "safe_open_wrapper(%s) returns %d\n", logFilename(), log_fd); } log_fp = fdopen(log_fd, "a+"); if (log_fp == NULL) { close(log_fd); EXCEPT("failed to fdopen log in append mode: " "fdopen(%s) returns %d\n", logFilename(), log_fd); } return true; }
bool CPlayerManager::ProcessPublicMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nSessionID ) { if ( prealMsg->usMsgType == MSG_PLAYER_LOGIN ) { stMsgOnPlayerLogin* pmsgenter = (stMsgOnPlayerLogin*)prealMsg ; CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer != NULL && pPlayer->GetUserUID() == pmsgenter->nUserUID ) { CLogMgr::SharedLogMgr()->ErrorLog("double nSession, this nSessionID already have player, already login , do not login again ? ") ; return true ; } if ( pPlayer != NULL && pPlayer->GetUserUID() != pmsgenter->nUserUID ) // switch account in main scene { // disconnect pre player OnPlayerOffline(pPlayer); } if ( ProcessIsAlreadyLogin(pmsgenter->nUserUID,nSessionID) ) { return true ; } // is offline peer MAP_UID_PLAYERS::iterator iterOfflien = m_vOfflinePlayers.begin(); for ( ; iterOfflien != m_vOfflinePlayers.end(); ++iterOfflien ) { if ( iterOfflien->second && iterOfflien->first == pmsgenter->nUserUID ) { iterOfflien->second->OnReactive(nSessionID) ; AddPlayer(iterOfflien->second) ; m_vOfflinePlayers.erase(iterOfflien) ; return true ; } } CPlayer* pNew = new CPlayer ; pNew->Init(pmsgenter->nUserUID,nSessionID ) ; AddPlayer(pNew) ; return true ; } // process player logout ; if ( MSG_DISCONNECT_CLIENT == prealMsg->usMsgType ) { CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer ) { // post online event ; OnPlayerOffline(pPlayer) ; } else { CLogMgr::SharedLogMgr()->ErrorLog("client disconnect ! client is NULL session id = %d",nSessionID) ; } //#ifdef _DEBUG LogState(); //#endif return true ; } if ( ProcessTaxasServerMsg(prealMsg,eSenderPort,nSessionID) ) { return true ; } return false ; }
bool CPlayerManager::ProcessPublicMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nSessionID ) { switch ( prealMsg->usMsgType ) { case MSG_CROSS_SERVER_REQUEST: { stMsgCrossServerRequest* pRet = (stMsgCrossServerRequest*)prealMsg ; Json::Value* pJsValue = nullptr ; Json::Value rootValue ; if ( pRet->nJsonsLen ) { Json::Reader reader; char* pstr = ((char*)&pRet->nJsonsLen) + sizeof(pRet->nJsonsLen) ; reader.parse(pstr,pstr + pRet->nJsonsLen,rootValue,false); pJsValue = &rootValue ; } if ( onCrossServerRequest(pRet,eSenderPort,pJsValue) == false ) { CPlayer* pPlayer = GetPlayerByUserUID(pRet->nTargetID); assert(pPlayer&&"this request no one to process or target id error"); if ( pPlayer && pPlayer->onCrossServerRequest(pRet,eSenderPort,pJsValue) ) { return true ; } CLogMgr::SharedLogMgr()->ErrorLog("cross request type = %d , subType = %d ,unprocessed",pRet->nRequestType,pRet->nRequestSubType); return false; } return true ; } break; case MSG_CROSS_SERVER_REQUEST_RET: { stMsgCrossServerRequestRet* pRet = (stMsgCrossServerRequestRet*)prealMsg ; Json::Value* pJsValue = nullptr ; Json::Value rootValue ; if ( pRet->nJsonsLen ) { Json::Reader reader; char* pstr = ((char*)&pRet->nJsonsLen) + sizeof(pRet->nJsonsLen) ; reader.parse(pstr,pstr + pRet->nJsonsLen,rootValue,false); pJsValue = &rootValue ; } if ( onCrossServerRequestRet(pRet,pJsValue) == false ) { CPlayer* pPlayer = GetPlayerByUserUID(pRet->nTargetID); assert(pPlayer&&"this request no one to process or target id error"); if ( pPlayer && pPlayer->onCrossServerRequestRet(pRet,pJsValue) ) { return true ; } CLogMgr::SharedLogMgr()->ErrorLog("cross request result type = %d , subType = %d ,unprocessed",pRet->nRequestType,pRet->nRequestSubType); return false; } return true ; } break; case MSG_REQUEST_PLAYER_DATA: { stMsgRequestPlayerData* pRet = (stMsgRequestPlayerData*)prealMsg ; stMsgRequestPlayerDataRet msgBack ; msgBack.nRet = 0 ; msgBack.isDetail = pRet->isDetail ; CPlayer* pPlayer = GetPlayerByUserUID(pRet->nPlayerUID); stPlayerDetailDataClient stData ; stData.nCurrentRoomID = 0 ; CAutoBuffer auB (sizeof(msgBack) + sizeof(stPlayerDetailData)); if ( pPlayer ) { CPlayerTaxas* pTaxasData = (CPlayerTaxas*)pPlayer->GetComponent(ePlayerComponent_PlayerTaxas); stData.nCurrentRoomID = pTaxasData->getCurRoomID() ; if ( stData.nCurrentRoomID ) // select take in { stMsgCrossServerRequest msgReq ; msgReq.nJsonsLen = 0 ; msgReq.nReqOrigID = nSessionID ; msgReq.nRequestSubType = eCrossSvrReqSub_SelectPlayerData ; msgReq.nRequestType = eCrossSvrReq_SelectTakeIn ; msgReq.nTargetID = stData.nCurrentRoomID ; msgReq.cSysIdentifer = ID_MSG_PORT_TAXAS ; msgReq.vArg[0] = pRet->nPlayerUID; msgReq.vArg[1] = pRet->isDetail ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,(char*)&msgReq,sizeof(msgReq)) ; CLogMgr::SharedLogMgr()->PrintLog("select take in for player detail") ; return true ; } if ( pRet->isDetail ) { pPlayer->GetBaseData()->GetPlayerDetailData(&stData); pTaxasData->getTaxasData(&stData.tTaxasData); } else { pPlayer->GetBaseData()->GetPlayerBrifData(&stData) ; } auB.addContent(&msgBack,sizeof(msgBack)); auB.addContent(&stData,pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ) ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,auB.getBufferPtr(),auB.getContentSize()) ; return true ; } if ( m_tPlayerDataCaher.getPlayerData(pRet->nPlayerUID,&stData,pRet->isDetail) ) { auB.addContent(&msgBack,sizeof(msgBack)); auB.addContent(&stData,pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ) ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,auB.getBufferPtr(),auB.getContentSize()) ; CLogMgr::SharedLogMgr()->PrintLog("get player data from cahe") ; return true ; } CLogMgr::SharedLogMgr()->PrintLog("req detail player not online , req from db target uid = %u",pRet->nPlayerUID) ; stMsgSelectPlayerData msgReq ; msgReq.isDetail = pRet->isDetail ; msgReq.nReqPlayerSessionID = nSessionID ; msgReq.nTargetPlayerUID = pRet->nPlayerUID ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,(char*)&msgReq,sizeof(msgReq)) ; } break; case MSG_SELECT_DB_PLAYER_DATA: { stMsgSelectPlayerDataRet* pRet = (stMsgSelectPlayerDataRet*)prealMsg ; stMsgRequestPlayerDataRet msgBack ; msgBack.nRet = pRet->nRet ; msgBack.isDetail = pRet->isDetail ; if ( pRet->nRet ) { CGameServerApp::SharedGameServerApp()->sendMsg(pRet->nReqPlayerSessionID,(char*)&msgBack,sizeof(msgBack)) ; } else { m_tPlayerDataCaher.cachePlayerData(pRet); CAutoBuffer auB (sizeof(msgBack) + sizeof(stPlayerDetailDataClient)); auB.addContent(&msgBack,sizeof(msgBack)); uint16_t nLen = pRet->isDetail ? sizeof(stPlayerDetailDataClient) : sizeof(stPlayerBrifData) ; auB.addContent((char*)prealMsg + sizeof(stMsgSelectPlayerDataRet),nLen ); CGameServerApp::SharedGameServerApp()->sendMsg(pRet->nReqPlayerSessionID,auB.getBufferPtr(),auB.getContentSize()) ; } CLogMgr::SharedLogMgr()->PrintLog("session id = %d req play data ret = %d",pRet->nReqPlayerSessionID,pRet->nRet ) ; } break; case MSG_PLAYER_LOGIN: { stMsgOnPlayerLogin* pmsgenter = (stMsgOnPlayerLogin*)prealMsg ; CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer != NULL && pPlayer->GetUserUID() == pmsgenter->nUserUID ) { CLogMgr::SharedLogMgr()->ErrorLog("double nSession, this nSessionID already have player, already login , do not login again id = %d? ",nSessionID) ; return true ; } if ( pPlayer != NULL && pPlayer->GetUserUID() != pmsgenter->nUserUID ) // switch account in main scene { // disconnect pre player OnPlayerOffline(pPlayer); } if ( ProcessIsAlreadyLogin(pmsgenter->nUserUID,nSessionID) ) { return true ; } // is offline peer MAP_UID_PLAYERS::iterator iterOfflien = m_vOfflinePlayers.begin(); for ( ; iterOfflien != m_vOfflinePlayers.end(); ++iterOfflien ) { if ( iterOfflien->second && iterOfflien->first == pmsgenter->nUserUID ) { iterOfflien->second->OnReactive(nSessionID) ; AddPlayer(iterOfflien->second) ; m_vOfflinePlayers.erase(iterOfflien) ; return true ; } } CPlayer* pNew = new CPlayer ; pNew->Init(pmsgenter->nUserUID,nSessionID ) ; AddPlayer(pNew) ; } break; case MSG_DISCONNECT_CLIENT: case MSG_PLAYER_LOGOUT: { CPlayer* pPlayer = GetPlayerBySessionID(nSessionID) ; if ( pPlayer ) { // post online event ; CLogMgr::SharedLogMgr()->PrintLog("player disconnect session id = %d",nSessionID); OnPlayerOffline(pPlayer) ; } else { CLogMgr::SharedLogMgr()->ErrorLog("client disconnect ! client is NULL session id = %d",nSessionID) ; } //#ifdef _DEBUG LogState(); //#endif } break; case MSG_TP_ORDER_LEAVE: { stMsgOrderTaxasPlayerLeaveRet* pRet = (stMsgOrderTaxasPlayerLeaveRet*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not inform leave",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; case MSG_TP_INFORM_LEAVE: { stMsgInformTaxasPlayerLeave* pRet = (stMsgInformTaxasPlayerLeave*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not inform leave",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; case MSG_TP_SYNC_PLAYER_DATA: { stMsgSyncTaxasPlayerData* pRet = (stMsgSyncTaxasPlayerData*)prealMsg ; CPlayer* pp = GetPlayerByUserUID(pRet->nUserUID) ; if (!pp) { CLogMgr::SharedLogMgr()->ErrorLog("uid = %d not find , so can not sys data",pRet->nUserUID); } else { pp->OnMessage(prealMsg,eSenderPort); } } break; default: return false; } return true ; }