aboutsummaryrefslogtreecommitdiff
path: root/src/trinitycore
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:35:07 -0700
committermaximius <none@none>2009-10-17 15:35:07 -0700
commit26b5e033ffde3d161382fc9addbfa99738379641 (patch)
treea344f369ca32945f787a02dee35c3dbe342bed7e /src/trinitycore
parentf21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff)
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
Diffstat (limited to 'src/trinitycore')
-rw-r--r--src/trinitycore/CliRunnable.cpp66
-rw-r--r--src/trinitycore/CliRunnable.h3
-rw-r--r--src/trinitycore/Main.cpp18
-rw-r--r--src/trinitycore/Master.cpp87
-rw-r--r--src/trinitycore/Master.h8
-rw-r--r--src/trinitycore/RASocket.cpp42
-rw-r--r--src/trinitycore/RASocket.h12
-rw-r--r--src/trinitycore/TrinityCore.rc9
-rw-r--r--src/trinitycore/WorldRunnable.cpp18
-rw-r--r--src/trinitycore/WorldRunnable.h3
-rw-r--r--src/trinitycore/resource.h1
11 files changed, 1 insertions, 266 deletions
diff --git a/src/trinitycore/CliRunnable.cpp b/src/trinitycore/CliRunnable.cpp
index 966b0b4dabb..42d465037d8 100644
--- a/src/trinitycore/CliRunnable.cpp
+++ b/src/trinitycore/CliRunnable.cpp
@@ -17,17 +17,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd
/// @{
/// \file
-
#include "Common.h"
#include "ObjectMgr.h"
#include "World.h"
#include "WorldSession.h"
#include "Config/ConfigEnv.h"
-
#include "AccountMgr.h"
#include "Chat.h"
#include "CliRunnable.h"
@@ -37,23 +34,19 @@
#include "Player.h"
#include "ScriptCalls.h"
#include "Util.h"
-
#if PLATFORM != WINDOWS
#include <readline/readline.h>
#include <readline/history.h>
-
char * command_finder(const char* text, int state)
{
static int idx,len;
const char* ret;
ChatCommand *cmd = ChatHandler::getCommandTable();
-
if(!state)
{
idx = 0;
len = strlen(text);
}
-
while(ret = cmd[idx].Name)
{
if(!cmd[idx].AllowConsole)
@@ -61,7 +54,6 @@ char * command_finder(const char* text, int state)
idx++;
continue;
}
-
idx++;
//printf("Checking %s \n", cmd[idx].Name);
if (strncmp(ret, text, len) == 0)
@@ -69,15 +61,12 @@ char * command_finder(const char* text, int state)
if(cmd[idx].Name == NULL)
break;
}
-
return ((char*)NULL);
}
-
char ** cli_completion(const char * text, int start, int end)
{
char ** matches;
matches = (char**)NULL;
-
if(start == 0)
matches = rl_completion_matches((char*)text,&command_finder);
else
@@ -85,7 +74,6 @@ char ** cli_completion(const char * text, int start, int end)
return (matches);
}
#endif
-
void utf8print(const char* str)
{
#if PLATFORM == PLATFORM_WINDOWS
@@ -93,7 +81,6 @@ void utf8print(const char* str)
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(temp_buf);
@@ -101,19 +88,16 @@ void utf8print(const char* str)
printf(str);
#endif
}
-
/// 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(const char* args)
{
if(!*args)
return false;
-
///- Get the account name from the command line
char *account_name_str=strtok ((char*)args," ");
if (!account_name_str)
return false;
-
std::string account_name = account_name_str;
if(!AccountMgr::normalizeString(account_name))
{
@@ -121,7 +105,6 @@ bool ChatHandler::HandleAccountDeleteCommand(const char* args)
SetSentErrorMessage(true);
return false;
}
-
uint32 account_id = accmgr.GetId(account_name);
if(!account_id)
{
@@ -129,13 +112,11 @@ bool ChatHandler::HandleAccountDeleteCommand(const char* args)
SetSentErrorMessage(true);
return false;
}
-
/// Commands not recommended call from chat, but support anyway
/// can delete only for account with less security
/// This is also reject self apply in fact
if(HasLowerSecurityAccount (NULL,account_id,true))
return false;
-
AccountOpResult result = accmgr.DeleteAccount(account_id);
switch(result)
{
@@ -155,26 +136,20 @@ bool ChatHandler::HandleAccountDeleteCommand(const char* args)
SetSentErrorMessage(true);
return false;
}
-
return true;
}
-
bool ChatHandler::HandleCharacterDeleteCommand(const char* args)
{
if(!*args)
return false;
-
char *character_name_str = strtok((char*)args," ");
if(!character_name_str)
return false;
-
std::string character_name = character_name_str;
if(!normalizePlayerName(character_name))
return false;
-
uint64 character_guid;
uint32 account_id;
-
Player *player = objmgr.GetPlayer(character_name.c_str());
if(player)
{
@@ -191,18 +166,14 @@ bool ChatHandler::HandleCharacterDeleteCommand(const char* args)
SetSentErrorMessage(true);
return false;
}
-
account_id = objmgr.GetPlayerAccountIdByGUID(character_guid);
}
-
std::string account_name;
accmgr.GetName (account_id,account_name);
-
Player::DeleteFromDB(character_guid, account_id, true);
PSendSysMessage(LANG_CHARACTER_DELETED,character_name.c_str(),GUID_LOPART(character_guid),account_name.c_str(), account_id);
return true;
}
-
/// Exit the realm
bool ChatHandler::HandleServerExitCommand(const char* /*args*/)
{
@@ -210,7 +181,6 @@ bool ChatHandler::HandleServerExitCommand(const char* /*args*/)
World::StopNow(SHUTDOWN_EXIT_CODE);
return true;
}
-
/// Display info on users currently in the realm
bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
{
@@ -221,59 +191,47 @@ bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
return true;
}
-
///- Display the list of account/characters online
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
SendSysMessage(LANG_ACCOUNT_LIST_HEADER);
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
-
///- Circle through accounts
do
{
Field *fieldsDB = resultDB->Fetch();
std::string name = fieldsDB[0].GetCppString();
uint32 account = fieldsDB[1].GetUInt32();
-
///- Get the username, last IP and GM level of each account
// No SQL injection. account is uint32.
// 0 1 2 3
QueryResult *resultLogin = loginDatabase.PQuery("SELECT username, last_ip, gmlevel, expansion FROM account WHERE id = '%u'",account);
-
if(resultLogin)
{
Field *fieldsLogin = resultLogin->Fetch();
PSendSysMessage(LANG_ACCOUNT_LIST_LINE,
fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsLogin[2].GetUInt32(),fieldsLogin[3].GetUInt32());
-
delete resultLogin;
}
else
PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
-
}while(resultDB->NextRow());
-
delete resultDB;
-
SendSysMessage(LANG_ACCOUNT_LIST_BAR);
return true;
}
-
/// Create an account
bool ChatHandler::HandleAccountCreateCommand(const char* args)
{
if(!*args)
return false;
-
///- %Parse the command line arguments
char *szAcc = strtok((char*)args, " ");
char *szPassword = strtok(NULL, " ");
if(!szAcc || !szPassword)
return false;
-
// normalized in accmgr.CreateAccount
std::string account_name = szAcc;
std::string password = szPassword;
-
AccountOpResult result = accmgr.CreateAccount(account_name, password);
switch(result)
{
@@ -297,60 +255,47 @@ bool ChatHandler::HandleAccountCreateCommand(const char* args)
SetSentErrorMessage(true);
return false;
}
-
return true;
}
-
/// Set the level of logging
bool ChatHandler::HandleServerSetLogFileLevelCommand(const char *args)
{
if(!*args)
return false;
-
char *NewLevel = strtok((char*)args, " ");
if (!NewLevel)
return false;
-
sLog.SetLogFileLevel(NewLevel);
return true;
}
-
/// Set the level of logging
bool ChatHandler::HandleServerSetLogLevelCommand(const char *args)
{
if(!*args)
return false;
-
char *NewLevel = strtok((char*)args, " ");
if (!NewLevel)
return false;
-
sLog.SetLogLevel(NewLevel);
return true;
}
-
/// set diff time record interval
bool ChatHandler::HandleServerSetDiffTimeCommand(const char *args)
{
if(!*args)
return false;
-
char *NewTimeStr = strtok((char*)args, " ");
if(!NewTimeStr)
return false;
-
int32 NewTime =atoi(NewTimeStr);
if(NewTime < 0)
return false;
-
sWorld.SetRecordDiffInterval(NewTime);
printf( "Record diff every %u ms\n", NewTime);
return true;
}
-
/// @}
-
#ifdef linux
// Non-blocking keypress detector, when return pressed, return 1, else always return 0
int kb_hit_return()
@@ -365,13 +310,11 @@ int kb_hit_return()
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];
bool canflush = true;
///- Display the list of available CLI functions then beep
@@ -381,18 +324,14 @@ void CliRunnable::run()
#endif
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("TC>");
-
///- As long as the World is running (no World::m_stopEvent), get the command line and handle it
while (!World::IsStopped())
{
fflush(stdout);
-
char *command_str ; // = fgets(commandbuf,sizeof(commandbuf),stdin);
-
#if PLATFORM == WINDOWS
command_str = fgets(commandbuf,sizeof(commandbuf),stdin);
#else
@@ -408,7 +347,6 @@ void CliRunnable::run()
break;
}
-
if(!*command_str)
{
#if PLATFORM == WINDOWS
@@ -416,7 +354,6 @@ void CliRunnable::run()
#endif
continue;
}
-
std::string command;
if(!consoleToUtf8(command_str,command)) // convert from console encoding to utf8
{
@@ -430,15 +367,12 @@ void CliRunnable::run()
#if PLATFORM != WINDOWS
add_history(command.c_str());
#endif
-
}
else if (feof(stdin))
{
World::StopNow(SHUTDOWN_EXIT_CODE);
}
-
}
-
///- End the database thread
WorldDatabase.ThreadEnd(); // free mySQL thread resources
}
diff --git a/src/trinitycore/CliRunnable.h b/src/trinitycore/CliRunnable.h
index cf745bbb195..34c677d69d2 100644
--- a/src/trinitycore/CliRunnable.h
+++ b/src/trinitycore/CliRunnable.h
@@ -17,14 +17,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd
/// @{
/// \file
-
#ifndef __CLIRUNNABLE_H
#define __CLIRUNNABLE_H
-
/// Command Line Interface handling thread
class CliRunnable : public ACE_Based::Runnable
{
diff --git a/src/trinitycore/Main.cpp b/src/trinitycore/Main.cpp
index 342252741fb..b33b05372a5 100644
--- a/src/trinitycore/Main.cpp
+++ b/src/trinitycore/Main.cpp
@@ -17,32 +17,25 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd Trinity Daemon
/// @{
/// \file
-
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
-
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "Config/ConfigEnv.h"
-
#include "Log.h"
#include "Master.h"
-
#ifndef _TRINITY_CORE_CONFIG
# define _TRINITY_CORE_CONFIG "TrinityCore.conf"
#endif //_TRINITY_CORE_CONFIG
-
// Format is YYYYMMDDRR where RR is the change in the conf file
// for that day.
#ifndef _TRINITY_CORE_CONFVER
# define _TRINITY_CORE_CONFVER 2009101701
#endif //_TRINITY_CORE_CONFVER
-
#ifdef WIN32
#include "ServiceWin32.h"
char serviceName[] = "TrinityCore";
@@ -56,13 +49,10 @@ char serviceDescription[] = "Massive Network Game Object Server";
*/
int m_ServiceStatus = -1;
#endif
-
DatabaseType WorldDatabase; ///< Accessor to the world database
DatabaseType CharacterDatabase; ///< Accessor to the character database
DatabaseType loginDatabase; ///< Accessor to the realm/login database
-
uint32 realmID; ///< Id of the realm
-
/// Print out the usage string for this program on the console.
void usage(const char *prog)
{
@@ -76,7 +66,6 @@ void usage(const char *prog)
#endif
,prog);
}
-
/// Launch the Trinity server
extern int main(int argc, char **argv)
{
@@ -96,7 +85,6 @@ extern int main(int argc, char **argv)
else
cfg_file = argv[c];
}
-
#ifdef WIN32
////////////
//Services//
@@ -136,14 +124,12 @@ extern int main(int argc, char **argv)
#endif
++c;
}
-
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
return 1;
}
sLog.outString("Using configuration file %s.", cfg_file);
-
uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
if (confVersion < _TRINITY_CORE_CONFVER)
{
@@ -155,7 +141,6 @@ extern int main(int argc, char **argv)
clock_t pause = 3000 + clock();
while (pause > clock()) {}
}
-
sLog.outDetail("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
if (SSLeay() < 0x009080bfL )
{
@@ -165,15 +150,12 @@ extern int main(int argc, char **argv)
while (pause > clock()) {}
return 1;
}
-
///- and run the 'Master'
/// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
return sMaster.Run();
-
// at sMaster return function exist with codes
// 0 - normal shutdown
// 1 - shutdown at error
// 2 - restart command used, this code can be used by restarter for restart Trinityd
}
-
/// @}
diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp
index 7e56cb7a636..6c334733ee0 100644
--- a/src/trinitycore/Master.cpp
+++ b/src/trinitycore/Master.cpp
@@ -17,13 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/** \file
\ingroup Trinityd
*/
-
#include <ace/OS_NS_signal.h>
-
#include "Common.h"
#include "SystemConfig.h"
#include "World.h"
@@ -33,7 +30,6 @@
#include "Config/ConfigEnv.h"
#include "Database/DatabaseEnv.h"
#include "Policies/SingletonImp.h"
-
#include "CliRunnable.h"
#include "Log.h"
#include "Master.h"
@@ -41,26 +37,20 @@
#include "ScriptCalls.h"
#include "Timer.h"
#include "Util.h"
-
#include "sockets/TcpSocket.h"
#include "sockets/Utility.h"
#include "sockets/Parse.h"
#include "sockets/Socket.h"
#include "sockets/SocketHandler.h"
#include "sockets/ListenSocket.h"
-
#ifdef WIN32
#include "ServiceWin32.h"
extern int m_ServiceStatus;
#endif
-
/// \todo Warning disabling not useful under VC++2005. Can somebody say on which compiler it is useful?
#pragma warning(disable:4305)
-
INSTANTIATE_SINGLETON_1( Master );
-
volatile uint32 Master::m_masterLoopCounter = 0;
-
class FreezeDetectorRunnable : public ACE_Based::Runnable
{
public:
@@ -83,7 +73,6 @@ public:
ACE_Based::Thread::Sleep(1000);
uint32 curtime = getMSTime();
//DEBUG_LOG("anti-freeze: time=%u, counters=[%u; %u]",curtime,Master::m_masterLoopCounter,World::m_worldLoopCounter);
-
// There is no Master anymore
// TODO: clear the rest of the code
// // normal work
@@ -98,7 +87,6 @@ public:
// sLog.outError("Main/Sockets Thread hangs, kicking out server!");
// *((uint32 volatile*)NULL) = 0; // bang crash
// }
-
// normal work
if(w_loops != World::m_worldLoopCounter)
{
@@ -115,19 +103,16 @@ public:
sLog.outString("Anti-freeze thread exiting without problems.");
}
};
-
class RARunnable : public ACE_Based::Runnable
{
public:
uint32 numLoops, loopCounter;
-
RARunnable ()
{
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
numLoops = (sConfig.GetIntDefault ("MaxPingTime", 30) * (MINUTE * 1000000 / socketSelecttime));
loopCounter = 0;
}
-
void checkping ()
{
// ping if need
@@ -140,15 +125,12 @@ public:
delete CharacterDatabase.Query ("SELECT 1 FROM bugreport LIMIT 1");
}
}
-
void run ()
{
SocketHandler h;
-
// Launch the RA listener socket
ListenSocket<RASocket> RAListenSocket (h);
bool usera = sConfig.GetBoolDefault ("Ra.Enable", false);
-
if (usera)
{
port_t raport = sConfig.GetIntDefault ("Ra.Port", 3443);
@@ -161,14 +143,11 @@ public:
else
{
h.Add (&RAListenSocket);
-
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
}
-
// Socket Selet time is in microseconds , not miliseconds!!
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
-
// if use ra spend time waiting for io, if not use ra ,just sleep
if (usera)
{
@@ -188,21 +167,17 @@ public:
}
}
};
-
Master::Master()
{
}
-
Master::~Master()
{
}
-
/// Main function
int Master::Run()
{
sLog.outString( "%s (core-daemon)", _FULLVERSION );
sLog.outString( "<Ctrl-C> to stop.\n" );
-
sLog.outString( " ______ __");
sLog.outString( "/\\__ _\\ __ __/\\ \\__");
sLog.outString( "\\/_/\\ \\/ _ __ /\\_\\ ___ /\\_\\ \\ ,_\\ __ __");
@@ -212,7 +187,6 @@ int Master::Run()
sLog.outString( " \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\");
sLog.outString( " C O R E /\\___/");
sLog.outString( "http://TrinityCore.org \\/__/\n");
-
/// worldd PID file creation
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
if(!pidfile.empty())
@@ -223,29 +197,21 @@ int Master::Run()
sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() );
return 1;
}
-
sLog.outString( "Daemon PID: %u\n", pid );
}
-
///- Start the databases
if (!_StartDB())
return 1;
-
///- Initialize the World
sWorld.SetInitialWorldSettings();
-
///- Catch termination signals
_HookSignals();
-
///- Launch WorldRunnable thread
ACE_Based::Thread world_thread(new WorldRunnable);
world_thread.setPriority(ACE_Based::Highest);
-
// set server online
loginDatabase.PExecute("UPDATE realmlist SET color = 0, population = 0 WHERE id = '%d'",realmID);
-
ACE_Based::Thread* cliThread = NULL;
-
#ifdef WIN32
if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
#else
@@ -255,24 +221,19 @@ int Master::Run()
///- Launch CliRunnable thread
cliThread = new ACE_Based::Thread(new CliRunnable);
}
-
ACE_Based::Thread rar_thread(new RARunnable);
-
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
{
HANDLE hProcess = GetCurrentProcess();
-
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if(Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
-
if(GetProcessAffinityMask(hProcess,&appAff,&sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
-
if(!curAff )
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for Trinityd. Accessible processors bitmask (hex): %x",Aff,appAff);
@@ -287,9 +248,7 @@ int Master::Run()
}
sLog.outString("");
}
-
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
-
// if(Prio && (m_ServiceStatus == -1)/* need set to default process priority class in service mode*/)
if(Prio)
{
@@ -301,12 +260,9 @@ int Master::Run()
}
}
#endif
-
uint32 realCurrTime, realPrevTime;
realCurrTime = realPrevTime = getMSTime();
-
uint32 socketSelecttime = sWorld.getConfig(CONFIG_SOCKET_SELECTTIME);
-
///- Start up freeze catcher thread
if(uint32 freeze_delay = sConfig.GetIntDefault("MaxCoreStuckTime", 0))
{
@@ -315,45 +271,34 @@ int Master::Run()
ACE_Based::Thread freeze_thread(fdr);
freeze_thread.setPriority(ACE_Based::Highest);
}
-
///- Launch the world listener socket
port_t wsport = sWorld.getConfig (CONFIG_PORT_WORLD);
std::string bind_ip = sConfig.GetStringDefault ("BindIP", "0.0.0.0");
-
if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1)
{
sLog.outError ("Failed to start network");
World::StopNow(ERROR_EXIT_CODE);
// go down and shutdown the server
}
-
sWorldSocketMgr->Wait ();
-
// set server offline
loginDatabase.PExecute("UPDATE realmlist SET color = 2 WHERE id = '%d'",realmID);
-
///- Remove signal handling before leaving
_UnhookSignals();
-
// when the main thread closes the singletons get unloaded
// since worldrunnable uses them, it will crash if unloaded after master
world_thread.wait();
rar_thread.wait ();
-
///- Clean database before leaving
clearOnlineAccounts();
-
///- Wait for delay threads to end
CharacterDatabase.HaltDelayThread();
WorldDatabase.HaltDelayThread();
loginDatabase.HaltDelayThread();
-
sLog.outString( "Halting process..." );
-
if (cliThread)
{
#ifdef WIN32
-
// this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API)
//_exit(1);
// send keyboard input to safely unblock the CLI thread
@@ -364,13 +309,11 @@ int Master::Run()
b[0].Event.KeyEvent.uChar.AsciiChar = 'X';
b[0].Event.KeyEvent.wVirtualKeyCode = 'X';
b[0].Event.KeyEvent.wRepeatCount = 1;
-
b[1].EventType = KEY_EVENT;
b[1].Event.KeyEvent.bKeyDown = FALSE;
b[1].Event.KeyEvent.uChar.AsciiChar = 'X';
b[1].Event.KeyEvent.wVirtualKeyCode = 'X';
b[1].Event.KeyEvent.wRepeatCount = 1;
-
b[2].EventType = KEY_EVENT;
b[2].Event.KeyEvent.bKeyDown = TRUE;
b[2].Event.KeyEvent.dwControlKeyState = 0;
@@ -378,7 +321,6 @@ int Master::Run()
b[2].Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
b[2].Event.KeyEvent.wRepeatCount = 1;
b[2].Event.KeyEvent.wVirtualScanCode = 0x1c;
-
b[3].EventType = KEY_EVENT;
b[3].Event.KeyEvent.bKeyDown = FALSE;
b[3].Event.KeyEvent.dwControlKeyState = 0;
@@ -388,32 +330,23 @@ int Master::Run()
b[3].Event.KeyEvent.wRepeatCount = 1;
DWORD numb;
BOOL ret = WriteConsoleInput(hStdIn, b, 4, &numb);
-
cliThread->wait();
-
- #else
-
+ #else
cliThread->destroy();
-
#endif
-
delete cliThread;
}
-
// for some unknown reason, unloading scripts here and not in worldrunnable
// fixes a memory leak related to detaching threads from the module
UnloadScriptingModule();
-
// Exit the process with specified return value
return World::GetExitCode();
}
-
/// Initialize connection to the databases
bool Master::_StartDB()
{
sLog.SetLogDB(false);
std::string dbstring;
-
///- Get world database info from configuration file
dbstring = sConfig.GetStringDefault("WorldDatabaseInfo", "");
if(dbstring.empty())
@@ -421,14 +354,12 @@ bool Master::_StartDB()
sLog.outError("Database not specified in configuration file");
return false;
}
-
///- Initialise the world database
if(!WorldDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Cannot connect to world database %s",dbstring.c_str());
return false;
}
-
///- Get character database info from configuration file
dbstring = sConfig.GetStringDefault("CharacterDatabaseInfo", "");
if(dbstring.empty())
@@ -436,14 +367,12 @@ bool Master::_StartDB()
sLog.outError("Character Database not specified in configuration file");
return false;
}
-
///- Initialise the Character database
if(!CharacterDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Cannot connect to Character database %s",dbstring.c_str());
return false;
}
-
///- Get login database info from configuration file
dbstring = sConfig.GetStringDefault("loginDatabaseInfo", "");
if(dbstring.empty())
@@ -451,14 +380,12 @@ bool Master::_StartDB()
sLog.outError("Login database not specified in configuration file");
return false;
}
-
///- Initialise the login database
if(!loginDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Cannot connect to login database %s",dbstring.c_str());
return false;
}
-
///- Get the realm Id from the configuration file
realmID = sConfig.GetIntDefault("RealmID", 0);
if(!realmID)
@@ -467,7 +394,6 @@ bool Master::_StartDB()
return false;
}
sLog.outString("Realm running as realm ID %d", realmID);
-
///- Initialize the DB logging system
if(sConfig.GetBoolDefault("EnableLogDB", false))
{
@@ -482,20 +408,15 @@ bool Master::_StartDB()
sLog.SetLogDB(false);
sLog.SetRealmID(realmID);
}
-
///- Clean the database before starting
clearOnlineAccounts();
-
///- Insert version info into DB
WorldDatabase.PExecute("UPDATE version SET core_version = '%s', core_revision = '%s'", _FULLVERSION, _REVISION);
-
sWorld.LoadDBVersion();
-
sLog.outString("Using World DB: %s", sWorld.GetDBVersion());
sLog.outString("Using creature EventAI: %s", sWorld.GetCreatureEventAIVersion());
return true;
}
-
/// Clear 'online' status for all accounts with characters in this realm
void Master::clearOnlineAccounts()
{
@@ -504,13 +425,10 @@ void Master::clearOnlineAccounts()
loginDatabase.PExecute(
"UPDATE account SET online = 0 WHERE online > 0 "
"AND id IN (SELECT acctid FROM realmcharacters WHERE realmid = '%d')",realmID);
-
CharacterDatabase.Execute("UPDATE characters SET online = 0 WHERE online<>0");
-
// Battleground instance ids reset at server restart
CharacterDatabase.Execute("UPDATE character_battleground_data SET instance_id = 0");
}
-
/// Handle termination signals
void Master::_OnSignal(int s)
{
@@ -527,10 +445,8 @@ void Master::_OnSignal(int s)
World::StopNow(SHUTDOWN_EXIT_CODE);
break;
}
-
signal(s, _OnSignal);
}
-
/// Define hook '_OnSignal' for all termination signals
void Master::_HookSignals()
{
@@ -541,7 +457,6 @@ void Master::_HookSignals()
signal(SIGBREAK, _OnSignal);
#endif
}
-
/// Unhook the signals before leaving
void Master::_UnhookSignals()
{
diff --git a/src/trinitycore/Master.h b/src/trinitycore/Master.h
index 967f497051a..49b29bd8639 100644
--- a/src/trinitycore/Master.h
+++ b/src/trinitycore/Master.h
@@ -17,17 +17,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd
/// @{
/// \file
-
#ifndef _MASTER_H
#define _MASTER_H
-
#include "Common.h"
#include "Policies/Singleton.h"
-
/// Start the server
class Master
{
@@ -36,17 +32,13 @@ class Master
~Master();
int Run();
static volatile uint32 m_masterLoopCounter;
-
private:
bool _StartDB();
-
void _HookSignals();
void _UnhookSignals();
static void _OnSignal(int s);
-
void clearOnlineAccounts();
};
-
#define sMaster Trinity::Singleton<Master>::Instance()
#endif
/// @}
diff --git a/src/trinitycore/RASocket.cpp b/src/trinitycore/RASocket.cpp
index d0ee5cc8053..a86acfb6078 100644
--- a/src/trinitycore/RASocket.cpp
+++ b/src/trinitycore/RASocket.cpp
@@ -17,11 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/** \file
\ingroup Trinityd
*/
-
#include "Common.h"
#include "Config/ConfigEnv.h"
#include "Database/DatabaseEnv.h"
@@ -30,51 +28,38 @@
#include "RASocket.h"
#include "Util.h"
#include "World.h"
-
/// \todo Make this thread safe if in the future 2 admins should be able to log at the same time.
SOCKET r;
-
#define dropclient {Sendf("I'm busy right now, come back later."); \
SetCloseAndDelete(); \
return; \
}
-
uint32 iSession=0; ///< Session number (incremented each time a new connection is made)
unsigned int iUsers=0; ///< Number of active administrators
-
typedef int(* pPrintf)(const char*,...);
-
void ParseCommand(CliCommandHolder::Print*, char*command);
-
/// RASocket constructor
RASocket::RASocket(ISocketHandler &h): TcpSocket(h)
{
-
///- Increment the session number
iSess =iSession++ ;
-
///- Get the config parameters
bSecure = sConfig.GetBoolDefault( "RA.Secure", true );
iMinLevel = sConfig.GetIntDefault( "RA.MinLevel", 3 );
-
///- Initialize buffer and data
iInputLength=0;
buff=new char[RA_BUFF_SIZE];
stage=NONE;
}
-
/// RASocket destructor
RASocket::~RASocket()
{
///- Delete buffer and decrease active admins count
delete [] buff;
-
sLog.outRemote("Connection was closed.\n");
-
if(stage==OK)
iUsers--;
}
-
/// Accept an incoming connection
void RASocket::OnAccept()
{
@@ -83,17 +68,14 @@ void RASocket::OnAccept()
///- If there is already an active admin, drop the connection
if(iUsers)
dropclient
-
///- Else print Motd
Sendf("%s\r\n",sWorld.GetMotd());
}
-
/// Read data from the network
void RASocket::OnRead()
{
///- Read data and check input length
TcpSocket::OnRead();
-
unsigned int sz=ibuf.GetLength();
if(iInputLength+sz>=RA_BUFF_SIZE)
{
@@ -101,14 +83,11 @@ void RASocket::OnRead()
SetCloseAndDelete();
return;
}
-
///- If there is already an active admin (other than you), drop the connection
if(stage!=OK && iUsers)
dropclient
-
char *inp = new char [sz+1];
ibuf.Read(inp,sz);
-
/// \todo Can somebody explain this 'Linux bugfix'?
if(stage==NONE)
if(sz>4) //linux remote telnet
@@ -117,7 +96,6 @@ void RASocket::OnRead()
delete [] inp;return;
printf("lin bugfix");
} //linux bugfix
-
///- Discard data after line break or line feed
bool gotenter=false;
unsigned int y=0;
@@ -127,14 +105,12 @@ void RASocket::OnRead()
gotenter=true;
break;
}
-
//No buffer overflow (checked above)
memcpy(&buff[iInputLength],inp,y);
iInputLength+=y;
delete [] inp;
if(gotenter)
{
-
buff[iInputLength]=0;
iInputLength=0;
switch(stage)
@@ -144,18 +120,13 @@ void RASocket::OnRead()
if(!memcmp(buff,"USER ",5)) //got "USER" cmd
{
szLogin=&buff[5];
-
///- Get the gmlevel and password from the account table
std::string login = szLogin;
-
///- Convert Account name to Upper Format
AccountMgr::normalizeString(login);
-
///- Escape the Login to allow quotes in names
loginDatabase.escape_string(login);
-
QueryResult* result = loginDatabase.PQuery("SELECT gmlevel FROM account WHERE username = '%s'",login.c_str());
-
///- If the user is not found, deny access
if(!result)
{
@@ -166,9 +137,7 @@ void RASocket::OnRead()
else
{
Field *fields = result->Fetch();
-
//szPass=fields[0].GetString();
-
///- if gmlevel is too low, deny access
if(fields[0].GetUInt32()<iMinLevel)
{
@@ -190,23 +159,19 @@ void RASocket::OnRead()
///- If password is correct, increment the number of active administrators
std::string login = szLogin;
std::string pw = &buff[5];
-
AccountMgr::normalizeString(login);
AccountMgr::normalizeString(pw);
loginDatabase.escape_string(login);
loginDatabase.escape_string(pw);
-
QueryResult *check = loginDatabase.PQuery(
"SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT('%s',':','%s'))",
login.c_str(), login.c_str(), pw.c_str());
-
if(check)
{
delete check;
r=GetSocket();
stage=OK;
++iUsers;
-
Sendf("+Logged in.\r\n");
sLog.outRemote("User %s has logged in.\n",szLogin.c_str());
Sendf("TC>");
@@ -232,28 +197,21 @@ void RASocket::OnRead()
break;
///</ul>
};
-
}
}
-
/// Output function
void RASocket::zprint( const char * szText )
{
if( !szText )
return;
-
#ifdef RA_CRYPT
-
char *megabuffer=strdup(szText);
unsigned int sz=strlen(megabuffer);
Encrypt(megabuffer,sz);
send(r,megabuffer,sz,0);
delete [] megabuffer;
-
#else
-
unsigned int sz=strlen(szText);
send(r,szText,sz,0);
-
#endif
}
diff --git a/src/trinitycore/RASocket.h b/src/trinitycore/RASocket.h
index 330c85defa4..813627766a5 100644
--- a/src/trinitycore/RASocket.h
+++ b/src/trinitycore/RASocket.h
@@ -17,35 +17,24 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd
/// @{
/// \file
-
#ifndef _RASOCKET_H
#define _RASOCKET_H
-
#include "sockets/TcpSocket.h"
-
#include "Common.h"
-
#define RA_BUFF_SIZE 1024
-
class ISocketHandler;
-
/// Remote Administration socket
class RASocket: public TcpSocket
{
public:
-
RASocket(ISocketHandler& h);
~RASocket();
-
void OnAccept();
void OnRead();
-
private:
-
char * buff;
std::string szLogin;
uint32 iSess;
@@ -61,7 +50,6 @@ class RASocket: public TcpSocket
LG, //only login was entered
OK, //both login and pass were given, and they are correct and user have enough priv.
}stage;
-
static void zprint( const char * szText );
};
#endif
diff --git a/src/trinitycore/TrinityCore.rc b/src/trinitycore/TrinityCore.rc
index 151185f3cec..156f1ac21f5 100644
--- a/src/trinitycore/TrinityCore.rc
+++ b/src/trinitycore/TrinityCore.rc
@@ -15,43 +15,34 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#include "resource.h"
#include "../shared/revision.h"
-
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "windows.h"
-
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
-
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
-
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_APPICON ICON "TrinityCore.ico"
-
/////////////////////////////////////////////////////////////////////////////
// Neutre (Par défaut système) resources
-
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUSD)
#ifdef _WIN32
LANGUAGE LANG_NEUTRAL, SUBLANG_SYS_DEFAULT
#pragma code_page(1252)
#endif //_WIN32
-
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
-
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILEVER
PRODUCTVERSION PRODUCTVER
diff --git a/src/trinitycore/WorldRunnable.cpp b/src/trinitycore/WorldRunnable.cpp
index 06c0e69fa16..8847f57cee3 100644
--- a/src/trinitycore/WorldRunnable.cpp
+++ b/src/trinitycore/WorldRunnable.cpp
@@ -17,33 +17,27 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/** \file
\ingroup Trinityd
*/
-
#include "Common.h"
#include "ObjectAccessor.h"
#include "World.h"
#include "WorldSocketMgr.h"
#include "Database/DatabaseEnv.h"
-
#include "BattleGroundMgr.h"
#include "MapManager.h"
#include "Timer.h"
#include "WorldRunnable.h"
-
#if (defined(WIN32) || defined(SHORT_SLEEP))
#define WORLD_SLEEP_CONST 50
#else
#define WORLD_SLEEP_CONST 100 //Is this still needed?? [On linux some time ago not working 50ms]
#endif
-
#ifdef WIN32
#include "ServiceWin32.h"
extern int m_ServiceStatus;
#endif
-
/// Heartbeat for the World
void WorldRunnable::run()
{
@@ -52,23 +46,17 @@ void WorldRunnable::run()
CharacterDatabase.ThreadStart();
loginDatabase.ThreadStart();
sWorld.InitResultQueue();
-
uint32 realCurrTime = 0;
uint32 realPrevTime = getMSTime();
-
uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST
-
///- While we have not World::m_stopEvent, update the world
while (!World::IsStopped())
{
++World::m_worldLoopCounter;
realCurrTime = getMSTime();
-
uint32 diff = getMSTimeDiff(realPrevTime,realCurrTime);
-
sWorld.Update( diff );
realPrevTime = realCurrTime;
-
// diff (D0) include time of previous sleep (d0) + tick time (t0)
// we want that next d1 + t1 == WORLD_SLEEP_CONST
// we can't know next t1 and then can use (t0 + d1) == WORLD_SLEEP_CONST requirement
@@ -80,23 +68,17 @@ void WorldRunnable::run()
}
else
prevSleepTime = 0;
-
#ifdef WIN32
if (m_ServiceStatus == 0) World::StopNow(SHUTDOWN_EXIT_CODE);
while (m_ServiceStatus == 2) Sleep(1000);
#endif
}
-
sWorld.KickAll(); // save and kick all players
sWorld.UpdateSessions( 1 ); // real players unload required UpdateSessions call
-
// unload battleground templates before different singletons destroyed
sBattleGroundMgr.DeleteAllBattleGrounds();
-
sWorldSocketMgr->StopNetwork();
-
MapManager::Instance().UnloadAll(); // unload all grids (including locked in memory)
-
///- End the database thread
WorldDatabase.ThreadEnd(); // free mySQL thread resources
CharacterDatabase.ThreadStart();
diff --git a/src/trinitycore/WorldRunnable.h b/src/trinitycore/WorldRunnable.h
index 07ce246b04f..036b8711a39 100644
--- a/src/trinitycore/WorldRunnable.h
+++ b/src/trinitycore/WorldRunnable.h
@@ -17,14 +17,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
/// \addtogroup Trinityd
/// @{
/// \file
-
#ifndef __WORLDRUNNABLE_H
#define __WORLDRUNNABLE_H
-
/// Heartbeat thread for the World
class WorldRunnable : public ACE_Based::Runnable
{
diff --git a/src/trinitycore/resource.h b/src/trinitycore/resource.h
index 7dc5cb9ef7b..33985dd3ede 100644
--- a/src/trinitycore/resource.h
+++ b/src/trinitycore/resource.h
@@ -2,7 +2,6 @@
// Microsoft Visual C++ generated include file.
// Used by TrinityCore.rc
//
-
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED