Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ add_executable(server
${PROJECT_SOURCE_DIR}/libs/game/src/stdafx.cpp
)

include(FetchContent)
FetchContent_Declare(
nats
GIT_REPOSITORY https://github.com/nats-io/nats.c.git
GIT_TAG v3.10.1
)
set(NATS_BUILD_EXAMPLES OFF CACHE INTERNAL "")
set(NATS_BUILD_STREAMING OFF CACHE INTERNAL "")
set(NATS_BUILD_WITH_TLS OFF CACHE INTERNAL "")
set(NATS_BUILD_LIB_SHARED OFF CACHE INTERNAL "")
set(NATS_BUILD_LIB_STATIC ON CACHE INTERNAL "")
set(BUILD_TESTING OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(nats)

if(MSVC)
target_compile_definitions(server PRIVATE
"$<$<CONFIG:Debug>:_ITERATOR_DEBUG_LEVEL=0>"
Expand All @@ -17,7 +31,7 @@ else()
target_link_libraries(server PRIVATE -static-libstdc++ -no-pie)
endif()

target_link_libraries(server PRIVATE GameCore GameLib)
target_link_libraries(server PRIVATE GameCore GameLib nats_static)

# copy *.pak next to the binary
file(COPY ${PROJECT_SOURCE_DIR}/assets/Project.pak
Expand Down
17 changes: 17 additions & 0 deletions apps/server/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include <vector>
#include <cfloat>
#include <nats.h>
#include "ConnectionsToClients.h"
#include "stdafx.h"
#include "@@headers.h"
#include "MyClass.h"

Vec2 dot_pos(0, 0);
MyClass myObject("ExampleObject", 42);
static natsConnection *gNatsConn = nullptr;
/******************************************************************************/
void InitPre()
{
Expand All @@ -31,13 +33,28 @@ bool Init()
{
LogN(S+"Init()");
SetupEnet();
natsStatus s = natsConnection_ConnectTo(&gNatsConn, NATS_DEFAULT_URL);
if(s == NATS_OK)
{
natsConnection_PublishString(gNatsConn, "server.started", "Hello from server");
natsConnection_FlushTimeout(gNatsConn, 1000);
}
else
{
LogN(S+"NATS connect failed: " + natsStatus_GetText(s));
}
return true;
}
/******************************************************************************/
void Shut()
{
LogN(S+"Shut()");
if(gServer) enet_host_destroy(gServer);
if(gNatsConn)
{
natsConnection_Destroy(gNatsConn);
nats_Close();
}
enet_deinitialize();
}
/******************************************************************************/
Expand Down