| 967 | class 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) { |
nothing calls this directly
no test coverage detected