MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ProcessChatMessagePluginHooks

Function ProcessChatMessagePluginHooks

src/openrct2/network/NetworkBase.cpp:2918–2952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 2

ServerHandleChatMethod · 0.85
SendChatFunction · 0.85

Calls 8

GetContextFunction · 0.85
JSFromStdStringFunction · 0.85
JSToOptionalStdStringFunction · 0.85
HasSubscriptionsMethod · 0.80
CallMethod · 0.80
valueMethod · 0.80
GetContextMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected