| 875 | } |
| 876 | |
| 877 | void PlayerManager::OnClientPrintf(edict_t *pEdict, const char *szMsg) |
| 878 | { |
| 879 | int client = IndexOfEdict(pEdict); |
| 880 | |
| 881 | CPlayer &player = m_Players[client]; |
| 882 | if (!player.IsConnected()) |
| 883 | RETURN_META(MRES_IGNORED); |
| 884 | |
| 885 | INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client)); |
| 886 | if (pNetChan == NULL) |
| 887 | RETURN_META(MRES_IGNORED); |
| 888 | |
| 889 | size_t nMsgLen = strlen(szMsg); |
| 890 | #if SOURCE_ENGINE == SE_EPISODEONE || SOURCE_ENGINE == SE_DARKMESSIAH |
| 891 | static const int nNumBitsWritten = 0; |
| 892 | #else |
| 893 | int nNumBitsWritten = pNetChan->GetNumBitsWritten(false); // SVC_Print uses unreliable netchan |
| 894 | #endif |
| 895 | |
| 896 | // if the msg is bigger than allowed then just let it fail |
| 897 | if (nMsgLen + 1 >= SVC_Print_BufferSize) // +1 for NETMSG_TYPE_BITS |
| 898 | RETURN_META(MRES_IGNORED); |
| 899 | |
| 900 | // enqueue msgs if we'd overflow the SVC_Print buffer (+7 as ceil) |
| 901 | if (!player.m_PrintfBuffer.empty() || (nNumBitsWritten + NETMSG_TYPE_BITS + 7) / 8 + nMsgLen >= SVC_Print_BufferSize) |
| 902 | { |
| 903 | // Don't send any more messages for this player until the buffer is empty. |
| 904 | // Queue up a gameframe hook to empty the buffer (if we haven't already) |
| 905 | if (player.m_PrintfBuffer.empty()) |
| 906 | g_SourceMod.AddFrameAction(PrintfBuffer_FrameAction, (void *)(uintptr_t)player.GetSerial()); |
| 907 | |
| 908 | player.m_PrintfBuffer.push_back(szMsg); |
| 909 | |
| 910 | RETURN_META(MRES_SUPERCEDE); |
| 911 | } |
| 912 | |
| 913 | RETURN_META(MRES_IGNORED); |
| 914 | } |
| 915 | |
| 916 | void PlayerManager::OnPrintfFrameAction(unsigned int serial) |
| 917 | { |
nothing calls this directly
no test coverage detected