Port server to Linux and add Docker Compose deployment
Rebuilds (not Wine) the login/char/world servers natively for Linux via CMake, and ships a single Docker image plus docker-compose stack (MariaDB + 3 servers) with all settings configurable via .env. Linux portability: - Src/Common/compat.h shims MSVC-only CRT calls (fopen_s, _strdup, strncpy_s, sprintf_s, SYSTEMTIME/GetLocalTime, WSAGetLastError, __cdecl) and adds a case-insensitive/backslash-tolerant path resolver for the Windows-authored STB/AIP data file paths. - Fixed case-sensitive header includes and filenames (charserver.h vs CharServer.h, worldserver.h vs WorldServer.h, ../common vs ../Common). - rose_inet_addr() resolves hostnames (not just literal IPs) for the server-to-server links, so docker-compose service names work. Fixed three real bugs that only crashed on 64-bit Linux (silently tolerated on 32-bit Windows): - CIntStb::LoadSTB had an inverted fopen success/failure check, so STB game data (zones, items, etc.) was never actually loaded. - GenerateCryptTables allocated its pointer table with sizeof(unsigned) instead of sizeof(unsigned*) -- a 1x vs 2x-size heap overflow on 64-bit. - Crypto bit-twiddling relies throughout on signed-overflow-as-wraparound, which is UB in C++; GCC's -O3 exploited it and miscompiled GenerateCryptTables (Release-only crash). Fixed via -fwrapv. Plus smaller fixes: off-by-one array bounds (inventory/storage/sell data), SO_REUSEADDR on server sockets (containers restarting in the same netns hit TIME_WAIT otherwise), and a va_list reused across multiple vprintf/vfprintf calls in Log() that garbled every formatted log line on the Linux ABI. Docker: - CMakeLists.txt builds all three servers + shared Common code. - Dockerfile: multi-stage build, one runtime image for all three servers, server role selected via `command: [login|char|world]`. - docker-compose.yml: MariaDB (auto-imports database sql files/ on first run) + login/char/world (single channel), config rendered from docker/conf/*.conf.tmpl via envsubst at container start. - .env.example documents every setting (ports, server names, rates, inter-server passwords, PUBLIC_HOST for internet-facing deployments). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a320bbe470
commit
764fcb3b3f
37 files changed
+811
-72
No files matched your search
@@ -434,7 +434,7 @@ PVOID WorldProcess( PVOID TS )
|
||||
// Shutdown Server Process
|
||||
void ShutdownServer(PVOID TS)
|
||||
{
|
||||
int minutes = (int)TS;
|
||||
int minutes = (int)(intptr_t)TS;
|
||||
#ifdef _WIN32
|
||||
Sleep(minutes*60000);
|
||||
#else
|
||||
|
||||
@@ -38,7 +38,9 @@ void StartSignal( )
|
||||
signal( SIGFPE, HandleSignal );
|
||||
signal( SIGSEGV, HandleSignal );
|
||||
signal( SIGTERM, HandleSignal );
|
||||
#ifdef _WIN32
|
||||
signal( SIGBREAK, HandleSignal );
|
||||
#endif
|
||||
signal( SIGABRT, HandleSignal );
|
||||
}
|
||||
|
||||
@@ -49,7 +51,9 @@ void StopSignal( )
|
||||
signal( SIGFPE, 0 );
|
||||
signal( SIGSEGV, 0 );
|
||||
signal( SIGTERM, 0 );
|
||||
#ifdef _WIN32
|
||||
signal( SIGBREAK, 0 );
|
||||
#endif
|
||||
signal( SIGABRT, 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ void CWorldServer::ReadAIP(strings path, dword index)
|
||||
|
||||
void CWorldServer::LoadAipData()
|
||||
{
|
||||
CStrStb* stbAip = new CStrStb("3DDATA\\STB\\FILE_AI.STB");
|
||||
CStrStb* stbAip = new CStrStb("3DData/STB/FILE_AI.STB");
|
||||
Log(MSG_INFO, "Loading AIP files");
|
||||
for(dword i = 1; i < stbAip->Rows(); i++)
|
||||
{
|
||||
|
||||
@@ -473,7 +473,7 @@
|
||||
|
||||
|
||||
|
||||
#include "../common/sockets.h"
|
||||
#include "../Common/sockets.h"
|
||||
|
||||
//LTB strings
|
||||
struct CLTBstring
|
||||
|
||||
@@ -55,9 +55,10 @@ class CPlayer: public CCharacter
|
||||
CRespawnPoints GMRespawnPoints;
|
||||
|
||||
// Inventory/storage
|
||||
CItem storageitems[MAX_STORAGE];
|
||||
// +1: slot indices throughout the codebase run 0..MAX_* inclusive
|
||||
CItem storageitems[MAX_STORAGE + 1];
|
||||
unsigned int nstorageitems;
|
||||
CItem items[MAX_INVENTORY];
|
||||
CItem items[MAX_INVENTORY + 1];
|
||||
|
||||
// skills/quickbar
|
||||
SKILLS cskills[MAX_SKILL];
|
||||
|
||||
@@ -13,7 +13,11 @@ public:
|
||||
unsigned dataoffset = 0;
|
||||
unsigned short fieldlen = 0;
|
||||
|
||||
if ( (fh = fopen( filename, "rb" )) != 0 ) {
|
||||
#ifdef _WIN32
|
||||
if ( (fh = fopen( filename, "rb" )) == 0 ) {
|
||||
#else
|
||||
if ( (fh = rose_fopen( filename, "rb" )) == 0 ) {
|
||||
#endif
|
||||
Log( MSG_ERROR, "Could not load STB '%s'", filename );
|
||||
return 1;
|
||||
}else{
|
||||
|
||||
@@ -219,7 +219,11 @@ class CRoseFile
|
||||
if( fopen_s( &fh, fname, fasciimode ) == 0 )
|
||||
{
|
||||
#else
|
||||
if( ( fh = fopen( fname, fasciimode ) ) != NULL )
|
||||
#ifdef _WIN32
|
||||
if( ( fh = fopen( fname, fasciimode ) ) != NULL )
|
||||
#else
|
||||
if( ( fh = rose_fopen( fname, fasciimode ) ) != NULL )
|
||||
#endif
|
||||
{
|
||||
#endif
|
||||
delete[] fasciimode;
|
||||
@@ -242,8 +246,10 @@ class CRoseFile
|
||||
}
|
||||
#ifndef CFILE_NODEPRECATE
|
||||
fopen_s( &fh, fname, fasciimode );
|
||||
#else
|
||||
#elif defined(_WIN32)
|
||||
fh = fopen( fname, fasciimode );
|
||||
#else
|
||||
fh = rose_fopen( fname, fasciimode );
|
||||
#endif
|
||||
SetAbsPos( 2 );
|
||||
ftype = FT_UNICODE;
|
||||
|
||||
@@ -184,8 +184,8 @@ QUESTREWD(002)
|
||||
|
||||
for(dword i = 0; i < data->iDataCnt; i++)
|
||||
{
|
||||
dword address = i * sizeof(STR_QUEST_DATA);
|
||||
address += (dword)data;
|
||||
uintptr_t address = i * sizeof(STR_QUEST_DATA);
|
||||
address += (uintptr_t)data;
|
||||
address += 4;
|
||||
STR_QUEST_DATA* curQst = (STR_QUEST_DATA*)address;
|
||||
if( client->questdebug )
|
||||
@@ -208,8 +208,8 @@ QUESTREWD(003)
|
||||
//byte btOp; pos 0x0c
|
||||
for(dword i = 0; i < data->iDataCnt; i++)
|
||||
{
|
||||
//dword address = i * 0x0C;
|
||||
//address += (dword)data;
|
||||
//uintptr_t address = i * 0x0C;
|
||||
//address += (uintptr_t)data;
|
||||
//address += 4;
|
||||
//STR_ABIL_DATA* curAbil = (STR_ABIL_DATA*)address;
|
||||
if( client->questdebug )
|
||||
|
||||
@@ -37,8 +37,8 @@ QUESTCOND(001)
|
||||
if( client->questdebug )server->SendPM(client, "Data Count for this quest %i",data->iDataCnt);
|
||||
for(int i = 0; i < data->iDataCnt; i++)
|
||||
{
|
||||
dword address = i * sizeof(STR_QUEST_DATA);
|
||||
address += (dword)data;
|
||||
uintptr_t address = i * sizeof(STR_QUEST_DATA);
|
||||
address += (uintptr_t)data;
|
||||
address += 4;
|
||||
STR_QUEST_DATA* curQst = (STR_QUEST_DATA*)address;
|
||||
word nValue = curQst->nValue;
|
||||
@@ -96,8 +96,8 @@ QUESTCOND(003)
|
||||
GETCONDDATA(003);
|
||||
for(int i = 0; i < data->iDataCnt; i++)
|
||||
{
|
||||
dword address = i * 0x0C;
|
||||
address += (dword)data;
|
||||
uintptr_t address = i * 0x0C;
|
||||
address += (uintptr_t)data;
|
||||
address += 4;
|
||||
STR_ABIL_DATA* curAbil = (STR_ABIL_DATA*)address;
|
||||
if( client->questdebug )
|
||||
@@ -175,8 +175,8 @@ QUESTCOND(004)
|
||||
GETCONDDATA(004);
|
||||
for(int i = 0; i < data->iDataCnt; i++)
|
||||
{
|
||||
dword address = i * 0x10;
|
||||
address += (dword)data;
|
||||
uintptr_t address = i * 0x10;
|
||||
address += (uintptr_t)data;
|
||||
address += 4;
|
||||
STR_ITEM_DATA* curItem = (STR_ITEM_DATA*)address;
|
||||
if( client->questdebug )
|
||||
|
||||
@@ -78,7 +78,7 @@ void CWorldServer::ReadQSD(strings path, dword index){
|
||||
}
|
||||
|
||||
void CWorldServer::LoadQuestData(){
|
||||
CStrStb* stbQuest = new CStrStb("3DDATA\\STB\\LIST_QUESTDATA.STB");
|
||||
CStrStb* stbQuest = new CStrStb("3DData/STB/LIST_QUESTDATA.STB");
|
||||
Log(MSG_INFO, "Loading QSD files");
|
||||
for(dword i = 1; i < stbQuest->Rows(); i++){
|
||||
if(stbQuest->Data(i, 0)){
|
||||
|
||||
@@ -22,31 +22,31 @@
|
||||
bool CWorldServer::LoadSTBData( )
|
||||
{
|
||||
Log( MSG_LOAD, "STB Data " );
|
||||
STBStoreData( "3DData\\STB\\LIST_NPC.STB", &STB_NPC );
|
||||
STBStoreData( "3DData\\STB\\LIST_SKILL.STB", &STB_SKILL );
|
||||
STBStoreData( "3DData\\STB\\LIST_STATUS.STB", &STB_STATUS );
|
||||
STBStoreData( "3DData\\STB\\LIST_QUEST.STB", &STB_QUEST );
|
||||
STBStoreData( "3DData\\STB\\LIST_FACEITEM.STB", &STB_ITEM[0] );
|
||||
STBStoreData( "3DData\\STB\\LIST_CAP.STB", &STB_ITEM[1] );
|
||||
STBStoreData( "3DData\\STB\\LIST_BODY.STB", &STB_ITEM[2] );
|
||||
STBStoreData( "3DData\\STB\\LIST_ARMS.STB", &STB_ITEM[3] );
|
||||
STBStoreData( "3DData\\STB\\LIST_FOOT.STB", &STB_ITEM[4] );
|
||||
STBStoreData( "3DData\\STB\\LIST_BACK.STB", &STB_ITEM[5] );
|
||||
STBStoreData( "3DData\\STB\\LIST_JEWEL.STB", &STB_ITEM[6] );
|
||||
STBStoreData( "3DData\\STB\\LIST_WEAPON.STB", &STB_ITEM[7] );
|
||||
STBStoreData( "3DData\\STB\\LIST_SUBWPN.STB", &STB_ITEM[8] );
|
||||
STBStoreData( "3DData\\STB\\LIST_USEITEM.STB", &STB_ITEM[9] );
|
||||
STBStoreData( "3DData\\STB\\LIST_JEMITEM.STB", &STB_ITEM[10] );
|
||||
STBStoreData( "3DData\\STB\\LIST_NATURAL.STB", &STB_ITEM[11] );
|
||||
STBStoreData( "3DData\\STB\\LIST_QUESTITEM.STB", &STB_ITEM[12] );
|
||||
STBStoreData( "3DData\\STB\\LIST_PAT.STB", &STB_ITEM[13] );
|
||||
STBStoreData( "3DData\\STB\\LIST_PRODUCT.STB", &STB_PRODUCT );
|
||||
STBStoreData( "3DData\\STB\\LIST_BREAK.STB", &STB_BREAK );
|
||||
STBStoreData( "3DData\\STB\\LIST_SELL.STB", &STB_SELL );
|
||||
STBStoreData( "3DData\\STB\\LIST_ZONE.STB", &STB_ZONE );
|
||||
//STBStoreData( "3DData\\STB\\ITEM_DROP.STB", &STB_DROP );
|
||||
STBStoreData("3DData\\STB\\LIST_GRADE.STB", &ListGrade);
|
||||
STBStoreData("3DData\\STB\\LIST_UPGRADE.STB", &ListUpGrade);
|
||||
STBStoreData( "3DData/STB/LIST_NPC.STB", &STB_NPC );
|
||||
STBStoreData( "3DData/STB/LIST_SKILL.STB", &STB_SKILL );
|
||||
STBStoreData( "3DData/STB/LIST_STATUS.STB", &STB_STATUS );
|
||||
STBStoreData( "3DData/STB/LIST_QUEST.STB", &STB_QUEST );
|
||||
STBStoreData( "3DData/STB/LIST_FACEITEM.STB", &STB_ITEM[0] );
|
||||
STBStoreData( "3DData/STB/LIST_CAP.STB", &STB_ITEM[1] );
|
||||
STBStoreData( "3DData/STB/LIST_BODY.STB", &STB_ITEM[2] );
|
||||
STBStoreData( "3DData/STB/LIST_ARMS.STB", &STB_ITEM[3] );
|
||||
STBStoreData( "3DData/STB/LIST_FOOT.STB", &STB_ITEM[4] );
|
||||
STBStoreData( "3DData/STB/LIST_BACK.STB", &STB_ITEM[5] );
|
||||
STBStoreData( "3DData/STB/LIST_JEWEL.STB", &STB_ITEM[6] );
|
||||
STBStoreData( "3DData/STB/LIST_WEAPON.STB", &STB_ITEM[7] );
|
||||
STBStoreData( "3DData/STB/LIST_SUBWPN.STB", &STB_ITEM[8] );
|
||||
STBStoreData( "3DData/STB/LIST_USEITEM.STB", &STB_ITEM[9] );
|
||||
STBStoreData( "3DData/STB/LIST_JEMITEM.STB", &STB_ITEM[10] );
|
||||
STBStoreData( "3DData/STB/LIST_NATURAL.STB", &STB_ITEM[11] );
|
||||
STBStoreData( "3DData/STB/LIST_QUESTITEM.STB", &STB_ITEM[12] );
|
||||
STBStoreData( "3DData/STB/LIST_PAT.STB", &STB_ITEM[13] );
|
||||
STBStoreData( "3DData/STB/LIST_PRODUCT.STB", &STB_PRODUCT );
|
||||
STBStoreData( "3DData/STB/LIST_BREAK.STB", &STB_BREAK );
|
||||
STBStoreData( "3DData/STB/LIST_SELL.STB", &STB_SELL );
|
||||
STBStoreData( "3DData/STB/LIST_ZONE.STB", &STB_ZONE );
|
||||
//STBStoreData( "3DData/STB/ITEM_DROP.STB", &STB_DROP );
|
||||
STBStoreData("3DData/STB/LIST_GRADE.STB", &ListGrade);
|
||||
STBStoreData("3DData/STB/LIST_UPGRADE.STB", &ListUpGrade);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -882,9 +882,18 @@ bool CWorldServer::LoadEquip( )
|
||||
for(int k=0;k<2;k++)
|
||||
newequip->stat2[k] = STB_ITEM[j].rows[i][(27+k)];
|
||||
|
||||
newequip->refinetype = STB_ITEM[j].rows[i][45]; //new this is the recipe for refining the item
|
||||
newequip->itemgrade = STB_ITEM[j].rows[i][46];
|
||||
newequip->raretype = STB_ITEM[j].rows[i][47];
|
||||
if (STB_ITEM[j].fieldcount>47)
|
||||
{
|
||||
newequip->refinetype = STB_ITEM[j].rows[i][45]; //new this is the recipe for refining the item
|
||||
newequip->itemgrade = STB_ITEM[j].rows[i][46];
|
||||
newequip->raretype = STB_ITEM[j].rows[i][47];
|
||||
}
|
||||
else
|
||||
{
|
||||
newequip->refinetype = 0;
|
||||
newequip->itemgrade = 0;
|
||||
newequip->raretype = 0;
|
||||
}
|
||||
|
||||
if(newequip->id > 4999)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ CMap::~CMap( )
|
||||
{
|
||||
for(UINT i=0;i<RespawnList.size();i++)
|
||||
delete RespawnList.at(i);
|
||||
if(GServer->Config.SpawnType == 0)
|
||||
if(GServer && GServer->Config.SpawnType == 0)
|
||||
{
|
||||
for(UINT i = 0; i < MobGroupList.size(); i++)
|
||||
{
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
WorldMonster.h
|
||||
@@ -100,7 +100,7 @@ CWorldServer::CWorldServer( string fn )
|
||||
PatList.nullpat = nullpat;
|
||||
CCSellData* nullsell = new CCSellData;
|
||||
nullsell->id = 0;
|
||||
for(UINT i=0;i<50;i++)
|
||||
for(UINT i=0;i<49;i++)
|
||||
nullsell->item[i] = 0;
|
||||
SellList.nullsell = nullsell ;
|
||||
for(UINT i=0;i<1000;i++)
|
||||
@@ -228,7 +228,6 @@ CWorldServer::~CWorldServer( )
|
||||
delete SellList.nullsell;
|
||||
delete UseList.nulluse;
|
||||
delete MapList.nullzone;
|
||||
delete [] GradeList;
|
||||
delete DB;
|
||||
}
|
||||
|
||||
@@ -608,7 +607,7 @@ bool CWorldServer::OnServerReady( )
|
||||
}
|
||||
struct sockaddr_in ain;
|
||||
ain.sin_family = AF_INET;
|
||||
ain.sin_addr.s_addr = inet_addr( Config.CharIP );
|
||||
ain.sin_addr.s_addr = rose_inet_addr( Config.CharIP );
|
||||
ain.sin_port = htons( Config.CharPort );
|
||||
if ( connect( csock, (SOCKADDR*) &ain, sizeof(ain) ) == SOCKET_ERROR )
|
||||
Log( MSG_WARNING, "Could not access charserver" );
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
WorldServer.h
|
||||
Reference in new issue
Block a user