Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
opus:p
opusfile:p
openssl:p
curl:p

- name: Checkout SDL3
if: contains(matrix.os, 'ubuntu')
Expand Down Expand Up @@ -104,7 +105,7 @@ jobs:
if: contains(matrix.os, 'macOS')
run: |
brew update || true
brew install pkg-config sdl3 python3 ninja opus opusfile openssl || true
brew install pkg-config sdl3 python3 ninja opus opusfile openssl curl || true
brew upgrade freetype
sudo rm -rf /Library/Developer/CommandLineTools

Expand Down Expand Up @@ -225,6 +226,7 @@ jobs:
opus:p
opusfile:p
openssl:p
curl:p

- name: Prepare Linux
if: contains(matrix.os, 'ubuntu')
Expand All @@ -248,7 +250,7 @@ jobs:
if: contains(matrix.os, 'macOS')
run: |
brew update
brew install sdl3 opus opusfile openssl || true
brew install sdl3 opus opusfile openssl curl || true
cd bam
./make_unix.sh

Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ if(NOT CMAKE_CROSSCOMPILING)
endif()
find_package(ZLIB)
find_package(Crypto)
find_package(Curl)
find_package(Freetype)
find_package(Git)
find_package(GTest)
Expand Down Expand Up @@ -283,6 +284,7 @@ if(TARGET_OS AND TARGET_OS STREQUAL "mac")
show_dependency_status("Hdiutil" HDIUTIL)
endif()
show_dependency_status("OpenSSL Crypto" CRYPTO)
show_dependency_status("Curl" CURL)
show_dependency_status("Pnglite" PNGLITE)
show_dependency_status("Python3" Python3)
show_dependency_status("SDL3" SDL3)
Expand All @@ -298,6 +300,10 @@ if(NOT(CRYPTO_FOUND))
message(SEND_ERROR "You must install OpenSSL Crypto to compile Teeworlds")
endif()

if(NOT(CURL_FOUND))
message(SEND_ERROR "You must install libcurl to compile Teeworlds")
endif()

if(CLIENT AND NOT(FREETYPE_FOUND))
message(SEND_ERROR "You must install Freetype to compile the Teeworlds client")
endif()
Expand Down Expand Up @@ -1254,6 +1260,8 @@ set_src(ENGINE_SHARED GLOB src/engine/shared
engine.cpp
filecollection.cpp
filecollection.h
http_request.cpp
http_request.h
huffman.cpp
huffman.h
jobs.cpp
Expand Down Expand Up @@ -1319,7 +1327,7 @@ set(GAME_GENERATED_SHARED
set(DEPS ${DEP_JSON} ${ZLIB_DEP})

# Libraries
set(LIBS ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${CRYPTO_LIBRARIES} ${PLATFORM_LIBS})
set(LIBS ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${CRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${PLATFORM_LIBS})

# Targets
add_library(engine-shared EXCLUDE_FROM_ALL OBJECT ${ENGINE_INTERFACE} ${ENGINE_SHARED} ${ENGINE_GENERATED_SHARED} ${BASE})
Expand Down Expand Up @@ -1915,7 +1923,7 @@ else()

list(REMOVE_DUPLICATES _DEPS)
set(DEP_WHITELIST_REGEX
\"(freetype|SDL3|libcrypto|libogg|libopus|libopusfile|libopusurl)\"
\"(freetype|SDL3|libcrypto|libcurl|libogg|libopus|libopusfile|libopusurl)\"
)

list(FILTER _DEPS INCLUDE REGEX \"\${DEP_WHITELIST_REGEX}\")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ Dependencies
sudo apt install build-essential cmake git libfreetype6-dev libsdl3-dev libpnglite-dev libopus-dev libopusfile-dev python3 libcurl4-openssl-dev

# Fedora
sudo dnf install @development-tools cmake gcc-c++ git freetype-devel pnglite-devel python3 SDL3-devel opus-devel opusfile-devel openssl-devel
sudo dnf install @development-tools cmake gcc-c++ git freetype-devel pnglite-devel python3 SDL3-devel opus-devel opusfile-devel openssl-devel libcurl-devel

# Arch Linux (doesn't have pnglite in its repositories)
sudo pacman -S --needed base-devel cmake freetype2 git python sdl3 opus opusfile openssl
sudo pacman -S --needed base-devel cmake freetype2 git python sdl3 opus opusfile openssl curl

# macOS
brew install cmake freetype sdl3 opus opusfile openssl
brew install cmake freetype sdl3 opus opusfile openssl curl

# MSYS2 (Windows)
pacman -S mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-openssl mingw-w64-ucrt-x86_64-freetype mingw-w64-ucrt-x86_64-sdl3 mingw-w64-ucrt-x86_64-zlib mingw-w64-ucrt-x86_64-opus mingw-w64-ucrt-x86_64-opusfile
pacman -S mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-openssl mingw-w64-ucrt-x86_64-freetype mingw-w64-ucrt-x86_64-sdl3 mingw-w64-ucrt-x86_64-zlib mingw-w64-ucrt-x86_64-opus mingw-w64-ucrt-x86_64-opusfile mingw-w64-ucrt-x86_64-curl
```

Downloading repository
Expand Down
3 changes: 3 additions & 0 deletions bam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CheckVersion("0.5")

Import("configure.lua")
Import("bamfind/crypto.lua")
Import("bamfind/curl.lua")
Import("bamfind/sdl.lua")
Import("bamfind/freetype.lua")
Import("bamfind/opus.lua")
Expand All @@ -15,6 +16,7 @@ config:Add(OptTestCompileC("minmacosxsdk", "int main(){return 0;}", "-mmacosx-ve
config:Add(OptTestCompileC("buildwithoutsseflag", "#include <immintrin.h>\nint main(){_mm_pause();return 0;}", ""))
config:Add(OptLibrary("zlib", "zlib.h", false))
config:Add(Crypto.OptFind("libcrypto", true))
config:Add(Curl.OptFind("libcurl", true))
config:Add(SDL.OptFind("sdl", true))
config:Add(FreeType.OptFind("freetype", true))
config:Add(Opus.OptFind("opus", true))
Expand Down Expand Up @@ -359,6 +361,7 @@ end

function BuildEngineCommon(settings)
config.libcrypto:Apply(settings)
config.libcurl:Apply(settings)
settings.link.extrafiles:Merge(Compile(settings, Collect("src/engine/shared/*.cpp")))

local c11_settings = settings:Copy();
Expand Down
48 changes: 48 additions & 0 deletions bamfind/curl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Curl = {
basepath = PathDir(ModuleFilename()),

OptFind = function (name, required)
local check = function(option, settings)
option.value = false
option.use_pkgconfig = false
option.lib_path = nil

if ExecuteSilent("pkg-config --exists libcurl") == 0 then
option.value = true
option.use_pkgconfig = true
end
end

local apply = function(option, settings)
if option.use_pkgconfig == true then
settings.cc.flags:Add(RunCommand("pkg-config --cflags libcurl"))
settings.link.flags:Add(RunCommand("pkg-config --libs libcurl"))
end
end

local save = function(option, output)
output:option(option, "value")
output:option(option, "use_pkgconfig")
end

local display = function(option)
if option.value == true then
if option.use_pkgconfig == true then return "using pkg-config" end
return "using unknown method"
else
if option.required then
return "not found (required)"
else
return "not found (optional)"
end
end
end

local o = MakeOption(name, 0, check, save, display)
o.Apply = apply
o.include_path = nil
o.lib_path = nil
o.required = required
return o
end
}
27 changes: 27 additions & 0 deletions cmake/FindCurl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
if(NOT CMAKE_CROSSCOMPILING)
find_package(PkgConfig QUIET)
pkg_check_modules(PC_CURL libcurl)
endif()

find_library(CURL_LIBRARY
NAMES curl
HINTS ${HINTS_CURL_LIBDIR} ${PC_CURL_LIBDIR} ${PC_CURL_LIBRARY_DIRS}
PATHS ${PATHS_CURL_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
)

find_path(CURL_INCLUDEDIR curl.h
PATH_SUFFIXES curl
HINTS ${HINTS_CURL_INCLUDEDIR} ${PC_CURL_INCLUDEDIR} ${PC_CURL_INCLUDE_DIRS}
PATHS ${PATHS_CURL_INCLUDEDIR}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Curl DEFAULT_MSG CURL_LIBRARY CURL_INCLUDEDIR)

mark_as_advanced(CURL_LIBRARY CURL_INCLUDEDIR)

if(CURL_FOUND)
set(CURL_LIBRARIES ${CURL_LIBRARY})
set(CURL_INCLUDE_DIRS ${CURL_INCLUDEDIR})
endif()
2 changes: 1 addition & 1 deletion src/base/tl/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class memory_stream : public stream
virtual unsigned write(const unsigned char *buffer, unsigned size)
{
unsigned start = mem_buffer->size();
mem_buffer->hint_size(start + size);
mem_buffer->set_size(start + size);
inplace_memory_stream stream((unsigned char *) mem_buffer->base_ptr() + start, size);
return stream.write(buffer, size);
}
Expand Down
109 changes: 39 additions & 70 deletions src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <engine/shared/datafile.h>
#include <engine/shared/demo.h>
#include <engine/shared/filecollection.h>
#include <engine/shared/http_request.h>
#include <engine/shared/jsonparser.h>
#include <engine/shared/mapchecker.h>
#include <engine/shared/network.h>
#include <engine/shared/packer.h>
Expand All @@ -39,8 +41,6 @@
#include <game/version.h>

#include <mastersrv/mastersrv.h>
#include <versionsrv/mapversions.h>
#include <versionsrv/versionsrv.h>

#include "contacts.h"
#include "serverbrowser.h"
Expand Down Expand Up @@ -305,7 +305,7 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta), m_DemoRecorder(&m_SnapshotD
m_SnapshotStorage.Init();
m_ReceivedSnapshots = 0;

m_VersionInfo.m_State = CVersionInfo::STATE_INIT;
m_pVersionRequest = 0;

m_pLocalServerProcess = 0;
}
Expand Down Expand Up @@ -1017,55 +1017,6 @@ int CClient::UnpackServerInfoPlayer(CUnpacker *pUnpacker, CServerInfo *pInfo, in

void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
{
// version server
if(m_VersionInfo.m_State == CVersionInfo::STATE_READY && net_addr_comp(&pPacket->m_Address, &m_VersionInfo.m_VersionServeraddr.m_Addr, true) == 0)
{
// version info
if(pPacket->m_DataSize == (int) (sizeof(VERSIONSRV_VERSION) + sizeof(GAME_RELEASE_VERSION)) &&
mem_comp(pPacket->m_pData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0)

{
char *pVersionData = (char *) pPacket->m_pData + sizeof(VERSIONSRV_VERSION);
int VersionMatch = !mem_comp(pVersionData, GAME_RELEASE_VERSION, sizeof(GAME_RELEASE_VERSION));

char aVersion[sizeof(GAME_RELEASE_VERSION)];
str_copy(aVersion, pVersionData, sizeof(aVersion));

char aBuf[256];
str_format(aBuf, sizeof(aBuf), "version does %s (%s)",
VersionMatch ? "match" : "NOT match",
aVersion);
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/version", aBuf);

// assume version is out of date when version-data doesn't match
if(!VersionMatch)
{
str_copy(m_aVersionStr, aVersion, sizeof(m_aVersionStr));
}

// request the map version list now
unsigned char aData[sizeof(VERSIONSRV_GETMAPLIST) + sizeof(unsigned)];
mem_copy(aData, VERSIONSRV_GETMAPLIST, sizeof(VERSIONSRV_GETMAPLIST));
uint_to_bytes_be(aData + sizeof(VERSIONSRV_GETMAPLIST), CLIENT_VERSION);
CNetChunk Packet;
Packet.m_ClientID = -1;
Packet.m_Address = m_VersionInfo.m_VersionServeraddr.m_Addr;
Packet.m_Flags = NETSENDFLAG_CONNLESS;
Packet.m_pData = aData;
Packet.m_DataSize = sizeof(aData);
m_ContactClient.Send(&Packet);
}

// map version list
if(pPacket->m_DataSize >= (int) sizeof(VERSIONSRV_MAPLIST) &&
mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0)
{
m_pMapChecker->AddMaplist(
(const CMapVersion *) ((char *) pPacket->m_pData + sizeof(VERSIONSRV_MAPLIST)),
unsigned(pPacket->m_DataSize - sizeof(VERSIONSRV_MAPLIST)) / sizeof(CMapVersion));
}
}

// server list from master server
if(pPacket->m_DataSize >= (int) sizeof(SERVERBROWSE_LIST) &&
mem_comp(pPacket->m_pData, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST)) == 0)
Expand Down Expand Up @@ -1788,35 +1739,46 @@ void CClient::Update()

void CClient::VersionUpdate()
{
if(m_VersionInfo.m_State == CVersionInfo::STATE_INIT)
if(!m_pVersionRequest)
{
Engine()->HostLookup(&m_VersionInfo.m_VersionServeraddr, Config()->m_ClVersionServer, m_ContactClient.NetType());
m_VersionInfo.m_State = CVersionInfo::STATE_START;
m_pVersionRequest = new CHttpRequest("GET", Config()->m_ClVersionUrl, 0L);
m_pVersionRequest->StartRun(Engine());
}
else if(m_VersionInfo.m_State == CVersionInfo::STATE_START)
else if(m_pVersionRequest->Status() == CJob::STATE_DONE && !m_pVersionRequest->IsChecked())
{
if(m_VersionInfo.m_VersionServeraddr.m_Job.Status() == CJob::STATE_DONE)
if(m_pVersionRequest->Result() == 0 && m_pVersionRequest->ResponseCode() == 200)
{
if(m_VersionInfo.m_VersionServeraddr.m_Job.Result() == 0)
CJsonParser Parser;
const json_value *pJsonData = Parser.ParseData(m_pVersionRequest->ReceivedData(), m_pVersionRequest->ReceivedDataSize());
if(pJsonData)
{
CNetChunk Packet;

mem_zero(&Packet, sizeof(Packet));
if((*pJsonData)["version"].type == json_string)
{
const char *pVersion = (*pJsonData)["version"];
bool VersionMatch = str_comp(GAME_RELEASE_VERSION, pVersion) == 0;

m_VersionInfo.m_VersionServeraddr.m_Addr.port = VERSIONSRV_PORT;
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "version does %s (%s)",
VersionMatch ? "match" : "NOT match",
pVersion);

Packet.m_ClientID = -1;
Packet.m_Address = m_VersionInfo.m_VersionServeraddr.m_Addr;
Packet.m_pData = VERSIONSRV_GETVERSION;
Packet.m_DataSize = sizeof(VERSIONSRV_GETVERSION);
Packet.m_Flags = NETSENDFLAG_CONNLESS;
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/version", aBuf);

m_ContactClient.Send(&Packet);
m_VersionInfo.m_State = CVersionInfo::STATE_READY;
// assume version is out of date when version-data doesn't match
if(!VersionMatch)
str_copy(m_aVersionStr, pVersion, sizeof(m_aVersionStr));
}
if((*pJsonData)["maps"].type == json_array)
m_pMapChecker->AddMaplist(&(*pJsonData)["maps"]);
}
else
m_VersionInfo.m_State = CVersionInfo::STATE_ERROR;
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "failed to load version.json, json error: %s", Parser.Error());
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/version", aBuf);
}
}
m_pVersionRequest->MarkAsChecked();
}
}

Expand Down Expand Up @@ -2207,6 +2169,9 @@ void CClient::Run()
m_ServerBrowser.SaveServerlist();

CloseLocalServer();

if(m_pVersionRequest)
delete m_pVersionRequest;
// shutdown SDL
SDL_Quit();
}
Expand Down Expand Up @@ -2663,6 +2628,10 @@ int main(int argc, const char **argv)
return -1;
}

CCurlInit Curl;
if(Curl.IsFailed())
return -1;

signal(SIGINT, HandleSigIntTerm);
signal(SIGTERM, HandleSigIntTerm);

Expand Down
Loading
Loading