mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-23 10:51:58 -05:00
Rename SocketServer to Listener
This commit is contained in:
parent
173a42f656
commit
0bddf5a5db
5 changed files with 26 additions and 26 deletions
14
distribution/openrct2.d.ts
vendored
14
distribution/openrct2.d.ts
vendored
|
@ -1222,7 +1222,7 @@ declare global {
|
|||
sendMessage(message: string): void;
|
||||
sendMessage(message: string, players: number[]): void;
|
||||
|
||||
createServer(): SocketServer;
|
||||
createListener(): Listener;
|
||||
createSocket(): Socket;
|
||||
}
|
||||
|
||||
|
@ -1682,18 +1682,18 @@ declare global {
|
|||
}
|
||||
|
||||
/**
|
||||
* Represents a server that can listen for incomming connections.
|
||||
* Listens for incomming connections.
|
||||
* Based on node.js net.Server, see https://nodejs.org/api/net.html for more information.
|
||||
*/
|
||||
interface SocketServer {
|
||||
interface Listener {
|
||||
readonly listening: boolean;
|
||||
|
||||
listen(port: number): SocketServer;
|
||||
close(): SocketServer;
|
||||
listen(port: number): Listener;
|
||||
close(): Listener;
|
||||
|
||||
on(event: 'connection', callback: (socket: Socket) => void): SocketServer;
|
||||
on(event: 'connection', callback: (socket: Socket) => void): Listener;
|
||||
|
||||
off(event: 'connection', callback: (socket: Socket) => void): SocketServer;
|
||||
off(event: 'connection', callback: (socket: Socket) => void): Listener;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -410,7 +410,7 @@
|
|||
<ClInclude Include="scripting\ScPark.hpp" />
|
||||
<ClInclude Include="scripting\ScRide.hpp" />
|
||||
<ClInclude Include="scripting\ScriptEngine.h" />
|
||||
<ClInclude Include="scripting\ScSocketServer.hpp" />
|
||||
<ClInclude Include="scripting\ScSocket.hpp" />
|
||||
<ClInclude Include="scripting\ScTile.hpp" />
|
||||
<ClInclude Include="sprites.h" />
|
||||
<ClInclude Include="title\TitleScreen.h" />
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# include "../network/NetworkAction.h"
|
||||
# include "../network/network.h"
|
||||
# include "Duktape.hpp"
|
||||
# include "ScSocketServer.hpp"
|
||||
# include "ScSocket.hpp"
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
|
@ -450,16 +450,16 @@ namespace OpenRCT2::Scripting
|
|||
}
|
||||
|
||||
# ifndef DISABLE_NETWORK
|
||||
std::shared_ptr<ScSocketServer> createServer()
|
||||
std::shared_ptr<ScListener> createListener()
|
||||
{
|
||||
auto& scriptEngine = GetContext()->GetScriptEngine();
|
||||
auto plugin = scriptEngine.GetExecInfo().GetCurrentPlugin();
|
||||
auto socket = std::make_shared<ScSocketServer>(plugin);
|
||||
auto socket = std::make_shared<ScListener>(plugin);
|
||||
scriptEngine.AddSocket(socket);
|
||||
return socket;
|
||||
}
|
||||
# else
|
||||
void createServer()
|
||||
void createListener()
|
||||
{
|
||||
duk_error(_context, DUK_ERR_ERROR, "Networking has been disabled.");
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ namespace OpenRCT2::Scripting
|
|||
dukglue_register_method(ctx, &ScNetwork::kickPlayer, "kickPlayer");
|
||||
dukglue_register_method(ctx, &ScNetwork::sendMessage, "sendMessage");
|
||||
|
||||
dukglue_register_method(ctx, &ScNetwork::createServer, "createServer");
|
||||
dukglue_register_method(ctx, &ScNetwork::createListener, "createListener");
|
||||
dukglue_register_method(ctx, &ScNetwork::createSocket, "createSocket");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -355,7 +355,7 @@ namespace OpenRCT2::Scripting
|
|||
}
|
||||
};
|
||||
|
||||
class ScSocketServer final : public ScSocketBase
|
||||
class ScListener final : public ScSocketBase
|
||||
{
|
||||
private:
|
||||
static constexpr uint32_t EVENT_NONE = std::numeric_limits<uint32_t>::max();
|
||||
|
@ -375,13 +375,13 @@ namespace OpenRCT2::Scripting
|
|||
return false;
|
||||
}
|
||||
|
||||
ScSocketServer* close()
|
||||
ScListener* close()
|
||||
{
|
||||
CloseSocket();
|
||||
return this;
|
||||
}
|
||||
|
||||
ScSocketServer* listen(int32_t port, const DukValue& dukHost)
|
||||
ScListener* listen(int32_t port, const DukValue& dukHost)
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
if (_disposed)
|
||||
|
@ -429,7 +429,7 @@ namespace OpenRCT2::Scripting
|
|||
return this;
|
||||
}
|
||||
|
||||
ScSocketServer* on(const std::string& eventType, const DukValue& callback)
|
||||
ScListener* on(const std::string& eventType, const DukValue& callback)
|
||||
{
|
||||
auto eventId = GetEventType(eventType);
|
||||
if (eventId != EVENT_NONE)
|
||||
|
@ -439,7 +439,7 @@ namespace OpenRCT2::Scripting
|
|||
return this;
|
||||
}
|
||||
|
||||
ScSocketServer* off(const std::string& eventType, const DukValue& callback)
|
||||
ScListener* off(const std::string& eventType, const DukValue& callback)
|
||||
{
|
||||
auto eventId = GetEventType(eventType);
|
||||
if (eventId != EVENT_NONE)
|
||||
|
@ -457,7 +457,7 @@ namespace OpenRCT2::Scripting
|
|||
}
|
||||
|
||||
public:
|
||||
ScSocketServer(const std::shared_ptr<Plugin>& plugin)
|
||||
ScListener(const std::shared_ptr<Plugin>& plugin)
|
||||
: ScSocketBase(plugin)
|
||||
{
|
||||
}
|
||||
|
@ -511,11 +511,11 @@ 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");
|
||||
dukglue_register_method(ctx, &ScSocketServer::off, "off");
|
||||
dukglue_register_property(ctx, &ScListener::listening_get, nullptr, "listening");
|
||||
dukglue_register_method(ctx, &ScListener::close, "close");
|
||||
dukglue_register_method(ctx, &ScListener::listen, "listen");
|
||||
dukglue_register_method(ctx, &ScListener::on, "on");
|
||||
dukglue_register_method(ctx, &ScListener::off, "off");
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2::Scripting
|
|
@ -33,7 +33,7 @@
|
|||
# include "ScObject.hpp"
|
||||
# include "ScPark.hpp"
|
||||
# include "ScRide.hpp"
|
||||
# include "ScSocketServer.hpp"
|
||||
# include "ScSocket.hpp"
|
||||
# include "ScTile.hpp"
|
||||
|
||||
# include <iostream>
|
||||
|
@ -396,7 +396,7 @@ void ScriptEngine::Initialise()
|
|||
ScGuest::Register(ctx);
|
||||
# ifndef DISABLE_NETWORK
|
||||
ScSocket::Register(ctx);
|
||||
ScSocketServer::Register(ctx);
|
||||
ScListener::Register(ctx);
|
||||
# endif
|
||||
ScStaff::Register(ctx);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue