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>
60 lines
1.2 KiB
C++
60 lines
1.2 KiB
C++
// Props to ExJam for this code :D
|
|
|
|
class CIntStb
|
|
{
|
|
public:
|
|
CIntStb() : rows(0) {}
|
|
CIntStb(char* filename) : rows(0){ LoadSTB(filename); }
|
|
~CIntStb(){ CleanUp(); }
|
|
|
|
int LoadSTB( char* filename ){
|
|
FILE* fh;
|
|
char tmpfield[512];
|
|
unsigned dataoffset = 0;
|
|
unsigned short fieldlen = 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{
|
|
fseek( fh, 4, SEEK_SET );
|
|
fread( &dataoffset, 4, 1, fh );
|
|
fread( &rowcount, 4, 1, fh );
|
|
fread( &fieldcount, 4, 1, fh );
|
|
|
|
rowcount--;
|
|
fieldcount--;
|
|
|
|
fseek( fh, dataoffset, SEEK_SET );
|
|
int* tmp = new int[rowcount*fieldcount];
|
|
rows = new int*[rowcount];
|
|
for(dword i = 0; i < rowcount; i++ ) rows[i] = &tmp[i*fieldcount];
|
|
for(dword j = 0; j < rowcount*fieldcount; j++) {
|
|
fread( &fieldlen, 2, 1, fh );
|
|
fread( tmpfield, 1, fieldlen, fh );
|
|
tmpfield[fieldlen]=0;
|
|
tmp[j] = atoi( tmpfield );
|
|
}
|
|
fclose( fh );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
dword rowcount;
|
|
dword fieldcount;
|
|
int** rows;
|
|
|
|
private:
|
|
void CleanUp(){
|
|
if(rows != NULL){
|
|
delete [] rows[0];
|
|
delete [] rows;
|
|
}
|
|
}
|
|
};
|