void CPlayer::OnPlayerDisconnect() { m_nDisconnectTime = time(NULL) ; // inform components; for ( int i = ePlayerComponent_None; i < ePlayerComponent_Max ; ++i ) { IPlayerComponent* p = m_vAllComponents[i] ; if ( p ) { p->OnPlayerDisconnect(); } } OnTimerSave(nullptr,0); m_tTimerSave.canncel() ; SetState(ePlayerState_Offline) ; LOGFMTE("player disconnect should inform other sever"); // save log stMsgSaveLog msgLog ; memset(msgLog.vArg,0,sizeof(msgLog.vArg)); msgLog.nJsonExtnerLen = 0 ; msgLog.nLogType = eLog_PlayerLogOut ; msgLog.nTargetID = GetUserUID() ; memset(msgLog.vArg,0,sizeof(msgLog.vArg)); msgLog.vArg[0] = GetBaseData()->getCoin() ; msgLog.vArg[1] = GetBaseData()->GetAllDiamoned(); SendMsgToClient((char*)&msgLog,sizeof(msgLog)); }
bool CPlayer::ProcessPublicPlayerMsg(stMsg* pMsg , eMsgPort eSenderPort) { switch ( pMsg->usMsgType ) { // case MSG_ROBOT_INFORM_IDLE: // { // CRobotManager::SharedRobotMgr()->AddIdleRobotPlayer(this) ; // } // break; case MSG_CLIENT_NET_STATE: { stMsgSyncClientNetState* pRet = (stMsgSyncClientNetState*)pMsg ; if ( 0 == pRet->nState ) { SetState(ePlayerState_WaitReconnect); } else { SetState(ePlayerState_Online) ; for ( int i = ePlayerComponent_None; i < ePlayerComponent_Max ; ++i ) { IPlayerComponent* p = m_vAllComponents[i] ; if ( p ) { p->onPlayerReconnected(); } } } } break ; case MSG_ADD_MONEY: { stMsgRobotAddMoney* pAdd = (stMsgRobotAddMoney*)pMsg ; GetBaseData()->AddMoney(pAdd->nWantCoin); stMsgRobotAddMoneyRet msgBack ; msgBack.cRet = 0 ; msgBack.nFinalCoin = GetBaseData()->GetAllCoin(); SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // save log stMsgSaveLog msgLog ; memset(msgLog.vArg,0,sizeof(msgLog.vArg)); msgLog.nJsonExtnerLen = 0 ; msgLog.nLogType = eLog_RobotAddCoin ; msgLog.nTargetID = GetUserUID() ; memset(msgLog.vArg,0,sizeof(msgLog.vArg)); msgLog.vArg[0] = pAdd->nWantCoin ; SendMsgToClient((char*)&msgLog,sizeof(msgLog)); } break; // case MSG_REQUEST_RANK: // { // stMsgPlayerRequestRank* pMsgRet = (stMsgPlayerRequestRank*)pMsg ; // CGameServerApp::SharedGameServerApp()->GetGameRanker()->SendRankToPlayer(this,(eRankType)pMsgRet->nRankType,pMsgRet->nFromIdx,pMsgRet->nCount ) ; // } // break; // case MSG_REQUEST_RANK_PEER_DETAIL: // { // stMsgPlayerRequestRankPeerDetail* pRetMsg = (stMsgPlayerRequestRankPeerDetail*)pMsg ; // CGameServerApp::SharedGameServerApp()->GetGameRanker()->SendRankDetailToPlayer(this,pRetMsg->nRankPeerUID,(eRankType)pRetMsg->nRankType); // } // break; // case MSG_PLAYER_SAY_BROCAST: // { // stMsgPlayerSayBrocast* pMsgRet = (stMsgPlayerSayBrocast*)pMsg ; // CPlayerItemComponent* pItemMgr = (CPlayerItemComponent*)GetComponent(ePlayerComponent_PlayerItemMgr); // stMsgPlayerSayBrocastRet msg ; // msg.nRet = 0 ; // if ( pItemMgr->OnUserItem(ITEM_ID_LA_BA) ) // { // CGameServerApp::SharedGameServerApp()->GetBrocaster()->PostPlayerSayMsg(this,((char*)pMsg) + sizeof(stMsgPlayerSayBrocast),pMsgRet->nContentLen) ; // } // else // { // msg.nRet = 1 ; // LOGFMTE(" you have no la ba") ; // } // SendMsgToClient((char*)&msg,sizeof(msg)) ; // } // break; // case MSG_PLAYER_REPLAY_BE_INVITED: // { // //stMsgPlayerRecievedInviteReply toMsgInviter; // who invite me ; // stMsgPlayerReplayBeInvitedToJoinRoom* pMsgRet = (stMsgPlayerReplayBeInvitedToJoinRoom*)pMsg ; // //toMsgInviter.nRet = 0 ; // stMsgPlayerReplayBeInvitedToJoinRoomRet msgBack ; // if ( pMsgRet->nReplyResult == 1 ) // refused // { // //toMsgInviter.nRet = 1 ; // msgBack.nRet = 0 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break; // } // else // i agreed ; // { // msgBack.nRet = 0 ; // CTaxasPokerPeer* pThisPeer = (CTaxasPokerPeer*)GetComponent(ePlayerComponent_RoomPeerTaxasPoker); // CRoomTexasPoker* pRoomToEnter = (CRoomTexasPoker*)CGameServerApp::SharedGameServerApp()->GetRoomMgr()->GetRoom(pMsgRet->nRoomType,pMsgRet->nRoomLevel,pMsgRet->nRoomID) ; // if ( !pRoomToEnter || pRoomToEnter->CanPeerSitDown(pThisPeer) == false ) // { // //toMsgInviter.nRet = 4 ; // msgBack.nRet = 2 ; // } // else // { // // join room ; // pThisPeer->LeaveRoom(); // if ( pRoomToEnter->AddBeInvitedPlayer(this,pMsgRet->nSitIdx) == false ) // { // //toMsgInviter.nRet = 3 ; // msgBack.nRet = 3 ; // } // } // // if ( msgBack.nRet != 0 ) // only failed , tell client , when success , directly enter room ; // { // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // } // } // //CPlayer* pToInvid = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nReplyToUserUID) ; // //if ( pToInvid && toMsgInviter.nRet != 0 ) // only failed situation ,tell inviter ; // //{ // // memcpy(toMsgInviter.nReplyerName,GetBaseData()->GetPlayerName(),MAX_LEN_CHARACTER_NAME); // // pToInvid->SendMsgToClient((char*)&toMsgInviter,sizeof(toMsgInviter)) ; // //} // //else // //{ // // LOGFMTD("the one who invite me had offline , his uid = %d",pMsgRet->nReplyToUserUID) ; // //} // } // break; // case MSG_PLAYER_FOLLOW_TO_ROOM: // { // stMsgPlayerFollowToRoom* pRetMsg = (stMsgPlayerFollowToRoom*)pMsg ; // CPlayer* pTargetPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pRetMsg->nTargetPlayerUID) ; // stMsgPlayerFollowToRoomRet msgBack ; // msgBack.nRet = 0 ; // if ( pTargetPlayer == NULL ) // { // msgBack.nRet = 1 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break ; // } // // if ( ePlayerState_Free == pTargetPlayer->GetState() ) // { // msgBack.nRet = 2 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break ; // } // // if ( ePlayerState_Free != GetState() ) // { // msgBack.nRet = 4 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break ; // } // // CRoomBaseNew* pStateRoom = pTargetPlayer->GetRoomCurStateIn() ; // if ( !pStateRoom ) // { // LOGFMTE("follow to a null room , but target player is not free , how , why ?") ; // msgBack.nRet = 2 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break; // } // // // if ( pStateRoom->CheckCanJoinThisRoom(pTargetPlayer) != 0) // { // msgBack.nRet = 3 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // break; // } // // // add to room // stMsgRoomEnter msgToEnterRoom ; // msgToEnterRoom.nPassword = 0 ; // msgToEnterRoom.nRoomID = pStateRoom->GetRoomID(); // msgToEnterRoom.nRoomLevel = pStateRoom->GetRoomLevel() ; // msgToEnterRoom.nRoomType = pStateRoom->GetRoomType() ; // OnMessage(&msgToEnterRoom); // } // break; // case MSG_PLAYER_SLOT_MACHINE: // { // stMsgPlayerSlotMachineRet msgBack ; // msgBack.nRet = 0 ; // stMsgPlayerSlotMachine* pRetMsg = (stMsgPlayerSlotMachine*)pMsg ; // if ( GetBaseData()->GetAllCoin() < pRetMsg->nBetCoin || GetBaseData()->GetAllDiamoned() < pRetMsg->nBetDiamoned ) // { // msgBack.nRet = 1 ; // } // else // { // CSlotMachine* pMachine = (CSlotMachine*)CGameServerApp::SharedGameServerApp()->GetConfigMgr()->GetConfig(CConfigManager::eConfig_SlotMachine) ; // float fRate = 0 ; // pMachine->RandSlotMachine(pRetMsg->cLevel,msgBack.vCard,fRate) ; // int64_t nOffsetCoin = pRetMsg->nBetCoin * ( fRate - 1.0 ); // int nOffsetDiamoned = pRetMsg->nBetDiamoned * ( fRate - 1.0 ); // nOffsetDiamoned = abs(nOffsetDiamoned) ; // nOffsetCoin = abs(nOffsetCoin) ; // int nOffset = fRate > 1 ? 1 : -1 ; // GetBaseData()->ModifyMoney(nOffsetCoin * nOffset); // GetBaseData()->ModifyMoney(nOffsetDiamoned * nOffset,true); // msgBack.nFinalAllCoin = GetBaseData()->GetAllCoin(); // msgBack.nFinalDiamoned = GetBaseData()->GetAllDiamoned() ; // msgBack.nTakeInCoin = GetBaseData()->GetTakeInMoney() ; // msgBack.nTakeInDiamoned = GetBaseData()->GetTakeInMoney(true) ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // } // } // break; // case MSG_ROOM_REQUEST_PEER_DETAIL: // { // stMsgRoomRequestPeerDetailRet msgBack ; // stMsgRoomRequestPeerDetail* pMsgRet = (stMsgRoomRequestPeerDetail*)pMsg ; // msgBack.nPeerSessionID = pMsgRet->nPeerSessionID ; // CPlayer* pDetailPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(pMsgRet->nPeerSessionID) ; // if ( pDetailPlayer == NULL ) // { // msgBack.nRet = 1 ; // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // return true ; // } // // pDetailPlayer->GetBaseData()->GetPlayerDetailData(&msgBack.stDetailInfo); // SendMsgToClient((char*)&msgBack,sizeof(msgBack)) ; // } // break; default: return false ; } return true ; }
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 CPlayerBaseData::onBeInviteBy(uint32_t nInviteUID ) { if ( m_stBaseData.nInviteUID ) { LOGFMTD("can not do twice be invited ") ; return ; } m_stBaseData.nInviteUID = nInviteUID ; m_bPlayerInfoDataDirty = true ; // give self prize ; AddMoney(COIN_BE_INVITED) ; // show dlg ; stMsgDlgNotice msg; msg.nNoticeType = eNotice_BeInvite ; Json::Value jNotice ; jNotice["targetUID"] = nInviteUID ; jNotice["addCoin"] = COIN_BE_INVITED ; Json::StyledWriter writer ; std::string strNotice = writer.write(jNotice) ; msg.nJsonLen = strNotice.size(); CAutoBuffer msgBuffer(sizeof(msg) + msg.nJsonLen ); msgBuffer.addContent(&msg,sizeof(msg)) ; msgBuffer.addContent(strNotice.c_str(),msg.nJsonLen) ; SendMsg((stMsg*)msgBuffer.getBufferPtr(),msgBuffer.getContentSize()) ; LOGFMTD("uid = %d be invite give prize coin = %d",GetPlayer()->GetUserUID(),COIN_BE_INVITED) ; // give prize to inviter ; auto player = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(nInviteUID) ; if ( player && player->IsState(CPlayer::ePlayerState_Online)) { player->GetBaseData()->addInvitePrize(COIN_INVITE_PRIZE); //stMsgDlgNotice msg; //msg.nNoticeType = eNotice_InvitePrize ; //Json::StyledWriter writer ; //std::string strNotice = writer.write(jNotice) ; //msg.nJsonLen = strNotice.size(); //CAutoBuffer msgBuffer(sizeof(msg) + msg.nJsonLen ); //msgBuffer.addContent(&msg,sizeof(msg)) ; //msgBuffer.addContent(strNotice.c_str(),msg.nJsonLen) ; //player->GetBaseData()->SendMsg((stMsg*)msgBuffer.getBufferPtr(),msgBuffer.getContentSize()) ; LOGFMTD("invite id = %d online just give prize ",nInviteUID) ; } else { Json::Value jconArg; jconArg["comment"] = "invitePrize" ; jconArg["addCoin"] = COIN_INVITE_PRIZE ; CPlayerMailComponent::PostOfflineEvent(CPlayerMailComponent::Event_AddCoin,jconArg,nInviteUID) ; LOGFMTD("invite id = %d not online just post a mail",nInviteUID) ; } // send a mail to inviter jNotice["targetUID"] = GetPlayer()->GetUserUID() ; jNotice["addCoin"] = COIN_INVITE_PRIZE ; Json::StyledWriter writerInfo ; strNotice = writerInfo.write(jNotice) ; CPlayerMailComponent::PostMailToPlayer(eMail_InvitePrize,strNotice.c_str(),strNotice.size(),nInviteUID); // send push notification ; CSendPushNotification::getInstance()->reset(); CSendPushNotification::getInstance()->addTarget(nInviteUID) ; CSendPushNotification::getInstance()->setContent(CServerStringTable::getInstance()->getStringByID(5),1) ; CSendPushNotification::getInstance()->postApns(CGameServerApp::SharedGameServerApp()->getAsynReqQueue(),false,"invite") ; }
//获取游戏状态信息 bool CServerGameDesk::OnGetGameStation(BYTE bDeskStation, UINT uSocketID, bool bWatchUser) { m_bIsCut[bDeskStation] = false; SuperLoad(); DebugPrintf("用户进来 位置=【%d】状态=【%d】",bDeskStation,m_bGameStation); switch (m_bGameStation) { case GS_WAIT_SETGAME: //游戏没有开始状态 case GS_WAIT_ARGEE: //等待玩家开始状态 { GameStation_2 GameStation; GetIniData(GameStation.s_Data); //获取读取INI文件数据 GetBaseData(GameStation.sBData, bDeskStation); //获取游戏基本数据 SendGameStation(bDeskStation,uSocketID,bWatchUser,&GameStation,sizeof(GameStation)); break; } case GS_SEND_CARD: //发牌状态 { GameStation_3 GameStation; GetIniData(GameStation.s_Data); //获取读取INI文件数据 GetBaseData(GameStation.sBData, bDeskStation); //获取游戏基本数据 ::CopyMemory(GameStation.iUCCount,m_iUCCount,sizeof(m_iUCCount)); ::CopyMemory(GameStation.byUCard,m_byUCard[bDeskStation],sizeof(m_byUCard[bDeskStation])); //不充许 旁观 if(bWatchUser && !m_bWatchOther[bDeskStation]) { ::memset(GameStation.byUCard,0x4D,sizeof(GameStation.byUCard)); } SendGameStation(bDeskStation,uSocketID,bWatchUser,&GameStation,sizeof(GameStation)); break; } case GS_PLAY_GAME: //游戏中状态 { GameStation_4 GameStation; GetIniData(GameStation.s_Data); //获取读取INI文件数据 GetBaseData(GameStation.sBData, bDeskStation); //获取游戏基本数据 ::CopyMemory(GameStation.iUCCount,m_iUCCount,sizeof(m_iUCCount)); ::CopyMemory(GameStation.byUCard,m_byUCard[bDeskStation],sizeof(m_byUCard[bDeskStation])); ::CopyMemory(GameStation.byDownCard,m_bBullCard[bDeskStation],sizeof(m_bBullCard[bDeskStation])); GameStation.iSurplusTime = m_iSurplusTime; //剩余的时间 //不充许 旁观 if(bWatchUser && !m_bWatchOther[bDeskStation]) { ::memset(GameStation.byUCard,0x4D,sizeof(GameStation.byUCard)); } SendGameStation(bDeskStation,uSocketID,bWatchUser,&GameStation,sizeof(GameStation)); break; } case GS_WAIT_NEXT: //等待下一盘游戏开始 { GameStation_5 GameStation; GetIniData(GameStation.s_Data); //获取读取INI文件数据 GetBaseData(GameStation.sBData, bDeskStation); //获取游戏基本数据 SendGameStation(bDeskStation,uSocketID,bWatchUser,&GameStation,sizeof(GameStation)); break; } } return true; }
bool CExchangeCenter::onMsg(stMsg* pMsg , eMsgPort eSenderPort , uint32_t nSessionID) { switch ( pMsg->usMsgType ) { case MSG_READ_EXCHANGE: { stMsgReadExchangesRet* pRet = (stMsgReadExchangesRet*)pMsg ; stExchangeItem* pItem = (stExchangeItem*)(((char*)pMsg) + sizeof(stMsgReadExchangesRet)); while (pRet->nCnt--) { stExchangeEntry* pentry = new stExchangeEntry ; memset(pentry,0,sizeof(stExchangeEntry)); pentry->bDirty = false ; pentry->nExchangedCnt = pItem->nExchangedCnt ; pentry->nExchangeID = pItem->nExchangeID ; vExchangeEntrys[pentry->nExchangeID] = pentry ; ++pItem ; } LOGFMTD("recived exchange recorders") ; } break; case MSG_PLAYER_EXCHANGE: { stMsgPlayerExchange* pRet = (stMsgPlayerExchange*)pMsg ; stMsgPlayerExchangeRet msgRet ; msgRet.nExchageID = pRet->nExchangeID ; auto pPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ; if ( !pPlayer ) { msgRet.nRet = 3 ; getSvrApp()->sendMsg(nSessionID,(char*)&msgRet,sizeof(msgRet)); break ; } auto pExchangeItem = m_tConfig.getExchangeByID(pRet->nExchangeID); if ( !pExchangeItem ) { msgRet.nRet = 1 ; getSvrApp()->sendMsg(nSessionID,(char*)&msgRet,sizeof(msgRet)); LOGFMTD("can not find exchange item uid = %d , exchange id = %d",pPlayer->GetUserUID(),pExchangeItem->nConfigID) ; break ; } if ( pPlayer->GetBaseData()->GetAllDiamoned() < pExchangeItem->nDiamondNeed ) { msgRet.nRet = 2 ; getSvrApp()->sendMsg(nSessionID,(char*)&msgRet,sizeof(msgRet)); LOGFMTD("uid = %d , you diamond is not enough",pPlayer->GetUserUID()) ; break ; } msgRet.nRet = 0 ; getSvrApp()->sendMsg(nSessionID,(char*)&msgRet,sizeof(msgRet)); pPlayer->GetBaseData()->decressMoney(pExchangeItem->nDiamondNeed,true) ; // get remarks Json::Reader reader; Json::Value rootValue ; char* pstr = ((char*)pRet) + sizeof(stMsgPlayerExchange) ; reader.parse(pstr,pstr + pRet->nJsonLen,rootValue,false); // give order stMsgSaveLog msgLog ; msgLog.nLogType = eLog_ExchangeOrder ; msgLog.nTargetID = pPlayer->GetUserUID() ; memset(msgLog.vArg,0,sizeof(msgLog.vArg)); msgLog.vArg[0] = pExchangeItem->nConfigID ; Json::Value jValue ; jValue["playerName"] = pPlayer->GetBaseData()->GetPlayerName() ; jValue["excDesc"] = pExchangeItem->strDesc ; jValue["address"] = rootValue["address"].asString() ; jValue["phoneNumber"] = rootValue["phoneNumber"].asString() ; Json::StyledWriter jWriter ; std::string strArg = jWriter.write(jValue) ; msgLog.nJsonExtnerLen = strArg.size() ; CAutoBuffer auBuffer(sizeof(msgLog) + msgLog.nJsonExtnerLen ); auBuffer.addContent(&msgLog,sizeof(msgLog)) ; auBuffer.addContent(strArg.c_str(),msgLog.nJsonExtnerLen) ; getSvrApp()->sendMsg(nSessionID,auBuffer.getBufferPtr(),auBuffer.getContentSize()) ; LOGFMTD("uid = %d do exchange item id = %d, remark = %s",pPlayer->GetUserUID(),pExchangeItem->nConfigID,rootValue["address"].asString()) ; // update recorder ; auto pRec = vExchangeEntrys.find(pRet->nExchangeID); if ( pRec != vExchangeEntrys.end() ) { ++pRec->second->nExchangedCnt ; pRec->second->bDirty = true ; } else { auto pp = new stExchangeEntry ; pp->bDirty = true ; pp->nExchangedCnt = 1 ; pp->nExchangeID = pRet->nExchangeID ; vExchangeEntrys[pp->nExchangeID] = pp ; } bItemBufferDirty = true ; } break; case MSG_REQUEST_EXCHANGE_DETAIL: { stMsgRequestExchangeDetail* pRet = (stMsgRequestExchangeDetail*)pMsg ; auto item = m_tConfig.getExchangeByID(pRet->nExchangeID) ; stMsgRequestExchangeDetailRet msgBack ; msgBack.nExchangeID = pRet->nExchangeID ; msgBack.nJsonLen = 0 ; msgBack.nRet = 0 ; if ( item == nullptr ) { msgBack.nRet = 1 ; getSvrApp()->sendMsg(nSessionID,(char*)&msgBack,sizeof(msgBack)); break ; } Json::Value jValue ; jValue["diamond"] = item->nDiamondNeed ; jValue["desc"] = item->strDesc ; jValue["icon"] = item->strIcon ; Json::StyledWriter jWriter ; std::string strArg = jWriter.write(jValue) ; msgBack.nJsonLen = strArg.size() ; CAutoBuffer auBuffer(sizeof(msgBack) + msgBack.nJsonLen ); auBuffer.addContent(&msgBack,sizeof(msgBack)) ; auBuffer.addContent(strArg.c_str(),msgBack.nJsonLen) ; getSvrApp()->sendMsg(nSessionID,auBuffer.getBufferPtr(),auBuffer.getContentSize()) ; LOGFMTD("session id = %d get exchange detail",nSessionID) ; } break; case MSG_REQUEST_EXCHANGE_LIST: { if ( bItemBufferDirty ) { bItemBufferDirty = false ; delete [] pItemsBuffer; pItemsBuffer = nullptr ; nItemsBufferLen = 0 ; } if ( pItemsBuffer == nullptr ) { stMsgRequestExchangeListRet msgBack ; msgBack.nCnt = m_tConfig.getExchangeItemCnt() ; CAutoBuffer auBuffer(sizeof(msgBack) + sizeof(stExchangeItem) * msgBack.nCnt ); auBuffer.addContent(&msgBack,sizeof(msgBack)) ; auto iter = m_tConfig.getBeginIter() ; stExchangeItem item ; for ( ; iter != m_tConfig.getEndItem() ; ++iter ) { item.nExchangeID = iter->second->nConfigID ; item.nExchangedCnt = 0 ; auto p = vExchangeEntrys.find(item.nExchangeID) ; if ( p != vExchangeEntrys.end() ) { item.nExchangedCnt = p->second->nExchangedCnt ; } auBuffer.addContent(&item,sizeof(item)) ; } getSvrApp()->sendMsg(nSessionID,auBuffer.getBufferPtr(),auBuffer.getContentSize()) ; pItemsBuffer = new char[auBuffer.getContentSize()] ; memcpy(pItemsBuffer,auBuffer.getBufferPtr(),auBuffer.getContentSize()); nItemsBufferLen = auBuffer.getContentSize() ; } else { getSvrApp()->sendMsg(nSessionID,pItemsBuffer,nItemsBufferLen) ; } LOGFMTD("session id = %d get exchange list",nSessionID) ; } break; default: return false ; } return true ; }