| 2916 | } |
| 2917 | |
| 2918 | static bool ProcessChatMessagePluginHooks(uint8_t playerId, std::string& text) |
| 2919 | { |
| 2920 | #ifdef ENABLE_SCRIPTING |
| 2921 | auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine(); |
| 2922 | if (hookEngine.HasSubscriptions(Scripting::HookType::networkChat)) |
| 2923 | { |
| 2924 | auto ctx = GetContext()->GetScriptEngine().GetContext(); |
| 2925 | |
| 2926 | // Create event args object |
| 2927 | JSValue obj = JS_NewObject(ctx); |
| 2928 | JS_SetPropertyStr(ctx, obj, "player", JS_NewInt32(ctx, playerId)); |
| 2929 | JS_SetPropertyStr(ctx, obj, "message", Scripting::JSFromStdString(ctx, text)); |
| 2930 | |
| 2931 | // Call the subscriptions |
| 2932 | hookEngine.Call(Scripting::HookType::networkChat, obj, false, true); |
| 2933 | |
| 2934 | // Update text from object if subscriptions changed it |
| 2935 | auto message = Scripting::JSToOptionalStdString(ctx, obj, "message"); |
| 2936 | JS_FreeValue(ctx, obj); |
| 2937 | |
| 2938 | if (!message.has_value()) |
| 2939 | { |
| 2940 | // Subscription set text to non-string, do not relay message |
| 2941 | return false; |
| 2942 | } |
| 2943 | text = message.value(); |
| 2944 | if (text.empty()) |
| 2945 | { |
| 2946 | // Subscription set text to empty string, do not relay message |
| 2947 | return false; |
| 2948 | } |
| 2949 | } |
| 2950 | #endif |
| 2951 | return true; |
| 2952 | } |
| 2953 | |
| 2954 | void NetworkBase::ServerHandleChat(Connection& connection, Packet& packet) |
| 2955 | { |
no test coverage detected