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 NetworkLogic::connectReturn(int errorCode, const ExitGames::Common::JString& errorString) { EGLOG(ExitGames::Common::DebugLevel::INFO, L""); if(errorCode) { EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"%ls", errorString.cstr()); mStateAccessor.setState(STATE_DISCONNECTING); return; } mOutputListener->writeLine(L"connected"); mStateAccessor.setState(STATE_CONNECTED); }
void NetworkLogic::connectReturn(int errorCode, const ExitGames::Common::JString& errorString) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_INFO, L""); if(errorCode) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_ERRORS, L"%ls", errorString.cstr()); mStateAccessor.setState(STATE_DISCONNECTING); return; } mOutputListener->writeLine(L"connected"); mStateAccessor.setState(STATE_CONNECTED); }
void NetworkLogic::leaveRoomReturn(int errorCode, const ExitGames::Common::JString& errorString) { EGLOG(ExitGames::Common::DebugLevel::INFO, L""); if(errorCode) { EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"%ls", errorString.cstr()); mOutputListener->writeLine(L"opLeaveRoom() failed: " + errorString); mStateAccessor.setState(STATE_DISCONNECTING); return; } mOutputListener->writeLine(L"game room has been successfully left"); mStateAccessor.setState(STATE_LEFT); }
void NetworkLogic::leaveRoomReturn(int errorCode, const ExitGames::Common::JString& errorString) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_INFO, L""); if(errorCode) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_ERRORS, L"%ls", errorString.cstr()); mOutputListener->writeLine(L"opLeaveRoom() failed: " + errorString); mStateAccessor.setState(STATE_DISCONNECTING); return; } mOutputListener->writeLine(L"game room has been successfully left"); mStateAccessor.setState(STATE_LEFT); }
void NetworkLogic::joinRoomReturn(int localPlayerNr, const ExitGames::Common::Hashtable& gameProperties, const ExitGames::Common::Hashtable& playerProperties, int errorCode, const ExitGames::Common::JString& errorString) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_INFO, L""); if(errorCode) { PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_ERRORS, L"%ls", errorString.cstr()); mOutputListener->writeLine(L"opJoinRoom() failed: " + errorString); mStateAccessor.setState(STATE_CONNECTED); return; } PhotonPeer_sendDebugOutput(&mLoadBalancingClient, DEBUG_LEVEL_INFO, L"localPlayerNr: %d", localPlayerNr); mOutputListener->writeLine(L"game room \"" + mLoadBalancingClient.getCurrentlyJoinedRoom().getName() + "\" has been successfully joined"); mOutputListener->writeLine(L"regularly sending dummy events now"); mStateAccessor.setState(STATE_JOINED); }
void NetworkLogic::createRoomReturn(int localPlayerNr, const ExitGames::Common::Hashtable& /*gameProperties*/, const ExitGames::Common::Hashtable& /*playerProperties*/, int errorCode, const ExitGames::Common::JString& errorString) { EGLOG(ExitGames::Common::DebugLevel::INFO, L""); if(errorCode) { EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"%ls", errorString.cstr()); mOutputListener->writeLine(L"opCreateRoom() failed: " + errorString); mStateAccessor.setState(STATE_CONNECTED); return; } EGLOG(ExitGames::Common::DebugLevel::INFO, L"localPlayerNr: %d", localPlayerNr); mOutputListener->writeLine(L"game room \"" + mLoadBalancingClient.getCurrentlyJoinedRoom().getName() + "\" has been created"); mOutputListener->writeLine(L"regularly sending dummy events now"); S3DX::user.sendEvent(S3DX::application.getCurrentUser(), S3DX::AIVariable("myPhotonCloud_AI"), S3DX::AIVariable("onCurrentUserEnterRoom"), S3DX::AIVariable(localPlayerNr)); mStateAccessor.setState(STATE_JOINED); }
void NetworkLogic::joinRoomReturn(int localPlayerNr, const ExitGames::Common::Hashtable& /*gameProperties*/, const ExitGames::Common::Hashtable& /*playerProperties*/, int errorCode, const ExitGames::Common::JString& errorString) { EGLOG(ExitGames::Common::DebugLevel::INFO, L""); if(errorCode) { EGLOG(ExitGames::Common::DebugLevel::ERRORS, L"%ls", errorString.cstr()); mOutputListener->writeLine(L"opJoinRoom() failed: " + errorString); mStateAccessor.setState(STATE_CONNECTED); return; } EGLOG(ExitGames::Common::DebugLevel::INFO, L"localPlayerNr: %d", localPlayerNr); mOutputListener->writeLine(L"game room \"" + mLoadBalancingClient.getCurrentlyJoinedRoom().getName() + "\" has been successfully joined"); mOutputListener->writeLine(L"regularly sending dummy events now"); S3DX::user.sendEvent(S3DX::application.getCurrentUser(), S3DX::AIVariable("myPhotonCloud_AI"), S3DX::AIVariable("onCurrentUserEnterRoom"), S3DX::AIVariable(localPlayerNr)); //Add other players to the session right now: ExitGames::Common::JVector<ExitGames::LoadBalancing::Player> mPlayers = mLoadBalancingClient.getCurrentlyJoinedRoom().getPlayers(); for (unsigned int i=0; i<mPlayers.getSize(); i++){ S3DX::user.sendEvent(S3DX::application.getCurrentUser(), S3DX::AIVariable("myPhotonCloud_AI"), S3DX::AIVariable("onUserEnterRoom"), S3DX::AIVariable(mPlayers[i].getNumber())); } mStateAccessor.setState(STATE_JOINED); }
void PhotonLib::debugReturn(PhotonPeer_DebugLevel /*debugLevel*/, const ExitGames::Common::JString& string) { fprintf(stderr, "%s\n", string.ANSIRepresentation().cstr()); }
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); }