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

Method sendMessage

src/openrct2/scripting/bindings/network/ScNetwork.cpp:267–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265 }
266
267 JSValue ScNetwork::sendMessage(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv)
268 {
269 #ifndef DISABLE_NETWORK
270 JS_UNPACK_STR(message, ctx, argv[0]);
271 JSValue players = argv[1];
272
273 if (JS_IsArray(players))
274 {
275 if (Network::GetMode() == Network::Mode::server)
276 {
277 std::vector<uint8_t> playerIds;
278 JSIterateArray(ctx, players, [&playerIds](JSContext* ctx2, JSValue val) {
279 playerIds.push_back(static_cast<uint8_t>(JSToInt(ctx2, val)));
280 });
281 if (!playerIds.empty())
282 {
283 Network::SendChat(message.c_str(), playerIds);
284 }
285 }
286 else
287 {
288 JS_ThrowPlainError(ctx, "Only servers can send private messages.");
289 return JS_EXCEPTION;
290 }
291 }
292 else
293 {
294 Network::SendChat(message.c_str());
295 }
296 #endif
297 return JS_UNDEFINED;
298 }
299
300 #ifndef DISABLE_NETWORK
301 JSValue ScNetwork::createListener(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv)

Callers

nothing calls this directly

Calls 6

GetModeFunction · 0.85
JSIterateArrayFunction · 0.85
JSToIntFunction · 0.85
SendChatFunction · 0.85
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected