Esempio n. 1
0
void RPC_HandleEvent(void *eventHandle)
{
	UInt8 clientId = 0;
	ResultDataBuffer_t *dataBuf;
	Result_t res = RESULT_OK;

	PACKET_BufHandle_t bufHandle = (PACKET_BufHandle_t) eventHandle;

	dataBuf = capi2_malloc(sizeof(ResultDataBuffer_t));

	if (dataBuf) {
		dataBuf->refCount = 1;
		res =
		    RPC_DeserializeMsg(RPC_PACKET_GetBufferData(bufHandle),
				       RPC_PACKET_GetBufferLength(bufHandle),
				       dataBuf);

		if (res == RESULT_OK) {
			Boolean isUnsolicited;
			UInt8 clientIndex =
			    GetClientIndex(dataBuf, &isUnsolicited);
			clientId = RPC_SYS_GetClientID(clientIndex);

			RPC_USER_LOCK(gRpcLock);

			RPC_DispatchMsg(dataBuf);

			RPC_USER_UNLOCK(gRpcLock);
		} else {
			capi2_free(dataBuf);
		}
	}

	RPC_PACKET_FreeBufferEx(bufHandle, clientId);
}
Esempio n. 2
0
void CGameServer::SetClientNickname(int iClient, const tstring& sNickname)
{
	if (iClient == GetClientIndex() && Game()->GetNumLocalPlayers())
	{
		Game()->GetLocalPlayer(0)->SetPlayerName(sNickname);
		return;
	}

	for (size_t i = 0; i < Game()->GetNumPlayers(); i++)
	{
		if (Game()->GetPlayer(i)->GetClient() == iClient)
		{
			Game()->GetPlayer(i)->SetPlayerName(sNickname);
			return;
		}
	}

	TMsg(sprintf(tstring("Can't find client %d to give nickname %s.\n"), iClient, sNickname.c_str()));
}
Esempio n. 3
0
void RPC_DispatchMsg(ResultDataBuffer_t* pDataBuf)
{
	UInt8 clientIndex;
	Boolean isUnsolicited = FALSE;
	RPC_Msg_t* pMsg = &(pDataBuf->rsp.rootMsg);
	int i;
	
	pDataBuf->refCount = 1;//set

	//Handle Ack first
	if(pMsg->msgId == MSG_CAPI2_ACK_RSP)
	{
		RPC_Ack_t	*ackRsp = (RPC_Ack_t*)pMsg->dataBuf;
		clientIndex = GetClientIndex(pDataBuf, &isUnsolicited);
		
		if(gClientMap[clientIndex].ackCb)
		{
			gClientMap[clientIndex].ackCb(pMsg->tid, pMsg->clientID, ackRsp->ackResult, ackRsp->ackUsrData);
			RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
		}
	}
	else
	{
		clientIndex = GetClientIndex(pDataBuf, &isUnsolicited);

		if(pDataBuf->rsp.msgType == RPC_TYPE_REQUEST)
		{
			if(gClientMap[clientIndex].reqCb != NULL)
			{
				(gClientMap[clientIndex].reqCb)(pMsg, (ResultDataBufHandle_t)pDataBuf, gClientMap[clientIndex].userData);
			}
		}
		else //RPC_TYPE_RESPONSE
		{
			if(clientIndex > 0 && (pMsg->tid != 0 || pMsg->clientID != 0) && !(isUnsolicited))
			{
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Unicast msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				if(gClientMap[clientIndex].respCb != NULL)
				{
					(gClientMap[clientIndex].respCb)(pMsg, (ResultDataBufHandle_t)pDataBuf,gClientMap[clientIndex].userData);
				}
			}
			else if((pMsg->tid == 0 && pMsg->clientID == 0) || isUnsolicited)//unsolicited
			{
				UInt32 numClients = 0;
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast msgId=0x%x xdrClient=%d tid=%d cid=%d unsol=%d ", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				//Set the ref count first
				pDataBuf->refCount = 0;//reset
				for(i=1;i<=gClientIndex;i++)
				{
					if(gClientMap[i].respCb != NULL && (gClientLocalMap[i].notifyUnsolicited || clientIndex == i) )
						pDataBuf->refCount++;
				}
				
				numClients = pDataBuf->refCount;
				//Broadcast the message
				for(i=1;i<=gClientIndex;i++)
				{
					if(gClientMap[i].respCb != NULL && (gClientLocalMap[i].notifyUnsolicited || clientIndex == i) )
					{
						_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Client ( Notify ) msgId=0x%x index=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
						(gClientMap[i].respCb)(pMsg, (ResultDataBufHandle_t)pDataBuf,gClientMap[i].userData);
					}
					else
					{
						_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Client ( Skip ) msgId=0x%x index=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
					}

				}

				//No clients handle this message?
				if(numClients == 0)
				{
					_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg Broadcast Ignored msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d regUnsol=%d", pMsg->msgId, i, pMsg->tid, pMsg->clientID, isUnsolicited, gClientLocalMap[i].notifyUnsolicited));
					
					pDataBuf->refCount = 1;
					RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
				}
			}
			else
			{
				_DBG_(RPC_TRACE_INFO("RPC_DispatchMsg IGNORED msgId=0x%x cIndex=%d tid=%d cid=%d unsol=%d", pMsg->msgId, clientIndex, pMsg->tid, pMsg->clientID, isUnsolicited));
				RPC_SYSFreeResultDataBuffer((ResultDataBufHandle_t)pDataBuf);
			}
		}//RPC_TYPE_RESPONSE
	}
}