Files
92thmsandClaude Sonnet 5 764fcb3b3f 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>
2026-07-08 06:32:39 +00:00

116 lines
4.0 KiB
C++

/*
Open Source Rose Online Team - http://osroseon.to.md/
note: the Server is develop with erose source server + eich source
*/
#ifndef __ROSE_SERVERS__
#define __ROSE_SERVERS__
#include <time.h>
#include "../Common/sockets.h"
#include "datatypes.h"
#define ClearItem(i) { i.durability=0; i.itemnum=0; i.itemtype=0; i.lifespan=0; i.refine=0; }
using namespace std;
// Clent class
class CCharClient : public CClientSocket
{
public:
CCharClient ( ); // constructor
~CCharClient ( ); // destructor
// User information
UINT userid;
bool platinum;
char username[17];
char password[33];
UINT accesslevel;
UINT channel;
// Character information
char charname[17];
UINT clanid;
int clan_rank;
UINT level;
UINT job;
UINT charid;
bool isLoggedIn;
bool returnedfromWS;
bool logout;
vector<CFriendList*> FriendList;
};
// Server class
class CCharServer : public CServerSocket
{
public:
CCharServer ( string );
~CCharServer( );
CCharClient* CreateClientSocket( );
void DeleteClientSocket( CClientSocket* thisclient );
void LoadEncryption( );
void OnClientDisconnect( CClientSocket* thisclient );
bool OnServerReady( );
void LoadConfigurations( const char* );
bool OnReceivePacket( CClientSocket* thisclient, CPacket* P );
bool Ping( );
// Extra functions
CChanels* GetChannelByID( UINT id );
CCharClient* GetClientByUserID( UINT id );
CCharClient* GetClientByID( UINT id );
CCharClient* GetClientByName( char *name );
CCharClient* GetClientByUserName( char *username );
CClans* GetClanByID( int id );
unsigned long int GetServerTime( );
// Community functions
bool ChangeMessengerStatus (CCharClient* thisclient, CCharClient* otherclient, int status);
bool pakMessengerManager ( CCharClient* thisclient, CPacket* P );
bool pakMessengerChat ( CCharClient* thisclient, CPacket* P );
// Clan Functions
bool SendClanInfo (CCharClient* thisclient);
bool ChangeClanStatus (CCharClient* thisclient, CCharClient* otherclient, int channel);
bool SendToClanMembers( int clanid,CPacket* pak );
bool UpdateClanWindow( int clanid );
bool pakClanMembers ( CCharClient* thisclient );
bool pakClanManager ( CCharClient* thisclient, CPacket* P );
bool pakClanChat ( CCharClient* thisclient, CPacket* P );
bool ClanLogout ( CCharClient* thisclient );
bool pakUploadCM ( CCharClient* thisclient, CPacket* P );
bool pakDownloadCM( CCharClient* thisclient, CPacket* P );
bool pakClanIconTime( CCharClient* thisclient, CPacket* P );
// General Packets
bool pakUpdateLevel( CCharClient* thisclient, CPacket* P );
bool pakDoIdentify( CCharClient* thisclient, CPacket* P );
bool pakGetCharacters( CCharClient* thisclient, CPacket* P );
bool pakRequestWorld( CCharClient* thisclient, CPacket* P );
bool pakCreateChar( CCharClient* thisclient, CPacket* P );
bool pakDeleteChar( CCharClient* thisclient, CPacket* P );
bool pakWSReady ( CCharClient* thisclient, CPacket* P );
bool pakWSCharSelect ( CCharClient* thisclient, CPacket* P );
bool pakLoginConnected ( CCharClient* thisclient, CPacket* P );
bool pakLoginDSClient( CCharClient* thisclient, CPacket* P );
bool pak7e5 ( CCharClient* thisclient, CPacket* P );
bool pakChatrooms ( CCharClient* thisclient, CPacket* P );
// Variables
string filename;
vector <CClans*> ClanList;
vector <CChanels*> ChannelList;
//Login
SOCKET lsock; // Socket to Login
char* lct; // Encryption table for login server
CDatabase* DB;
};
void StartSignal( );
void StopSignal( );
void HandleSignal( int num );
extern class CCharServer* GServer;
#endif