-
Notifications
You must be signed in to change notification settings - Fork 11
[Feature] Etheos Websockets #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
|
|
||
| # Download and unpack IXWebSocket at configure time | ||
| if (NOT EOSERV_OFFLINE) | ||
| configure_file(${CMAKE_SOURCE_DIR}/cmake/ixwebsocketproj.cmake ixwebsocket-download/CMakeLists.txt) | ||
|
|
||
| execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
| RESULT_VARIABLE result | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-download ) | ||
| if(result) | ||
| message(FATAL_ERROR "CMake step for IXWebSocket failed: ${result}") | ||
| endif() | ||
|
|
||
| execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
| RESULT_VARIABLE result | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-download ) | ||
| if(result) | ||
| message(FATAL_ERROR "Build step for IXWebSocket failed: ${result}") | ||
| endif() | ||
| endif() | ||
|
|
||
| # Configure IXWebSocket options before adding subdirectory | ||
| set(USE_TLS OFF CACHE BOOL "" FORCE) | ||
| set(USE_OPEN_SSL OFF CACHE BOOL "" FORCE) | ||
| set(USE_MBED_TLS OFF CACHE BOOL "" FORCE) | ||
| set(IXWEBSOCKET_INSTALL OFF CACHE BOOL "" FORCE) | ||
|
|
||
| # Add IXWebSocket directly to our build | ||
| add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-src | ||
| ${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-build | ||
| EXCLUDE_FROM_ALL) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
|
|
||
| project(ixwebsocket-download NONE) | ||
|
|
||
| include(ExternalProject) | ||
| ExternalProject_Add(ixwebsocket | ||
| GIT_REPOSITORY https://github.com/machinezone/IXWebSocket.git | ||
| GIT_TAG v11.4.5 | ||
| SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-src" | ||
| BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-build" | ||
| CONFIGURE_COMMAND "" | ||
| BUILD_COMMAND "" | ||
| INSTALL_COMMAND "" | ||
| TEST_COMMAND "" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,10 @@ | |
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #ifdef WEBSOCKET_SUPPORT | ||
| #include "wsserver.hpp" | ||
| #endif | ||
|
|
||
| void server_ping_all(void *server_void) | ||
| { | ||
| EOServer *server = static_cast<EOServer *>(server_void); | ||
|
|
@@ -67,7 +71,7 @@ void server_check_hangup(void *server_void) | |
| { | ||
| EOClient *client = static_cast<EOClient *>(rawclient); | ||
|
|
||
| if (client->Connected() && !client->Accepted() && client->start + delay < now) | ||
| if (client->Connected() && !client->Accepted() && !client->IsWebSocket() && client->start + delay < now) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was hoping to have it so that all clients (both regular socket clients and web socket clients) could be in the same collection so that the implementation could handle stuff like this (i.e. |
||
| { | ||
| server->RecordClientRejection(client->GetRemoteAddr(), "hanging up on idle client"); | ||
| client->Close(true); | ||
|
|
@@ -193,6 +197,26 @@ void EOServer::Initialize(std::shared_ptr<DatabaseFactory> databaseFactory, cons | |
| this->start = Timer::GetTime(); | ||
|
|
||
| this->UpdateConfig(); | ||
|
|
||
| #ifdef WEBSOCKET_SUPPORT | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the CMake arg and the |
||
| if (this->world->config["WebSocketEnabled"]) | ||
| { | ||
| int ws_port = int(this->world->config["WebSocketPort"]); | ||
| std::string host = std::string(this->world->config["Host"]); | ||
| this->wsserver = new WSServer(this, host, ws_port); | ||
|
|
||
| if (this->wsserver->Start()) | ||
| { | ||
| Console::Out("WebSocket server listening on %s:%i", host.c_str(), ws_port); | ||
| } | ||
| else | ||
| { | ||
| Console::Err("Failed to start WebSocket server on port %i", ws_port); | ||
| delete this->wsserver; | ||
| this->wsserver = nullptr; | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| Client *EOServer::ClientFactory(const Socket &sock) | ||
|
|
@@ -295,6 +319,13 @@ void EOServer::Tick() | |
|
|
||
| this->BuryTheDead(); | ||
|
|
||
| #ifdef WEBSOCKET_SUPPORT | ||
| if (this->wsserver) | ||
| { | ||
| this->wsserver->Tick(); | ||
| } | ||
| #endif | ||
|
|
||
| this->world->timer.Tick(); | ||
| } | ||
|
|
||
|
|
@@ -312,8 +343,29 @@ void EOServer::RecordClientRejection(const IPAddress& ip, const char* reason) | |
| } | ||
| } | ||
|
|
||
| void EOServer::OnClientRemoved(Client *client) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not seeing where this is called. What is this used for? Can |
||
| { | ||
| #ifdef WEBSOCKET_SUPPORT | ||
| if (client->IsWebSocket() && this->wsserver) | ||
| { | ||
| this->wsserver->RemoveClient(client); | ||
| } | ||
| #else | ||
| (void)client; | ||
| #endif | ||
| } | ||
|
|
||
| EOServer::~EOServer() | ||
| { | ||
| #ifdef WEBSOCKET_SUPPORT | ||
| if (this->wsserver) | ||
| { | ||
| this->wsserver->Stop(); | ||
| delete this->wsserver; | ||
| this->wsserver = nullptr; | ||
| } | ||
| #endif | ||
|
|
||
| // All clients must be fully closed before the world ends | ||
| UTIL_FOREACH(this->clients, client) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
| /* $Id$ | ||
| * EOSERV is released under the zlib license. | ||
| * See LICENSE.txt for more info. | ||
| */ | ||
|
|
||
| #ifndef FWD_WSCLIENT_HPP_INCLUDED | ||
| #define FWD_WSCLIENT_HPP_INCLUDED | ||
|
|
||
| #ifdef WEBSOCKET_SUPPORT | ||
| class WSClient; | ||
| #endif // WEBSOCKET_SUPPORT | ||
|
|
||
| #endif // FWD_WSCLIENT_HPP_INCLUDED |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
| /* $Id$ | ||
| * EOSERV is released under the zlib license. | ||
| * See LICENSE.txt for more info. | ||
| */ | ||
|
|
||
| #ifndef FWD_WSSERVER_HPP_INCLUDED | ||
| #define FWD_WSSERVER_HPP_INCLUDED | ||
|
|
||
| #ifdef WEBSOCKET_SUPPORT | ||
| class WSServer; | ||
| #endif // WEBSOCKET_SUPPORT | ||
|
|
||
| #endif // FWD_WSSERVER_HPP_INCLUDED |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,7 @@ class Client | |
| Server *server; | ||
| bool connected; | ||
| bool accepted = false; | ||
| bool is_websocket = false; | ||
| std::time_t closed_time; | ||
| std::time_t connect_time; | ||
|
|
||
|
|
@@ -270,9 +271,10 @@ class Client | |
|
|
||
| bool Accepted() const { return accepted; } | ||
| void MarkAccepted() { accepted = true; } | ||
| bool IsWebSocket() const { return is_websocket; } | ||
|
|
||
| virtual bool Connected() const; | ||
| IPAddress GetRemoteAddr() const; | ||
| virtual IPAddress GetRemoteAddr() const; | ||
|
|
||
| void AsyncOpPending(bool asyncOpPending) { this->async_op_pending = asyncOpPending; } | ||
| bool IsAsyncOpPending() const { return this->async_op_pending; } | ||
|
|
@@ -437,7 +439,9 @@ class Server | |
| return this->maxconn; | ||
| } | ||
|
|
||
| virtual ~Server(); | ||
| virtual void OnClientRemoved(Client *) {} | ||
|
|
||
| virtual ~Server(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the indentation here |
||
| }; | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this default enabled, I want web sockets to be a native feature not an optional addon