* Delivering file deletions...
--HG-- branch : trunk
This commit is contained in:
@@ -1,37 +0,0 @@
|
|||||||
#include "AuthCodes.h"
|
|
||||||
|
|
||||||
namespace AuthHelper
|
|
||||||
{
|
|
||||||
|
|
||||||
bool IsPreBCAcceptedClientBuild(int build)
|
|
||||||
{
|
|
||||||
int accepted_versions[] = PRE_BC_ACCEPTED_CLIENT_BUILD;
|
|
||||||
for (int i = 0; accepted_versions[i]; ++i)
|
|
||||||
{
|
|
||||||
if (build == accepted_versions[i])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsPostBCAcceptedClientBuild(int build)
|
|
||||||
{
|
|
||||||
int accepted_versions[] = POST_BC_ACCEPTED_CLIENT_BUILD;
|
|
||||||
for (int i = 0; accepted_versions[i]; ++i)
|
|
||||||
{
|
|
||||||
if (build == accepted_versions[i])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsAcceptedClientBuild(int build)
|
|
||||||
{
|
|
||||||
return (IsPostBCAcceptedClientBuild(build) || IsPreBCAcceptedClientBuild(build));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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 realmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _AUTHCODES_H
|
|
||||||
#define _AUTHCODES_H
|
|
||||||
|
|
||||||
enum AuthResult
|
|
||||||
{
|
|
||||||
WOW_SUCCESS = 0x00,
|
|
||||||
WOW_FAIL_UNKNOWN0 = 0x01, ///< ? Unable to connect
|
|
||||||
WOW_FAIL_UNKNOWN1 = 0x02, ///< ? Unable to connect
|
|
||||||
WOW_FAIL_BANNED = 0x03, ///< This <game> account has been closed and is no longer available for use. Please go to <site>/banned.html for further information.
|
|
||||||
WOW_FAIL_UNKNOWN_ACCOUNT = 0x04, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
|
|
||||||
WOW_FAIL_INCORRECT_PASSWORD = 0x05, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
|
|
||||||
WOW_FAIL_ALREADY_ONLINE = 0x06, ///< This account is already logged into <game>. Please check the spelling and try again.
|
|
||||||
WOW_FAIL_NO_TIME = 0x07, ///< You have used up your prepaid time for this account. Please purchase more to continue playing
|
|
||||||
WOW_FAIL_DB_BUSY = 0x08, ///< Could not log in to <game> at this time. Please try again later.
|
|
||||||
WOW_FAIL_VERSION_INVALID = 0x09, ///< Unable to validate game version. This may be caused by file corruption or interference of another program. Please visit <site> for more information and possible solutions to this issue.
|
|
||||||
WOW_FAIL_VERSION_UPDATE = 0x0A, ///< Downloading
|
|
||||||
WOW_FAIL_INVALID_SERVER = 0x0B, ///< Unable to connect
|
|
||||||
WOW_FAIL_SUSPENDED = 0x0C, ///< This <game> account has been temporarily suspended. Please go to <site>/banned.html for further information
|
|
||||||
WOW_FAIL_FAIL_NOACCESS = 0x0D, ///< Unable to connect
|
|
||||||
WOW_SUCCESS_SURVEY = 0x0E, ///< Connected.
|
|
||||||
WOW_FAIL_PARENTCONTROL = 0x0F, ///< Access to this account has been blocked by parental controls. Your settings may be changed in your account preferences at <site>
|
|
||||||
WOW_FAIL_LOCKED_ENFORCED = 0x10, ///< You have applied a lock to your account. You can change your locked status by calling your account lock phone number.
|
|
||||||
WOW_FAIL_TRIAL_ENDED = 0x11, ///< Your trial subscription has expired. Please visit <site> to upgrade your account.
|
|
||||||
WOW_FAIL_USE_BATTLENET = 0x12, ///< WOW_FAIL_OTHER This account is now attached to a Battle.net account. Please login with your Battle.net account email address and password.
|
|
||||||
};
|
|
||||||
|
|
||||||
enum LoginResult
|
|
||||||
{
|
|
||||||
LOGIN_OK = 0x00,
|
|
||||||
LOGIN_FAILED = 0x01,
|
|
||||||
LOGIN_FAILED2 = 0x02,
|
|
||||||
LOGIN_BANNED = 0x03,
|
|
||||||
LOGIN_UNKNOWN_ACCOUNT = 0x04,
|
|
||||||
LOGIN_UNKNOWN_ACCOUNT3 = 0x05,
|
|
||||||
LOGIN_ALREADYONLINE = 0x06,
|
|
||||||
LOGIN_NOTIME = 0x07,
|
|
||||||
LOGIN_DBBUSY = 0x08,
|
|
||||||
LOGIN_BADVERSION = 0x09,
|
|
||||||
LOGIN_DOWNLOAD_FILE = 0x0A,
|
|
||||||
LOGIN_FAILED3 = 0x0B,
|
|
||||||
LOGIN_SUSPENDED = 0x0C,
|
|
||||||
LOGIN_FAILED4 = 0x0D,
|
|
||||||
LOGIN_CONNECTED = 0x0E,
|
|
||||||
LOGIN_PARENTALCONTROL = 0x0F,
|
|
||||||
LOGIN_LOCKED_ENFORCED = 0x10,
|
|
||||||
};
|
|
||||||
|
|
||||||
//multirealm supported versions:
|
|
||||||
//1.12.1 build 5875
|
|
||||||
//1.12.2 build 6005
|
|
||||||
//2.4.3 build 8606
|
|
||||||
//3.1.3 build 9947
|
|
||||||
//3.1.3 build 10146 Chinese build
|
|
||||||
//3.2.2a build 10505
|
|
||||||
//3.3.0a build 11159
|
|
||||||
//3.3.2 build 11403
|
|
||||||
//3.3.3a build 11723
|
|
||||||
|
|
||||||
#define POST_BC_ACCEPTED_CLIENT_BUILD {11723, 11403, 11159, 10571, 10505, 10146, 9947, 8606, 0}
|
|
||||||
#define PRE_BC_ACCEPTED_CLIENT_BUILD {5875, 6005, 0}
|
|
||||||
|
|
||||||
#define POST_BC_EXP_FLAG 0x2
|
|
||||||
#define PRE_BC_EXP_FLAG 0x1
|
|
||||||
#define NO_VALID_EXP_FLAG 0x0
|
|
||||||
|
|
||||||
namespace AuthHelper
|
|
||||||
{
|
|
||||||
bool IsAcceptedClientBuild(int build);
|
|
||||||
bool IsPostBCAcceptedClientBuild(int build);
|
|
||||||
bool IsPreBCAcceptedClientBuild(int build);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// \addtogroup realmd
|
|
||||||
/// @{
|
|
||||||
/// \file
|
|
||||||
|
|
||||||
#ifndef _AUTHSOCKET_H
|
|
||||||
#define _AUTHSOCKET_H
|
|
||||||
|
|
||||||
#include "Common.h"
|
|
||||||
#include "Auth/BigNumber.h"
|
|
||||||
|
|
||||||
#include "RealmSocket.h"
|
|
||||||
|
|
||||||
enum RealmFlags
|
|
||||||
{
|
|
||||||
REALM_FLAG_NONE = 0x00,
|
|
||||||
REALM_FLAG_INVALID = 0x01,
|
|
||||||
REALM_FLAG_OFFLINE = 0x02,
|
|
||||||
REALM_FLAG_SPECIFYBUILD = 0x04, // client will show realm version in RealmList screen in form "RealmName (major.minor.revision.build)"
|
|
||||||
REALM_FLAG_UNK1 = 0x08,
|
|
||||||
REALM_FLAG_UNK2 = 0x10,
|
|
||||||
REALM_FLAG_RECOMMENDED = 0x20, // client checks pop == 600f
|
|
||||||
REALM_FLAG_NEW = 0x40, // client checks pop == 200f
|
|
||||||
REALM_FLAG_FULL = 0x80 // client checks pop == 400f
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Handle login commands
|
|
||||||
class AuthSocket: public RealmSocket::Session
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
const static int s_BYTE_SIZE = 32;
|
|
||||||
|
|
||||||
AuthSocket(RealmSocket& socket);
|
|
||||||
virtual ~AuthSocket(void);
|
|
||||||
|
|
||||||
virtual void OnRead(void);
|
|
||||||
virtual void OnAccept(void);
|
|
||||||
virtual void OnClose(void);
|
|
||||||
|
|
||||||
bool _HandleLogonChallenge();
|
|
||||||
bool _HandleLogonProof();
|
|
||||||
bool _HandleReconnectChallenge();
|
|
||||||
bool _HandleReconnectProof();
|
|
||||||
bool _HandleRealmList();
|
|
||||||
//data transfer handle for patch
|
|
||||||
|
|
||||||
bool _HandleXferResume();
|
|
||||||
bool _HandleXferCancel();
|
|
||||||
bool _HandleXferAccept();
|
|
||||||
|
|
||||||
void _SetVSFields(const std::string& rI);
|
|
||||||
|
|
||||||
FILE *pPatch;
|
|
||||||
ACE_Thread_Mutex patcherLock;
|
|
||||||
|
|
||||||
private:
|
|
||||||
RealmSocket& socket_;
|
|
||||||
RealmSocket& socket(void) { return socket_; }
|
|
||||||
|
|
||||||
BigNumber N, s, g, v;
|
|
||||||
BigNumber b, B;
|
|
||||||
BigNumber K;
|
|
||||||
BigNumber _reconnectProof;
|
|
||||||
|
|
||||||
bool _authed;
|
|
||||||
|
|
||||||
std::string _login;
|
|
||||||
std::string _safelogin;
|
|
||||||
|
|
||||||
// Since GetLocaleByName() is _NOT_ bijective, we have to store the locale as a string. Otherwise we can't differ
|
|
||||||
// between enUS and enGB, which is important for the patch system
|
|
||||||
std::string _localizationName;
|
|
||||||
uint16 _build;
|
|
||||||
uint8 _expversion;
|
|
||||||
AccountTypes _accountSecurityLevel;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
/// @}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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 realmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __REALMACCEPTOR_H__
|
|
||||||
#define __REALMACCEPTOR_H__
|
|
||||||
|
|
||||||
#include <ace/Acceptor.h>
|
|
||||||
#include <ace/SOCK_Acceptor.h>
|
|
||||||
|
|
||||||
#include "RealmSocket.h"
|
|
||||||
#include "AuthSocket.h"
|
|
||||||
|
|
||||||
class RealmAcceptor : public ACE_Acceptor<RealmSocket, ACE_SOCK_Acceptor>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RealmAcceptor(void) { }
|
|
||||||
virtual ~RealmAcceptor(void) { }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual int make_svc_handler(RealmSocket *&sh)
|
|
||||||
{
|
|
||||||
if (sh == 0)
|
|
||||||
ACE_NEW_RETURN(sh, RealmSocket, -1);
|
|
||||||
|
|
||||||
sh->reactor(reactor());
|
|
||||||
sh->set_session(new AuthSocket(*sh));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __REALMACCEPTOR_H__ */
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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 realmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Common.h"
|
|
||||||
#include "RealmList.h"
|
|
||||||
#include "Database/DatabaseEnv.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern DatabaseType LoginDatabase;
|
|
||||||
|
|
||||||
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load the realm list from the database
|
|
||||||
void RealmList::Initialize(uint32 updateInterval)
|
|
||||||
{
|
|
||||||
m_UpdateInterval = updateInterval;
|
|
||||||
|
|
||||||
///- Get the content of the realmlist table in the database
|
|
||||||
UpdateRealms(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealmList::UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build)
|
|
||||||
{
|
|
||||||
///- Create new if not exist or update existed
|
|
||||||
Realm& realm = m_realms[name];
|
|
||||||
|
|
||||||
realm.m_ID = ID;
|
|
||||||
realm.name = name;
|
|
||||||
realm.icon = icon;
|
|
||||||
realm.color = color;
|
|
||||||
realm.timezone = timezone;
|
|
||||||
realm.allowedSecurityLevel = allowedSecurityLevel;
|
|
||||||
realm.populationLevel = popu;
|
|
||||||
|
|
||||||
///- Append port to IP address.
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << address << ":" << port;
|
|
||||||
realm.address = ss.str();
|
|
||||||
realm.gamebuild = build;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealmList::UpdateIfNeed()
|
|
||||||
{
|
|
||||||
// maybe disabled or updated recently
|
|
||||||
if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_NextUpdateTime = time(NULL) + m_UpdateInterval;
|
|
||||||
|
|
||||||
// Clears Realm list
|
|
||||||
m_realms.clear();
|
|
||||||
|
|
||||||
// Get the content of the realmlist table in the database
|
|
||||||
UpdateRealms(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealmList::UpdateRealms(bool init)
|
|
||||||
{
|
|
||||||
sLog.outDetail("Updating Realm List...");
|
|
||||||
|
|
||||||
QueryResult_AutoPtr result = LoginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name");
|
|
||||||
|
|
||||||
///- Circle through results and add them to the realm map
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Field *fields = result->Fetch();
|
|
||||||
|
|
||||||
uint8 allowedSecurityLevel = fields[7].GetUInt8();
|
|
||||||
|
|
||||||
UpdateRealm(fields[0].GetUInt32(), fields[1].GetCppString(),fields[2].GetCppString(),fields[3].GetUInt32(),fields[4].GetUInt8(), fields[5].GetUInt8(), fields[6].GetUInt8(), (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), fields[8].GetFloat(), fields[9].GetUInt32());
|
|
||||||
if (init)
|
|
||||||
sLog.outString("Added realm \"%s\".", fields[1].GetString());
|
|
||||||
} while(result->NextRow());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// \addtogroup realmd
|
|
||||||
/// @{
|
|
||||||
/// \file
|
|
||||||
|
|
||||||
#ifndef _REALMLIST_H
|
|
||||||
#define _REALMLIST_H
|
|
||||||
|
|
||||||
#include <ace/Singleton.h>
|
|
||||||
#include <ace/Null_Mutex.h>
|
|
||||||
#include "Common.h"
|
|
||||||
|
|
||||||
/// Storage object for a realm
|
|
||||||
struct Realm
|
|
||||||
{
|
|
||||||
std::string address;
|
|
||||||
std::string name;
|
|
||||||
uint8 icon;
|
|
||||||
uint8 color;
|
|
||||||
uint8 timezone;
|
|
||||||
uint32 m_ID;
|
|
||||||
AccountTypes allowedSecurityLevel;
|
|
||||||
float populationLevel;
|
|
||||||
uint32 gamebuild;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Storage object for the list of realms on the server
|
|
||||||
class RealmList
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Null_Mutex is safe because the singleton initialized before the acceptor initialized(another place where the singleton called)
|
|
||||||
static RealmList* instance() { return ACE_Singleton<RealmList, ACE_Null_Mutex>::instance(); }
|
|
||||||
|
|
||||||
typedef std::map<std::string, Realm> RealmMap;
|
|
||||||
|
|
||||||
RealmList();
|
|
||||||
~RealmList() {}
|
|
||||||
|
|
||||||
void Initialize(uint32 updateInterval);
|
|
||||||
|
|
||||||
void UpdateIfNeed();
|
|
||||||
|
|
||||||
void AddRealm(Realm NewRealm) {m_realms[NewRealm.name] = NewRealm;}
|
|
||||||
|
|
||||||
RealmMap::const_iterator begin() const { return m_realms.begin(); }
|
|
||||||
RealmMap::const_iterator end() const { return m_realms.end(); }
|
|
||||||
uint32 size() const { return m_realms.size(); }
|
|
||||||
private:
|
|
||||||
void UpdateRealms(bool init);
|
|
||||||
void UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build);
|
|
||||||
private:
|
|
||||||
RealmMap m_realms; ///< Internal map of realms
|
|
||||||
uint32 m_UpdateInterval;
|
|
||||||
time_t m_NextUpdateTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define sRealmList RealmList::instance()
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/// @}
|
|
||||||
@@ -1,324 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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 realmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "RealmSocket.h"
|
|
||||||
|
|
||||||
#include "Log.h"
|
|
||||||
|
|
||||||
#include <ace/OS_NS_string.h>
|
|
||||||
#include <ace/INET_Addr.h>
|
|
||||||
#include <ace/SString.h>
|
|
||||||
|
|
||||||
#ifndef MSG_NOSIGNAL
|
|
||||||
#define MSG_NOSIGNAL 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RealmSocket::Session::Session(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RealmSocket::Session::~Session(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RealmSocket::RealmSocket(void):
|
|
||||||
session_(NULL),
|
|
||||||
input_buffer_(4096),
|
|
||||||
remote_address_()
|
|
||||||
{
|
|
||||||
reference_counting_policy().value(
|
|
||||||
ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
|
|
||||||
|
|
||||||
msg_queue()->high_water_mark(8*1024*1024);
|
|
||||||
msg_queue()->low_water_mark(8*1024*1024);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
RealmSocket::~RealmSocket(void)
|
|
||||||
{
|
|
||||||
if (msg_queue())
|
|
||||||
msg_queue()->close();
|
|
||||||
|
|
||||||
// delete RealmSocketObject must never be called from our code.
|
|
||||||
closing_ = true;
|
|
||||||
|
|
||||||
if (session_)
|
|
||||||
delete session_;
|
|
||||||
|
|
||||||
peer().close();
|
|
||||||
}
|
|
||||||
|
|
||||||
int RealmSocket::open(void * arg)
|
|
||||||
{
|
|
||||||
ACE_INET_Addr addr;
|
|
||||||
|
|
||||||
if (peer ().get_remote_addr (addr) == -1)
|
|
||||||
{
|
|
||||||
sLog.outError ("RealmSocket::open: peer ().get_remote_addr errno = %s", ACE_OS::strerror (errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
remote_address_ = addr.get_host_addr();
|
|
||||||
|
|
||||||
// Register with ACE Reactor
|
|
||||||
if (Base::open(arg) == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (session_ != NULL)
|
|
||||||
{
|
|
||||||
session_->OnAccept();
|
|
||||||
}
|
|
||||||
|
|
||||||
// reactor takes care of the socket from now on
|
|
||||||
remove_reference();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int RealmSocket::close(int)
|
|
||||||
{
|
|
||||||
shutdown();
|
|
||||||
|
|
||||||
closing_ = true;
|
|
||||||
|
|
||||||
remove_reference();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ACE_CString& RealmSocket::get_remote_address(void) const
|
|
||||||
{
|
|
||||||
return remote_address_;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t RealmSocket::recv_len(void) const
|
|
||||||
{
|
|
||||||
return input_buffer_.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RealmSocket::recv_soft(char *buf, size_t len)
|
|
||||||
{
|
|
||||||
if (input_buffer_.length() < len)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ACE_OS::memcpy(buf, input_buffer_.rd_ptr(), len);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RealmSocket::recv(char *buf, size_t len)
|
|
||||||
{
|
|
||||||
bool ret = recv_soft(buf, len);
|
|
||||||
|
|
||||||
if (ret)
|
|
||||||
recv_skip(len);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RealmSocket::recv_skip(size_t len)
|
|
||||||
{
|
|
||||||
input_buffer_.rd_ptr(len);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t RealmSocket::noblk_send(ACE_Message_Block &message_block)
|
|
||||||
{
|
|
||||||
const size_t len = message_block.length();
|
|
||||||
|
|
||||||
if (len == 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// Try to send the message directly.
|
|
||||||
ssize_t n = peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
if (errno == EWOULDBLOCK)
|
|
||||||
// Blocking signal
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
// Error happened
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (n == 0)
|
|
||||||
{
|
|
||||||
// Can this happen ?
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return bytes transmitted
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RealmSocket::send(const char *buf, size_t len)
|
|
||||||
{
|
|
||||||
if (buf == NULL || len == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
ACE_Data_Block db(
|
|
||||||
len,
|
|
||||||
ACE_Message_Block::MB_DATA,
|
|
||||||
(const char*)buf,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
ACE_Message_Block::DONT_DELETE,
|
|
||||||
0);
|
|
||||||
|
|
||||||
ACE_Message_Block message_block(
|
|
||||||
&db,
|
|
||||||
ACE_Message_Block::DONT_DELETE,
|
|
||||||
0);
|
|
||||||
|
|
||||||
message_block.wr_ptr(len);
|
|
||||||
|
|
||||||
if (msg_queue()->is_empty())
|
|
||||||
{
|
|
||||||
// Try to send it directly.
|
|
||||||
ssize_t n = noblk_send(message_block);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
return false;
|
|
||||||
else if (n == len)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// fall down
|
|
||||||
message_block.rd_ptr((size_t)n);
|
|
||||||
}
|
|
||||||
|
|
||||||
ACE_Message_Block *mb = message_block.clone();
|
|
||||||
|
|
||||||
if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
|
||||||
{
|
|
||||||
mb->release();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int RealmSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
|
||||||
{
|
|
||||||
if (closing_)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ACE_Message_Block *mb = 0;
|
|
||||||
|
|
||||||
if (msg_queue()->is_empty())
|
|
||||||
{
|
|
||||||
reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ssize_t n = noblk_send(*mb);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
mb->release();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (n == mb->length())
|
|
||||||
{
|
|
||||||
mb->release();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mb->rd_ptr(n);
|
|
||||||
|
|
||||||
if (msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
|
||||||
{
|
|
||||||
mb->release();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ACE_NOTREACHED(return -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int RealmSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask /*m*/)
|
|
||||||
{
|
|
||||||
// As opposed to WorldSocket::handle_close, we don't need locks here.
|
|
||||||
|
|
||||||
closing_ = true;
|
|
||||||
|
|
||||||
if (h == ACE_INVALID_HANDLE)
|
|
||||||
peer ().close_writer ();
|
|
||||||
|
|
||||||
if (session_ != NULL)
|
|
||||||
{
|
|
||||||
session_->OnClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int RealmSocket::handle_input(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
|
||||||
{
|
|
||||||
if (closing_)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
const ssize_t space = input_buffer_.space();
|
|
||||||
|
|
||||||
ssize_t n = peer().recv(input_buffer_.wr_ptr(), space);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
return errno == EWOULDBLOCK ? 0 : -1;
|
|
||||||
}
|
|
||||||
else if (n == 0)
|
|
||||||
{
|
|
||||||
// EOF
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_buffer_.wr_ptr((size_t)n);
|
|
||||||
|
|
||||||
if (session_ != NULL)
|
|
||||||
{
|
|
||||||
session_->OnRead();
|
|
||||||
|
|
||||||
input_buffer_.crunch();
|
|
||||||
}
|
|
||||||
|
|
||||||
// return 1 in case there is more data to read from OS
|
|
||||||
return n == space ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void RealmSocket::set_session(Session* session)
|
|
||||||
{
|
|
||||||
if (session_ != NULL)
|
|
||||||
delete session_;
|
|
||||||
|
|
||||||
session_ = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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 realmd
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __REALMSOCKET_H__
|
|
||||||
#define __REALMSOCKET_H__
|
|
||||||
|
|
||||||
#include <ace/Basic_Types.h>
|
|
||||||
#include <ace/Synch_Traits.h>
|
|
||||||
#include <ace/Svc_Handler.h>
|
|
||||||
#include <ace/SOCK_Stream.h>
|
|
||||||
#include <ace/Message_Block.h>
|
|
||||||
#include <ace/Basic_Types.h>
|
|
||||||
|
|
||||||
class RealmSocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
|
|
||||||
|
|
||||||
public:
|
|
||||||
class Session
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Session(void);
|
|
||||||
virtual ~Session(void);
|
|
||||||
|
|
||||||
virtual void OnRead(void) = 0;
|
|
||||||
virtual void OnAccept(void) = 0;
|
|
||||||
virtual void OnClose(void) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
RealmSocket(void);
|
|
||||||
virtual ~RealmSocket(void);
|
|
||||||
|
|
||||||
size_t recv_len(void) const;
|
|
||||||
bool recv_soft(char *buf, size_t len);
|
|
||||||
bool recv(char *buf, size_t len);
|
|
||||||
void recv_skip(size_t len);
|
|
||||||
|
|
||||||
bool send(const char *buf, size_t len);
|
|
||||||
|
|
||||||
const ACE_CString& get_remote_address(void) const;
|
|
||||||
|
|
||||||
virtual int open(void *);
|
|
||||||
|
|
||||||
virtual int close(int);
|
|
||||||
|
|
||||||
virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
|
|
||||||
virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
|
|
||||||
|
|
||||||
virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
|
|
||||||
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
|
||||||
|
|
||||||
void set_session(Session* session);
|
|
||||||
|
|
||||||
private:
|
|
||||||
ssize_t noblk_send(ACE_Message_Block &message_block);
|
|
||||||
|
|
||||||
private:
|
|
||||||
ACE_Message_Block input_buffer_;
|
|
||||||
Session* session_;
|
|
||||||
ACE_CString remote_address_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __REALMSOCKET_H__ */
|
|
||||||
@@ -1,445 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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"
|
|
||||||
#include "Language.h"
|
|
||||||
#include "Log.h"
|
|
||||||
#include "MapManager.h"
|
|
||||||
#include "Player.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)
|
|
||||||
{
|
|
||||||
idx++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
idx++;
|
|
||||||
//printf("Checking %s \n", cmd[idx].Name);
|
|
||||||
if (strncmp(ret, text, len) == 0)
|
|
||||||
return strdup(ret);
|
|
||||||
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
|
|
||||||
rl_bind_key('\t',rl_abort);
|
|
||||||
return (matches);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void utf8print(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(temp_buf);
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
va_list v;
|
|
||||||
vprintf(str, v);
|
|
||||||
va_end(v);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
#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))
|
|
||||||
{
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 account_id = accmgr.GetId(account_name);
|
|
||||||
if(!account_id)
|
|
||||||
{
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
case AOR_OK:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_DELETED,account_name.c_str());
|
|
||||||
break;
|
|
||||||
case AOR_NAME_NOT_EXIST:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
case AOR_DB_INTERNAL_ERROR:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_DELETED_SQL_ERROR,account_name.c_str());
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_DELETED,account_name.c_str());
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
character_guid = player->GetGUID();
|
|
||||||
account_id = player->GetSession()->GetAccountId();
|
|
||||||
player->GetSession()->KickPlayer();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
character_guid = objmgr.GetPlayerGUIDByName(character_name);
|
|
||||||
if(!character_guid)
|
|
||||||
{
|
|
||||||
PSendSysMessage(LANG_NO_PLAYER,character_name.c_str());
|
|
||||||
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*/)
|
|
||||||
{
|
|
||||||
SendSysMessage(LANG_COMMAND_EXIT);
|
|
||||||
World::StopNow(SHUTDOWN_EXIT_CODE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Display info on users currently in the realm
|
|
||||||
bool ChatHandler::HandleAccountOnlineListCommand(const char* /*args*/)
|
|
||||||
{
|
|
||||||
///- Get the list of accounts ID logged to the realm
|
|
||||||
QueryResult_AutoPtr resultDB = CharacterDatabase.Query("SELECT name,account,map,zone FROM characters WHERE online > 0");
|
|
||||||
if (!resultDB)
|
|
||||||
{
|
|
||||||
SendSysMessage(LANG_ACCOUNT_LIST_EMPTY);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
///- Display the list of account/characters online
|
|
||||||
SendSysMessage(LANG_ACCOUNT_LIST_BAR_HEADER);
|
|
||||||
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.
|
|
||||||
QueryResult_AutoPtr resultLogin =
|
|
||||||
LoginDatabase.PQuery("SELECT a.username, a.last_ip, aa.gmlevel, a.expansion "
|
|
||||||
"FROM account a "
|
|
||||||
"LEFT JOIN account_access aa "
|
|
||||||
"ON (a.id = aa.id) "
|
|
||||||
"WHERE a.id = '%u'", account);
|
|
||||||
if(resultLogin)
|
|
||||||
{
|
|
||||||
Field *fieldsLogin = resultLogin->Fetch();
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_LIST_LINE,
|
|
||||||
fieldsLogin[0].GetString(),name.c_str(),fieldsLogin[1].GetString(),fieldsDB[2].GetInt32(),fieldsDB[3].GetInt32(),fieldsLogin[3].GetUInt32(),fieldsLogin[2].GetUInt32());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_LIST_ERROR,name.c_str());
|
|
||||||
|
|
||||||
}while(resultDB->NextRow());
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
case AOR_OK:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_CREATED,account_name.c_str());
|
|
||||||
break;
|
|
||||||
case AOR_NAME_TOO_LONG:
|
|
||||||
SendSysMessage(LANG_ACCOUNT_TOO_LONG);
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
case AOR_NAME_ALREDY_EXIST:
|
|
||||||
SendSysMessage(LANG_ACCOUNT_ALREADY_EXIST);
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
case AOR_DB_INTERNAL_ERROR:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_CREATED_SQL_ERROR,account_name.c_str());
|
|
||||||
SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
PSendSysMessage(LANG_ACCOUNT_NOT_CREATED,account_name.c_str());
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
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 PLATFORM != WINDOWS
|
|
||||||
rl_attempted_completion_function = cli_completion;
|
|
||||||
#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
|
|
||||||
command_str = readline("TC>");
|
|
||||||
rl_bind_key('\t',rl_complete);
|
|
||||||
#endif
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
#if PLATFORM == WINDOWS
|
|
||||||
printf("TC>");
|
|
||||||
#endif
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string command;
|
|
||||||
if(!consoleToUtf8(command_str,command)) // convert from console encoding to utf8
|
|
||||||
{
|
|
||||||
#if PLATFORM == WINDOWS
|
|
||||||
printf("TC>");
|
|
||||||
#endif
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
sWorld.QueueCliCommand(&utf8print,command.c_str());
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void run();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
/// @}
|
|
||||||
@@ -1,265 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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"
|
|
||||||
#include "AccountMgr.h"
|
|
||||||
#include "Log.h"
|
|
||||||
#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()
|
|
||||||
{
|
|
||||||
std::string ss=GetRemoteAddress();
|
|
||||||
sLog.outRemote("Incoming connection from %s.\n",ss.c_str());
|
|
||||||
///- 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)
|
|
||||||
{
|
|
||||||
sLog.outRemote("Input buffer overflow, possible DOS attack.\n");
|
|
||||||
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
|
|
||||||
if(memcmp(inp ,"USER ",5))
|
|
||||||
{
|
|
||||||
delete [] inp;return;
|
|
||||||
printf("lin bugfix");
|
|
||||||
} //linux bugfix
|
|
||||||
|
|
||||||
///- Discard data after line break or line feed
|
|
||||||
bool gotenter=false;
|
|
||||||
unsigned int y=0;
|
|
||||||
for (; y<sz; y++)
|
|
||||||
if(inp[y]=='\r'||inp[y]=='\n')
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
/// <ul> <li> If the input is 'USER <username>'
|
|
||||||
case NONE:
|
|
||||||
if(!memcmp(buff,"USER ",5)) //got "USER" cmd
|
|
||||||
{
|
|
||||||
szLogin=&buff[5];
|
|
||||||
|
|
||||||
///- Get the 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_AutoPtr result = LoginDatabase.PQuery("SELECT a.id, aa.gmlevel, aa.RealmID FROM account a LEFT JOIN account_access aa ON (a.id = aa.id) WHERE a.username = '%s'",login.c_str ());
|
|
||||||
|
|
||||||
///- If the user is not found, deny access
|
|
||||||
if(!result)
|
|
||||||
{
|
|
||||||
Sendf("-No such user.\r\n");
|
|
||||||
sLog.outRemote("User %s does not exist.\n",szLogin.c_str());
|
|
||||||
if(bSecure)SetCloseAndDelete();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Field *fields = result->Fetch();
|
|
||||||
|
|
||||||
//szPass=fields[0].GetString();
|
|
||||||
|
|
||||||
///- if gmlevel is too low, deny access
|
|
||||||
if(fields[1].GetUInt32()<iMinLevel || fields[1].GetUInt32() == NULL)
|
|
||||||
{
|
|
||||||
Sendf("-Not enough privileges.\r\n");
|
|
||||||
sLog.outRemote("User %s has no privilege.\n",szLogin.c_str());
|
|
||||||
if(bSecure)SetCloseAndDelete();
|
|
||||||
}
|
|
||||||
else if(fields[2].GetInt32() != -1)
|
|
||||||
{
|
|
||||||
///- if RealmID isn't -1, deny access
|
|
||||||
Sendf("-Not enough privileges.\r\n");
|
|
||||||
sLog.outRemote("User %s has to be assigned on all realms (with RealmID = '-1').\n",szLogin.c_str());
|
|
||||||
if(bSecure)SetCloseAndDelete();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stage=LG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
///<li> If the input is 'PASS <password>' (and the user already gave his username)
|
|
||||||
case LG:
|
|
||||||
if(!memcmp(buff,"PASS ",5)) //got "PASS" cmd
|
|
||||||
{ //login+pass ok
|
|
||||||
///- 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_AutoPtr 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)
|
|
||||||
{
|
|
||||||
r=GetSocket();
|
|
||||||
stage=OK;
|
|
||||||
++iUsers;
|
|
||||||
|
|
||||||
Sendf("+Logged in.\r\n");
|
|
||||||
sLog.outRemote("User %s has logged in.\n",szLogin.c_str());
|
|
||||||
Sendf("TC>");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
///- Else deny access
|
|
||||||
Sendf("-Wrong pass.\r\n");
|
|
||||||
sLog.outRemote("User %s has failed to log in.\n",szLogin.c_str());
|
|
||||||
if(bSecure)SetCloseAndDelete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
///<li> If user is logged, parse and execute the command
|
|
||||||
case OK:
|
|
||||||
if(strlen(buff))
|
|
||||||
{
|
|
||||||
sLog.outRemote("Got '%s' cmd.\n",buff);
|
|
||||||
sWorld.QueueCliCommand(&RASocket::zprint , buff);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Sendf("TC>");
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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;
|
|
||||||
unsigned int iInputLength;
|
|
||||||
bool bLog;
|
|
||||||
bool bSecure; //kick on wrong pass, non exist. user, user with no priv
|
|
||||||
//will protect from DOS, bruteforce attacks
|
|
||||||
//some 'smart' protection must be added for more security
|
|
||||||
uint8 iMinLevel;
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
NONE, //initial value
|
|
||||||
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
|
|
||||||
/// @}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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"
|
|
||||||
|
|
||||||
#define WORLD_SLEEP_CONST 50
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include "ServiceWin32.h"
|
|
||||||
extern int m_ServiceStatus;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Heartbeat for the World
|
|
||||||
void WorldRunnable::run()
|
|
||||||
{
|
|
||||||
///- Init new SQL thread for the world database
|
|
||||||
WorldDatabase.ThreadStart(); // let thread do safe mySQL requests (one connection call enough)
|
|
||||||
|
|
||||||
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
|
|
||||||
// d1 = WORLD_SLEEP_CONST - t0 = WORLD_SLEEP_CONST - (D0 - d0) = WORLD_SLEEP_CONST + d0 - D0
|
|
||||||
if (diff <= WORLD_SLEEP_CONST+prevSleepTime)
|
|
||||||
{
|
|
||||||
prevSleepTime = WORLD_SLEEP_CONST+prevSleepTime-diff;
|
|
||||||
ACE_Based::Thread::Sleep(prevSleepTime);
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* 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
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void run();
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
/// @}
|
|
||||||
Reference in New Issue
Block a user