diff options
Diffstat (limited to 'modules/websocket/websocket_server.cpp')
| -rw-r--r-- | modules/websocket/websocket_server.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index c7414075ed..b20b925dec 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -34,13 +34,13 @@ GDCINULL(WebSocketServer); WebSocketServer::WebSocketServer() { _peer_id = 1; + bind_ip = IP_Address("*"); } WebSocketServer::~WebSocketServer() { } void WebSocketServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_listening"), &WebSocketServer::is_listening); ClassDB::bind_method(D_METHOD("listen", "port", "protocols", "gd_mp_api"), &WebSocketServer::listen, DEFVAL(Vector<String>()), DEFVAL(false)); ClassDB::bind_method(D_METHOD("stop"), &WebSocketServer::stop); @@ -49,6 +49,10 @@ void WebSocketServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketServer::get_peer_port); ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "code", "reason"), &WebSocketServer::disconnect_peer, DEFVAL(1000), DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_bind_ip"), &WebSocketServer::get_bind_ip); + ClassDB::bind_method(D_METHOD("set_bind_ip"), &WebSocketServer::set_bind_ip); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "bind_ip"), "set_bind_ip", "get_bind_ip"); + ClassDB::bind_method(D_METHOD("get_private_key"), &WebSocketServer::get_private_key); ClassDB::bind_method(D_METHOD("set_private_key"), &WebSocketServer::set_private_key); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "private_key", PROPERTY_HINT_RESOURCE_TYPE, "CryptoKey", 0), "set_private_key", "get_private_key"); @@ -67,6 +71,16 @@ void WebSocketServer::_bind_methods() { ADD_SIGNAL(MethodInfo("data_received", PropertyInfo(Variant::INT, "id"))); } +IP_Address WebSocketServer::get_bind_ip() const { + return bind_ip; +} + +void WebSocketServer::set_bind_ip(const IP_Address &p_bind_ip) { + ERR_FAIL_COND(is_listening()); + ERR_FAIL_COND(!p_bind_ip.is_valid() && !p_bind_ip.is_wildcard()); + bind_ip = p_bind_ip; +} + Ref<CryptoKey> WebSocketServer::get_private_key() const { return private_key; } @@ -95,19 +109,18 @@ void WebSocketServer::set_ca_chain(Ref<X509Certificate> p_ca_chain) { } NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { - if (is_listening()) + if (is_listening()) { return CONNECTION_CONNECTED; + } return CONNECTION_DISCONNECTED; -}; +} bool WebSocketServer::is_server() const { - return true; } void WebSocketServer::_on_peer_packet(int32_t p_peer_id) { - if (_is_multiplayer) { _process_multiplayer(get_peer(p_peer_id), p_peer_id); } else { @@ -116,7 +129,6 @@ void WebSocketServer::_on_peer_packet(int32_t p_peer_id) { } void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) { - if (_is_multiplayer) { // Send add to clients _send_add(p_peer_id); @@ -127,7 +139,6 @@ void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) { } void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool p_was_clean) { - if (_is_multiplayer) { // Send delete to clients _send_del(p_peer_id); @@ -138,6 +149,5 @@ void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool p_was_clean) { } void WebSocketServer::_on_close_request(int32_t p_peer_id, int p_code, String p_reason) { - emit_signal("client_close_request", p_peer_id, p_code, p_reason); } |
