void PhotonLib::debugReturn(PhotonPeer_DebugLevel /*debugLevel*/, const ExitGames::Common::JString& string)
{
	fprintf(stderr, "%s\n", string.ANSIRepresentation().cstr());
}
Example #2
0
void CPhotonLib::onEvent(const ExitGames::Photon::EventData& eventData)
{
	nByte x = 0, y = 0;
	ExitGames::Common::JString n;

	int c = 0, p = 0, amountOfActors = 0;
	int* actors = 0;

	ExitGames::Common::Hashtable* eventDataContent = NULL;

	CCLOG(eventData.toString(true, true).ANSIRepresentation());

	ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>* objEventData;
	objEventData = (ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>*)(eventData.getParameters().getValue(P_DATA));
	
	if(objEventData)
		eventDataContent = objEventData->getDataAddress();

	switch(eventData.getCode())
	{
	case EV_MOVE:
		CCLOG("Client: onEvent : EV_MOVE");
		try
		{
			if(eventData.getParameters().getValue(P_ACTORNR))
				p = ((ExitGames::Common::ValueObject<int>*)(eventData.getParameters().getValue(P_ACTORNR)))->getDataCopy();
			if(eventDataContent->getValue(STATUS_PLAYER_POS_X))
				x = ((ExitGames::Common::ValueObject<nByte>*)(eventDataContent->getValue(STATUS_PLAYER_POS_X)))->getDataCopy();
			if(eventDataContent->getValue(STATUS_PLAYER_POS_Y))
				y = ((ExitGames::Common::ValueObject<nByte>*)(eventDataContent->getValue(STATUS_PLAYER_POS_Y)))->getDataCopy();

			CCLOG("EV_MOVE-Data received: %d   %d   %d", p, x, y);

			//recieve data
			//mpSample->updatePlayerPositions(p, x, y);
		}
		catch(...)
		{
			CCLOG("Exception on event EV_MOVE");
		}
		break;
	case EV_PLAYERINFO:
		CCLOG("Client: onEvent : EV_PLAYERINFO");
		try
		{
			if(eventData.getParameters().getValue(P_ACTORNR))
				p = ((ExitGames::Common::ValueObject<int>*)(eventData.getParameters().getValue(P_ACTORNR)))->getDataCopy();

			if(eventDataContent->getValue(STATUS_PLAYER_NAME))
				n = ((ExitGames::Common::ValueObject<ExitGames::Common::JString>*)(eventDataContent->getValue(STATUS_PLAYER_NAME)))->getDataCopy();
			if(eventDataContent->getValue(STATUS_PLAYER_COLOR))
				c = ((ExitGames::Common::ValueObject<int>*)(eventDataContent->getValue(STATUS_PLAYER_COLOR)))->getDataCopy();

			CCLOG("EV_PLAYERINFO-Data received: %d   %s   %d", p, n.ANSIRepresentation().cstr(), c);

			/*for(int i=0; i<mpSample->getCurrentPlayers(); i++)
			{
				if(mpSample->player[i].number == p)
				{
					strcpy(mpSample->player[i].username, n.ANSIRepresentation());
					mpSample->player[i].setColor(c);
					mpSample->player[i].x = mpSample->START_X;
					mpSample->player[i].y = mpSample->START_Y;
					mpSample->player[i].hasPlayerInfo = true;
				}
			}*/
		}
		catch(...)
		{
			CCLOG("Exception on event EV_PLAYERINFO");
		}
		break;
	case EV_RT_JOIN:
		CCLOG("Client: onEvent : EV_RT_JOIN");
		try
		{
			if(eventData.getParameters().getValue(P_ACTORNR))
				p = ((ExitGames::Common::ValueObject<int>*)(eventData.getParameters().getValue(P_ACTORNR)))->getDataCopy();
			if(eventData.getParameters().getValue(P_ACTOR_LIST))
				actors = ((ExitGames::Common::ValueObject<int*>*)(eventData.getParameters().getValue(P_ACTOR_LIST)))->getDataCopy();
			if(eventData.getParameters().getValue(P_ACTOR_LIST))
				amountOfActors = *((ExitGames::Common::ValueObject<int*>*)(eventData.getParameters().getValue(P_ACTOR_LIST)))->getSizes();
		}
		catch(...)
		{
			CCLOG("Exception on event EV_RT_JOIN");
		}

		CCLOG("Client %d joined complete", p);
		CCLOG("amount of connected Actors: %d", amountOfActors);
		for(int i=0; i<amountOfActors; i++)
			CCLOG("connected Actors: %d", actors[i]);

		//if(mpSample->player[0].number == -1) // if local player is the joining player
		//{
		//	mpSample->player[0].number = p;
		//	for(int i=0; i<amountOfActors; i++)
		//	{
		//		if(actors[i] != mpSample->player[0].number) // for every existing player except local player
		//		{
		//			mpSample->player[mpSample->getCurrentPlayers()].erasePlayerInfo(actors[i]);
		//			mpSample->increaseCurrentPlayers();
		//		}
		//	}
		//}
		//else
		//{
		//	mpSample->player[mpSample->getCurrentPlayers()].erasePlayerInfo(p);
		//	mpSample->increaseCurrentPlayers();
		//}
		sendData(EV_PLAYERINFO);
		break;
	case EV_RT_LEAVE:
		try
		{
			if(eventData.getParameters().getValue(P_ACTORNR))
				p = ((ExitGames::Common::ValueObject<int>*)(eventData.getParameters().getValue(P_ACTORNR)))->getDataCopy();
			if(eventData.getParameters().getValue(P_ACTOR_LIST))
				actors = ((ExitGames::Common::ValueObject<int*>*)(eventData.getParameters().getValue(P_ACTOR_LIST)))->getDataCopy();
			if(eventData.getParameters().getValue(P_ACTOR_LIST))
				amountOfActors = *((ExitGames::Common::ValueObject<int*>*)(eventData.getParameters().getValue(P_ACTOR_LIST)))->getSizes();
		}
		catch(...)
		{
			CCLOG("Exception on event EV_RT_LEAVE");
		}

		CCLOG("Client %d leaving complete", p);
		CCLOG("amount of connected Actors: %d", amountOfActors);
		for(int i=0; i<amountOfActors; i++)
			CCLOG("connected Actors: %d", actors[i]);

		/*int aP = mpSample->getCurrentPlayers();
		for(int i=0; i<aP; i++)
		{
			if(mpSample->player[i].number == p)
			{
				mpSample->removePlayerInfo(i);

				if(i != aP-1)
					mpSample->player[i] = mpSample->player[aP-1];
				mpSample->decreaseCurrentPlayers();
				aP = 0;
				CCLOG("Client %d removed", p);
			}
		}*/
		break;
	}
	FREE(actors);
}