Skip to content

Commit

Permalink
New thread pool reactor implementation and refactoring world daemon. (i…
Browse files Browse the repository at this point in the history
…ke3#8)

* New thread pool reactor implementation and refactoring world daemon.

* Fix Linux build.

* Fix Windows debug builds.
  • Loading branch information
H0zen authored and billy1arm committed Feb 11, 2017
1 parent 81394c3 commit 39b058e
Show file tree
Hide file tree
Showing 27 changed files with 1,608 additions and 2,005 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ message(
To set an option simply type -D<OPTION>=<VALUE> after 'cmake <srcs>'.
Also, you can specify the generator with -G. see 'cmake --help' for more details
For example: cmake .. -DDEBUG=1 -DCMAKE_INSTALL_PREFIX=/opt/mangos
Note: On UNIX systems, CONF_DIR is relative to the bin folder."
)
message("")
Expand Down
103 changes: 0 additions & 103 deletions src/mangosd/Comm/CliRunnable.cpp → src/game/ChatCommands/Level4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,10 @@
#include "Config/Config.h"
#include "Util.h"
#include "AccountMgr.h"
#include "CliRunnable.h"
#include "MapManager.h"
#include "Player.h"
#include "Chat.h"

void utf8print(void* /*arg*/, const char* str)
{
#if PLATFORM == PLATFORM_WINDOWS
wchar_t wtemp_buf[6000];
size_t wtemp_len = 6000 - 1;
if (!Utf8toWStr(str, strlen(str), wtemp_buf, wtemp_len))
{ return; }

char temp_buf[6000];
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len + 1);
printf("%s", temp_buf);
#else
printf("%s", str);
#endif
}

void commandFinished(void*, bool /*sucess*/)
{
printf("mangos>");
fflush(stdout);
}

/// Delete a user account and all associated characters in this realm
/// \todo This function has to be enhanced to respect the login/realm split (delete char, delete account chars in realm, delete account chars in realm then delete account
bool ChatHandler::HandleAccountDeleteCommand(char* args)
Expand Down Expand Up @@ -575,83 +552,3 @@ bool ChatHandler::HandleServerLogLevelCommand(char* args)
}

/// @}

#if (PLATFORM == PLATFORM_APPLE) || (PLATFORM == PLATFORM_UNIX)
// Non-blocking keypress detector, when return pressed, return 1, else always return 0
int kb_hit_return()
{
struct timeval tv;
fd_set fds;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
return FD_ISSET(STDIN_FILENO, &fds);
}
#endif

/// %Thread start
void CliRunnable::run()
{
///- Init new SQL thread for the world database (one connection call enough)
WorldDatabase.ThreadStart(); // let thread do safe mySQL requests

char commandbuf[256];

///- Display the list of available CLI functions then beep
sLog.outString();

if (sConfig.GetBoolDefault("BeepAtStart", true))
{ printf("\a"); } // \a = Alert

// print this here the first time
// later it will be printed after command queue updates
printf("mangos>");

///- As long as the World is running (no World::m_stopEvent), get the command line and handle it
while (!World::IsStopped())
{
fflush(stdout);
#if (PLATFORM == PLATFORM_APPLE) || (PLATFORM == PLATFORM_UNIX)
while (!kb_hit_return() && !World::IsStopped())
// With this, we limit CLI to 10commands/second
{ usleep(100); }
if (World::IsStopped())
{ break; }
#endif
char* command_str = fgets(commandbuf, sizeof(commandbuf), stdin);
if (command_str != NULL)
{
for (int x = 0; command_str[x]; ++x)
if (command_str[x] == '\r' || command_str[x] == '\n')
{
command_str[x] = 0;
break;
}


if (!*command_str)
{
printf("mangos>");
continue;
}

std::string command;
if (!consoleToUtf8(command_str, command)) // convert from console encoding to utf8
{
printf("mangos>");
continue;
}

sWorld.QueueCliCommand(new CliCommandHolder(0, SEC_CONSOLE, NULL, command.c_str(), &utf8print, &commandFinished));
}
else if (feof(stdin))
{
World::StopNow(SHUTDOWN_EXIT_CODE);
}
}

///- End the database thread
WorldDatabase.ThreadEnd(); // free mySQL thread resources
}
8 changes: 3 additions & 5 deletions src/game/Server/WorldSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
class ACE_Message_Block;
class WorldPacket;
class WorldSession;
class WorldSocket;

/// Handler that can communicate over stream sockets.
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > WorldAcceptor;

/**
* WorldSocket.
Expand Down Expand Up @@ -92,16 +93,13 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
* notification.
*
*/

class WorldSocket : protected WorldHandler
{
public:
/// Declare some friends
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
friend class WorldSocketMgr;
friend class ReactorRunnable;

/// Declare the acceptor for this class
typedef ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR > Acceptor;

/// Mutex type used for various synchronizations.
typedef ACE_Thread_Mutex LockType;
Expand Down
Loading

0 comments on commit 39b058e

Please sign in to comment.