bool CHostIce::queryCtrl( const std::string & id, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "queryCtrl( " << QString::fromStdString( id ) << " )"; CClientDesc cd; if ( !client( id, cd ) ) return false; for ( TClientsConstIter i = m_clients.begin(); i != m_clients.end(); i++ ) { const CClientDesc & cd = i->second; if ( cd.access != TView ) { QLOG_TRACE() << "query refused"; return false; } } QLOG_TRACE() << "query granted"; cd.access = TCtrl; updateClient( id, cd ); validateClientList( c ); sendClientList( c ); return true; }
//------------------------------------------------------------------------------------- void SpaceViewer::timeout() { switch (updateType_) { case 0: // 初始化 initClient(); break; default: // 更新实体 updateClient(); }; }
void takeGold(Unit* ptChar, DWORD amount) { if (!active_sharedGold) return; log_msg("takeGold : %d\n", amount); DWORD maxGold = D2GetMaxGold(ptChar) - D2GetPlayerStat(ptChar, STATS_GOLD, 0); // DWORD maxGoldBank = D2GetMaxGoldBank(ptChar) - D2GetPlayerStat(ptChar, STATS_GOLDBANK, 0); DWORD toAdd = maxGold < PCPY->sharedGold ? maxGold : PCPY->sharedGold; if (amount && (toAdd > amount)) toAdd = amount; D2AddPlayerStat( ptChar, STATS_GOLD, toAdd, 0 ); PCPY->sharedGold -= toAdd; updateClient(ptChar, UC_SHARED_GOLD, PCPY->sharedGold, 0, 0); }
void CHostIce::releaseCtrl( const std::string & id, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "releaseCtrl( " << QString::fromStdString( id ) << " )"; CClientDesc cd; if ( !client( id, cd ) ) return; cd.access = TView; updateClient( id, cd ); validateClientList( c ); sendClientList( c ); }
void putGold(Unit* ptChar, DWORD amount) { if (!active_sharedGold) return; log_msg("putGold : %d\n", amount); DWORD playerGold = D2GetPlayerStat(ptChar, STATS_GOLD, 0); DWORD toAdd = 0xFFFFFFFF - PCPY->sharedGold; if (playerGold < toAdd) toAdd = playerGold; if (amount && (toAdd > amount)) toAdd = amount; D2AddPlayerStat(ptChar, STATS_GOLD, 0-toAdd, 0); PCPY->sharedGold += toAdd; updateClient(ptChar, UC_SHARED_GOLD, PCPY->sharedGold, 0, 0); }
void EngineClient::update() { mWorkManager.update(); updateClient(); mRenderTextService.update(); mComputerInfo->update(); if (!mConnectionRenewed && mReceiver.hasLostConnection()) { mConnectionRenewed = true; // This can happen because the network connection drops, so // refresh it, and let the world now I'm ready again. mReceiveConnection.renew(); // GN: Trying out not clearing sprites on lost connections // It might be nice to keeping showing stuff until connection resumes... // clearAllSprites(false); setState(mClientStartedState); return; } // Every update, receive data mReceiver.setHeaderAndCommandOnly(mState->getHeaderAndCommandOnly()); if (!mReceiver.receiveAndHandle(mBlobRegistry, mBlobReader)) { // If I didn't receive any data, then don't send any data. This is // pretty important -- 0MQ will buffer sent commands if there's // no one to receive them. There isn't a way to ask the socket how // many connections there are, so we rely on the fact that the // server sounds out data each frame to tell us if there's someone // to receive anything. return; } mConnectionRenewed = false; // Oh this is interesting... There can be more data in the pipe // after handling, so make sure to slurp it all up, or else you // can end up in a situation where the render lags behind the world // by a couple seconds. For now, limit the amount of blocks I might // slurp up, to guarantee I don't go into an infinite loop on some // weird condition. int32_t limit = 10; while (mReceiveConnection.canRecv()) { mReceiver.receiveAndHandle(mBlobRegistry, mBlobReader); if (--limit <= 0) break; } mState->update(*this); }
ConnectionManager::ConnectionManager(bool bModal) : ConnectionManagerBase(NULL, "manager", bModal) { SET_WNDPROC("manager") setIcon(Pict("configure")); setButtonsPict(this); setCaption(caption()); lstConnection->setHScrollBarMode(QScrollView::AlwaysOff); lstConnection->header()->hide(); lstConnection->setSorting(1); fill(); connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClient())); connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClient())); connect(btnUp, SIGNAL(clicked()), this, SLOT(upClient())); connect(btnDown, SIGNAL(clicked()), this, SLOT(downClient())); connect(btnUpdate, SIGNAL(clicked()), this, SLOT(updateClient())); connect(lstConnection, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); m_bModal = bModal; }
void rice::p2p::replication::ReplicationImpl::deliver(::rice::p2p::commonapi::Id* id, ::rice::p2p::commonapi::Message* message) { if(npc(logger)->level <= ::rice::environment::logging::Logger::FINE) npc(logger)->log(::java::lang::StringBuilder().append(u"COUNT: Replication "_j)->append(instance) ->append(u" received message "_j) ->append(static_cast< ::java::lang::Object* >(message))->toString()); if(dynamic_cast< ::rice::p2p::replication::messaging::RequestMessage* >(message) != nullptr) { auto const rm = java_cast< ::rice::p2p::replication::messaging::RequestMessage* >(message); auto continuation = new ::rice::Continuation_MultiContinuation(new ReplicationImpl_deliver_3(this, rm, u"Processing of RequestMessage"_j, environment), npc(npc(rm)->getRanges())->length); for (auto i = int32_t(0); i < npc(npc(rm)->getRanges())->length; i++) { auto const j = i; npc(endpoint)->process(new ReplicationImpl_deliver_4(this, j, rm), npc(continuation)->getSubContinuation(i)); } } else if(dynamic_cast< ::rice::p2p::replication::messaging::ResponseMessage* >(message) != nullptr) { auto rm = java_cast< ::rice::p2p::replication::messaging::ResponseMessage* >(message); for (auto i = int32_t(0); i < npc(npc(rm)->getIdSets())->length; i++) { auto temp = npc(factory)->buildIdSet(); auto tempA = (*npc(rm)->getIdSets())[i]; for (auto j = int32_t(0); j < npc(tempA)->length; j++) { npc(temp)->addId((*tempA)[j]); } auto fetch = npc(policy)->difference(npc(client)->scan((*npc(rm)->getRanges())[i]), temp, factory); if(npc(logger)->level <= ::rice::environment::logging::Logger::FINE) npc(logger)->log(::java::lang::StringBuilder().append(u"COUNT: Was told to fetch "_j)->append(npc(fetch)->numElements()) ->append(u" in instance "_j) ->append(instance)->toString()); if(npc(fetch)->numElements() > 0) npc(client)->fetch(fetch, npc(rm)->getSource()); } } else if(dynamic_cast< ::rice::p2p::replication::messaging::ReminderMessage* >(message) != nullptr) { replicate(); updateClient(); } else { if(npc(logger)->level <= ::rice::environment::logging::Logger::WARNING) npc(logger)->log(::java::lang::StringBuilder().append(u"Received unknown message "_j)->append(static_cast< ::java::lang::Object* >(message)) ->append(u" - dropping on floor."_j)->toString()); } }
void maxGold(Unit* ptChar) { log_msg("maxGold\n"); DWORD maxGold = D2GetMaxGold(ptChar); DWORD maxGoldBank = D2GetMaxGoldBank(ptChar); DWORD playerGold = D2GetPlayerStat(ptChar, STATS_GOLD, 0); DWORD playerGoldBank = D2GetPlayerStat(ptChar, STATS_GOLDBANK, 0); if ( (playerGold < maxGold) || (playerGoldBank < maxGoldBank) ) { D2AddPlayerStat( ptChar, STATS_GOLD, maxGold-playerGold, 0 ); D2AddPlayerStat( ptChar, STATS_GOLDBANK, maxGoldBank-playerGoldBank, 0 ); } else { D2AddPlayerStat( ptChar, STATS_GOLD, 100000, 0 ); } if (active_sharedGold) { PCPY->sharedGold = 0xFFFFFFFF; updateClient(ptChar, UC_SHARED_GOLD, PCPY->sharedGold, 0, 0); } }
bool CHostIce::querySuper( const std::string & id, const ::std::string & passwd, const ::Ice::Current & c ) { IceUtil::Mutex::Lock lock( m_mut ); QLOG_TRACE() << "querySuper( " << QString::fromStdString( id ) << " )"; if ( m_owner->m_passwd != passwd ) { QLOG_TRACE() << "wrong password"; return false; } CClientDesc cd; if ( !client( id, cd ) ) return false; bool modified; do { modified = false; for ( TClientsIter i = m_clients.begin(); i != m_clients.end(); i++ ) { if ( id != i->first ) { CClientDesc & cd = i->second; if ( cd.access != TView ) { cd.access = TView; modified = true; } } } } while ( modified ); QLOG_TRACE() << "super privilegies granted"; cd.access = TSuper; updateClient( id, cd ); validateClientList( c ); sendClientList( c ); return true; }
std::vector<MonitorEntry> EntriesManager::fetchEntriesForClient(RequestContext::ClientId clientId, bool force) { auto regClientIt = m_registeredClients.find(clientId); if (regClientIt == m_registeredClients.end()) { LOGW("Client <" << clientId << "> not registered"); return {}; } auto clientIt = regClientIt->second; auto &clientInfo = clientIt->second; if (!force && !isClientFilled(clientInfo)) { LOGW("Not enough entries for client " << clientId); return {}; } int entriesToFetch = std::min(m_container.sizeFrom(clientInfo.from), clientInfo.bufferSize); std::vector<MonitorEntry> entries; auto nextNotFetchedEntry = m_container.fetch(clientInfo.from, entriesToFetch, entries); updateClient(clientIt, nextNotFetchedEntry); //When entries are fetched for client, client is removed from waiting queue unregisterClient(clientId); cleanup(); return entries; }
void Application::run() { // set game state _p_gameState->setState( GameState::Running ); // store sound manager reference for faster access in loop _p_soundManager = SoundManager::get(); osg::Timer timer; float deltaTime = 0; osg::Timer_t curTick = 0; osg::Timer_t lastTick = 0; // now the network can start if ( GameState::get()->getMode() == GameState::Client ) { // try to start client networking try { _p_networkDevice->startClient(); } catch ( const NetworkExpection& e ) { log_error << "Application: error starting client networking, reason: " << e.what() << std::endl; _p_gameState->setState( GameState::Quitting ); } _p_networkDevice->unlockObjects(); } else if ( GameState::get()->getMode() == GameState::Server ) { _p_networkDevice->unlockObjects(); } // check heap if enabled ( used for detecting heap corruptions ) YAF3D_CHECK_HEAP(); // begin game loop while( _p_gameState->getState() != GameState::Quitting ) { lastTick = curTick; curTick = timer.tick(); deltaTime = timer.delta_s( lastTick, curTick ); // limit the deltaTime as we have to be carefull with stability of physics calculation etc. if ( deltaTime > UPPER_UPDATE_PERIOD_LIMIT ) { deltaTime = UPPER_UPDATE_PERIOD_LIMIT; } else if ( deltaTime < LOWER_UPDATE_PERIOD_LIMIT ) { // limit the upper fps to about 60 frames / second ( there are crash problems in some gpu cards when vsynch is disabled ) do { OpenThreads::Thread::microSleep( 100 ); curTick = timer.tick(); deltaTime = timer.delta_s( lastTick, curTick ); } while ( deltaTime < LOWER_UPDATE_PERIOD_LIMIT ); } // update game if ( GameState::get()->getMode() == GameState::Server ) updateServer( deltaTime ); else if ( GameState::get()->getMode() == GameState::Client ) updateClient( deltaTime ); else updateStandalone( deltaTime ); // check heap if enabled ( used for detecting heap corruptions ) YAF3D_CHECK_HEAP(); } }
void CSceneMatch::update() { // replay mode if(bReplayMode) { renderReplay(); return; } // multiplayer: wait for connection if(sGlobal->bMultiplayer) { // wait for client if(sGlobal->bServer && !bClientReady) { if(cServer->receiveMessage(&sClientAddress, sUDPBuffer, MSG_SIZE) > 0 && sUDPBuffer[0] == MSG_REQ) { sUDPBuffer[0] = MSG_ACK; cServer->sendMessage(sClientAddress, sUDPBuffer, MSG_SIZE); bClientReady = true; return; } sprintf(sMessage, "Waiting for client..."); render(); return; } // wait for server if(!sGlobal->bServer && !bServerReady) { if(cClient->receiveMessage(sUDPBuffer, MSG_SIZE) > 0 && sUDPBuffer[0] == MSG_ACK) { bServerReady = true; return; } // new request to the server if(iCurrentFrame % sGlobal->iFPS == 0) { sUDPBuffer[0] = MSG_REQ; cClient->sendMessage(sUDPBuffer, MSG_SIZE); } sprintf(sMessage, "Waiting for server..."); render(); return; } } sprintf(sMessage, ""); iCurrentFrame++; // set player 1 position if(sGlobal->bKinect) { // check Kinect status // two players if(sGlobal->iHumanPlayers == 2 && (!kHandPosition.PlayerReady[0] || !kHandPosition.PlayerReady[1])) { if(!kHandPosition.PlayerReady[0] || !kHandPosition.PlayerReady[1]) { if(!kHandPosition.PlayerReady[0] && !kHandPosition.PlayerReady[1]) sprintf(sMessage, "Kinect: waiting for the players..."); else if(!kHandPosition.PlayerReady[0]) sprintf(sMessage, "Kinect: waiting for player 1..."); else sprintf(sMessage, "Kinect: waiting for player 2..."); render(); return; } } // single player else if(!kHandPosition.PlayerReady[0]) { sprintf(sMessage, "Kinect: waiting for player..."); if(!kHandPosition.PlayerReady[0]) { render(); return; } } // Kinect (two players) if(sGlobal->iHumanPlayers == 2) { cGame->setMouseRatio(-kCalibration.Width * 2 - 50, -50, kCalibration.MinimumDistance, kCalibration.MaximumDistance); cGame->setMousePositionPlayer1(kHandPosition.x[0], kHandPosition.z[0]); cGame->setMouseRatio(kCalibration.Width * 2 + 50, 50, kCalibration.MinimumDistance, kCalibration.MaximumDistance); cGame->setMousePositionPlayer2(kHandPosition.x[1], kHandPosition.z[1]); } // Kinect (single player) else { cGame->setMousePositionPlayer1(kHandPosition.x[0], kHandPosition.z[0]); } } else { // mouse cGame->setMousePositionPlayer1((float)iMouseX, (float)iMouseY); } // multiplayer: client if(sGlobal->bMultiplayer && !sGlobal->bServer) { updateClient(); return; } // game time if(iCurrentFrame % sGlobal->iFPS == 0) { iTimeSec--; if(iTimeSec < 0) { iTimeSec = 59; iTimeMin--; } if(iTimeMin < 0) { iTimeMin = 0; iTimeSec = 0; endOfTheMatch(); } // send time to client if(sGlobal->bMultiplayer) { sUDPBuffer[0] = MSG_TIME; sUDPBuffer[1] = (char)iTimeMin; sUDPBuffer[2] = (char)iTimeSec; cServer->sendMessage(sClientAddress, sUDPBuffer, MSG_SIZE); } } // set player 2 position (CPU) if(sGlobal->iHumanPlayers == 1 && !sGlobal->bMultiplayer) cGame->setTablePositionPlayer2(cPlayer2AI->update()); // check goals bPuckVisible = true; if(cGame->checkEvent() == AH_EVENT_GOAL_P1 || cGame->checkEvent() == AH_EVENT_GOAL_P2) { bPuckVisible = false; // send "goal" to client if(sGlobal->bMultiplayer) { sUDPBuffer[0] = MSG_GOAL; sUDPBuffer[1] = (char)cGame->getGoalsPlayer2(); sUDPBuffer[2] = (char)cGame->getGoalsPlayer1(); cServer->sendMessage(sClientAddress, sUDPBuffer, MSG_SIZE); } // automatic replay if(sGlobal->bAutomaticReplay && !sGlobal->bMultiplayer) { // only goals without rebounds if((cGame->checkEvent() == AH_EVENT_GOAL_P1 && cGame->getLastPlayerWhoHitThePuck() == 1) || (cGame->checkEvent() == AH_EVENT_GOAL_P2 && cGame->getLastPlayerWhoHitThePuck() == 2)) { replayMode(); return; } } // pause and then back to the game render(); Sleep(1000); } // end of the match? if(cGame->getGoalsPlayer1() == sGlobal->iGameMaxGoals || cGame->getGoalsPlayer2() == sGlobal->iGameMaxGoals) { endOfTheMatch(); return; } // replay data sReplayFrame[iCurrentReplayRecordFrame].PositionPlayer1 = cGame->getRenderPositionPlayer1(); sReplayFrame[iCurrentReplayRecordFrame].PositionPlayer2 = cGame->getRenderPositionPlayer2(); sReplayFrame[iCurrentReplayRecordFrame].PositionPuck = cGame->getRenderPositionPuck(); sReplayFrame[iCurrentReplayRecordFrame].PuckVisible = bPuckVisible; sReplayFrame[iCurrentReplayRecordFrame].Interpolate = !(cGame->checkEvent() == AH_EVENT_GOAL_P1 || cGame->checkEvent() == AH_EVENT_GOAL_P2); iCurrentReplayRecordFrame++; if(iCurrentReplayRecordFrame == REPLAY_FRAMES) iCurrentReplayRecordFrame = 0; // game status update cGame->update(); // send game data to client if(sGlobal->bMultiplayer && (iCurrentFrame % MULTIPLAYER_DATA_RATE) == 0) sendDataToClient(); // video and audio render(); playSounds(cGame->checkEvent()); }
void Application::run() { // set game state _p_gameState->setState( GameState::StartRunning ); // now the network can start if ( GameState::get()->getMode() == GameState::Client ) { // try to start client networking try { _p_networkDevice->startClient(); // send the notification on established network session EntityNotification ennotify( YAF3D_NOTIFY_NETWORKING_ESTABLISHED ); EntityManager::get()->sendNotification( ennotify ); } catch ( const NetworkException& e ) { log_error << "Application: error starting client networking, reason: " << e.what() << std::endl; _p_gameState->setState( GameState::Quitting ); } } // check heap if enabled ( used for detecting heap corruptions ) YAF3D_CHECK_HEAP(); osg::Timer timer; osg::Timer_t curTick = timer.tick(); osg::Timer_t lastTick = curTick; float deltaTime = LOWER_UPDATE_PERIOD_LIMIT; // set game state _p_gameState->setState( GameState::MainLoop ); // begin game loop while( _p_gameState->getState() != GameState::Quitting ) { // limit the deltaTime as we have to be carefull with stability of physics calculation etc. if ( deltaTime > UPPER_UPDATE_PERIOD_LIMIT ) { deltaTime = UPPER_UPDATE_PERIOD_LIMIT; } else if ( deltaTime < LOWER_UPDATE_PERIOD_LIMIT ) { // limit the upper fps to about 60 frames / second ( there are crash problems in some gpu cards when vsync is disabled ) do { OpenThreads::Thread::microSleep( 100 ); curTick = timer.tick(); deltaTime = timer.delta_s( lastTick, curTick ); } while ( deltaTime < LOWER_UPDATE_PERIOD_LIMIT ); } // update the simulation, lock it in order to give a chance to asynchronous threads for accessing resources if ( !_updateMutex.trylock() ) { // update game if ( GameState::get()->getMode() == GameState::Server ) updateServer( deltaTime ); else if ( GameState::get()->getMode() == GameState::Client ) updateClient( deltaTime ); else updateStandalone( deltaTime ); // calculate new delta-time lastTick = curTick; curTick = timer.tick(); deltaTime = timer.delta_s( lastTick, curTick ); // we handle Ctrl+C in main thread context if ( _ctrlCPressed ) { _p_gameState->setState( GameState::Quitting ); } // check for stopping application if ( _stopApplication ) _p_gameState->setState( GameState::Quitting ); // unlock the update mutex _updateMutex.unlock(); } // check heap if enabled ( used for detecting heap corruptions ) YAF3D_CHECK_HEAP(); } }
void rice::p2p::replication::ReplicationImpl::update(::rice::p2p::commonapi::NodeHandle* handle, bool joined) { updateClient(); }
void intrupt(void) { if (testtime == -1) { struct reserved_spacket sp; /* Give a reasonable period of time to respond to query (and test code if they need to) */ #define RSAREPLYTIMER 30 #ifdef RSA RSA_Client = 0; #endif testtime = RSAREPLYTIMER * 10; makeReservedPacket(&sp); memcpy(testdata, sp.data, RESERVED_SIZE); sendClientPacket(&sp); } else if (testtime != 0) { testtime--; if (testtime==0) { if (report_ident) pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s using %s", me->p_mapchars, me->p_ident); #if defined(RSA) && defined(SHOW_RSA) && defined(SHOW_RSA_FAILURE) if (!hidden && !whitelisted && !bypassed) pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s %.16s is not using a trusted client", ranks[me->p_stats.st_rank].name, me->p_name); #endif if (bypassed) { /* Deal with .bypass entries */ ERROR(3,(".bypass person : %s - logged on\n",me->p_login)); me->p_stats.st_flags |= ST_CYBORG; /* mark for reference */ new_warning(UNDEF,"You are in the .bypass file, be good"); } else { /* User failed to respond to verification query. Bye! */ if (!binconfirm) me->p_stats.st_flags |= ST_CYBORG; /* mark for reference 7/27/91 TC */ else { me->p_explode = 10; me->p_whydead = KQUIT; me->p_status = PEXPLODE; ERROR(3,("User binary failed to verify\n")); #ifdef RSA #ifdef SHOW_RSA pmessage2(0, MALL | MJOIN, "GOD->ALL", me->p_no, "%s %.16s failed to verify", ranks[me->p_stats.st_rank].name, me->p_name); #endif if (RSA_Client==1) new_warning(UNDEF,"No customized binaries. Please use a blessed one."); else if (RSA_Client==2) new_warning(UNDEF,"Wrong Client Version Number!"); else new_warning(UNDEF,"You need a spiffy new RSA client for this server!"); #else new_warning(UNDEF,"No customized binaries. Please use a blessed one."); #endif } } } } if (me->p_status == PFREE) { ERROR(1,("intrupt: exitGame() on PFREE (pid %i)\n",getpid())); exitGame(0); } if (!Observer || me->p_status == PEXPLODE) { if (me->p_status == PEXPLODE || me->p_status == PDEAD) { FD_ZERO(&inputMask); } if (((me->p_status == PDEAD) || (me->p_status == POUTFIT)) && (me->p_ntorp <= 0) && (me->p_nplasmatorp <= 0)) { death(); return; } } if (clue) { if (RECHECK_CLUE && (clueFuse > CLUEINTERVAL)) { clueVerified = 0; clueFuse = 0; clueCount = 0; } if (!clueVerified && (inl_mode || (queues[QU_PICKUP].count != 0))) { clueFuse++; clue_check(); } } auto_features(); updateClient(); }