chore(Core/Worldserver): restyle worldserver lib with astyle (#3463)

This commit is contained in:
Kargatum
2020-09-11 10:41:31 +07:00
committed by GitHub
parent c141be8684
commit d47d6d34f3
11 changed files with 139 additions and 137 deletions
+3 -2
View File
@@ -35,7 +35,7 @@ void ACSoapRunnable::run()
continue; // ran into an accept timeout continue; // ran into an accept timeout
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "ACSoap: accepted connection from IP=%d.%d.%d.%d", (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF); sLog->outDebug(LOG_FILTER_NETWORKIO, "ACSoap: accepted connection from IP=%d.%d.%d.%d", (int)(soap.ip >> 24) & 0xFF, (int)(soap.ip >> 16) & 0xFF, (int)(soap.ip >> 8) & 0xFF, (int)soap.ip & 0xFF);
#endif #endif
struct soap* thread_soap = soap_copy(&soap);// make a safe copy struct soap* thread_soap = soap_copy(&soap);// make a safe copy
@@ -151,7 +151,8 @@ void SOAPCommand::commandFinished(void* soapconnection, bool success)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct Namespace namespaces[] = struct Namespace namespaces[] =
{ { "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", nullptr, nullptr }, // must be first {
{ "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", nullptr, nullptr }, // must be first
{ "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", nullptr, nullptr }, // must be second { "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", nullptr, nullptr }, // must be second
{ "xsi", "http://www.w3.org/1999/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL }, { "xsi", "http://www.w3.org/1999/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL },
{ "xsd", "http://www.w3.org/1999/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL }, { "xsd", "http://www.w3.org/1999/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL },
+35 -35
View File
@@ -16,57 +16,57 @@
class ACSoapRunnable : public acore::Runnable class ACSoapRunnable : public acore::Runnable
{ {
public: public:
ACSoapRunnable() : _port(0) { } ACSoapRunnable() : _port(0) { }
void run(); void run();
void SetListenArguments(const std::string& host, uint16 port) void SetListenArguments(const std::string& host, uint16 port)
{ {
_host = host; _host = host;
_port = port; _port = port;
} }
private: private:
void process_message(ACE_Message_Block* mb); void process_message(ACE_Message_Block* mb);
std::string _host; std::string _host;
uint16 _port; uint16 _port;
}; };
class SOAPCommand class SOAPCommand
{ {
public: public:
SOAPCommand(): pendingCommands(0, USYNC_THREAD, "pendingCommands"), m_success(false) {} SOAPCommand(): pendingCommands(0, USYNC_THREAD, "pendingCommands"), m_success(false) {}
~SOAPCommand() { } ~SOAPCommand() { }
void appendToPrintBuffer(const char* msg) void appendToPrintBuffer(const char* msg)
{ {
m_printBuffer += msg; m_printBuffer += msg;
} }
ACE_Semaphore pendingCommands; ACE_Semaphore pendingCommands;
void setCommandSuccess(bool val) void setCommandSuccess(bool val)
{ {
m_success = val; m_success = val;
} }
bool hasCommandSucceeded() const bool hasCommandSucceeded() const
{ {
return m_success; return m_success;
} }
static void print(void* callbackArg, const char* msg) static void print(void* callbackArg, const char* msg)
{ {
((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg); ((SOAPCommand*)callbackArg)->appendToPrintBuffer(msg);
} }
static void commandFinished(void* callbackArg, bool success); static void commandFinished(void* callbackArg, bool success);
bool m_success; bool m_success;
std::string m_printBuffer; std::string m_printBuffer;
}; };
#endif #endif
@@ -70,9 +70,9 @@ char** cli_completion(const char* text, int start, int /*end*/)
int cli_hook_func() int cli_hook_func()
{ {
if (World::IsStopped()) if (World::IsStopped())
rl_done = 1; rl_done = 1;
return 0; return 0;
} }
#endif #endif
@@ -81,18 +81,18 @@ void utf8print(void* /*arg*/, const char* str)
{ {
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
wchar_t wtemp_buf[6000]; wchar_t wtemp_buf[6000];
size_t wtemp_len = 6000-1; size_t wtemp_len = 6000 - 1;
if (!Utf8toWStr(str, strlen(str), wtemp_buf, wtemp_len)) if (!Utf8toWStr(str, strlen(str), wtemp_buf, wtemp_len))
return; return;
char temp_buf[6000]; char temp_buf[6000];
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len+1); CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len + 1);
printf(temp_buf); printf(temp_buf);
#else #else
{ {
printf("%s", str); printf("%s", str);
fflush(stdout); fflush(stdout);
} }
#endif #endif
} }
@@ -112,7 +112,7 @@ int kb_hit_return()
tv.tv_usec = 0; tv.tv_usec = 0;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds); FD_SET(STDIN_FILENO, &fds);
select(STDIN_FILENO+1, &fds, nullptr, nullptr, &tv); select(STDIN_FILENO + 1, &fds, nullptr, nullptr, &tv);
return FD_ISSET(STDIN_FILENO, &fds); return FD_ISSET(STDIN_FILENO, &fds);
} }
#endif #endif
@@ -139,7 +139,7 @@ void CliRunnable::run()
{ {
fflush(stdout); fflush(stdout);
char *command_str ; // = fgets(commandbuf, sizeof(commandbuf), stdin); char* command_str ; // = fgets(commandbuf, sizeof(commandbuf), stdin);
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
char commandbuf[256]; char commandbuf[256];
@@ -151,7 +151,7 @@ void CliRunnable::run()
if (command_str != nullptr) if (command_str != nullptr)
{ {
for (int x=0; command_str[x]; ++x) for (int x = 0; command_str[x]; ++x)
if (command_str[x] == '\r' || command_str[x] == '\n') if (command_str[x] == '\r' || command_str[x] == '\n')
{ {
command_str[x] = 0; command_str[x] = 0;
@@ -14,8 +14,8 @@
/// Command Line Interface handling thread /// Command Line Interface handling thread
class CliRunnable : public acore::Runnable class CliRunnable : public acore::Runnable
{ {
public: public:
void run(); void run();
}; };
#endif #endif
+2 -2
View File
@@ -82,7 +82,7 @@ extern int main(int argc, char** argv)
configFile = argv[c]; configFile = argv[c];
} }
#ifdef _WIN32 #ifdef _WIN32
if (strcmp(argv[c], "-s") == 0) // Services if (strcmp(argv[c], "-s") == 0) // Services
{ {
if (++c >= argc) if (++c >= argc)
@@ -114,7 +114,7 @@ extern int main(int argc, char** argv)
if (strcmp(argv[c], "--service") == 0) if (strcmp(argv[c], "--service") == 0)
WinServiceRun(); WinServiceRun();
#endif #endif
++c; ++c;
} }
+22 -22
View File
@@ -46,27 +46,27 @@ extern int m_ServiceStatus;
/// Handle worldservers's termination signals /// Handle worldservers's termination signals
class WorldServerSignalHandler : public acore::SignalHandler class WorldServerSignalHandler : public acore::SignalHandler
{ {
public: public:
virtual void HandleSignal(int sigNum) virtual void HandleSignal(int sigNum)
{
switch (sigNum)
{ {
switch (sigNum) case SIGINT:
{ World::StopNow(RESTART_EXIT_CODE);
case SIGINT: break;
World::StopNow(RESTART_EXIT_CODE); case SIGTERM:
break;
case SIGTERM:
#ifdef _WIN32 #ifdef _WIN32
case SIGBREAK: case SIGBREAK:
if (m_ServiceStatus != 1) if (m_ServiceStatus != 1)
#endif #endif
World::StopNow(SHUTDOWN_EXIT_CODE); World::StopNow(SHUTDOWN_EXIT_CODE);
break; break;
/*case SIGSEGV: /*case SIGSEGV:
sLog->outString("ZOMG! SIGSEGV handled!"); sLog->outString("ZOMG! SIGSEGV handled!");
World::StopNow(SHUTDOWN_EXIT_CODE); World::StopNow(SHUTDOWN_EXIT_CODE);
break;*/ break;*/
}
} }
}
}; };
class FreezeDetectorRunnable : public acore::Runnable class FreezeDetectorRunnable : public acore::Runnable
@@ -84,7 +84,7 @@ public:
if (!_delayTime) if (!_delayTime)
return; return;
sLog->outString("Starting up anti-freeze thread (%u seconds max stuck time)...", _delayTime/1000); sLog->outString("Starting up anti-freeze thread (%u seconds max stuck time)...", _delayTime / 1000);
while (!World::IsStopped()) while (!World::IsStopped())
{ {
uint32 curtime = getMSTime(); uint32 curtime = getMSTime();
@@ -166,9 +166,9 @@ int Master::Run()
///- Initialize the signal handlers ///- Initialize the signal handlers
WorldServerSignalHandler signalINT, signalTERM; //, signalSEGV WorldServerSignalHandler signalINT, signalTERM; //, signalSEGV
#ifdef _WIN32 #ifdef _WIN32
WorldServerSignalHandler signalBREAK; WorldServerSignalHandler signalBREAK;
#endif /* _WIN32 */ #endif /* _WIN32 */
///- Register worldserver's signal handlers ///- Register worldserver's signal handlers
ACE_Sig_Handler handle; ACE_Sig_Handler handle;
@@ -283,7 +283,7 @@ int Master::Run()
acore::Thread* freezeThread = nullptr; acore::Thread* freezeThread = nullptr;
if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0)) if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
{ {
FreezeDetectorRunnable* runnable = new FreezeDetectorRunnable(freezeDelay*1000); FreezeDetectorRunnable* runnable = new FreezeDetectorRunnable(freezeDelay * 1000);
freezeThread = new acore::Thread(runnable); freezeThread = new acore::Thread(runnable);
freezeThread->setPriority(acore::Priority_Highest); freezeThread->setPriority(acore::Priority_Highest);
} }
@@ -334,7 +334,7 @@ int Master::Run()
if (cliThread) if (cliThread)
{ {
#ifdef _WIN32 #ifdef _WIN32
// this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API) // this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API)
//_exit(1); //_exit(1);
@@ -373,11 +373,11 @@ int Master::Run()
cliThread->wait(); cliThread->wait();
#else #else
cliThread->destroy(); cliThread->destroy();
#endif #endif
delete cliThread; delete cliThread;
} }
@@ -411,7 +411,7 @@ bool Master::_StartDB()
if (async_threads < 1 || async_threads > 32) if (async_threads < 1 || async_threads > 32)
{ {
sLog->outError("World database: invalid number of worker threads specified. " sLog->outError("World database: invalid number of worker threads specified. "
"Please pick a value between 1 and 32."); "Please pick a value between 1 and 32.");
return false; return false;
} }
@@ -435,7 +435,7 @@ bool Master::_StartDB()
if (async_threads < 1 || async_threads > 32) if (async_threads < 1 || async_threads > 32)
{ {
sLog->outError("Character database: invalid number of worker threads specified. " sLog->outError("Character database: invalid number of worker threads specified. "
"Please pick a value between 1 and 32."); "Please pick a value between 1 and 32.");
return false; return false;
} }
@@ -460,7 +460,7 @@ bool Master::_StartDB()
if (async_threads < 1 || async_threads > 32) if (async_threads < 1 || async_threads > 32)
{ {
sLog->outError("Login database: invalid number of worker threads specified. " sLog->outError("Login database: invalid number of worker threads specified. "
"Please pick a value between 1 and 32."); "Please pick a value between 1 and 32.");
return false; return false;
} }
+7 -7
View File
@@ -16,15 +16,15 @@
/// Start the server /// Start the server
class Master class Master
{ {
public: public:
static Master* instance(); static Master* instance();
int Run(); int Run();
private: private:
bool _StartDB(); bool _StartDB();
void _StopDB(); void _StopDB();
void ClearOnlineAccounts(); void ClearOnlineAccounts();
}; };
#define sMaster Master::instance() #define sMaster Master::instance()
@@ -25,7 +25,7 @@ RASocket::RASocket()
_commandExecuting = false; _commandExecuting = false;
} }
int RASocket::open(void *) int RASocket::open(void*)
{ {
ACE_INET_Addr remoteAddress; ACE_INET_Addr remoteAddress;
@@ -105,16 +105,16 @@ int RASocket::recv_line(std::string& out_line)
char buf[4096]; char buf[4096];
ACE_Data_Block db(sizeof (buf), ACE_Data_Block db(sizeof (buf),
ACE_Message_Block::MB_DATA, ACE_Message_Block::MB_DATA,
buf, buf,
0, 0,
0, 0,
ACE_Message_Block::DONT_DELETE, ACE_Message_Block::DONT_DELETE,
0); 0);
ACE_Message_Block message_block(&db, ACE_Message_Block message_block(&db,
ACE_Message_Block::DONT_DELETE, ACE_Message_Block::DONT_DELETE,
0); 0);
if (recv_line(message_block) == -1) if (recv_line(message_block) == -1)
{ {
@@ -135,7 +135,8 @@ int RASocket::process_command(const std::string& command)
sLog->outRemote("Got command: %s", command.c_str()); sLog->outRemote("Got command: %s", command.c_str());
// handle quit, exit and logout commands to terminate connection // handle quit, exit and logout commands to terminate connection
if (command == "quit" || command == "exit" || command == "logout") { if (command == "quit" || command == "exit" || command == "logout")
{
(void) send("Bye\r\n"); (void) send("Bye\r\n");
return -1; return -1;
} }
@@ -262,23 +263,23 @@ int RASocket::subnegotiate()
char buf[1024]; char buf[1024];
ACE_Data_Block db(sizeof (buf), ACE_Data_Block db(sizeof (buf),
ACE_Message_Block::MB_DATA, ACE_Message_Block::MB_DATA,
buf, buf,
0, 0,
0, 0,
ACE_Message_Block::DONT_DELETE, ACE_Message_Block::DONT_DELETE,
0); 0);
ACE_Message_Block message_block(&db, ACE_Message_Block message_block(&db,
ACE_Message_Block::DONT_DELETE, ACE_Message_Block::DONT_DELETE,
0); 0);
const size_t recv_size = message_block.space(); const size_t recv_size = message_block.space();
// Wait a maximum of 1000ms for negotiation packet - not all telnet clients may send it // Wait a maximum of 1000ms for negotiation packet - not all telnet clients may send it
ACE_Time_Value waitTime = ACE_Time_Value(1); ACE_Time_Value waitTime = ACE_Time_Value(1);
const ssize_t n = peer().recv(message_block.wr_ptr(), const ssize_t n = peer().recv(message_block.wr_ptr(),
recv_size, &waitTime); recv_size, &waitTime);
if (n <= 0) if (n <= 0)
return int(n); return int(n);
@@ -291,7 +292,7 @@ int RASocket::subnegotiate()
buf[n] = '\0'; buf[n] = '\0';
#ifdef _DEBUG #ifdef _DEBUG
for (uint8 i = 0; i < n; ) for (uint8 i = 0; i < n; )
{ {
uint8 iac = buf[i]; uint8 iac = buf[i];
@@ -323,7 +324,7 @@ int RASocket::subnegotiate()
} }
++i; ++i;
} }
#endif #endif
//! Just send back end of subnegotiation packet //! Just send back end of subnegotiation packet
uint8 const reply[2] = {0xFF, 0xF0}; uint8 const reply[2] = {0xFF, 0xF0};
@@ -371,7 +372,7 @@ int RASocket::svc(void)
return 0; return 0;
} }
void RASocket::zprint(void* callbackArg, const char * szText) void RASocket::zprint(void* callbackArg, const char* szText)
{ {
if (!szText || !callbackArg) if (!szText || !callbackArg)
return; return;
@@ -405,8 +406,8 @@ void RASocket::commandFinished(void* callbackArg, bool /*success*/)
// hence we don't put timeout, because it shouldn't increase queue size and shouldn't block // hence we don't put timeout, because it shouldn't increase queue size and shouldn't block
if (socket->putq(mb->duplicate()) == -1) if (socket->putq(mb->duplicate()) == -1)
{ {
// getting here is bad, command can't be marked as complete // getting here is bad, command can't be marked as complete
//sLog->outDebug(LOG_FILTER_REMOTECOMMAND, "Failed to enqueue command end message. Error is %s", ACE_OS::strerror(errno)); //sLog->outDebug(LOG_FILTER_REMOTECOMMAND, "Failed to enqueue command end message. Error is %s", ACE_OS::strerror(errno));
} }
mb->release(); mb->release();
+20 -20
View File
@@ -22,30 +22,30 @@
/// Remote Administration socket /// Remote Administration socket
class RASocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH> class RASocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
{ {
public: public:
RASocket(); RASocket();
virtual ~RASocket() { } virtual ~RASocket() { }
virtual int svc(); virtual int svc();
virtual int open(void* = 0); virtual int open(void* = 0);
virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
private: private:
int recv_line(std::string& outLine); int recv_line(std::string& outLine);
int recv_line(ACE_Message_Block& buffer); int recv_line(ACE_Message_Block& buffer);
int process_command(const std::string& command); int process_command(const std::string& command);
int authenticate(); int authenticate();
int subnegotiate(); ///< Used by telnet protocol RFC 854 / 855 int subnegotiate(); ///< Used by telnet protocol RFC 854 / 855
int check_access_level(const std::string& user); int check_access_level(const std::string& user);
int check_password(const std::string& user, const std::string& pass); int check_password(const std::string& user, const std::string& pass);
int send(const std::string& line); int send(const std::string& line);
static void zprint(void* callbackArg, const char* szText); static void zprint(void* callbackArg, const char* szText);
static void commandFinished(void* callbackArg, bool success); static void commandFinished(void* callbackArg, bool success);
private: private:
uint8 _minLevel; ///< Minimum security level required to connect uint8 _minLevel; ///< Minimum security level required to connect
std::atomic_long _commandExecuting; std::atomic_long _commandExecuting;
}; };
#endif #endif
@@ -53,15 +53,15 @@ void WorldRunnable::run()
avgDiffTracker.Update(executionTimeDiff > WORLD_SLEEP_CONST ? executionTimeDiff : WORLD_SLEEP_CONST); avgDiffTracker.Update(executionTimeDiff > WORLD_SLEEP_CONST ? executionTimeDiff : WORLD_SLEEP_CONST);
if (executionTimeDiff < WORLD_SLEEP_CONST) if (executionTimeDiff < WORLD_SLEEP_CONST)
acore::Thread::Sleep(WORLD_SLEEP_CONST-executionTimeDiff); acore::Thread::Sleep(WORLD_SLEEP_CONST - executionTimeDiff);
#ifdef _WIN32 #ifdef _WIN32
if (m_ServiceStatus == 0) if (m_ServiceStatus == 0)
World::StopNow(SHUTDOWN_EXIT_CODE); World::StopNow(SHUTDOWN_EXIT_CODE);
while (m_ServiceStatus == 2) while (m_ServiceStatus == 2)
Sleep(1000); Sleep(1000);
#endif #endif
} }
sLog->SetLogDB(false); sLog->SetLogDB(false);
@@ -14,14 +14,14 @@
/// Heartbeat thread for the World /// Heartbeat thread for the World
class WorldRunnable : public acore::Runnable class WorldRunnable : public acore::Runnable
{ {
public: public:
void run(); void run();
}; };
class AuctionListingRunnable : public acore::Runnable class AuctionListingRunnable : public acore::Runnable
{ {
public: public:
void run(); void run();
}; };
#endif #endif
/// @} /// @}