MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / execute

Method execute

src/bzfs/bzfsClientMessages.cpp:969–1035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

967class PauseHandler : public PlayerFirstHandler {
968 public:
969 virtual bool execute(uint16_t& /*code*/, void* buf, int len) {
970 if (!player || (len < 2)) {
971 return false;
972 }
973 if (!player->player.isCompletelyAdded()) {
974 return false;
975 }
976
977 uint8_t pauseCode;
978 nboUnpackUInt8(buf, pauseCode);
979 switch (pauseCode) {
980 case PauseCodeEnable:
981 case PauseCodeDisable: {
982 break;
983 }
984 default: { // ignore unexpected pause codes
985 debugf(1, "unexpected pause code: %s sent %d\n",
986 player->player.getCallSign(), (int)pauseCode);
987 return true;
988 }
989 }
990 const bool wantPause = (pauseCode == PauseCodeEnable);
991
992 // notify plugins, and let them block the request
993 const int playerIndex = player->player.getPlayerIndex();
994 bz_PlayerPauseRequestData_V1 eventData(playerIndex, wantPause);
995 worldEventManager.callEvents(bz_ePlayerPauseRequestEvent, &eventData);
996 if (eventData.allow == false) {
997 std::string reason = eventData.reason.c_str();
998 if (reason.empty()) {
999 reason = "pause request denied";
1000 }
1001 NetMessage netMsg;
1002 netMsg.packUInt8(player->getIndex());
1003 netMsg.packUInt8(PauseCodeCancel);
1004 netMsg.packStdString(reason);
1005 netMsg.send(player->netHandler, MsgPause);
1006 return true;
1007 }
1008
1009 if (!wantPause) { // unpause immediately
1010 pausePlayer(playerIndex, false);
1011 return true;
1012 }
1013
1014 if (player->pauseRequested) {
1015 return true; // ignore repeat requests
1016 }
1017
1018 static BZDB_float pauseDelay("_pauseDelay");
1019 // delayed pausing
1020 BzTime activeTime = BzTime::getCurrent();
1021 activeTime += pauseDelay;
1022 player->pauseActiveTime = activeTime;
1023 player->pauseRequested = true;
1024
1025 // send the PauseCodeAcknowledge message
1026 if (player->netHandler) {

Callers

nothing calls this directly

Calls 14

nboUnpackUInt8Function · 0.85
debugfFunction · 0.85
pausePlayerFunction · 0.85
isCompletelyAddedMethod · 0.80
getPlayerIndexMethod · 0.80
c_strMethod · 0.80
packUInt8Method · 0.80
packStdStringMethod · 0.80
packFloatMethod · 0.80
getCallSignMethod · 0.45
callEventsMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected