From 7dfb748500f8131bf34152a144d67853cdbee36b Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Aug 2020 16:54:13 +0100 Subject: [PATCH] Add listening property --- distribution/openrct2.d.ts | 11 ++++++++++- src/openrct2/scripting/ScSocketServer.hpp | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 293cbe419c..35d5873f92 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -1686,10 +1686,14 @@ declare global { * Based on node.js net.Server, see https://nodejs.org/api/net.html for more information. */ interface SocketServer { + readonly listening: boolean; + listen(port: number): SocketServer; close(): SocketServer; on(event: 'connection', callback: (socket: Socket) => void): SocketServer; + + off(event: 'connection', callback: (socket: Socket) => void): SocketServer; } /** @@ -1703,7 +1707,12 @@ declare global { end(data?: string): Socket; write(data: string): boolean; - on(event: 'data', callback: (data: string) => void): Socket; on(event: 'close', callback: (hadError: boolean) => void): Socket; + on(event: 'error', callback: (hadError: boolean) => void): Socket; + on(event: 'data', callback: (data: string) => void): Socket; + + off(event: 'close', callback: (hadError: boolean) => void): Socket; + off(event: 'error', callback: (hadError: boolean) => void): Socket; + off(event: 'data', callback: (data: string) => void): Socket; } } diff --git a/src/openrct2/scripting/ScSocketServer.hpp b/src/openrct2/scripting/ScSocketServer.hpp index 8533fe562e..12c23775e2 100644 --- a/src/openrct2/scripting/ScSocketServer.hpp +++ b/src/openrct2/scripting/ScSocketServer.hpp @@ -358,6 +358,15 @@ namespace OpenRCT2::Scripting std::vector> _scClientSockets; bool _disposed{}; + bool listening_get() + { + if (_socket != nullptr) + { + return _socket->GetStatus() == SOCKET_STATUS_LISTENING; + } + return false; + } + ScSocketServer* close() { Dispose(); @@ -482,6 +491,7 @@ namespace OpenRCT2::Scripting static void Register(duk_context* ctx) { + dukglue_register_property(ctx, &ScSocketServer::listening_get, nullptr, "listening"); dukglue_register_method(ctx, &ScSocketServer::close, "close"); dukglue_register_method(ctx, &ScSocketServer::listen, "listen"); dukglue_register_method(ctx, &ScSocketServer::on, "on");