示例#1
0
void NetworkLogic::customEventAction(int playerNr, nByte eventCode, const ExitGames::Common::Hashtable& eventContent)
{
	// you do not receive your own events, unless you specify yourself as one of the receivers explicitly, so you must start 2 clients, to receive the events, which you have sent, as sendEvent() uses the default receivers of opRaiseEvent() (all players in same room like the sender, except the sender itself)
	
	//mOutputListener->write(L"recieve something");
	if(eventCode==EV_PLAYERINFO){
		if(eventContent.getValue(USER_NAME_KEY)){
			CCLOG("RECIEVE PLAYER NAME");
			ExitGames::Common::JString n;
			n = ((ExitGames::Common::ValueObject<ExitGames::Common::JString>*)(eventContent.getValue(USER_NAME_KEY)))->getDataCopy();
			CCLOG(n.UTF8Representation().cstr());
			if(mGameScene->oppInfo->id != -1){

			}else{
				std::strcpy(mGameScene->oppInfo->user_name, n.UTF8Representation().cstr());
				mGameScene->oppInfo->id = 2;
				sendEvent(EV_PLAYERINFO);
				mGameScene->netStartGame();
			}
		}
	}else if(eventCode == EV_DISCONNECT){
		CCLOG("RECIEVE DISCONNECT");
		mGameScene->oppDisconnect();
	}else if(eventCode == EV_HPCHANGE){
		
		int oppHp = mGameScene->oppInfo->hp;
		oppHp = ((ExitGames::Common::ValueObject<int>)(eventContent.getValue(HP_CHANGE_KEY))).getDataCopy();
		mGameScene->oppInfo->setHp(oppHp);
		//mGameScene->oppInfo->hp = oppHp;
	}else if(eventCode == EV_LOST){
		mGameScene->oppDisconnect();
		//mGameScene->showWin(NULL);
	}
}
void PhotonLib::onEvent(const ExitGames::Photon::EventData& eventData)
{
	ExitGames::Common::ValueObject<ExitGames::Common::Hashtable> objEventDataContent = eventData.getParameterForCode(P_DATA);
	ExitGames::Common::Hashtable* eventDataContent = objEventDataContent.getDataAddress();
	switch(eventData.getCode())
	{
	case 101:
		if(eventDataContent->getValue((nByte)0))
			mReceiveCount = ((ExitGames::Common::ValueObject<int64>*)(eventDataContent->getValue((nByte)0)))->getDataCopy();
		if(mState == State::SENT_DATA && mReceiveCount >= mSendCount)
		{
			mState = State::RECEIVED_DATA;
			mSendCount = 0;
			mReceiveCount = 0;
		}
		break;
	default:
		break;
	}
}
示例#3
0
文件: Game.cpp 项目: Dezlan/EchoBlade
void Game::updateStateFromProps(const ExitGames::Common::Hashtable& changedCustomProps)
{
	const int BUF_SIZE = 20; // 1 int with some prefix
	char buf[BUF_SIZE];
	for(int i = 0;i < TILE_COUNT;++i)
	{		
		sprintf(buf, "%d", i);
		Object const* v = changedCustomProps.getValue(buf);
		if(v)
			tiles[i] = ((ValueObject<nByte>*)v)->getDataCopy();
	}
	Object const* v = changedCustomProps.getValue("flips");
	if(v)
	{
		if(v->getDimensions() == 1 && v->getSizes()[0] == 2) 
		{
			nByte* data = ((ValueObject<nByte*>*)v)->getDataCopy();
			flippedTiles[0] = data[0];
			flippedTiles[1] = data[1];
		}
		else
			view->warn("Bad flips incoming data");
	}
	
	v = changedCustomProps.getValue("pt");
	if(v)
		nextTurnPlayer = ((ValueObject<int>*)v)->getDataCopy();
	v = changedCustomProps.getValue("t#");
	if(v)
		turnNumber = ((ValueObject<int>*)v)->getDataCopy();

	sprintf(buf, "pt%d", myActorNr());
	v = changedCustomProps.getValue(buf);
	if(v)
		myPoints = ((ValueObject<nByte>*)v)->getDataCopy();
	v = changedCustomProps.getValue("abandoned");
	if(v)
		abandoned = ((ValueObject<bool>*)v)->getDataCopy();

	int otherId = lbl->getNextPlayer(myActorNr());
	if(otherId != myActorNr())
	{
		sprintf(buf, "pt%d", otherId);
		v = changedCustomProps.getValue(buf);
		if(v)
			othersPoints = ((ValueObject<nByte>*)v)->getDataCopy();
	}

	logic();
}
bool LoadBalancingListener::updateGridSize(const ExitGames::Common::Hashtable& props) 
{
	if(props.contains("s")) 
	{
		const Object* v = props.getValue("s");
		switch(v->getType()) 
		{
		case 'i':
			mGridSize = ((ValueObject<int>*)v)->getDataCopy();
			return true;
		case 'd':
			mGridSize = (int)((ValueObject<double>*)v)->getDataCopy();
			return true;
		}
	}
	return false;
}
void LoadBalancingListener::customEventAction(int playerNr, nByte eventCode, const Object& eventContentObj)
{
	ExitGames::Common::Hashtable eventContent = ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>(eventContentObj).getDataCopy();
	if(eventCode == 1)
	{
		Object const* obj = eventContent.getValue("1");
		if(obj == NULL) obj = eventContent.getValue((nByte)1);
		if(obj == NULL) obj = eventContent.getValue(1);
		if(obj == NULL) obj = eventContent.getValue(1.0);
		if(obj) 
		{
			int color = (int)(obj->getType() == 'd' ?  ((ValueObject<double>*)obj)->getDataCopy() : ((ValueObject<int>*)obj)->getDataCopy());
			mpView->changePlayerColor(playerNr, color);
		}
		else 
			mpView->warn("bad color event");
	}
	else if(eventCode == 2)
	{
		Object const* obj = eventContent.getValue("1");
		if(obj == NULL) obj = eventContent.getValue((nByte)1);
		if(obj == NULL) obj = eventContent.getValue(1);
		if(obj == NULL) obj = eventContent.getValue(1.0);
		if(obj && obj->getDimensions() == 1 && obj->getSizes()[0] == 2) 
		{
			int x = 0; int y = 0;
			if(obj->getType() == 'd') 
			{
				double* data = ((ValueObject<double*>*)obj)->getDataCopy();
				x = (int)data[0];
				y = (int)data[1];
			}
			if(obj->getType() == 'i') 
			{
				int* data = ((ValueObject<int*>*)obj)->getDataCopy();
				x = (int)data[0];
				y = (int)data[1];
			}
			else if(obj->getType() == 'b') 
			{
				nByte* data = ((ValueObject<nByte*>*)obj)->getDataCopy();
				x = (int)data[0];
				y = (int)data[1];
			}
			else if(obj->getType() == 'z') 
			{
				Object* data = ((ValueObject<Object*>*)obj)->getDataCopy();
				if(data[0].getType() == 'i') 
				{
					x = ((ValueObject<int>*)(data + 0))->getDataCopy();
					y = ((ValueObject<int>*)(data + 1))->getDataCopy();
				}
				else 
				{
					x = (int)((ValueObject<double>*)(data + 0))->getDataCopy();
					y = (int)((ValueObject<double>*)(data + 1))->getDataCopy();
				}
			}
			mpView->changePlayerPos(playerNr, x, y);
		}
		else 
			mpView->warn("Bad position event");
	}
}
示例#6
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);
}