Headless client work

This commit is contained in:
KimLS 2016-11-15 21:30:43 -08:00
parent 84367e1f77
commit c86d4be1ae
15 changed files with 7798 additions and 64 deletions

View File

@ -36,6 +36,7 @@ SET(common_sources
ipc_mutex.cpp
item.cpp
item_base.cpp
json_config.cpp
light_source.cpp
md5.cpp
memory_buffer.cpp
@ -73,6 +74,7 @@ SET(common_sources
xml_parser.cpp
platform.cpp
event/event_loop.cpp
json/jsoncpp.cpp
net/crc32.cpp
net/daybreak_connection.cpp
net/eqstream.cpp
@ -165,6 +167,7 @@ SET(common_headers
item.h
item_base.h
item_fieldlist.h
json_config.h
languages.h
light_source.h
linked_list.h
@ -218,6 +221,8 @@ SET(common_headers
event/background_task.h
event/event_loop.h
event/timer.h
json/json.h
json/json-forwards.h
net/crc32.h
net/daybreak_connection.h
net/daybreak_structs.h
@ -294,6 +299,12 @@ SOURCE_GROUP(Event FILES
event/timer.h
)
SOURCE_GROUP(Json FILES
json/json.h
json/jsoncpp.cpp
json/json-forwards.h
)
SOURCE_GROUP(Net FILES
net/crc32.cpp
net/crc32.h

255
common/json/json-forwards.h Normal file
View File

@ -0,0 +1,255 @@
/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/).
/// It is intended to be used with #include "json/json-forwards.h"
/// This header provides forward declaration for all JsonCpp types.
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: LICENSE
// //////////////////////////////////////////////////////////////////////
/*
The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following
conditions...
The author (Baptiste Lepilleur) explicitly disclaims copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the
conditions of the MIT License (see below), or 3) under the terms of dual
Public Domain/MIT License conditions described here, as they choose.
The MIT License is about as close to Public Domain as a license can get, and is
described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License
The full text of the MIT License follows:
========================================================================
Copyright (c) 2007-2010 Baptiste Lepilleur
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
========================================================================
(END LICENSE TEXT)
The MIT license is compatible with both the GPL and commercial
software, affording one all of the rights of Public Domain with the
minor nuisance of being required to keep the above copyright notice
and license text in the source code. Note also that by accepting the
Public Domain "license" you can re-license your copy using whatever
license you like.
*/
// //////////////////////////////////////////////////////////////////////
// End of content of file: LICENSE
// //////////////////////////////////////////////////////////////////////
#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED
# define JSON_FORWARD_AMALGATED_H_INCLUDED
/// If defined, indicates that the source file is amalgated
/// to prevent private header inclusion.
#define JSON_IS_AMALGAMATION
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: include/json/config.h
// //////////////////////////////////////////////////////////////////////
// Copyright 2007-2010 Baptiste Lepilleur
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#ifndef JSON_CONFIG_H_INCLUDED
#define JSON_CONFIG_H_INCLUDED
/// If defined, indicates that json library is embedded in CppTL library.
//# define JSON_IN_CPPTL 1
/// If defined, indicates that json may leverage CppTL library
//# define JSON_USE_CPPTL 1
/// If defined, indicates that cpptl vector based map should be used instead of
/// std::map
/// as Value container.
//# define JSON_USE_CPPTL_SMALLMAP 1
// If non-zero, the library uses exceptions to report bad input instead of C
// assertion macros. The default is to use exceptions.
#ifndef JSON_USE_EXCEPTION
#define JSON_USE_EXCEPTION 1
#endif
/// If defined, indicates that the source file is amalgated
/// to prevent private header inclusion.
/// Remarks: it is automatically defined in the generated amalgated header.
// #define JSON_IS_AMALGAMATION
#ifdef JSON_IN_CPPTL
#include <cpptl/config.h>
#ifndef JSON_USE_CPPTL
#define JSON_USE_CPPTL 1
#endif
#endif
#ifdef JSON_IN_CPPTL
#define JSON_API CPPTL_API
#elif defined(JSON_DLL_BUILD)
#if defined(_MSC_VER)
#define JSON_API __declspec(dllexport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif // if defined(_MSC_VER)
#elif defined(JSON_DLL)
#if defined(_MSC_VER)
#define JSON_API __declspec(dllimport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif // if defined(_MSC_VER)
#endif // ifdef JSON_IN_CPPTL
#if !defined(JSON_API)
#define JSON_API
#endif
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
// integer
// Storages, and 64 bits integer support is disabled.
// #define JSON_NO_INT64 1
#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
// Microsoft Visual Studio 6 only support conversion from __int64 to double
// (no conversion from unsigned __int64).
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
// characters in the debug information)
// All projects I've ever seen with VS6 were using this globally (not bothering
// with pragma push/pop).
#pragma warning(disable : 4786)
#endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
#if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
/// Indicates that the following function is deprecated.
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
#elif defined(__clang__) && defined(__has_feature)
#if __has_feature(attribute_deprecated_with_message)
#define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
#endif
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
#define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
#endif
#if !defined(JSONCPP_DEPRECATED)
#define JSONCPP_DEPRECATED(message)
#endif // if !defined(JSONCPP_DEPRECATED)
namespace Json {
typedef int Int;
typedef unsigned int UInt;
#if defined(JSON_NO_INT64)
typedef int LargestInt;
typedef unsigned int LargestUInt;
#undef JSON_HAS_INT64
#else // if defined(JSON_NO_INT64)
// For Microsoft Visual use specific types as long long is not supported
#if defined(_MSC_VER) // Microsoft Visual Studio
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else // if defined(_MSC_VER) // Other platforms, use long long
typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif // if defined(_MSC_VER)
typedef Int64 LargestInt;
typedef UInt64 LargestUInt;
#define JSON_HAS_INT64
#endif // if defined(JSON_NO_INT64)
} // end namespace Json
#endif // JSON_CONFIG_H_INCLUDED
// //////////////////////////////////////////////////////////////////////
// End of content of file: include/json/config.h
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: include/json/forwards.h
// //////////////////////////////////////////////////////////////////////
// Copyright 2007-2010 Baptiste Lepilleur
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#ifndef JSON_FORWARDS_H_INCLUDED
#define JSON_FORWARDS_H_INCLUDED
#if !defined(JSON_IS_AMALGAMATION)
#include "config.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
namespace Json {
// writer.h
class FastWriter;
class StyledWriter;
// reader.h
class Reader;
// features.h
class Features;
// value.h
typedef unsigned int ArrayIndex;
class StaticString;
class Path;
class PathArgument;
class Value;
class ValueIteratorBase;
class ValueIterator;
class ValueConstIterator;
} // namespace Json
#endif // JSON_FORWARDS_H_INCLUDED
// //////////////////////////////////////////////////////////////////////
// End of content of file: include/json/forwards.h
// //////////////////////////////////////////////////////////////////////
#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED

1981
common/json/json.h Normal file

File diff suppressed because it is too large Load Diff

4945
common/json/jsoncpp.cpp Normal file

File diff suppressed because it is too large Load Diff

89
common/json_config.cpp Normal file
View File

@ -0,0 +1,89 @@
#include "json_config.h"
#include <fstream>
EQ::JsonConfigFile::JsonConfigFile()
{
}
EQ::JsonConfigFile::JsonConfigFile(const Json::Value &value)
{
m_root = value;
}
EQ::JsonConfigFile::~JsonConfigFile()
{
}
EQ::JsonConfigFile EQ::JsonConfigFile::Load(const std::string &filename)
{
JsonConfigFile ret;
ret.m_root = Json::Value();
std::ifstream ifs;
ifs.open(filename, std::ifstream::in);
if (!ifs.good()) {
return ret;
}
try {
ifs >> ret.m_root;
}
catch (std::exception) {
return ret;
}
return ret;
}
std::string EQ::JsonConfigFile::GetVariableString(const std::string &title, const std::string &parameter, const std::string &default_value) {
try {
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
return m_root[title][parameter].asString();
}
}
catch (std::exception) {
return default_value;
}
return default_value;
}
int EQ::JsonConfigFile::GetVariableInt(const std::string &title, const std::string &parameter, const int default_value) {
try {
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
return m_root[title][parameter].asInt();
}
}
catch (std::exception) {
return default_value;
}
return default_value;
}
bool EQ::JsonConfigFile::GetVariableBool(const std::string &title, const std::string &parameter, const bool default_value) {
try {
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
return m_root[title][parameter].asBool();
}
}
catch (std::exception) {
return default_value;
}
return default_value;
}
double EQ::JsonConfigFile::GetVariableDouble(const std::string &title, const std::string &parameter, const double default_value) {
try {
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
return m_root[title][parameter].asDouble();
}
}
catch (std::exception) {
return default_value;
}
return default_value;
}

26
common/json_config.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include "json/json.h"
namespace EQ
{
class JsonConfigFile
{
public:
JsonConfigFile(const Json::Value &value);
~JsonConfigFile();
static JsonConfigFile Load(const std::string &filename);
std::string GetVariableString(const std::string &title, const std::string &parameter, const std::string &default_value);
int GetVariableInt(const std::string &title, const std::string &parameter, const int default_value);
bool GetVariableBool(const std::string &title, const std::string &parameter, const bool default_value);
double GetVariableDouble(const std::string &title, const std::string &parameter, const double default_value);
Json::Value& RawHandle() { return m_root; }
private:
JsonConfigFile();
Json::Value m_root;
};
}

View File

@ -106,6 +106,7 @@ void EQ::Net::DaybreakConnectionManager::Process()
if (status == StatusDisconnecting) {
iter = m_connections.erase(iter);
connection->FlushBuffer();
connection->ChangeStatus(StatusDisconnected);
continue;
}
@ -114,14 +115,14 @@ void EQ::Net::DaybreakConnectionManager::Process()
auto time_since_last_recv = std::chrono::duration_cast<std::chrono::milliseconds>(now - connection->m_last_recv);
if ((size_t)time_since_last_recv.count() > m_options.connect_stale_ms) {
iter = m_connections.erase(iter);
connection->ChangeStatus(StatusDisconnected);
connection->ChangeStatus(StatusDisconnecting);
continue;
}
} else if (status == StatusConnected) {
auto time_since_last_recv = std::chrono::duration_cast<std::chrono::milliseconds>(now - connection->m_last_recv);
if ((size_t)time_since_last_recv.count() > m_options.stale_connection_ms) {
iter = m_connections.erase(iter);
connection->ChangeStatus(StatusDisconnected);
connection->ChangeStatus(StatusDisconnecting);
continue;
}
}
@ -319,7 +320,7 @@ void EQ::Net::DaybreakConnection::Close()
ChangeStatus(StatusDisconnecting);
}
else {
ChangeStatus(StatusDisconnected);
ChangeStatus(StatusDisconnecting);
}
}
@ -700,7 +701,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
InternalSend(out);
}
ChangeStatus(StatusDisconnected);
ChangeStatus(StatusDisconnecting);
break;
}

View File

@ -1,12 +1,14 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(hc_sources
eq.cpp
main.cpp
login.cpp
world.cpp
)
SET(hc_headers
eq.h
login.h
world.h
)

340
hc/eq.cpp Normal file
View File

@ -0,0 +1,340 @@
#include "eq.h"
#include "../common/net/dns.h"
const char* eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char* buffer_out, bool enc) {
DES_key_schedule k;
DES_cblock v;
memset(&k, 0, sizeof(DES_key_schedule));
memset(&v, 0, sizeof(DES_cblock));
if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) {
return nullptr;
}
DES_ncbc_encrypt((const unsigned char*)buffer_in, (unsigned char*)buffer_out, (long)buffer_in_sz, &k, &v, enc);
return buffer_out;
}
EverQuest::EverQuest(const std::string &host, int port, const std::string &user, const std::string &pass, const std::string &server, const std::string &character)
{
m_host = host;
m_port = port;
m_user = user;
m_pass = pass;
m_server = server;
m_character = character;
m_dbid = 0;
EQ::Net::DNSLookup(m_host, port, false, [&](const std::string &addr) {
if (addr.empty()) {
Log.OutF(Logs::General, Logs::Headless_Client, "Could not resolve address: {0}", m_host);
return;
}
else {
m_host = addr;
m_login_connection_manager.reset(new EQ::Net::DaybreakConnectionManager());
m_login_connection_manager->OnNewConnection(std::bind(&EverQuest::LoginOnNewConnection, this, std::placeholders::_1));
m_login_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::LoginOnStatusChangeReconnectEnabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_login_connection_manager->OnPacketRecv(std::bind(&EverQuest::LoginOnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_login_connection_manager->Connect(m_host, m_port);
}
});
}
EverQuest::~EverQuest()
{
}
void EverQuest::LoginOnNewConnection(std::shared_ptr<EQ::Net::DaybreakConnection> connection)
{
m_login_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting...");
}
void EverQuest::LoginOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connected.");
LoginSendSessionReady();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "Login connection lost before we got to world, reconnecting.");
m_key.clear();
m_dbid = 0;
m_login_connection.reset();
m_login_connection_manager->Connect(m_host, m_port);
}
}
void EverQuest::LoginOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_login_connection.reset();
}
}
void EverQuest::LoginOnPacketRecv(std::shared_ptr<EQ::Net::DaybreakConnection> conn, const EQ::Net::Packet & p)
{
auto opcode = p.GetUInt16(0);
switch (opcode) {
case 0x0017: //OP_ChatMessage
LoginSendLogin();
break;
case 0x0018:
LoginProcessLoginResponse(p);
break;
case 0x0019:
LoginProcessServerPacketList(p);
break;
case 0x0022:
LoginProcessServerPlayResponse(p);
break;
}
}
void EverQuest::LoginSendSessionReady()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 1); //OP_SessionReady
p.PutUInt32(2, 2);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendLogin()
{
size_t buffer_len = m_user.length() + m_pass.length() + 2;
std::unique_ptr<char[]> buffer(new char[buffer_len]);
strcpy(&buffer[0], m_user.c_str());
strcpy(&buffer[m_user.length() + 1], m_pass.c_str());
size_t encrypted_len = buffer_len;
if (encrypted_len % 8 > 0) {
encrypted_len = ((encrypted_len / 8) + 1) * 8;
}
EQ::Net::DynamicPacket p;
p.Resize(12 + encrypted_len);
p.PutUInt16(0, 2); //OP_Login
p.PutUInt32(2, 3);
eqcrypt_block(&buffer[0], buffer_len, (char*)p.Data() + 12, true);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendServerRequest()
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 4); //OP_ServerListRequest
p.PutUInt32(2, 4);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginSendPlayRequest(uint32_t id)
{
EQ::Net::DynamicPacket p;
p.PutUInt16(0, 0x000d);
p.PutUInt16(2, 5);
p.PutUInt32(4, 0);
p.PutUInt32(8, 0);
p.PutUInt32(12, id);
m_login_connection->QueuePacket(p);
}
void EverQuest::LoginProcessLoginResponse(const EQ::Net::Packet & p)
{
auto encrypt_size = p.Length() - 12;
if (encrypt_size % 8 > 0) {
encrypt_size = (encrypt_size / 8) * 8;
}
std::unique_ptr<char[]> decrypted(new char[encrypt_size]);
eqcrypt_block((char*)p.Data() + 12, encrypt_size, &decrypted[0], false);
EQ::Net::StaticPacket sp(&decrypted[0], encrypt_size);
auto response_error = sp.GetUInt16(1);
if (response_error > 101) {
Log.OutF(Logs::General, Logs::Headless_Client, "Error logging in response code: {0}", response_error);
LoginDisableReconnect();
}
else {
m_key = sp.GetCString(12);
m_dbid = sp.GetUInt32(8);
Log.OutF(Logs::General, Logs::Headless_Client, "Logged in successfully with dbid {0} and key {1}", m_dbid, m_key);
LoginSendServerRequest();
}
}
void EverQuest::LoginProcessServerPacketList(const EQ::Net::Packet & p)
{
m_world_servers.clear();
auto number_of_servers = p.GetUInt32(18);
size_t idx = 22;
for (auto i = 0U; i < number_of_servers; ++i) {
WorldServer ws;
ws.address = p.GetCString(idx);
idx += (ws.address.length() + 1);
ws.type = p.GetInt32(idx);
idx += 4;
auto id = p.GetUInt32(idx);
idx += 4;
ws.long_name = p.GetCString(idx);
idx += (ws.long_name.length() + 1);
ws.lang = p.GetCString(idx);
idx += (ws.lang.length() + 1);
ws.region = p.GetCString(idx);
idx += (ws.region.length() + 1);
ws.status = p.GetInt32(idx);
idx += 4;
ws.players = p.GetInt32(idx);
idx += 4;
m_world_servers[id] = ws;
}
for (auto server : m_world_servers) {
if (server.second.long_name.compare(m_server) == 0) {
Log.OutF(Logs::General, Logs::Headless_Client, "Found world server {0}, attempting to login.", m_server);
LoginSendPlayRequest(server.first);
return;
}
}
Log.OutF(Logs::General, Logs::Headless_Client, "Got response from login server but could not find world server {0} disconnecting.", m_server);
LoginDisableReconnect();
}
void EverQuest::LoginProcessServerPlayResponse(const EQ::Net::Packet &p)
{
auto allowed = p.GetUInt8(12);
if (allowed) {
auto server = p.GetUInt32(18);
auto ws = m_world_servers.find(server);
if (ws != m_world_servers.end()) {
ConnectToWorld();
LoginDisableReconnect();
}
}
else {
auto message = p.GetUInt16(13);
Log.OutF(Logs::General, Logs::Headless_Client, "Failed to login to server with message {0}");
LoginDisableReconnect();
}
}
void EverQuest::LoginDisableReconnect()
{
m_login_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::LoginOnStatusChangeReconnectDisabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_login_connection->Close();
}
void EverQuest::ConnectToWorld()
{
m_world_connection_manager.reset(new EQ::Net::DaybreakConnectionManager());
m_world_connection_manager->OnNewConnection(std::bind(&EverQuest::WorldOnNewConnection, this, std::placeholders::_1));
m_world_connection_manager->OnConnectionStateChange(std::bind(&EverQuest::WorldOnStatusChangeReconnectEnabled, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_world_connection_manager->OnPacketRecv(std::bind(&EverQuest::WorldOnPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
m_world_connection_manager->Connect(m_host, 9000);
}
void EverQuest::WorldOnNewConnection(std::shared_ptr<EQ::Net::DaybreakConnection> connection)
{
m_world_connection = connection;
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting to world...");
}
void EverQuest::WorldOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusConnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connected.");
WorldSendClientAuth();
}
if (to == EQ::Net::StatusDisconnected) {
Log.OutF(Logs::General, Logs::Headless_Client, "World connection lost, reconnecting.");
m_world_connection.reset();
m_world_connection_manager->Connect(m_host, 9000);
}
}
void EverQuest::WorldOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to)
{
if (to == EQ::Net::StatusDisconnected) {
m_world_connection.reset();
}
}
void EverQuest::WorldOnPacketRecv(std::shared_ptr<EQ::Net::DaybreakConnection> conn, const EQ::Net::Packet & p)
{
Log.OutF(Logs::General, Logs::Headless_Client, "Packet in:\n{0}", p.ToString());
auto opcode = p.GetUInt16(0);
switch (opcode) {
case 0x7499:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_ApproveWorld");
break;
case 0x7ceb:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_LogServer");
break;
case 0x578f:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_EnterWorld");
break;
case 0x6259:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_PostEnterWorld");
break;
case 0x590d:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_ExpansionInfo");
break;
case 0x507a:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_GuildsList");
break;
case 0x5475:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_SendMaxCharacters");
break;
case 0x7acc:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_SendMembership");
break;
case 0x057b:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_SendMembershipDetails");
break;
case 0x00d2:
Log.OutF(Logs::General, Logs::Headless_Client, "OP_SendCharInfo");
break;
default:
Log.OutF(Logs::General, Logs::Headless_Client, "Ignored packet: {0:#x}", opcode);
}
}
void EverQuest::WorldSendClientAuth()
{
EQ::Net::DynamicPacket p;
p.Resize(2 + 464);
p.PutUInt16(0, 0x7a09U);
std::string dbid_str = std::to_string(m_dbid);
p.PutCString(2, dbid_str.c_str());
p.PutCString(2 + dbid_str.length() + 1, m_key.c_str());
m_world_connection->QueuePacket(p);
}

71
hc/eq.h Normal file
View File

@ -0,0 +1,71 @@
#pragma once
#include "../common/eqemu_logsys.h"
#include "../common/net/daybreak_connection.h"
#include "../common/event/timer.h"
#include <openssl/des.h>
#include <string>
#include <map>
struct WorldServer
{
std::string long_name;
std::string address;
int type;
std::string lang;
std::string region;
int status;
int players;
};
class EverQuest
{
public:
EverQuest(const std::string &host, int port, const std::string &user, const std::string &pass, const std::string &server, const std::string &character);
~EverQuest();
private:
//Login
void LoginOnNewConnection(std::shared_ptr<EQ::Net::DaybreakConnection> connection);
void LoginOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void LoginOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void LoginOnPacketRecv(std::shared_ptr<EQ::Net::DaybreakConnection> conn, const EQ::Net::Packet &p);
void LoginSendSessionReady();
void LoginSendLogin();
void LoginSendServerRequest();
void LoginSendPlayRequest(uint32_t id);
void LoginProcessLoginResponse(const EQ::Net::Packet &p);
void LoginProcessServerPacketList(const EQ::Net::Packet &p);
void LoginProcessServerPlayResponse(const EQ::Net::Packet &p);
void LoginDisableReconnect();
std::unique_ptr<EQ::Net::DaybreakConnectionManager> m_login_connection_manager;
std::shared_ptr<EQ::Net::DaybreakConnection> m_login_connection;
std::map<uint32_t, WorldServer> m_world_servers;
//World
void ConnectToWorld();
void WorldOnNewConnection(std::shared_ptr<EQ::Net::DaybreakConnection> connection);
void WorldOnStatusChangeReconnectEnabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void WorldOnStatusChangeReconnectDisabled(std::shared_ptr<EQ::Net::DaybreakConnection> conn, EQ::Net::DbProtocolStatus from, EQ::Net::DbProtocolStatus to);
void WorldOnPacketRecv(std::shared_ptr<EQ::Net::DaybreakConnection> conn, const EQ::Net::Packet &p);
void WorldSendClientAuth();
std::unique_ptr<EQ::Net::DaybreakConnectionManager> m_world_connection_manager;
std::shared_ptr<EQ::Net::DaybreakConnection> m_world_connection;
//Variables
std::string m_host;
int m_port;
std::string m_user;
std::string m_pass;
std::string m_server;
std::string m_character;
std::string m_key;
uint32_t m_dbid;
};

View File

@ -1,4 +1,4 @@
#include "login.h"
/*#include "login.h"
#include "../common/eqemu_logsys.h"
#include <openssl/des.h>
@ -252,3 +252,4 @@ void LoginConnection::ProcessServerPlayResponse(const EQ::Net::Packet &p)
Kill();
}
}
*/

View File

@ -2,10 +2,10 @@
#include "../common/eqemu_logsys.h"
#include "../common/crash.h"
#include "../common/platform.h"
#include "../common/json_config.h"
#include <thread>
#include "login.h"
#include "world.h"
#include "eq.h"
EQEmuLogSys Log;
@ -16,12 +16,31 @@ int main() {
Log.OutF(Logs::General, Logs::Headless_Client, "Starting EQEmu Headless Client.");
std::unique_ptr<LoginConnection> login_connection(new LoginConnection("testuser", "testpass", "127.0.0.1", 5999, "KLS Test"));
std::unique_ptr<WorldConnection> world_connection;
login_connection->OnCanLoginToWorld([&](const WorldServer &ws, const std::string &key, uint32_t dbid) {
Log.OutF(Logs::General, Logs::Headless_Client, "Connect to world server {1} - {0}:9000", ws.address, ws.long_name);
world_connection.reset(new WorldConnection(key, dbid, ws.address));
});
auto config = EQ::JsonConfigFile::Load("hc.json");
auto config_handle = config.RawHandle();
std::vector<std::unique_ptr<EverQuest>> eq_list;
try {
for (int i = 0; i < config_handle.size(); ++i) {
auto c = config_handle[i];
auto host = c["host"].asString();
auto port = c["port"].asInt();
auto user = c["user"].asString();
auto pass = c["pass"].asString();
auto server = c["server"].asString();
auto character = c["character"].asString();
Log.OutF(Logs::General, Logs::Headless_Client, "Connecting to {0}:{1} as Account '{2}' to Server '{3}' under Character '{4}'", host, port, user, server, character);
eq_list.push_back(std::unique_ptr<EverQuest>(new EverQuest(host, port, user, pass, server, character)));
}
}
catch (std::exception &ex) {
Log.OutF(Logs::General, Logs::Headless_Client, "Error parsing config file: {0}", ex.what());
return 0;
}
for (;;) {
EQ::EventLoop::Get().Process();

View File

@ -49,6 +49,12 @@ bool Client::Process()
DumpPacket(app);
}
if (status == cs_failed_to_login) {
delete app;
app = connection->PopPacket();
continue;
}
switch(app->GetOpcode())
{
case OP_SessionReady:
@ -325,6 +331,8 @@ void Client::Handle_Login(const char* data, unsigned int size)
connection->QueuePacket(outapp);
delete outapp;
status = cs_failed_to_login;
}
}

View File

@ -35,6 +35,7 @@ enum LSClientStatus
{
cs_not_sent_session_ready,
cs_waiting_for_login,
cs_failed_to_login,
cs_logged_in
};

View File

@ -172,7 +172,6 @@ void Client::SendExpansionInfo() {
ExpansionInfo_Struct *eis = (ExpansionInfo_Struct*)outapp->pBuffer;
if(RuleB(World, UseClientBasedExpansionSettings)) {
eis->Expansions = EQEmu::versions::ConvertClientVersionToExpansion(eqs->ClientVersion());
//eis->Expansions = ExpansionFromClientVersion(this->GetCLE.
} else {
eis->Expansions = (RuleI(World, ExpansionSettings));
}
@ -1340,56 +1339,41 @@ void Client::SendApproveWorld()
outapp = new EQApplicationPacket(OP_ApproveWorld, sizeof(ApproveWorld_Struct));
ApproveWorld_Struct* aw = (ApproveWorld_Struct*)outapp->pBuffer;
uchar foo[] = {
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x95,0x5E,0x30,0xA5,0xCA,0xD4,0xEA,0xF5,
//0xCB,0x14,0xFC,0xF7,0x78,0xE2,0x73,0x15,0x90,0x17,0xCE,0x7A,0xEB,0xEC,0x3C,0x34,
//0x5C,0x6D,0x10,0x05,0xFC,0xEA,0xED,0x19,0xC5,0x0D,0x7A,0x82,0x17,0xCC,0xCC,0x71,
//0x56,0x38,0xDF,0x78,0x8D,0xE6,0x44,0xD3,0x6F,0xDB,0xE3,0xCF,0x21,0x30,0x75,0x2F,
//0xCD,0xDC,0xE9,0xB4,0xA4,0x4E,0x58,0xDE,0xEE,0x54,0xDD,0x87,0xDA,0xE9,0xC6,0xC8,
//0x02,0xDD,0xC4,0xFD,0x94,0x36,0x32,0xAD,0x1B,0x39,0x0F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x87,0x13,0xbe,0xc8,0xa7,0x77,0xcb,
0x27,0xed,0xe1,0xe6,0x5d,0x1c,0xaa,0xd3,0x3c,0x26,0x3b,0x6d,0x8c,0xdb,0x36,0x8d,
0x91,0x72,0xf5,0xbb,0xe0,0x5c,0x50,0x6f,0x09,0x6d,0xc9,0x1e,0xe7,0x2e,0xf4,0x38,
0x1b,0x5e,0xa8,0xc2,0xfe,0xb4,0x18,0x4a,0xf7,0x72,0x85,0x13,0xf5,0x63,0x6c,0x16,
0x69,0xf4,0xe0,0x17,0xff,0x87,0x11,0xf3,0x2b,0xb7,0x73,0x04,0x37,0xca,0xd5,0x77,
0xf8,0x03,0x20,0x0a,0x56,0x8b,0xfb,0x35,0xff,0x59,0x00,0x00,0x00,0x00,0x00,0x00,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x42,0x69,0x2a,0x87,0xdd,0x04,0x3d,
//0x7f,0xb1,0xb3,0xbb,0xde,0xd5,0x5f,0xfc,0x1f,0xb3,0x25,0x94,0x16,0xd5,0xf3,0x97,
//0x43,0xdf,0xb9,0x69,0x68,0xdf,0x2b,0x64,0x98,0xf5,0x44,0xbe,0x38,0x65,0xef,0xff,
//0x36,0x89,0x90,0xcf,0x26,0xbb,0x9f,0x76,0xd5,0xaf,0x6d,0xf2,0x08,0xbe,0xce,0xd8,
//0x3e,0x4b,0x53,0x8a,0xf3,0x44,0x7c,0x19,0x49,0x5d,0x97,0x99,0xd8,0x8b,0xee,0x10,
//0x1a,0x7d,0xb7,0x8b,0x49,0x9b,0x40,0x8c,0xea,0x49,0x09,0x00,0x00,0x00,0x00,0x00,
//
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x15,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x53,0xC3,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00
};
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x87,0x13,0xbe,0xc8,0xa7,0x77,0xcb,
0x27,0xed,0xe1,0xe6,0x5d,0x1c,0xaa,0xd3,0x3c,0x26,0x3b,0x6d,0x8c,0xdb,0x36,0x8d,
0x91,0x72,0xf5,0xbb,0xe0,0x5c,0x50,0x6f,0x09,0x6d,0xc9,0x1e,0xe7,0x2e,0xf4,0x38,
0x1b,0x5e,0xa8,0xc2,0xfe,0xb4,0x18,0x4a,0xf7,0x72,0x85,0x13,0xf5,0x63,0x6c,0x16,
0x69,0xf4,0xe0,0x17,0xff,0x87,0x11,0xf3,0x2b,0xb7,0x73,0x04,0x37,0xca,0xd5,0x77,
0xf8,0x03,0x20,0x0a,0x56,0x8b,0xfb,0x35,0xff,0x59,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x15,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x53,0xC3,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00
};
memcpy(aw->unknown544, foo, sizeof(foo));
QueuePacket(outapp);
safe_delete(outapp);