Beispiel #1
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();
        }
    }
}
BOOL CDealCMDThread::Command_ReqCMDStatus(BOOL bSuccess)
{
	NM_CMD_S nmCmd;
	memset(&nmCmd,0,sizeof(NM_CMD_S));
	nmCmd.dwCmd = bSuccess ? CMD_SUCCESS : CMD_ERROR;
	return SendMsgToClient(&nmCmd,sizeof(NM_CMD_S));
}
Beispiel #3
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 #4
0
void CPlayer::OnAnotherClientLoginThisPeer(unsigned int nSessionID )
{
	// tell prelogin client to disconnect ;
	stMsgPlayerOtherLogin msg ;
	SendMsgToClient((char*)&msg,sizeof(msg)) ;

	if ( m_nTaxasRoomID != 0 )  // order to leave 
	{
		stMsgOrderTaxasPlayerLeave msgLeave ;
		msgLeave.nRoomID = m_nTaxasRoomID ;
		CGameServerApp::SharedGameServerApp()->SendMsg(GetSessionID(),(char*)&msgLeave,sizeof(msgLeave) ) ;
	}

	CLogMgr::SharedLogMgr()->ErrorLog("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 ;
	for ( int i = ePlayerComponent_None; i < ePlayerComponent_Max ; ++i )
	{
		IPlayerComponent* p = m_vAllComponents[i] ;
		if ( p )
		{
			p->OnOtherDoLogined();
		}
	}
}
Beispiel #5
0
static void AsyncResponse_AddBugTestHandler
(
    void* contextPtr
)
{
    le_msg_MessageRef_t _msgRef;
    _Message_t* _msgPtr;
    _ServerData_t* serverDataPtr = (_ServerData_t*)contextPtr;


    // Will not be used if no data is sent back to client
    __attribute__((unused)) uint8_t* _msgBufPtr;

    // Create a new message object and get the message buffer
    _msgRef = le_msg_CreateMsg(serverDataPtr->clientSessionRef);
    _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    _msgPtr->id = _MSGID_AddBugTestHandler;
    _msgBufPtr = _msgPtr->buffer;

    // Always pack the client context pointer first
    _msgBufPtr = PackData( _msgBufPtr, &(serverDataPtr->contextPtr), sizeof(void*) );

    // Pack the input parameters


    // Send the async response to the client
    LE_DEBUG("Sending message to client session %p : %ti bytes sent",
             serverDataPtr->clientSessionRef,
             _msgBufPtr-_msgPtr->buffer);
    SendMsgToClient(_msgRef);
}
// 发送系统信息到客户端
BOOL CDealCMDThread::Command_SendSystemInfo()
{
	SYSTEM_INFO_S emSysInfo;
	FillSystemInfo(emSysInfo);
	
	NM_CMD_S nmCmd;
	memset(&nmCmd,0,sizeof(NM_CMD_S));
	nmCmd.dwCmd = CMD_GETSYSTEMINFO;
	memcpy(nmCmd.pBuff , &emSysInfo,sizeof(SYSTEM_INFO_S));

	return SendMsgToClient(&nmCmd,sizeof(NM_CMD_S));
}
void ParseTheBuff(char * buffer, int *sock_array, int clientsd)
{
	char *reqline[5];
	reqline[0] = strtok (buffer, "$");
	reqline[1] = strtok (NULL, "$");
	reqline[2] = strtok (NULL, "$");
	reqline[3] = strtok (NULL, "$");
	reqline[4] = strtok (NULL, "$");

	if(reqline[0]!=NULL){
	printf("the client id is :%s\n\n",reqline[0]);
	printf("the access group name is :%s\n\n",reqline[1]);
	printf("the Message type is :%s\n\n",reqline[2]);
	printf("the filename is :%s\n\n",reqline[3]);
	printf("the recd. key is :%s\n\n",reqline[4]);

	if (strcmp(reqline[2], "IN")==0)
	{
		return ;
		// add clientid and socket desc details to socket table
		//
	}
	else if(strcmp(reqline[2], "AD")==0)
	{

		// send message to other clients with info about the new file
		unsigned char key[100];
		int i=0;
		strcpy(key,reqline[4]);
		while(key[i]!='\0')
		{

			printf(" %d=%d ",i,key[i]);
			i++;
		}
	     printf("the buffer is : %s\n",buffer);
	     SendMsgToClient(clientsd,sock_array,reqline[4],reqline[3]);

	}
	else if(strcmp(reqline[2], "TE")==0)
	{
		//sock_arr[clie]=0;
		close(clientsd);
		exit(clientsd);
		// Remove client entry from socket table and close the corresponding SD

	}

	}
}
Beispiel #8
0
static void AsyncResponse_TestCallback
(
    uint32_t data,
    const char* name,
    int dataFile,
    void* contextPtr
)
{
    le_msg_MessageRef_t _msgRef;
    _Message_t* _msgPtr;
    _ServerData_t* serverDataPtr = (_ServerData_t*)contextPtr;

    // This is a one-time handler; if the server accidently calls it a second time, then
    // the client sesssion ref would be NULL.
    if ( serverDataPtr->clientSessionRef == NULL )
    {
        LE_FATAL("Handler passed to TestCallback() can't be called more than once");
    }

    // Will not be used if no data is sent back to client
    __attribute__((unused)) uint8_t* _msgBufPtr;

    // Create a new message object and get the message buffer
    _msgRef = le_msg_CreateMsg(serverDataPtr->clientSessionRef);
    _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    _msgPtr->id = _MSGID_TestCallback;
    _msgBufPtr = _msgPtr->buffer;

    // Always pack the client context pointer first
    _msgBufPtr = PackData( _msgBufPtr, &(serverDataPtr->contextPtr), sizeof(void*) );

    // Pack the input parameters
    _msgBufPtr = PackData( _msgBufPtr, &data, sizeof(uint32_t) );
    _msgBufPtr = PackString( _msgBufPtr, name );
    le_msg_SetFd(_msgRef, dataFile);

    // Send the async response to the client
    LE_DEBUG("Sending message to client session %p : %ti bytes sent",
             serverDataPtr->clientSessionRef,
             _msgBufPtr-_msgPtr->buffer);
    SendMsgToClient(_msgRef);

    // The registered handler has been called, so no longer need the server data.
    // Explicitly set clientSessionRef to NULL, so that we can catch if this function gets
    // accidently called again.
    serverDataPtr->clientSessionRef = NULL;
    le_mem_Release(serverDataPtr);
}
Beispiel #9
0
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 ;
}