Beispiel #1
0
void CGateClientMgr::OnPeerDisconnected(CONNECT_ID nPeerDisconnected, ConnectInfo* IpInfo  )
{
	// client disconnected ;
	stGateClient* pDstClient = GetGateClientByNetWorkID(nPeerDisconnected) ;
	if ( pDstClient )
	{
		if ( pDstClient->tTimeForRemove )
		{
			LOGFMTE("already wait to reconnected");
			return ;
		}

		pDstClient->tTimeForRemove = time(NULL) + TIME_WAIT_FOR_RECONNECTE ;
		m_vWaitToReconnect[pDstClient->nSessionId] = pDstClient;

		stMsgSyncClientNetState msgRet ;
		msgRet.nState = 0 ;
		CGateServer::SharedGateServer()->sendMsg(pDstClient->nSessionId,(char*)&msgRet,sizeof(msgRet)) ;

		if ( IpInfo )
		{
			LOGFMTI("client disconnected ip = %s, port = %d, wait for reconnect",IpInfo->strAddress,IpInfo->nPort ) ;
		}
		return ;
	}

	if ( IpInfo )
	{
		LOGFMTE("not verify peer disconnected ip = %s, port = %d",IpInfo->strAddress,IpInfo->nPort ) ;
	}
}
Beispiel #2
0
void CGroup::dismissGroup(uint32_t nGroupID )
{
	auto iter = m_vGroups.find(nGroupID) ;
	if ( iter != m_vGroups.end() )
	{
		// remove from sorted list 
		auto siter = std::find(m_vSortedGroups.begin(),m_vSortedGroups.end(),iter->second) ;
		if ( siter == m_vSortedGroups.end() )
		{
			LOGFMTE("why can not find the group in sorted list") ;
		}
		else
		{
			m_vSortedGroups.erase(siter);
		}
		// do delete 
		delete iter->second ;
		iter->second = nullptr ;
		m_vGroups.erase(iter) ;

		// do delete
		Json::Value jssql ;
		char pBuffer[512] = {0};
		sprintf(pBuffer,"update clubs set isDelete = 1 where clubID = '%u';",nGroupID);
		jssql["sql"] = pBuffer;
		getSvrApp()->getAsynReqQueue()->pushAsyncRequest(ID_MSG_PORT_DB,eAsync_DB_Update,jssql);
		return ;
	}
	LOGFMTE("can not find dismiss group id = %u",nGroupID) ;
}
Beispiel #3
0
bool ApnsService::init_ssl_ctx()
{
	if (access(apns_params_.CertFile.c_str(), 0) == -1)
	{
		LOGFMTE("can't find cert file");
		return false;
	}

	if (access(apns_params_.KeyFile.c_str(), 0) == -1)
	{
		LOGFMTE("can't find key file");
		return false;
	}

	//生产环境下建立连接有问题,换成 context::tlsv1_client
	if (apns_params_.Developer)
	{
		ssl_ctx_.reset(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv12_client));
	}
	else 
	{
		ssl_ctx_.reset(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1_client));
	}
	
	ssl_ctx_->use_certificate_file(apns_params_.CertFile.c_str(), boost::asio::ssl::context_base::pem);
	ssl_ctx_->use_rsa_private_key_file(apns_params_.KeyFile.c_str(), boost::asio::ssl::context_base::pem);

	return true;
}
Beispiel #4
0
void CGateClientMgr::OnServerMsg( const char* pRealMsgData, uint16_t nDataLen,uint32_t uTargetSessionID )
{
	stGateClient* pClient = GetGateClientBySessionID(uTargetSessionID) ;
	stMsg* pReal = (stMsg*)pRealMsgData ;
	if ( NULL == pClient )
	{
		LOGFMTE("big error !!!! can not send msg to session id = %d , client is null , msg = %d",uTargetSessionID,pReal->usMsgType  ) ;
		return  ;
	}

	if ( pClient->tTimeForRemove )
	{
		LOGFMTD("client is waiting for reconnected session id = %d, msg = %d",uTargetSessionID,pReal->usMsgType) ;
		return ;
	}

	std::string strOut = "" ;
	if ( tranlateMsgToWebClient(pReal,strOut) )
	{
		CGateServer::SharedGateServer()->SendMsgToClient(strOut.c_str(),pClient->nNetWorkID ) ;
	}
	else
	{
		LOGFMTE("msg = %u not translate to client",pReal->usMsgType) ;
	}
}
Beispiel #5
0
void CDBManager::OnDBResult(stDBResult* pResult)
{
	stArgData*pdata = (stArgData*)pResult->pUserData ;
	switch ( pResult->nRequestUID )
	{
	case MSG_SAVE_LOG:
	case MSG_SAVE_PLAYER_ADVICE:
		{
			if ( pResult->nAffectRow != 1 )
			{
				LOGFMTE("save log error",pdata->nExtenArg1) ;
			}
			else
			{
				LOGFMTD("save log success");
			}
		}
		break;
	default:
		{
			if ( pResult->nAffectRow <= 0 )
			{
				LOGFMTE("unprocessed db result msg id = %d , row cnt = %d  ", pResult->nRequestUID,pResult->nAffectRow );
			}
			else
			{
				LOGFMTE("unprocessed db result msg id = %d , row cnt = %d  ", pResult->nRequestUID,pResult->nAffectRow );
			}
		}
	}
	m_vReserverArgData.push_back(pdata) ;
}
Beispiel #6
0
void CPlayerBaseData::OnProcessContinueLogin( bool bNewDay, time_t nLastLogin)
{
 	if ( nLastLogin == 0 )
 	{
 		m_stBaseData.nContinueDays = 1 ;
 	}
 	else
 	{
 		time_t nCur = time(NULL) ;
 		struct tm* pTempTimer = NULL;
 		pTempTimer = localtime(&nCur) ;
 		struct tm pTimeCur ;
 		if ( pTempTimer )
 		{
 			pTimeCur = *pTempTimer ;
 		}
 		else
 		{
 			LOGFMTE("local time return null ?") ;
 		}
		
		time_t tLastLoginTime = m_stBaseData.tLastLoginTime;
 		pTempTimer = localtime(&tLastLoginTime) ;
 		struct tm pTimeLastLogin  ;
 		if ( pTempTimer )
 		{
 			pTimeLastLogin = *pTempTimer ;
 		}
 		else
 		{
 			LOGFMTE("local time return null ?") ;
 		}
 		
 		if ( pTimeCur.tm_year == pTimeLastLogin.tm_year && pTimeCur.tm_yday == pTimeLastLogin.tm_yday )
 		{
 			m_stBaseData.tLastLoginTime = (unsigned int)nCur ;
 			m_bGivedLoginReward = true ;
 			return ; // do nothing ; same day ;
 		}
 
 		double nDiffe = difftime(nCur,m_stBaseData.tLastLoginTime) ;
 		bool bContine = abs(nDiffe) - 60 * 60 * 24 <= 0 ;
 		
 		if ( bContine )
 		{
 			++m_stBaseData.nContinueDays ;   // real contiune ;
 		}
 		else
 		{
 			m_stBaseData.nContinueDays = 1 ;    // disturbed ;
 		}
 
 		m_stBaseData.tLastLoginTime = (unsigned int)nCur ;
 	}
}
Beispiel #7
0
bool CGateClientMgr::onTranlatedWebMsgToOtherSvr( Packet* pData )
{
	// verify identify 
	stMsg* pMsg = (stMsg*)pData->_orgdata ;
	CHECK_MSG_SIZE(stMsg,pData->_len);
	if ( MSG_VERIFY_CLIENT == pMsg->usMsgType )
	{
		stGateClient* pGateClient = GetReserverGateClient();
		if ( !pGateClient )
		{
			pGateClient = new stGateClient ;
		}

		pGateClient->Reset(CGateServer::SharedGateServer()->GenerateSessionID(),pData->_connectID,"127.0.0.1") ;
		AddClientGate(pGateClient);
		LOGFMTI("a Client connected ip = %s Session id = %d",pGateClient->strIPAddress.c_str(),pGateClient->nSessionId ) ;
		LOGFMTI("current online cnt = %d", m_vSessionGateClient.size() - m_vWaitToReconnect.size() ) ;
		return true;
	}

	// transfer to center server 
	stGateClient* pDstClient = GetGateClientByNetWorkID(pData->_connectID) ;
	if ( pDstClient == NULL )
	{
		LOGFMTE("can not send message to Center Server , client is NULL or not verified, so close the unknown connect") ;
		//CGateServer::SharedGateServer()->GetNetWorkForClients()->ClosePeerConnection(pData->_connectID) ;
		return true ;
	}

	if ( CheckServerStateOk(pDstClient) == false )
	{
		LOGFMTE("center server is disconnected so can not send msg to it ");
		return true ;
	}

	stMsgTransferData msgTransData ;
	msgTransData.nSenderPort = ID_MSG_PORT_CLIENT ;
	msgTransData.bBroadCast = false ;
	msgTransData.nSessionID = pDstClient->nSessionId ;
	int nLne = sizeof(msgTransData) ;
	if ( nLne + pData->_len >= MAX_MSG_BUFFER_LEN )
	{
		stMsg* pmsg = (stMsg*)pData->_orgdata ;
		LOGFMTE("msg from session id = %d , is too big , cannot send , msg id = %d ",pDstClient->nSessionId,pmsg->usMsgType) ;
		return true ;
	}
	memcpy(m_pMsgBuffer,&msgTransData,nLne);
	memcpy(m_pMsgBuffer + nLne , pData->_orgdata,pData->_len );
	nLne += pData->_len ;
	CGateServer::SharedGateServer()->SendMsgToCenterServer(m_pMsgBuffer,nLne);
	return true ;
}
Beispiel #8
0
void CGateClientMgr::UpdateReconectClientLife()
{
	if ( m_vWaitToReconnect.empty() )
	{
		return ;
	}

	time_t tNow = time(NULL) ;
	LIST_GATE_CLIENT vWillRemove ;
	MAP_SESSIONID_GATE_CLIENT::iterator iter = m_vWaitToReconnect.begin();
	for ( ; iter != m_vWaitToReconnect.end(); ++iter )
	{
		if ( iter->second == NULL )
		{
			LOGFMTE("why this null client wait reconnect");
			continue;
		}

		if ( iter->second->tTimeForRemove == 0 )
		{
			LOGFMTE("big error , timeForRemove can not be 0 ") ;
		}

		if ( iter->second->tTimeForRemove <= tNow )
		{
			vWillRemove.push_back(iter->second) ;
		}
	}

	// do remove 
	LIST_GATE_CLIENT::iterator iterRemove = vWillRemove.begin() ;
	for ( ; iterRemove != vWillRemove.end(); ++iterRemove )
	{
		stGateClient* p = *iterRemove ;
		if ( p == NULL )
		{
			continue;
		}
		// tell other server the peer disconnect
		{
			stMsgClientDisconnect msgdis ;
			msgdis.nSeesionID = p->nSessionId ;
			CGateServer::SharedGateServer()->SendMsgToCenterServer((char*)&msgdis,sizeof(msgdis));
		}

		// do remove 
		LOGFMTI("session id = %d , ip = %s , wait reconnect time out ,do exit game",p->nSessionId,p->strIPAddress.c_str()) ;
		RemoveClientGate(p);
	}
	vWillRemove.clear();
}
Beispiel #9
0
void ApnsConnection::process_reponse_error(char* reponse)
{
	//parse
	ErrorrResponse err;
	err.cmd = reponse[0];
	if (err.cmd != 8)
	{
		LOGFMTE("error response commond, %d", err.cmd);
		return;
	}
	err.status = reponse[1];
	memcpy(&err.id, reponse + 2, 4);
	err.id = boost::endian::big_to_native(err.id);

	LOGFMTE("read response :%s", ResponseErrorToString((ErrorResponse)err.status));

	//重新发送失败id后的所有消息
	bool find = false;
	size_t c = sended_queue_.size();
	PushNotification* notice = NULL;

	//找到直到遇到失败的那个消息
	for (int i = 0; i < c; ++i)
	{
		notice = sended_queue_[i];
		if (notice == NULL)
		{
			continue;
		}

		if (find)
		{
			send_queue_.push_back(notice);
			sended_queue_[i] = NULL;
		}
		else
		{
			//找到失败的那条消息,
			if (err.id == notice->Id())
			{
				find = true;
				if (err.status == ERROR_CODE_INVALID_TOKEN)
				{
					apns_service_->AddInvalidToken(notice->Token());
				}
				notice->Clear();
				gNoticePool.Put(notice);
			}
		}
	}
}
Beispiel #10
0
bool IRoom::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID )
{
	if ( m_pCurRoomState && m_pCurRoomState->onMessage(prealMsg,eSenderPort,nPlayerSessionID) )
	{
		return true ;
	}

	switch ( prealMsg->usMsgType )
	{
	case MSG_MODIFY_ROOM_RANK:
		{
			stMsgRobotModifyRoomRank* pRet = (stMsgRobotModifyRoomRank*)prealMsg ;
			if ( getDelegate() && getPlayerByUserUID(pRet->nTargetUID) )
			{
				getDelegate()->onUpdatePlayerGameResult(this,pRet->nTargetUID,pRet->nOffset);
				LOGFMTI("modify uid = %u offset = %d",pRet->nTargetUID,pRet->nOffset) ;
			}
			else
			{
				LOGFMTE("modify room rank uid = %u not in room ", pRet->nTargetUID);
			}
		}
		break;
	case MSG_PLAYER_LEAVE_ROOM:
		{
			LOGFMTD("player apply to leave ") ;
			stMsgPlayerLeaveRoomRet msg ;
			stStandPlayer* pp = getPlayerBySessionID(nPlayerSessionID) ;
			if ( pp )
			{
				onPlayerWillLeaveRoom(pp) ;
				LOGFMTD("do leave remove object") ;
				playerDoLeaveRoom(pp);
				msg.nRet = 0 ;
			}
			else
			{
				msg.nRet = 1 ;
				LOGFMTE("session id not in this room how to leave session id = %d",nPlayerSessionID) ;
			}
			sendMsgToPlayer(&msg,sizeof(msg),nPlayerSessionID) ;
			LOGFMTD("finish leave room msg");
		}
		break;
	default:
		return false ;
	}

	return true ;
}
Beispiel #11
0
void CTaxasRoom::didCaculateGameResult()
{
	// save serve log 
	writeGameResultLog();
	
	// update coin Tax  and insurance ;
	Json::Value arrayJs ;
	for ( uint8_t nIdx = 0 ; nIdx < getSeatCount(); ++nIdx )
	{
		CTaxasPlayer* pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
		if ( pPlayer == nullptr || pPlayer->isHaveState(eRoomPeer_StayThisRound) == false || pPlayer->getGameOffset() < (int)0 ) 
		{
			continue;
		}
		LOGFMTE("game end update offset");
		int32_t nTaxFee = (int32_t)(pPlayer->getGameOffset() * getChouShuiRate()) + pPlayer->getInsuranceLoseCoin();
		pPlayer->setCoin(pPlayer->getCoin() - nTaxFee );
		addTotoalProfit((uint32_t)nTaxFee);
		LOGFMTD("room id = %u uid = %u , give tax = %d coin = %u",getRoomID(),nTaxFee,pPlayer->getCoin()) ;

		Json::Value jsPeer ;
		jsPeer["idx"] = nIdx ;
		jsPeer["coin"] = pPlayer->getCoin() ;
		arrayJs[arrayJs.size()] = jsPeer ;
	}

	Json::Value jsmsg ;
	jsmsg["players"] = arrayJs ;
	sendRoomMsg(jsmsg,MSG_SYNC_TAXAS_ROOM_PLAYER_COIN) ;
}
Beispiel #12
0
void CTaxasRoom::onPlayerWillStandUp(ISitableRoomPlayer* pPlayer )
{
	if ( pPlayer->isHaveState(eRoomPeer_WaitCaculate) )
	{
		ISitableRoom::onPlayerWillStandUp(pPlayer) ;
		return ;
	}

	if ( pPlayer->isHaveState(eRoomPeer_StayThisRound) )
	{
		if ( getCurRoomState()->getStateID() != eRoomState_DidGameOver )
		{
			CTaxasPlayer* p = (CTaxasPlayer*)pPlayer ;
			LOGFMTE("will stand up update offset uid = %d",pPlayer->getUserUID());

			if ( getDelegate() )
			{
				getDelegate()->onUpdatePlayerGameResult(this,pPlayer->getUserUID(),p->getGameOffset());
			}
		}
		else
		{
			LOGFMTI("if here update player uid = %d offeset will occure a bug ",pPlayer->getUserUID() ) ;
		}
	}
	playerDoStandUp(pPlayer);
}
Beispiel #13
0
void CPlayer::OnAnotherClientLoginThisPeer(unsigned int nSessionID )
{
    // tell prelogin client to disconnect ;
    stMsgPlayerOtherLogin msg ;
    SendMsgToClient((char*)&msg,sizeof(msg)) ;

    LOGFMTE("pls remember inform other server this envent OnAnotherClientLoginThisPeer ") ;

    for ( int i = ePlayerComponent_None; i < ePlayerComponent_Max ; ++i )
    {
        IPlayerComponent* p = m_vAllComponents[i] ;
        if ( p )
        {
            p->OnOtherWillLogined();
        }
    }
    // bind new client ;
    m_nSessionID = nSessionID ;
    m_eSate = ePlayerState_Online;
    for ( int i = ePlayerComponent_None; i < ePlayerComponent_Max ; ++i )
    {
        IPlayerComponent* p = m_vAllComponents[i] ;
        if ( p )
        {
            p->OnOtherDoLogined();
        }
    }
}
Beispiel #14
0
void CTaxasRoom::OnPlayerActTimeOut()
{
	stMsgTaxasPlayerAct msg ;
	msg.cSysIdentifer = 0 ;
	msg.nValue = 0 ;
	msg.nRoomID = getRoomID() ;
	CTaxasPlayer* pPlayer = (CTaxasPlayer*)getPlayerByIdx(m_nCurWaitPlayerActionIdx);
	if ( pPlayer == nullptr )
	{
		LOGFMTE("why cur wait player is null ");
		return ;
	}

	if ( m_nMostBetCoinThisRound == pPlayer->getBetCoinThisRound() )
	{
		msg.nPlayerAct = eRoomPeerAction_Pass ;
	}
	else
	{
		msg.nPlayerAct = eRoomPeerAction_GiveUp ;
	}
	LOGFMTD("wait player act time out auto act room id = %d",getRoomID()) ;
	onMessage(&msg,ID_MSG_PORT_CLIENT,pPlayer->getSessionID()) ;
	pPlayer->increaseNoneActTimes();
}
Beispiel #15
0
void ApnsService::send(PushNotification* notice)
{
	if (stopped_)
	{
		gNoticePool.Put(notice);
		return;
	}

	// 检测token
	if (!CheckToken(notice->Token()))
	{
		notice->Clear();
		gNoticePool.Put(notice);
		return;
	}

	//寻找一个有效的连接,发送
	ApnsConnection* conn = GetVaildConn();
	if (conn != NULL)
	{
		conn->SendNotification(notice);
	}
	else
	{
		gNoticePool.Put(notice);
		LOGFMTE("%s :no valid apnsconn error", apns_params_.Name.c_str());
	}
}
Beispiel #16
0
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));
}
Beispiel #17
0
// return dis card cnt ;
uint8_t CTaxasRoom::DistributePublicCard()
{
	LOGFMTD("pulick card = %d",m_nPublicCardRound);
	stMsgTaxasRoomPublicCard msgPublicCard ;
	msgPublicCard.nCardSeri = m_nPublicCardRound++ ;
	// distr 3 
	if ( m_nPublicCardRound == 1 )
	{
		for ( uint8_t nIdx = 0 ; nIdx < 3 ; ++nIdx )
		{
			msgPublicCard.vCard[nIdx] = m_vPublicCardNums[nIdx] ;
		}
		// send msg to tell client ;
		sendRoomMsg(&msgPublicCard,sizeof(msgPublicCard)) ;
		return 3 ;
	}

	if ( m_nPublicCardRound == 2 )
	{
		msgPublicCard.vCard[0] = m_vPublicCardNums[3] ;
		sendRoomMsg(&msgPublicCard,sizeof(msgPublicCard)) ;
		return 1 ;
	}

	if ( m_nPublicCardRound == 3 )
	{
		msgPublicCard.vCard[0] = m_vPublicCardNums[4] ;
		sendRoomMsg(&msgPublicCard,sizeof(msgPublicCard)) ;
		return 1 ;
	}

	LOGFMTE("already finish public card why one more time ") ;
	return 0 ;
}
Beispiel #18
0
void ApnsConnection::post()
{
	send_time();

	if (!send_queue_.empty())
	{
		PushNotification* notice_send = send_queue_.front();
		if (notice_send == NULL)
		{
			send_queue_.pop_front();
			return;
		}

		char * data = notice_send->Bytes();
		size_t len = notice_send->BytesLen();
		if (len > 0)
		{
			conn_tsl_->Write(data, len);
		}
		else
		{
			notice_send->Clear();
			gNoticePool.Put(notice_send);
			send_queue_.pop_front();
			LOGFMTE("notice len == 0");
		}
	}
}
Beispiel #19
0
void IRoom::onPlayerEnterRoom(stEnterRoomData* pEnterRoomPlayer ,int8_t& nSubIdx)
{
	stStandPlayer* pp = getPlayerByUserUID(pEnterRoomPlayer->nUserUID);
	stStandPlayer * pStandPlayer = nullptr ;
	if ( pp )
	{
		LOGFMTE("player uid = %d , already in this room, can not enter twice, data svr crashed ?",pEnterRoomPlayer->nUserUID) ;
		pStandPlayer = pp ;
		pStandPlayer->nUserSessionID = pEnterRoomPlayer->nUserSessionID;
	}
	else
	{
		pStandPlayer = new stStandPlayer ;
		memset(pStandPlayer,0,sizeof(stStandPlayer));
	}

	memcpy_s(pStandPlayer,sizeof(stStandPlayer),pEnterRoomPlayer,sizeof(stEnterRoomData));
	if ( getDelegate() && getDelegate()->isOmitNewPlayerHalo(this)  )
	{
		pStandPlayer->nNewPlayerHaloWeight = 0 ;
		LOGFMTD("room id = %d omit new player halo so halo weith = 0  for uid = %d", getRoomID(),pStandPlayer->nUserUID) ;
	}

	addRoomPlayer(pStandPlayer) ;
}
Beispiel #20
0
bool CRobotCenter::onMsg(Json::Value& prealMsg ,uint16_t nMsgType, eMsgPort eSenderPort , uint32_t nSessionID)
{
	switch (nMsgType)
	{
	case MSG_TELL_ROBOT_IDLE:
		{
			auto ppPLayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerBySessionID(nSessionID) ;
			if ( ppPLayer == nullptr )
			{
				LOGFMTE("this robot not login session id = %u",nSessionID) ;
				return true;
			}

			if ( isRobotInTheList(ppPLayer->GetUserUID()) )
			{
				onRobotOtherLogin(ppPLayer->GetUserUID(),nSessionID) ;
			}
			else
			{
				stIdleRobot* pR = new stIdleRobot ;
				pR->nLevel = 0 ;
				pR->nSessionID = nSessionID ;
				pR->nUserUID = ppPLayer->GetUserUID() ;
				m_vIdleRobots.push_back(pR) ;
			}
			LOGFMTD("a robot uid = %u enter idle ",ppPLayer->GetUserUID()) ;
			processRobotReq();
		}
		break;
	default:
		return false;
	}
	return true ;
}
bool CNiuNiuRoomStatePlayerCaculateCardState::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID )
{
	if ( IRoomState::onMessage(prealMsg,eSenderPort,nPlayerSessionID) )
	{
		return true ;
	}

	switch ( prealMsg->usMsgType )
	{
	case MSG_NN_PLAYER_CACULATE_CARD_OK:
		{
			ISitableRoomPlayer* pPlayer = m_pRoom->getSitdownPlayerBySessionID(nPlayerSessionID) ;
			if ( pPlayer == nullptr )
			{
				LOGFMTE("you are not sit down how to caculate card session id = %d",nPlayerSessionID) ;
				return true ;
			}

			if ( pPlayer->isHaveState(eRoomPeer_CanAct) == false )
			{
				LOGFMTE("you are not player in this game , how to cacuate card session id = %d", nPlayerSessionID ) ;
				return true ;
			}

			if ( m_vOperoateRecord.find(nPlayerSessionID) != m_vOperoateRecord.end() )
			{
				LOGFMTE("don't do twice cacualte card session id %d",nPlayerSessionID ) ;
				return true ;
			}
			m_vOperoateRecord[nPlayerSessionID] = 1 ;

			--m_nWaitOperPlayerCnt;
			stMsgNNCaculateCardOk msg ;
			msg.nPlayerIdx = pPlayer->getIdx() ;
			m_pRoom->sendRoomMsg(&msg,sizeof(msg));
			if ( m_nWaitOperPlayerCnt <= 0 )
			{
				onStateDuringTimeUp();
			}
		}
		break;
	default:
		return false;
	}
	return true ;
}
Beispiel #22
0
void CGateClientMgr::AddClientGate(stGateClient* pGateClient )
{
	if ( m_vNetWorkIDGateClientIdx.find(pGateClient->nNetWorkID) != m_vNetWorkIDGateClientIdx.end() )
	{
		LOGFMTE("why this pos already have data client") ;
		m_vNetWorkIDGateClientIdx.erase(m_vNetWorkIDGateClientIdx.find(pGateClient->nNetWorkID));
	}

	if ( m_vSessionGateClient.find(pGateClient->nSessionId) != m_vSessionGateClient.end() )
	{
		LOGFMTE("why this pos session id = %d had client data",pGateClient->nSessionId) ;
		m_vSessionGateClient.erase(m_vSessionGateClient.find(pGateClient->nSessionId));
	}

	m_vNetWorkIDGateClientIdx[pGateClient->nNetWorkID] = pGateClient ;
	m_vSessionGateClient[pGateClient->nSessionId] = pGateClient ;
}
Beispiel #23
0
void CTaxasRoom::doCaculateInsurance()
{
	if ( !m_isInsured )
	{
		return ;
	}

	if ( !isAnyOneBuyInsurace() )
	{
		return ;
	}

	uint16_t nIdx = 0 ;
	std::vector<uint8_t> vOuts ;
	m_pInsurance->getOuts(nIdx,vOuts);
	uint8_t nCurCard = 0 ;
	if ( m_nPublicCardRound == 2 )
	{
		nCurCard = m_vPublicCardNums[3] ;
	}
	else if ( 3 == m_nPublicCardRound )
	{
		nCurCard = m_vPublicCardNums[4] ;
	}
	else
	{
		assert("invalid round , this time can not do calculate" && 0 );
	}
	
	auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx) ;
	if ( pPlayer->getInsuredAmount() == 0 )
	{
		LOGFMTE("why buy insurance is 0 ") ;
		return ;
	}
	bool isHit = std::find(vOuts.begin(),vOuts.end(),nCurCard) != vOuts.end();
	assert(pPlayer && "why buyer is null ?" );
	uint32_t nProfit = 0 ;
	uint32_t nAmout = pPlayer->getInsuredAmount();
	if ( isHit )  // hit the point , player win coin
	{
		nProfit = m_pInsurance->getInsuredProfit(nAmout);
		pPlayer->addWinInsuredCoin(nProfit);
	}
	else  // not hit point , player lose coin
	{
		pPlayer->setInsuranceLoseCoin(pPlayer->getInsuranceLoseCoin() + nAmout) ;
	}

	pPlayer->setInsuredAmount(0) ;
	// send msg tell the result 
	Json::Value jsresult ;
	jsresult["idx"] = nIdx ;
	int32_t nOffset = isHit ? nProfit : (((int32_t)nAmout) * -1 );
	jsresult["offset"] = nOffset;
	LOGFMTD("insurance offset = %d",nOffset) ;
	sendRoomMsg(jsresult,MSG_INSURANCE_CALCULATE_RESULT);
}
Beispiel #24
0
bool ApnsService::Start()
{
	auto iter = resolver_addr(false);
	if (iter == boost::asio::ip::tcp::resolver::iterator())
	{
		LOGFMTE("resolver apns host faild");
		return false;
	}

	if (!init_ssl_ctx())
	{
		return false;
	}

	for (size_t i = 0; i < apns_params_.ApnsConnCount; i++)
	{
		auto conn = std::make_shared<ApnsConnection>(*io_service_, *ssl_ctx_, iter, this);
		conn->SetIdleTime(apns_params_.IdleTime);
		conn->Connect();
		apns_conns_.push_back(conn);
	}


	//feed back service
	auto iter_feedback = resolver_addr(true);
	if (iter_feedback == boost::asio::ip::tcp::resolver::iterator())
	{
		LOGFMTE("resolver apns feedback host faild");
		return false;
	}

	fd_conn_.reset(new  ApnsFeedBackConnection(*io_service_, *ssl_ctx_, iter_feedback, this));
	//get feedback time interval
	int t = 24 * 3600;
	if (apns_params_.FeedBackTime > 0 && apns_params_.FeedBackTime < (30 * t))
	{
		t = apns_params_.FeedBackTime;
	}

	SetTimer(1, 1000 * t, NULL);

	LOGFMTD("ApnsService %s start!", apns_params_.Name.c_str());
	stopped_ = false;
	return true;
}
Beispiel #25
0
bool CTaxasRoom::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID )
{
	if ( ISitableRoom::onMessage(prealMsg,eSenderPort,nPlayerSessionID) )
	{
		return true ;
	}

	switch (prealMsg->usMsgType )
	{
	//case MSG_TP_REQUEST_ROOM_INFO:
	//	{
	//		LOGFMTI("send room info to player session id = %d",nPlayerSessionID );
	//		sendRoomInfoToPlayer(nPlayerSessionID);
	//	}
	//	break;
	//case MSG_REQUEST_ROOM_DETAIL:
	//	{
	//		stMsgRequestRoomDetailRet msgRet ;
	//		msgRet.detailInfo.nCreatOwnerUID = getOwnerUID();
	//		msgRet.detailInfo.nCurrentCount = GetPlayerCntWithState(eRoomPeer_SitDown);
	//		msgRet.detailInfo.nRoomID = GetRoomID();
	//		msgRet.detailInfo.nSmiallBlind = getLittleBlind();
	//		msgRet.detailInfo.nSeatCnt = getSeatCnt();
	//		sprintf_s(msgRet.detailInfo.vRoomName,sizeof(msgRet.detailInfo.vRoomName),"%s",getRoomName());
	//		SendMsgToPlayer(nPlayerSessionID,&msgRet,sizeof(msgRet)) ;
	//	}
	//	break;
	//case MSG_REQUEST_MY_OWN_ROOM_DETAIL:
	//	{
	//		stMsgRequestMyOwnRoomDetailRet msgRet ;
	//		msgRet.nRet = 0 ;
	//		msgRet.nRoomType = eRoom_TexasPoker ;
	//		msgRet.nCanWithdrawProfit = m_nRoomProfit ;
	//		msgRet.nConfigID = m_stRoomConfig.nConfigID ;
	//		msgRet.nDeadTime = m_nDeadTime ;
	//		msgRet.nFollows = 2 ;
	//		msgRet.nRoomID = GetRoomID() ;
	//		msgRet.nTotalProfit = m_nTotalProfit ;
	//		sprintf_s(msgRet.vRoomName,sizeof(msgRet.vRoomName),"%s",getRoomName());
	//		SendMsgToPlayer(nPlayerSessionID,&msgRet,sizeof(msgRet)) ;
	//	}
	//	break;
	case MSG_TP_CHANGE_ROOM:
		{
			LOGFMTE("change room function canncel");
			return true ;
			stMsgTaxasPlayerLeave leave ;
			onMessage(&leave,ID_MSG_PORT_CLIENT,nPlayerSessionID);
			
			return true ;
		}
		break;
	default:
		return false ;
	}
	return true ;
}
Beispiel #26
0
bool IServerApp::OnLostSever(Packet* pMsg)
{
	m_nTargetSvrNetworkID = INVALID_CONNECT_ID ;
	LOGFMTE("Target server disconnected !") ;
	m_eConnectState = CNetWorkMgr::eConnectType_Disconnectd ;

	m_fReconnectTick = TIME_WAIT_FOR_RECONNECT ;// right now start reconnect ;
	return false ;
}
Beispiel #27
0
void CGateClientMgr::AddClientGate(stGateClient* pGateClient )
{
	auto iter = m_vNetWorkIDGateClientIdx.find(pGateClient->nNetWorkID) ;
	if ( iter != m_vNetWorkIDGateClientIdx.end() )
	{
		LOGFMTE("why this pos already have data client") ;
		RemoveClientGate(iter->second);
	}

	auto iterS = m_vSessionGateClient.find(pGateClient->nSessionId) ;
	if ( iterS != m_vSessionGateClient.end() )
	{
		LOGFMTE("why this pos session id = %d had client data",pGateClient->nSessionId) ;
		RemoveClientGate(iterS->second);
	}

	m_vNetWorkIDGateClientIdx[pGateClient->nNetWorkID] = pGateClient ;
	m_vSessionGateClient[pGateClient->nSessionId] = pGateClient ;
}
Beispiel #28
0
void CTaxasRoom::startGame()
{
	// init running data 
	m_nBankerIdx = GetFirstInvalidIdxWithState(m_nBankerIdx + 1 , eRoomPeer_CanAct) ;
	m_nLittleBlindIdx = GetFirstInvalidIdxWithState(m_nBankerIdx + 1 , eRoomPeer_CanAct) ;
	m_nBigBlindIdx = GetFirstInvalidIdxWithState(m_nLittleBlindIdx + 1 , eRoomPeer_CanAct) ;

	// bet coin this 
	auto pTaxPlayer = (CTaxasPlayer*)getPlayerByIdx(m_nLittleBlindIdx);
	pTaxPlayer->betCoin( m_nLittleBlind ) ;

	pTaxPlayer = (CTaxasPlayer*)getPlayerByIdx(m_nBigBlindIdx);
	pTaxPlayer->betCoin( m_nLittleBlind * 2 ) ;
	m_nMostBetCoinThisRound = m_nLittleBlind * 2 ;

	stMsgTaxasRoomStartRound msgStart ;
	msgStart.nBankerIdx = m_nBankerIdx ;
	msgStart.nBigBlindIdx = m_nBigBlindIdx ;
	msgStart.nLittleBlindIdx = m_nLittleBlindIdx ;
	sendRoomMsg(&msgStart,sizeof(msgStart));

	// send card msg ;
	stMsgTaxasRoomPrivateCard msgPrivate ;
	msgPrivate.nPlayerCnt = (uint8_t)getPlayerCntWithState(eRoomPeer_CanAct) ;
	uint16_t nBuferLen = sizeof(msgPrivate) + sizeof(stTaxasHoldCardItems) * msgPrivate.nPlayerCnt;
	char* pBuffer = new char[nBuferLen] ;
	uint16_t nOffset = 0 ;
	memcpy(pBuffer,&msgPrivate,sizeof(msgPrivate));
	nOffset += sizeof(msgPrivate);

	for ( uint8_t nIdx = 0 ; nIdx < getSeatCount() ; ++nIdx)
	{
		auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
		if ( pPlayer == nullptr || ( pPlayer->isHaveState(eRoomPeer_CanAct) == false ) )
		{
			continue; 
		}

		stTaxasHoldCardItems privateCards ;
		privateCards.cPlayerIdx = nIdx ;
		privateCards.vCards[0] = pPlayer->getPeerCardByIdx(0);
		privateCards.vCards[1] = pPlayer->getPeerCardByIdx(1);
		memcpy(pBuffer + nOffset , &privateCards,sizeof(privateCards) );
		nOffset += sizeof(privateCards);
	}

	if ( nOffset != nBuferLen )
	{
		LOGFMTE("buffer error for private cards") ;
		return ;
	}
	sendRoomMsg((stMsg*)pBuffer,nBuferLen) ;
	delete[] pBuffer ;
	pBuffer = NULL ;
}
Beispiel #29
0
void stGroupItem::addMember(uint32_t nMemberUID )
{
#ifdef _DEBUG
	if ( isHaveMember(nMemberUID) )
	{
		LOGFMTE("already have member uid = %u , why add twice ? group id = %u",nMemberUID,nGroupID) ;
		return ;
	}
#endif // _DEBUG
	vMembers.push_back(nMemberUID) ;
}
Beispiel #30
0
void CGateClientMgr::RemoveClientGate(stGateClient* pGateClient )
{
	if ( pGateClient == NULL )
	{
		LOGFMTE("why remove a null client ") ;
		return ;
	}

	MAP_NETWORKID_GATE_CLIENT::iterator iterN = m_vNetWorkIDGateClientIdx.find(pGateClient->nNetWorkID) ;
	if ( iterN != m_vNetWorkIDGateClientIdx.end() )
	{
		m_vNetWorkIDGateClientIdx.erase(iterN) ;
	}
	else
	{
		LOGFMTE("can not find net work id = %d to remove",pGateClient->nNetWorkID ) ;
	}
	
	MAP_SESSIONID_GATE_CLIENT::iterator iterS = m_vSessionGateClient.find(pGateClient->nSessionId );
	if ( iterS != m_vSessionGateClient.end() )
	{
		m_vSessionGateClient.erase(iterS) ;
	}
	else
	{
		LOGFMTD("can not find session id = %d to remove",pGateClient->nSessionId ) ;
	}

	iterS = m_vWaitToReconnect.find(pGateClient->nSessionId) ;
	if ( iterS != m_vWaitToReconnect.end() )
	{
		m_vWaitToReconnect.erase(iterS) ;
	}
	else
	{
		LOGFMTE("why can not find session id = %d to remove from vWaiReconecte",pGateClient->nSessionId) ;
	}
	
	pGateClient->Reset(0,INVALID_CONNECT_ID,NULL) ;
	m_vGateClientReserver.push_back(pGateClient) ;
}