void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive) { sortGroup (state, keepGroupsAtStart, getUndoManager()); if (recursive) for (int i = getNumChildren(); --i >= 0;) getChild(i).sortAlphabetically (keepGroupsAtStart, true); }
static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart) { if (state.getNumChildren() == 0) return false; if (state.getNumChildren() == 1) return true; ValueTree stateCopy (state.createCopy()); sortGroup (stateCopy, keepGroupsAtStart, nullptr); return stateCopy.isEquivalentTo (state); }
bool CGroup::onMsg(Json::Value& prealMsg ,uint16_t nMsgType, eMsgPort eSenderPort , uint32_t nSessionID) { if ( IGlobalModule::onMsg(prealMsg,nMsgType,eSenderPort,nSessionID) ) { return true ; } switch ( nMsgType ) { case MSG_CREATE_CLUB: { auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( pPlayer == nullptr ) { LOGFMTE("session id = %u , player is null , can not create club",nSessionID) ; return true ; } uint16_t nOwnClubCnt = getClubCntByUserUID(pPlayer->GetUserUID()); uint16_t nMaxCanCreate = pPlayer->GetBaseData()->getMaxCanCreateClubCount() ; Json::Value jsMsgBack ; jsMsgBack["newClubID"] = prealMsg["newClubID"].asUInt() ; if ( nOwnClubCnt >= nMaxCanCreate ) { jsMsgBack["ret"] = 1 ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,jsMsgBack,nMsgType) ; return true ; } jsMsgBack["ret"] = 0 ; stGroupItem* pItem = new stGroupItem() ; pItem->nCityCode = prealMsg["cityCode"].asUInt() ; pItem->nCreaterUID = pPlayer->GetUserUID() ; pItem->nGroupID = prealMsg["newClubID"].asUInt() ; pItem->addMember(pPlayer->GetUserUID()); addGroup(pItem) ; LOGFMTD("player uid = %u create new club id = %u city code = %u",pPlayer->GetUserUID(),pItem->nGroupID,pItem->nCityCode) ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,jsMsgBack,nMsgType) ; } break ; case MSG_DISMISS_CLUB: { uint32_t nClubID = prealMsg["clubID"].asUInt() ; auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; auto pClub = getGroupByID(nClubID) ; Json::Value jsMsgBack ; jsMsgBack["ret"] = 0 ; if ( pClub == nullptr || pClub->nCreaterUID != pPlayer->GetUserUID() ) { jsMsgBack["ret"] = 1 ; CGameServerApp::SharedGameServerApp()->sendMsg( nSessionID,jsMsgBack,nMsgType) ; return true ; } if ( pClub->isRoomKeepRunning() ) { jsMsgBack["ret"] = 2 ; CGameServerApp::SharedGameServerApp()->sendMsg(nSessionID,jsMsgBack,nMsgType) ; return true ; } dismissGroup(nClubID) ; CGameServerApp::SharedGameServerApp()->sendMsg( nSessionID,jsMsgBack,nMsgType) ; LOGFMTD("player uid = %u dismiss club id = %u",pPlayer->GetUserUID(),nClubID) ; } break ; case MSG_REQ_PLAYER_JOINED_CLUBS: { uint32_t nReqUID = prealMsg["uid"].asUInt() ; Json::Value jsJoinedClubs ; for ( auto vclub : m_vGroups ) { if ( vclub.second->isHaveMember(nReqUID) ) { jsJoinedClubs[jsJoinedClubs.size()] = vclub.second->nGroupID ; } } prealMsg["clubIDs"] = jsJoinedClubs ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; } break; case MSG_REQ_CLUB_ROOM: { Json::Value jsMsgBack; jsMsgBack["ret"] = 0 ; auto pg = getGroupByID(prealMsg["clubID"].asUInt()) ; if ( pg == nullptr ) { jsMsgBack["ret"] = 1 ; getSvrApp()->sendMsg(nSessionID,jsMsgBack,MSG_REQ_CLUB_ROOM) ; break ; } Json::Value jsRoomIDs ; auto pgameCenter = CGameServerApp::SharedGameServerApp()->getGameRoomCenter() ; std::vector<uint32_t> vAllRoomIDs ; pgameCenter->getClubOwnRooms(vAllRoomIDs,pg->nGroupID) ; for ( auto rid : vAllRoomIDs ) { jsRoomIDs[jsRoomIDs.size()] = rid ; } jsMsgBack["rooms"] = jsRoomIDs ; getSvrApp()->sendMsg(nSessionID,jsMsgBack,MSG_REQ_CLUB_ROOM) ; } break; case MSG_REQ_CLUB_INFO: { uint32_t nGroupID = prealMsg["groupID"].asUInt() ; auto pGroup = getGroupByID(nGroupID) ; if ( !pGroup ) { prealMsg["ret"] = 1 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } prealMsg["ret"] = 0 ; prealMsg["curCnt"] = pGroup->getMemberCnt() ; prealMsg["capacity"] = pGroup->getCapacity(); prealMsg["level"] = pGroup->nLevel ; prealMsg["deadTime"] = pGroup->m_tLevelRunOutTime ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; } break; case MSG_CLUB_DELETE_MEMBER: { uint32_t nGroupID = prealMsg["groupID"].asUInt(); uint32_t nAccountUID = prealMsg["userAccount"].asUInt() ; auto pClub = getGroupByID(nGroupID) ; prealMsg["ret"] = 0 ; if ( pClub == nullptr ) { prealMsg["ret"] = 1 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } if ( pClub->isHaveMember(nAccountUID) == false ) { prealMsg["ret"] = 2 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break; } auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( !pPlayer || ( pPlayer->GetUserUID() != nAccountUID && pPlayer->GetUserUID() != pClub->getOwnerUID() )) { prealMsg["ret"] = 3 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break; } // do add member /*Json::Value cValue ;*/ // cValue["email"] = "*****@*****.**" ; // cValue["devpwd"] = "bill007" ; //#ifndef ONLINE_APP_KEY // cValue["appkey"] = "e87f31bb-e86c-4d87-a3f3-57b3da76b3d6"; //#else // cValue["appkey"] = "abffee4b-deea-4e96-ac8d-b9d58f246c3f" ; //#endif // DEBUG //cValue["appkey"] = "abffee4b-deea-4e96-ac8d-b9d58f246c3f" ; //cValue["group_id"] = std::to_string(nGroupID); //cValue["user_account"] = std::to_string(nAccountUID); //Json::StyledWriter sWrite ; //std::string str = sWrite.write(cValue); auto pQinJia = CGameServerApp::SharedGameServerApp()->getQinjiaModule(); Json::Value cValue ; cValue["group_id"] = std::to_string(nGroupID); cValue["user_account"] = std::to_string(nAccountUID); Json::Value jUserData ; jUserData["clubID"] = nGroupID ; jUserData["delUID"] = nAccountUID ; jUserData["actSID"] = nSessionID; pQinJia->sendQinJiaRequest("DelGroupMember",cValue,[this](Json::Value& jsResult, Json::Value& jsUserData){ auto nClubID = jsUserData["clubID"].asUInt(); uint32_t nUID = jsUserData["delUID"].asUInt() ; auto nSessionID = jsUserData["actSID"].asUInt(); Json::Value jsmsgBack ; jsmsgBack["groupID"] = nClubID ; jsmsgBack["userAccount"] = nUID ; jsmsgBack["ret"] = 0 ; auto nActUID = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID)->GetUserUID() ; if ( jsResult.isNull() ) { LOGFMTE("del member club gotype request result is null , uid = %u ,clubID = %u", nUID,nClubID) ; return ; } if ( jsResult["errcode"].asUInt() != 200 ) { LOGFMTE("del member club gotype request failed error code = %u,uid = %u ,clubID = %u", jsResult["errcode"].asUInt(), nUID,nClubID) ; return ; } auto pClub = getGroupByID(nClubID); pClub->removeMember(nUID); if ( nActUID != nUID ) { CPlayerMailComponent::PostDlgNotice(eNotice_BeRemoveFromClub,jsUserData,nUID ) ; } LOGFMTD("del club = %u member ok uid = %u ",nClubID,nUID) ; m_isSortDirty = true ; getSvrApp()->sendMsg(nSessionID,jsmsgBack,MSG_CLUB_DELETE_MEMBER) ; },jUserData) ; //if ( nMsgType == MSG_CLUB_ADD_MEMBER ) //{ // //if ( pClub->isGroupFull() ) // //{ // // prealMsg["ret"] = 3 ; // // getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; // // LOGFMTD("group is full") ; // // break ; // //} // //if ( pClub->isHaveMember(nAccountUID) ) // //{ // // prealMsg["ret"] = 4 ; // // getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; // // LOGFMTD("already in group ") ; // // break ; // //} // //stClubMemberChangeReqArg* pArg = new stClubMemberChangeReqArg ; // //pArg->nMsgType = nMsgType ; // //pArg->nTargetUID = nAccountUID; // //pArg->pOwenClub = pClub ; // //m_pGoTyeAPI.performRequest("AddGroupMember",str.c_str(),str.size(),pArg,eReq_AddMember ); // //LOGFMTD("add member accountUid = %u",nAccountUID) ; //} //else //{ // stClubMemberChangeReqArg* pArg = new stClubMemberChangeReqArg ; // pArg->nMsgType = nMsgType ; // pArg->nTargetUID = nAccountUID; // pArg->pOwenClub = pClub ; // m_pGoTyeAPI.performRequest("DelGroupMember",str.c_str(),str.size(),pArg,eReq_DeleteMember ); // LOGFMTD("delete member accountUid = %u",nAccountUID) ; //} } break ; case MSG_REQ_LEVEL_UP_CLUB: { static uint32_t vLevelPriceDiamon[] = { 15,30,3000,4500,7200 } ; uint32_t nclubID = prealMsg["clubID"].asUInt(); uint32_t nLevel = prealMsg["level"].asUInt() ; auto pClub = getGroupByID(nclubID) ; if ( !pClub ) { prealMsg["ret"] = 1 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } pClub->getCapacity() ; // update the level and time; uint16_t nTargetLevel = prealMsg["level"].asUInt() ; if ( nTargetLevel == 0 || nTargetLevel < pClub->nLevel ) { prealMsg["ret"] = 4 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } if ( nTargetLevel > sizeof(vLevelPriceDiamon) / sizeof(uint32_t) ) { prealMsg["ret"] = 3 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } uint32_t nDiamondPrice = vLevelPriceDiamon[nTargetLevel-1] ; auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( !pPlayer ) { prealMsg["ret"] = 3 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; LOGFMTE("session id = %u not online , so can not do this operate") ; break ; } if ( pPlayer->GetBaseData()->GetAllDiamoned() < nDiamondPrice ) { prealMsg["ret"] = 2 ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; break ; } pPlayer->GetBaseData()->decressMoney(nDiamondPrice,true) ; uint32_t nAddDuiringTime = 15 * 24 * 60 * 60; if ( pClub->nLevel == nTargetLevel ) { pClub->m_tLevelRunOutTime += nAddDuiringTime; } else { pClub->m_tLevelRunOutTime = (uint32_t)time(nullptr) + nAddDuiringTime ; } pClub->nLevel = nTargetLevel ; pClub->isDirty = true ; prealMsg["ret"] = 0 ; prealMsg["deadTime"] = pClub->m_tLevelRunOutTime ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; m_isSortDirty = true ; break ; } break ; case MSG_REQ_RECORMED_CLUB: { sortGroup(); Json::Value jsArray ; auto iter = m_vSortedGroups.begin(); for ( ; iter != m_vSortedGroups.end() ; ++iter ) { jsArray[jsArray.size()] = (*iter)->nGroupID; if ( jsArray.size() >= 10 ) { break; } } prealMsg["clubIDs"] = jsArray ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType) ; } break ; case MSG_REQ_CLUB_MEMBER: { uint32_t nClubID = prealMsg["clubID"].asUInt(); uint32_t nPageIdx = prealMsg["pageIdx"].asUInt() ; auto pGroup = getGroupByID(nClubID) ; Json::Value jsMembers ; prealMsg["ret"] = 0 ; do { if ( pGroup == nullptr ) { prealMsg["ret"] = 1 ; break; } uint32_t nSkipCnt = CNT_PER_PAGE * nPageIdx ; if (nSkipCnt >= pGroup->getMemberCnt() ) { break; } for ( auto& ref : pGroup->vMembers ) { if ( nSkipCnt > 0 ) { --nSkipCnt; continue; } jsMembers[jsMembers.size()] = ref ; if ( jsMembers.size() >= CNT_PER_PAGE ) { break; } } } while (0); prealMsg["members"] = jsMembers ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType); } break ; case MSG_REQ_CITY_CLUB: { sortGroup() ; uint32_t nCityCode = prealMsg["cityCode"].asUInt(); uint32_t nPageIdx = prealMsg["pageIdx"].asUInt() ; uint32_t nSkipCnt = CNT_PER_PAGE * nPageIdx ; Json::Value jsClubs ; if ( nSkipCnt >= m_vSortedGroups.size() ) { prealMsg["clubs"] = jsClubs ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType); break ; } for ( auto& pClub : m_vSortedGroups ) { if ( pClub->nCityCode != nCityCode ) { continue; } if ( nSkipCnt > 0 ) { --nSkipCnt; continue; } jsClubs[jsClubs.size()] = pClub->nGroupID ; if ( jsClubs.size() >= CNT_PER_PAGE ) { break; } } prealMsg["clubs"] = jsClubs ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType); } break; case MSG_CLUB_APPLY_TO_JOIN: { uint32_t nClubID = prealMsg["clubID"].asUInt() ; auto text = prealMsg["text"]; auto pClub = getGroupByID(nClubID); uint8_t nRet = 0 ; do { if ( pClub == nullptr ) { nRet = 1 ; break; } if ( pClub->isGroupFull() ) { nRet = 2 ; break; } auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID); if ( !pPlayer ) { nRet = 3 ; break; } if ( pClub->isHaveMember(pPlayer->GetUserUID()) ) { nRet = 4 ; break; } Json::Value jArg ; jArg["applicantUID"] = pPlayer->GetUserUID() ; jArg["clubID"] = nClubID ; jArg["text"] = text ; CPlayerMailComponent::PostDlgNotice(eNotice_RecivedApplyToJoinClub,jArg,pClub->getOwnerUID() ) ; auto ppOwner = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pClub->getOwnerUID()) ; if ( !ppOwner ) { // send push notification ; CSendPushNotification::getInstance()->reset(); CSendPushNotification::getInstance()->addTarget(pClub->getOwnerUID()) ; CSendPushNotification::getInstance()->setContent(CServerStringTable::getInstance()->getStringByID(2),1) ; CSendPushNotification::getInstance()->postApns(CGameServerApp::SharedGameServerApp()->getAsynReqQueue(),false,"apply") ; } } while (false); prealMsg["ret"] = nRet ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType); } break; case MSG_CLUB_REPLY_APPLY_TO_JOIN: { uint32_t nClubID = prealMsg["clubID"].asUInt(); uint32_t nApplyerUID = prealMsg["applicantUID"].asUInt() ; uint8_t nIsAgree = prealMsg["isAgree"].asUInt(); auto text = prealMsg["text"]; uint8_t nRet = 0 ; do { // check add if ( !nIsAgree ) // do agree { Json::Value jArg ; jArg["isAgree"] = nIsAgree ; jArg["clubID"] = nClubID ; jArg["text"] = text ; CPlayerMailComponent::PostDlgNotice(eNotice_RecivedReplyForApplyForJoinClub,jArg,nApplyerUID ) ; break; } auto pGroup = getGroupByID(nClubID) ; if ( !pGroup ) { nRet = 2 ; break; } if ( pGroup->isGroupFull() ) { nRet = 1 ; break ; } auto pp = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( pp == nullptr || pGroup->getOwnerUID() != pp->GetUserUID() ) { nRet = 3 ; break; } if ( pGroup->isHaveMember(nApplyerUID) ) { nRet = 4 ; break; } // do add auto pQinJia = CGameServerApp::SharedGameServerApp()->getQinjiaModule(); Json::Value cValue ; cValue["group_id"] = std::to_string(nClubID); cValue["user_account"] = std::to_string(nApplyerUID); Json::Value jUserData ; jUserData["isAgree"] = nIsAgree ; jUserData["clubID"] = nClubID ; jUserData["text"] = text ; jUserData["addUID"] = nApplyerUID ; pQinJia->sendQinJiaRequest("AddGroupMember",cValue,[this](Json::Value& jsResult, Json::Value& jsUserData){ auto nClubID = jsUserData["clubID"].asUInt(); uint32_t nUID = jsUserData["addUID"].asUInt() ; if ( jsResult.isNull() ) { LOGFMTE("add member club gotype request result is null , uid = %u ,clubID = %u", nUID,nClubID) ; return ; } if ( jsResult["errcode"].asUInt() != 200 ) { LOGFMTE("add member club gotype request failed error code = %u,uid = %u ,clubID = %u", jsResult["errcode"].asUInt(), nUID,nClubID) ; return ; } auto pClub = getGroupByID(nClubID); pClub->addMember(nUID); m_isSortDirty = true ; CPlayerMailComponent::PostDlgNotice(eNotice_RecivedReplyForApplyForJoinClub,jsUserData,nUID ) ; LOGFMTD("add club member ok uid = %u ",nUID) ; auto ppApplyer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(nUID) ; if ( !ppApplyer ) { // send push notification ; CSendPushNotification::getInstance()->reset(); CSendPushNotification::getInstance()->addTarget(nUID) ; CSendPushNotification::getInstance()->setContent(CServerStringTable::getInstance()->getStringByID(1),1) ; CSendPushNotification::getInstance()->postApns(CGameServerApp::SharedGameServerApp()->getAsynReqQueue(),false,"reply Apply") ; } },jUserData) ; } while (false); prealMsg["ret"] = nRet ; getSvrApp()->sendMsg(nSessionID,prealMsg,nMsgType); } break ; case MSG_CLUB_UPDATE_NAME: { auto nClubID = prealMsg["clubID"].asUInt() ; auto pName = prealMsg["newName"].asCString() ; auto pClub = getGroupByID(nClubID) ; auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( !pPlayer ) { LOGFMTE("player session = %u , is null can not update club name",nSessionID) ; break ; } if ( pClub == nullptr ) { LOGFMTE("club is null how to update name player uid = %u ",pPlayer->GetUserUID() ) ; break ; } if ( pClub->getOwnerUID() != pPlayer->GetUserUID() ) { LOGFMTE("player uid = %u , is not club id = %u , owner ,so can not update club name",pPlayer->GetUserUID(),nClubID); break ; } pClub->setName(pName); LOGFMTD("club id = %u update name to new = %s", nClubID,pName); } break; case MSG_CLUB_CHAT_MESSAGE: { auto nClubID = prealMsg["clubID"].asUInt() ; auto nType = prealMsg["type"].asUInt() ; auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( !pPlayer ) { LOGFMTE("player session id = %u not online , why chat msg",nSessionID ) ; break; } auto pClub = getGroupByID( nClubID ); if ( !pClub ) { LOGFMTE("club is not exist how can speak id = %u",nClubID ) ; break; } if ( !pClub->isHaveMember(pPlayer->GetUserUID() ) ) { LOGFMTE("uid id = %u not in club id = %u , can not chat",pPlayer->GetUserUID(),nClubID) ; break; } const char* pContent = CServerStringTable::getInstance()->getStringByID(9) ; //if ( nType == 0 ) //{ // pContent = "Text Message"; //} //else if ( 1 == nType ) //{ // pContent = "Voice Message"; //} auto pAsync = getSvrApp()->getAsynReqQueue(); Json::Value jsTarget ; jsTarget[0u] = nClubID ; Json::Value jsapns ; jsapns["apnsType"] = 0; jsapns["targets"] = jsTarget ; std::string strContent = pClub->getName() ; strContent.append(":["); strContent += pContent ; strContent.append("]"); jsapns["content"] = strContent ; jsapns["msgID"] = "clubChat"; jsapns["msgdesc"] = std::to_string(nClubID) ; pAsync->pushAsyncRequest(ID_MSG_PORT_VERIFY,eAsync_Apns,jsapns); LOGFMTD("apns club id = %u chat msg = %s",nClubID , pContent) ; } break; default: return false ; } return true ; }
void Project::Item::sortAlphabetically (bool keepGroupsAtStart) { sortGroup (state, keepGroupsAtStart, getUndoManager()); }