mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
Legacy connection wip
This commit is contained in:
parent
3e38055f20
commit
f07b5d9032
@ -72,11 +72,13 @@ SET(common_sources
|
||||
worldconn.cpp
|
||||
xml_parser.cpp
|
||||
platform.cpp
|
||||
event/event_loop.cpp
|
||||
net/crc32.cpp
|
||||
net/daybreak_connection.cpp
|
||||
net/eqstream.cpp
|
||||
net/packet.cpp
|
||||
net/servertalk_client_connection.cpp
|
||||
net/servertalk_legacy_client_connection.cpp
|
||||
net/servertalk_server.cpp
|
||||
net/servertalk_server_connection.cpp
|
||||
net/tcp_connection.cpp
|
||||
@ -224,6 +226,7 @@ SET(common_headers
|
||||
net/eqstream.h
|
||||
net/packet.h
|
||||
net/servertalk_client_connection.h
|
||||
net/servertalk_legacy_client_connection.h
|
||||
net/servertalk_common.h
|
||||
net/servertalk_server.h
|
||||
net/servertalk_server_connection.h
|
||||
@ -286,6 +289,7 @@ SET(common_headers
|
||||
|
||||
SOURCE_GROUP(Event FILES
|
||||
event/background_task.h
|
||||
event/event_loop.cpp
|
||||
event/event_loop.h
|
||||
event/timer.h
|
||||
)
|
||||
@ -306,6 +310,8 @@ SOURCE_GROUP(Net FILES
|
||||
net/packet.h
|
||||
net/servertalk_client_connection.cpp
|
||||
net/servertalk_client_connection.h
|
||||
net/servertalk_legacy_client_connection.cpp
|
||||
net/servertalk_legacy_client_connection.h
|
||||
net/servertalk_common.h
|
||||
net/servertalk_server.cpp
|
||||
net/servertalk_server.h
|
||||
|
||||
@ -1534,8 +1534,6 @@ uint32 Database::GetGroupID(const char* name){
|
||||
|
||||
if (results.RowCount() == 0)
|
||||
{
|
||||
// Commenting this out until logging levels can prevent this from going to console
|
||||
//Log.Out(Logs::General, Logs::None,, "Character not in a group: %s", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -66,6 +66,10 @@ void EQEmuConfig::do_world(TiXmlElement *ele)
|
||||
if (text) {
|
||||
LoginPort = atoi(text);
|
||||
}
|
||||
text = ParseTextBlock(sub_ele, "legacy", true);
|
||||
if (text) {
|
||||
LoginLegacy = atoi(text) > 0 ? true : false;
|
||||
}
|
||||
text = ParseTextBlock(sub_ele, "account", true);
|
||||
if (text) {
|
||||
LoginAccount = text;
|
||||
@ -89,6 +93,10 @@ void EQEmuConfig::do_world(TiXmlElement *ele)
|
||||
if (text) {
|
||||
loginconfig->LoginPort = atoi(text);
|
||||
}
|
||||
text = ParseTextBlock(sub_ele, "legacy", true);
|
||||
if (text) {
|
||||
loginconfig->LoginLegacy = atoi(text) > 0 ? true : false;
|
||||
}
|
||||
text = ParseTextBlock(sub_ele, "account", true);
|
||||
if (text) {
|
||||
loginconfig->LoginAccount = text;
|
||||
@ -370,6 +378,9 @@ std::string EQEmuConfig::GetByName(const std::string &var_name) const
|
||||
if (var_name == "LoginPort") {
|
||||
return (itoa(LoginPort));
|
||||
}
|
||||
if (var_name == "LoginLegacy") {
|
||||
return (itoa(LoginLegacy ? 1 : 0));
|
||||
}
|
||||
if (var_name == "Locked") {
|
||||
return (Locked ? "true" : "false");
|
||||
}
|
||||
@ -495,6 +506,7 @@ void EQEmuConfig::Dump() const
|
||||
std::cout << "LoginAccount = " << LoginAccount << std::endl;
|
||||
std::cout << "LoginPassword = " << LoginPassword << std::endl;
|
||||
std::cout << "LoginPort = " << LoginPort << std::endl;
|
||||
std::cout << "LoginLegacy = " << LoginLegacy << std::endl;
|
||||
std::cout << "Locked = " << Locked << std::endl;
|
||||
std::cout << "WorldTCPPort = " << WorldTCPPort << std::endl;
|
||||
std::cout << "WorldIP = " << WorldIP << std::endl;
|
||||
|
||||
@ -26,6 +26,7 @@ struct LoginConfig {
|
||||
std::string LoginAccount;
|
||||
std::string LoginPassword;
|
||||
uint16 LoginPort;
|
||||
bool LoginLegacy;
|
||||
};
|
||||
|
||||
class EQEmuConfig : public XMLParser
|
||||
@ -42,6 +43,7 @@ class EQEmuConfig : public XMLParser
|
||||
std::string LoginAccount;
|
||||
std::string LoginPassword;
|
||||
uint16 LoginPort;
|
||||
bool LoginLegacy;
|
||||
uint32 LoginCount;
|
||||
LinkedList<LoginConfig*> loginlist;
|
||||
bool Locked;
|
||||
@ -127,8 +129,9 @@ class EQEmuConfig : public XMLParser
|
||||
#include "eqemu_config_elements.h"
|
||||
// Set sane defaults
|
||||
// Login server
|
||||
LoginHost = "eqemulator.net";
|
||||
LoginHost = "login.eqemulator.net";
|
||||
LoginPort = 5998;
|
||||
LoginLegacy = true;
|
||||
// World
|
||||
Locked = false;
|
||||
WorldTCPPort = 9000;
|
||||
|
||||
0
common/event/event_loop.cpp
Normal file
0
common/event/event_loop.cpp
Normal file
@ -19,7 +19,6 @@ EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager(const DaybreakConn
|
||||
m_attached = nullptr;
|
||||
m_options = opts;
|
||||
memset(&m_timer, 0, sizeof(uv_timer_t));
|
||||
memset(&m_resend_timer, 0, sizeof(uv_timer_t));
|
||||
memset(&m_socket, 0, sizeof(uv_udp_t));
|
||||
|
||||
Attach(EQ::EventLoop::Get().Handle());
|
||||
@ -34,19 +33,15 @@ void EQ::Net::DaybreakConnectionManager::Attach(uv_loop_t *loop)
|
||||
{
|
||||
if (!m_attached) {
|
||||
uv_timer_init(loop, &m_timer);
|
||||
uv_timer_init(loop, &m_resend_timer);
|
||||
m_timer.data = this;
|
||||
m_resend_timer.data = this;
|
||||
|
||||
auto update_rate = (uint64_t)(1000.0 / m_options.tic_rate_hertz);
|
||||
|
||||
uv_timer_start(&m_timer, [](uv_timer_t *handle) {
|
||||
DaybreakConnectionManager *c = (DaybreakConnectionManager*)handle->data;
|
||||
c->Process();
|
||||
}, 2, 2);
|
||||
|
||||
uv_timer_start(&m_resend_timer, [](uv_timer_t *handle) {
|
||||
DaybreakConnectionManager *c = (DaybreakConnectionManager*)handle->data;
|
||||
c->ProcessResend();
|
||||
}, 5, 5);
|
||||
}, update_rate, update_rate);
|
||||
|
||||
uv_udp_init(loop, &m_socket);
|
||||
m_socket.data = this;
|
||||
@ -187,12 +182,12 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
|
||||
try {
|
||||
auto connection = FindConnectionByEndpoint(endpoint, port);
|
||||
if (connection) {
|
||||
ReadOnlyPacket p((void*)data, size);
|
||||
StaticPacket p((void*)data, size);
|
||||
connection->ProcessPacket(p);
|
||||
}
|
||||
else {
|
||||
if (data[0] == 0 && data[1] == OP_SessionRequest) {
|
||||
ReadOnlyPacket p((void*)data, size);
|
||||
StaticPacket p((void*)data, size);
|
||||
auto request = p.GetSerialize<DaybreakConnect>(0);
|
||||
|
||||
connection = std::shared_ptr<DaybreakConnection>(new DaybreakConnection(this, request, endpoint, port));
|
||||
@ -232,7 +227,7 @@ void EQ::Net::DaybreakConnectionManager::SendDisconnect(const std::string &addr,
|
||||
header.opcode = OP_SessionDisconnect;
|
||||
header.connect_code = 0;
|
||||
|
||||
WritablePacket out;
|
||||
DynamicPacket out;
|
||||
out.PutSerialize(0, header);
|
||||
|
||||
uv_udp_send_t *send_req = new uv_udp_send_t;
|
||||
@ -270,6 +265,9 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner
|
||||
m_buffered_packets_length = 0;
|
||||
m_resend_delay = m_owner->m_options.resend_delay_ms;
|
||||
m_rolling_ping = 100;
|
||||
m_combined.reset(new char[512]);
|
||||
m_combined[0] = 0;
|
||||
m_combined[1] = OP_Combined;
|
||||
m_last_session_stats = Clock::now();
|
||||
}
|
||||
|
||||
@ -304,7 +302,7 @@ void EQ::Net::DaybreakConnection::Close()
|
||||
disconnect.zero = 0;
|
||||
disconnect.opcode = OP_SessionDisconnect;
|
||||
disconnect.connect_code = HostToNetwork(m_connect_code);
|
||||
WritablePacket out;
|
||||
DynamicPacket out;
|
||||
out.PutSerialize(0, disconnect);
|
||||
InternalSend(out);
|
||||
|
||||
@ -328,7 +326,7 @@ void EQ::Net::DaybreakConnection::QueuePacket(Packet &p, int stream)
|
||||
void EQ::Net::DaybreakConnection::QueuePacket(Packet &p, int stream, bool reliable)
|
||||
{
|
||||
if (*(char*)p.Data() == 0) {
|
||||
WritablePacket packet;
|
||||
DynamicPacket packet;
|
||||
packet.PutUInt8(0, 0);
|
||||
packet.PutPacket(1, p);
|
||||
InternalQueuePacket(packet, stream, reliable);
|
||||
@ -395,7 +393,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
|
||||
return;
|
||||
}
|
||||
|
||||
EQ::Net::WritablePacket temp;
|
||||
EQ::Net::DynamicPacket temp;
|
||||
temp.PutPacket(0, p);
|
||||
temp.Resize(temp.Length() - m_crc_bytes);
|
||||
|
||||
@ -412,7 +410,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
|
||||
}
|
||||
}
|
||||
|
||||
ProcessDecodedPacket(ReadOnlyPacket(temp.Data(), temp.Length()));
|
||||
ProcessDecodedPacket(StaticPacket(temp.Data(), temp.Length()));
|
||||
}
|
||||
else {
|
||||
ProcessDecodedPacket(p);
|
||||
@ -454,7 +452,7 @@ void EQ::Net::DaybreakConnection::AddToQueue(int stream, uint16_t seq, const Pac
|
||||
auto s = &m_streams[stream];
|
||||
auto iter = s->packet_queue.find(seq);
|
||||
if (iter == s->packet_queue.end()) {
|
||||
WritablePacket *out = new WritablePacket();
|
||||
DynamicPacket *out = new DynamicPacket();
|
||||
out->PutPacket(0, p);
|
||||
|
||||
s->packet_queue.insert(std::make_pair(seq, out));
|
||||
@ -480,7 +478,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessDecodedPacket(ReadOnlyPacket(current, subpacket_length));
|
||||
ProcessDecodedPacket(StaticPacket(current, subpacket_length));
|
||||
current += subpacket_length;
|
||||
}
|
||||
break;
|
||||
@ -525,7 +523,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
current += 1;
|
||||
}
|
||||
|
||||
ProcessDecodedPacket(ReadOnlyPacket(current, subpacket_length));
|
||||
ProcessDecodedPacket(StaticPacket(current, subpacket_length));
|
||||
current += subpacket_length;
|
||||
}
|
||||
}
|
||||
@ -548,7 +546,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
reply.max_packet_size = HostToNetwork(m_max_packet_size);
|
||||
reply.encode_pass1 = m_encode_passes[0];
|
||||
reply.encode_pass2 = m_encode_passes[1];
|
||||
WritablePacket p;
|
||||
DynamicPacket p;
|
||||
p.PutSerialize(0, reply);
|
||||
InternalSend(p);
|
||||
}
|
||||
@ -578,7 +576,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
RemoveFromQueue(stream_id, sequence);
|
||||
SendAck(stream_id, stream->sequence_in);
|
||||
stream->sequence_in++;
|
||||
ReadOnlyPacket next((char*)p.Data() + DaybreakReliableHeader::size(), p.Length() - DaybreakReliableHeader::size());
|
||||
StaticPacket next((char*)p.Data() + DaybreakReliableHeader::size(), p.Length() - DaybreakReliableHeader::size());
|
||||
ProcessDecodedPacket(next);
|
||||
}
|
||||
|
||||
@ -670,7 +668,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
disconnect.zero = 0;
|
||||
disconnect.opcode = OP_SessionDisconnect;
|
||||
disconnect.connect_code = HostToNetwork(m_connect_code);
|
||||
WritablePacket out;
|
||||
DynamicPacket out;
|
||||
out.PutSerialize(0, disconnect);
|
||||
InternalSend(out);
|
||||
}
|
||||
@ -683,7 +681,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
{
|
||||
auto self = m_self.lock();
|
||||
if (m_owner->m_on_packet_recv && self) {
|
||||
m_owner->m_on_packet_recv(self, ReadOnlyPacket((char*)p.Data() + 1, p.Length() - 1));
|
||||
m_owner->m_on_packet_recv(self, StaticPacket((char*)p.Data() + 1, p.Length() - 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -700,7 +698,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(const Packet &p)
|
||||
response.client_recv = request.packets_recv;
|
||||
response.server_sent = EQ::Net::HostToNetwork(m_stats.sent_packets);
|
||||
response.server_recv = EQ::Net::HostToNetwork(m_stats.recv_packets);
|
||||
WritablePacket out;
|
||||
DynamicPacket out;
|
||||
out.PutSerialize(0, response);
|
||||
InternalSend(out);
|
||||
break;
|
||||
@ -1023,7 +1021,7 @@ void EQ::Net::DaybreakConnection::SendAck(int stream_id, uint16_t seq)
|
||||
ack.opcode = OP_Ack + stream_id;
|
||||
ack.sequence = HostToNetwork(seq);
|
||||
|
||||
WritablePacket p;
|
||||
DynamicPacket p;
|
||||
p.PutSerialize(0, ack);
|
||||
|
||||
InternalBufferedSend(p);
|
||||
@ -1036,7 +1034,7 @@ void EQ::Net::DaybreakConnection::SendOutOfOrderAck(int stream_id, uint16_t seq)
|
||||
ack.opcode = OP_OutOfOrderAck + stream_id;
|
||||
ack.sequence = HostToNetwork(seq);
|
||||
|
||||
WritablePacket p;
|
||||
DynamicPacket p;
|
||||
p.PutSerialize(0, ack);
|
||||
|
||||
InternalBufferedSend(p);
|
||||
@ -1076,7 +1074,7 @@ void EQ::Net::DaybreakConnection::InternalBufferedSend(Packet &p)
|
||||
FlushBuffer();
|
||||
}
|
||||
|
||||
WritablePacket copy;
|
||||
DynamicPacket copy;
|
||||
copy.PutPacket(0, p);
|
||||
m_buffered_packets.push_back(copy);
|
||||
m_buffered_packets_length += p.Length();
|
||||
@ -1095,7 +1093,7 @@ void EQ::Net::DaybreakConnection::SendConnect()
|
||||
connect.connect_code = (uint32_t)HostToNetwork(m_connect_code);
|
||||
connect.max_packet_size = HostToNetwork((uint32_t)m_owner->m_options.max_packet_size);
|
||||
|
||||
WritablePacket p;
|
||||
DynamicPacket p;
|
||||
p.PutSerialize(0, connect);
|
||||
|
||||
InternalSend(p);
|
||||
@ -1107,7 +1105,7 @@ void EQ::Net::DaybreakConnection::SendKeepAlive()
|
||||
keep_alive.zero = 0;
|
||||
keep_alive.opcode = OP_KeepAlive;
|
||||
|
||||
WritablePacket p;
|
||||
DynamicPacket p;
|
||||
p.PutSerialize(0, keep_alive);
|
||||
|
||||
InternalSend(p);
|
||||
@ -1123,7 +1121,7 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
|
||||
};
|
||||
|
||||
if (PacketCanBeEncoded(p)) {
|
||||
WritablePacket out;
|
||||
DynamicPacket out;
|
||||
out.PutPacket(0, p);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
@ -1210,7 +1208,7 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
||||
|
||||
size_t used = 0;
|
||||
size_t sublen = m_max_packet_size - m_crc_bytes - DaybreakReliableFragmentHeader::size();
|
||||
WritablePacket first_packet;
|
||||
DynamicPacket first_packet;
|
||||
first_packet.PutSerialize(0, first_header);
|
||||
first_packet.PutData(DaybreakReliableFragmentHeader::size(), (char*)p.Data() + used, sublen);
|
||||
used += sublen;
|
||||
@ -1227,7 +1225,7 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
||||
|
||||
while (used < length) {
|
||||
auto left = length - used;
|
||||
WritablePacket packet;
|
||||
DynamicPacket packet;
|
||||
DaybreakReliableHeader header;
|
||||
header.zero = 0;
|
||||
header.opcode = OP_Fragment + stream_id;
|
||||
@ -1255,7 +1253,7 @@ void EQ::Net::DaybreakConnection::InternalQueuePacket(Packet &p, int stream_id,
|
||||
}
|
||||
}
|
||||
else {
|
||||
WritablePacket packet;
|
||||
DynamicPacket packet;
|
||||
DaybreakReliableHeader header;
|
||||
header.zero = 0;
|
||||
header.opcode = OP_Packet + stream_id;
|
||||
@ -1282,22 +1280,15 @@ void EQ::Net::DaybreakConnection::FlushBuffer()
|
||||
}
|
||||
|
||||
if (m_buffered_packets.size() > 1) {
|
||||
WritablePacket out;
|
||||
DaybreakHeader header;
|
||||
header.zero = 0;
|
||||
header.opcode = OP_Combined;
|
||||
size_t offset = 0;
|
||||
|
||||
out.PutSerialize(offset, header);
|
||||
offset += DaybreakHeader::size();
|
||||
|
||||
StaticPacket out(m_combined.get(), 512);
|
||||
size_t length = 2;
|
||||
for (auto &p : m_buffered_packets) {
|
||||
out.PutUInt8(offset, (uint8_t)p.Length());
|
||||
offset += 1;
|
||||
out.PutPacket(offset, p);
|
||||
offset += p.Length();
|
||||
out.PutUInt8(length, (uint8_t)p.Length());
|
||||
out.PutPacket(length + 1, p);
|
||||
length += (1 + p.Length());
|
||||
}
|
||||
|
||||
out.Resize(length);
|
||||
InternalSend(out);
|
||||
}
|
||||
else {
|
||||
|
||||
@ -140,8 +140,9 @@ namespace EQ
|
||||
Timestamp m_last_recv;
|
||||
DbProtocolStatus m_status;
|
||||
Timestamp m_hold_time;
|
||||
std::list<WritablePacket> m_buffered_packets;
|
||||
std::list<DynamicPacket> m_buffered_packets;
|
||||
size_t m_buffered_packets_length;
|
||||
std::unique_ptr<char[]> m_combined;
|
||||
Timestamp m_last_stats;
|
||||
DaybreakConnectionStats m_stats;
|
||||
Timestamp m_last_session_stats;
|
||||
@ -150,7 +151,7 @@ namespace EQ
|
||||
|
||||
struct DaybreakSentPacket
|
||||
{
|
||||
WritablePacket packet;
|
||||
DynamicPacket packet;
|
||||
Timestamp last_sent;
|
||||
Timestamp first_sent;
|
||||
size_t times_resent;
|
||||
@ -169,7 +170,7 @@ namespace EQ
|
||||
uint16_t sequence_out;
|
||||
std::map<uint16_t, Packet*> packet_queue;
|
||||
|
||||
WritablePacket fragment_packet;
|
||||
DynamicPacket fragment_packet;
|
||||
uint32_t fragment_current_bytes;
|
||||
uint32_t fragment_total_bytes;
|
||||
|
||||
@ -216,12 +217,12 @@ namespace EQ
|
||||
{
|
||||
DaybreakConnectionManagerOptions() {
|
||||
max_connection_count = 0;
|
||||
keepalive_delay_ms = 0;
|
||||
resend_delay_ms = 10;
|
||||
resend_delay_factor = 1.25;
|
||||
stats_delay_ms = 0;
|
||||
keepalive_delay_ms = 9000;
|
||||
resend_delay_ms = 25;
|
||||
resend_delay_factor = 1.5;
|
||||
stats_delay_ms = 9000;
|
||||
connect_delay_ms = 1000;
|
||||
stale_connection_ms = 135000;
|
||||
stale_connection_ms = 30000;
|
||||
crc_length = 2;
|
||||
max_packet_size = 512;
|
||||
encode_passes[0] = DaybreakEncodeType::EncodeNone;
|
||||
@ -231,6 +232,7 @@ namespace EQ
|
||||
hold_length_ms = 50;
|
||||
simulated_in_packet_loss = 0;
|
||||
simulated_out_packet_loss = 0;
|
||||
tic_rate_hertz = 20.0;
|
||||
}
|
||||
|
||||
size_t max_packet_size;
|
||||
@ -246,6 +248,7 @@ namespace EQ
|
||||
size_t hold_length_ms;
|
||||
size_t simulated_in_packet_loss;
|
||||
size_t simulated_out_packet_loss;
|
||||
double tic_rate_hertz;
|
||||
DaybreakEncodeType encode_passes[2];
|
||||
int port;
|
||||
};
|
||||
@ -269,7 +272,6 @@ namespace EQ
|
||||
|
||||
EQEmu::Random m_rand;
|
||||
uv_timer_t m_timer;
|
||||
uv_timer_t m_resend_timer;
|
||||
uv_udp_t m_socket;
|
||||
uv_loop_t *m_attached;
|
||||
DaybreakConnectionManagerOptions m_options;
|
||||
|
||||
@ -42,7 +42,7 @@ void EQ::Net::EQStreamManager::DaybreakPacketRecv(std::shared_ptr<DaybreakConnec
|
||||
auto iter = m_streams.find(connection);
|
||||
if (iter != m_streams.end()) {
|
||||
auto &stream = iter->second;
|
||||
std::unique_ptr<EQ::Net::Packet> t(new EQ::Net::WritablePacket());
|
||||
std::unique_ptr<EQ::Net::Packet> t(new EQ::Net::DynamicPacket());
|
||||
t->PutPacket(0, p);
|
||||
stream->m_packet_queue.push_back(std::move(t));
|
||||
|
||||
@ -73,7 +73,7 @@ void EQ::Net::EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
|
||||
opcode = (*m_opcode_manager)->EmuToEQ(p->GetOpcode());
|
||||
}
|
||||
|
||||
EQ::Net::WritablePacket out;
|
||||
EQ::Net::DynamicPacket out;
|
||||
switch (m_owner->m_options.opcode_size) {
|
||||
case 1:
|
||||
out.PutUInt8(0, opcode);
|
||||
|
||||
@ -334,3 +334,12 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool EQ::Net::StaticPacket::Resize(size_t new_size)
|
||||
{
|
||||
if (new_size > m_max_data_length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_data_length = new_size;
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace EQ {
|
||||
class Packet
|
||||
{
|
||||
public:
|
||||
Packet() { }
|
||||
Packet() : m_stream(std::ios::out | std::ios::binary) { }
|
||||
virtual ~Packet() { }
|
||||
|
||||
virtual const void *Data() const = 0;
|
||||
@ -36,11 +36,11 @@ namespace EQ {
|
||||
|
||||
template<typename T>
|
||||
void PutSerialize(size_t offset, const T &value) {
|
||||
std::stringstream buffer(std::ios::in | std::ios::out | std::ios::binary);
|
||||
cereal::BinaryOutputArchive output(buffer);
|
||||
m_stream.clear();
|
||||
cereal::BinaryOutputArchive output(m_stream);
|
||||
output(value);
|
||||
|
||||
auto str = buffer.str();
|
||||
auto &str = m_stream.str();
|
||||
if (Length() < offset + str.length()) {
|
||||
if (!Resize(offset + str.length())) {
|
||||
throw std::out_of_range("Packet::PutSerialize(), could not resize packet and would of written past the end.");
|
||||
@ -80,38 +80,41 @@ namespace EQ {
|
||||
|
||||
std::string ToString() const;
|
||||
std::string ToString(size_t line_length) const;
|
||||
protected:
|
||||
std::stringstream m_stream;
|
||||
};
|
||||
|
||||
class ReadOnlyPacket : public Packet
|
||||
class StaticPacket : public Packet
|
||||
{
|
||||
public:
|
||||
ReadOnlyPacket(void *data, size_t size) { m_data = data; m_data_length = size; }
|
||||
virtual ~ReadOnlyPacket() { }
|
||||
ReadOnlyPacket(const ReadOnlyPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
||||
ReadOnlyPacket& operator=(const ReadOnlyPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
|
||||
ReadOnlyPacket(ReadOnlyPacket &&o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
||||
StaticPacket(void *data, size_t size) { m_data = data; m_data_length = size; m_max_data_length = size; }
|
||||
virtual ~StaticPacket() { }
|
||||
StaticPacket(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
||||
StaticPacket& operator=(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
|
||||
StaticPacket(StaticPacket &&o) { m_data = o.m_data; m_data_length = o.m_data_length; }
|
||||
|
||||
virtual const void *Data() const { return m_data; }
|
||||
virtual void *Data() { return m_data; }
|
||||
virtual size_t Length() const { return m_data_length; }
|
||||
virtual size_t Length() { return m_data_length; }
|
||||
virtual bool Clear() { return false; }
|
||||
virtual bool Resize(size_t new_size) { return false; }
|
||||
virtual bool Resize(size_t new_size);
|
||||
virtual void Reserve(size_t new_size) { }
|
||||
|
||||
protected:
|
||||
void *m_data;
|
||||
size_t m_data_length;
|
||||
size_t m_max_data_length;
|
||||
};
|
||||
|
||||
class WritablePacket : public Packet
|
||||
class DynamicPacket : public Packet
|
||||
{
|
||||
public:
|
||||
WritablePacket() { }
|
||||
virtual ~WritablePacket() { }
|
||||
WritablePacket(WritablePacket &&o) { m_data = std::move(o.m_data); }
|
||||
WritablePacket(const WritablePacket &o) { m_data = o.m_data; }
|
||||
WritablePacket& operator=(const WritablePacket &o) { m_data = o.m_data; return *this; }
|
||||
DynamicPacket() { }
|
||||
virtual ~DynamicPacket() { }
|
||||
DynamicPacket(DynamicPacket &&o) { m_data = std::move(o.m_data); }
|
||||
DynamicPacket(const DynamicPacket &o) { m_data = o.m_data; }
|
||||
DynamicPacket& operator=(const DynamicPacket &o) { m_data = o.m_data; return *this; }
|
||||
|
||||
virtual const void *Data() const { return &m_data[0]; }
|
||||
virtual void *Data() { return &m_data[0]; }
|
||||
|
||||
@ -21,7 +21,7 @@ EQ::Net::ServertalkClient::~ServertalkClient()
|
||||
|
||||
void EQ::Net::ServertalkClient::Send(uint16_t opcode, EQ::Net::Packet &p)
|
||||
{
|
||||
EQ::Net::WritablePacket out;
|
||||
EQ::Net::DynamicPacket out;
|
||||
#ifdef ENABLE_SECURITY
|
||||
if (m_encrypted) {
|
||||
if (p.Length() == 0) {
|
||||
@ -52,7 +52,7 @@ void EQ::Net::ServertalkClient::Send(uint16_t opcode, EQ::Net::Packet &p)
|
||||
|
||||
void EQ::Net::ServertalkClient::SendPacket(ServerPacket *p)
|
||||
{
|
||||
EQ::Net::ReadOnlyPacket pout(p->pBuffer, p->size);
|
||||
EQ::Net::StaticPacket pout(p->pBuffer, p->size);
|
||||
Send(p->opcode, pout);
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ void EQ::Net::ServertalkClient::ProcessData(EQ::Net::TCPConnection *c, const uns
|
||||
|
||||
void EQ::Net::ServertalkClient::SendHello()
|
||||
{
|
||||
EQ::Net::WritablePacket p;
|
||||
EQ::Net::DynamicPacket p;
|
||||
InternalSend(ServertalkClientHello, p);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ void EQ::Net::ServertalkClient::InternalSend(ServertalkPacketType type, EQ::Net:
|
||||
if (!m_connection)
|
||||
return;
|
||||
|
||||
EQ::Net::WritablePacket out;
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutUInt32(0, (uint32_t)p.Length());
|
||||
out.PutUInt8(4, (uint8_t)type);
|
||||
if (p.Length() > 0) {
|
||||
@ -145,7 +145,7 @@ void EQ::Net::ServertalkClient::ProcessReadBuffer()
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
EQ::Net::WritablePacket p;
|
||||
EQ::Net::DynamicPacket p;
|
||||
switch (type) {
|
||||
case ServertalkServerHello:
|
||||
ProcessHello(p);
|
||||
@ -156,7 +156,7 @@ void EQ::Net::ServertalkClient::ProcessReadBuffer()
|
||||
}
|
||||
}
|
||||
else {
|
||||
EQ::Net::ReadOnlyPacket p(&m_buffer[current + 5], length);
|
||||
EQ::Net::StaticPacket p(&m_buffer[current + 5], length);
|
||||
switch (type) {
|
||||
case ServertalkServerHello:
|
||||
ProcessHello(p);
|
||||
@ -272,7 +272,7 @@ void EQ::Net::ServertalkClient::ProcessMessage(EQ::Net::Packet &p)
|
||||
return;
|
||||
}
|
||||
|
||||
EQ::Net::ReadOnlyPacket decrypted_packet(&decrypted_text[0], message_len);
|
||||
EQ::Net::StaticPacket decrypted_packet(&decrypted_text[0], message_len);
|
||||
|
||||
(*(uint64_t*)&m_nonce_theirs[0])++;
|
||||
|
||||
@ -283,7 +283,7 @@ void EQ::Net::ServertalkClient::ProcessMessage(EQ::Net::Packet &p)
|
||||
}
|
||||
else {
|
||||
size_t message_len = length;
|
||||
EQ::Net::ReadOnlyPacket packet(&data[0], message_len);
|
||||
EQ::Net::StaticPacket packet(&data[0], message_len);
|
||||
|
||||
auto cb = m_message_callbacks.find(opcode);
|
||||
if (cb != m_message_callbacks.end()) {
|
||||
@ -309,7 +309,7 @@ void EQ::Net::ServertalkClient::ProcessMessage(EQ::Net::Packet &p)
|
||||
|
||||
void EQ::Net::ServertalkClient::SendHandshake(bool downgrade)
|
||||
{
|
||||
EQ::Net::WritablePacket handshake;
|
||||
EQ::Net::DynamicPacket handshake;
|
||||
#ifdef ENABLE_SECURITY
|
||||
if (m_encrypted) {
|
||||
crypto_box_keypair(m_public_key_ours, m_private_key_ours);
|
||||
|
||||
145
common/net/servertalk_legacy_client_connection.cpp
Normal file
145
common/net/servertalk_legacy_client_connection.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include "servertalk_legacy_client_connection.h"
|
||||
#include "dns.h"
|
||||
#include "../eqemu_logsys.h"
|
||||
|
||||
EQ::Net::ServertalkLegacyClient::ServertalkLegacyClient(const std::string &addr, int port, bool ipv6)
|
||||
: m_timer(std::unique_ptr<EQ::Timer>(new EQ::Timer(100, true, std::bind(&EQ::Net::ServertalkLegacyClient::Connect, this))))
|
||||
{
|
||||
m_port = port;
|
||||
m_ipv6 = ipv6;
|
||||
m_connecting = false;
|
||||
DNSLookup(addr, port, false, [this](const std::string &address) {
|
||||
m_addr = address;
|
||||
});
|
||||
}
|
||||
|
||||
EQ::Net::ServertalkLegacyClient::~ServertalkLegacyClient()
|
||||
{
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::Send(uint16_t opcode, EQ::Net::Packet &p)
|
||||
{
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutUInt16(0, opcode);
|
||||
out.PutUInt16(2, p.Length());
|
||||
out.PutPacket(4, p);
|
||||
|
||||
InternalSend(ServertalkMessage, out);
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::SendPacket(ServerPacket *p)
|
||||
{
|
||||
EQ::Net::StaticPacket pout(p->pBuffer, p->size);
|
||||
Send(p->opcode, pout);
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::OnMessage(uint16_t opcode, std::function<void(uint16_t, EQ::Net::Packet&)> cb)
|
||||
{
|
||||
m_message_callbacks.insert(std::make_pair(opcode, cb));
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::Connect()
|
||||
{
|
||||
if (m_addr.length() == 0 || m_port == 0 || m_connection || m_connecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_connecting = true;
|
||||
EQ::Net::TCPConnection::Connect(m_addr, m_port, false, [this](std::shared_ptr<EQ::Net::TCPConnection> connection) {
|
||||
if (connection == nullptr) {
|
||||
Log.OutF(Logs::General, Logs::TCP_Connection, "Error connecting to {0}:{1}, attempting to reconnect...", m_addr, m_port);
|
||||
m_connecting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Log.OutF(Logs::General, Logs::TCP_Connection, "Connected to {0}:{1}", m_addr, m_port);
|
||||
m_connection = connection;
|
||||
m_connection->OnDisconnect([this](EQ::Net::TCPConnection *c) {
|
||||
Log.OutF(Logs::General, Logs::TCP_Connection, "Connection lost to {0}:{1}, attempting to reconnect...", m_addr, m_port);
|
||||
m_connection.reset();
|
||||
});
|
||||
|
||||
m_connection->OnRead(std::bind(&EQ::Net::ServertalkLegacyClient::ProcessData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
||||
m_connection->Start();
|
||||
m_connecting = false;
|
||||
|
||||
if (m_on_connect_cb) {
|
||||
m_on_connect_cb(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::ProcessData(EQ::Net::TCPConnection *c, const unsigned char *data, size_t length)
|
||||
{
|
||||
m_buffer.insert(m_buffer.end(), (const char*)data, (const char*)data + length);
|
||||
ProcessReadBuffer();
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::InternalSend(ServertalkPacketType type, EQ::Net::Packet &p)
|
||||
{
|
||||
if (!m_connection)
|
||||
return;
|
||||
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutUInt32(0, (uint32_t)p.Length());
|
||||
out.PutUInt8(4, (uint8_t)type);
|
||||
if (p.Length() > 0) {
|
||||
out.PutPacket(5, p);
|
||||
}
|
||||
|
||||
m_connection->Write((const char*)out.Data(), out.Length());
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkLegacyClient::ProcessReadBuffer()
|
||||
{
|
||||
size_t current = 0;
|
||||
size_t total = m_buffer.size();
|
||||
|
||||
while (current < total) {
|
||||
auto left = total - current;
|
||||
|
||||
/*
|
||||
//header:
|
||||
//uint16 opcode;
|
||||
//uint16 length;
|
||||
*/
|
||||
uint16_t length = 0;
|
||||
uint16_t opcode = 0;
|
||||
if (left < 4) {
|
||||
break;
|
||||
}
|
||||
|
||||
opcode = *(uint16_t*)&m_buffer[current];
|
||||
length = *(uint16_t*)&m_buffer[current + 2] - 4;
|
||||
|
||||
if (current + 4 + length > total) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
EQ::Net::DynamicPacket p;
|
||||
|
||||
auto cb = m_message_callbacks.find(opcode);
|
||||
if (cb != m_message_callbacks.end()) {
|
||||
cb->second(opcode, p);
|
||||
}
|
||||
}
|
||||
else {
|
||||
EQ::Net::StaticPacket p(&m_buffer[current + 4], length);
|
||||
|
||||
auto cb = m_message_callbacks.find(opcode);
|
||||
if (cb != m_message_callbacks.end()) {
|
||||
cb->second(opcode, p);
|
||||
}
|
||||
}
|
||||
|
||||
current += length + 4;
|
||||
}
|
||||
|
||||
if (current == total) {
|
||||
m_buffer.clear();
|
||||
}
|
||||
else {
|
||||
m_buffer.erase(m_buffer.begin(), m_buffer.begin() + current);
|
||||
}
|
||||
}
|
||||
43
common/net/servertalk_legacy_client_connection.h
Normal file
43
common/net/servertalk_legacy_client_connection.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "tcp_connection.h"
|
||||
#include "../event/timer.h"
|
||||
#include "servertalk_common.h"
|
||||
#include "packet.h"
|
||||
|
||||
namespace EQ
|
||||
{
|
||||
namespace Net
|
||||
{
|
||||
class ServertalkLegacyClient
|
||||
{
|
||||
public:
|
||||
ServertalkLegacyClient(const std::string &addr, int port, bool ipv6);
|
||||
~ServertalkLegacyClient();
|
||||
|
||||
void Send(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void SendPacket(ServerPacket *p);
|
||||
void OnConnect(std::function<void(ServertalkLegacyClient*)> cb) { m_on_connect_cb = cb; }
|
||||
void OnMessage(uint16_t opcode, std::function<void(uint16_t, EQ::Net::Packet&)> cb);
|
||||
bool Connected() const { return m_connecting != true; }
|
||||
|
||||
std::shared_ptr<EQ::Net::TCPConnection> Handle() { return m_connection; }
|
||||
private:
|
||||
void Connect();
|
||||
void ProcessData(EQ::Net::TCPConnection *c, const unsigned char *data, size_t length);
|
||||
void InternalSend(ServertalkPacketType type, EQ::Net::Packet &p);
|
||||
void ProcessReadBuffer();
|
||||
|
||||
std::unique_ptr<EQ::Timer> m_timer;
|
||||
|
||||
std::string m_addr;
|
||||
bool m_connecting;
|
||||
int m_port;
|
||||
bool m_ipv6;
|
||||
std::shared_ptr<EQ::Net::TCPConnection> m_connection;
|
||||
std::vector<char> m_buffer;
|
||||
std::unordered_map<uint16_t, std::function<void(uint16_t, EQ::Net::Packet&)>> m_message_callbacks;
|
||||
std::function<void(ServertalkLegacyClient*)> m_on_connect_cb;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ EQ::Net::ServertalkServerConnection::~ServertalkServerConnection()
|
||||
|
||||
void EQ::Net::ServertalkServerConnection::Send(uint16_t opcode, EQ::Net::Packet & p)
|
||||
{
|
||||
EQ::Net::WritablePacket out;
|
||||
EQ::Net::DynamicPacket out;
|
||||
#ifdef ENABLE_SECURITY
|
||||
if (m_encrypted) {
|
||||
if (p.Length() == 0) {
|
||||
@ -50,7 +50,7 @@ void EQ::Net::ServertalkServerConnection::Send(uint16_t opcode, EQ::Net::Packet
|
||||
|
||||
void EQ::Net::ServertalkServerConnection::SendPacket(ServerPacket * p)
|
||||
{
|
||||
EQ::Net::ReadOnlyPacket pout(p->pBuffer, p->size);
|
||||
EQ::Net::StaticPacket pout(p->pBuffer, p->size);
|
||||
Send(p->opcode, pout);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ void EQ::Net::ServertalkServerConnection::ProcessReadBuffer()
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
EQ::Net::WritablePacket p;
|
||||
EQ::Net::DynamicPacket p;
|
||||
switch (type) {
|
||||
case ServertalkClientHello:
|
||||
{
|
||||
@ -108,7 +108,7 @@ void EQ::Net::ServertalkServerConnection::ProcessReadBuffer()
|
||||
}
|
||||
}
|
||||
else {
|
||||
EQ::Net::ReadOnlyPacket p(&m_buffer[current + 5], length);
|
||||
EQ::Net::StaticPacket p(&m_buffer[current + 5], length);
|
||||
switch (type) {
|
||||
case ServertalkClientHello:
|
||||
{
|
||||
@ -145,7 +145,7 @@ void EQ::Net::ServertalkServerConnection::OnDisconnect(TCPConnection *c)
|
||||
|
||||
void EQ::Net::ServertalkServerConnection::SendHello()
|
||||
{
|
||||
EQ::Net::WritablePacket hello;
|
||||
EQ::Net::DynamicPacket hello;
|
||||
|
||||
#ifdef ENABLE_SECURITY
|
||||
memset(m_public_key_ours, 0, crypto_box_PUBLICKEYBYTES);
|
||||
@ -178,7 +178,7 @@ void EQ::Net::ServertalkServerConnection::InternalSend(ServertalkPacketType type
|
||||
if (!m_connection)
|
||||
return;
|
||||
|
||||
EQ::Net::WritablePacket out;
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutUInt32(0, (uint32_t)p.Length());
|
||||
out.PutUInt8(4, (uint8_t)type);
|
||||
if (p.Length() > 0) {
|
||||
@ -290,7 +290,7 @@ void EQ::Net::ServertalkServerConnection::ProcessMessage(EQ::Net::Packet &p)
|
||||
return;
|
||||
}
|
||||
|
||||
EQ::Net::ReadOnlyPacket decrypted_packet(&decrypted_text[0], message_len);
|
||||
EQ::Net::StaticPacket decrypted_packet(&decrypted_text[0], message_len);
|
||||
|
||||
(*(uint64_t*)&m_nonce_theirs[0])++;
|
||||
|
||||
@ -301,7 +301,7 @@ void EQ::Net::ServertalkServerConnection::ProcessMessage(EQ::Net::Packet &p)
|
||||
}
|
||||
else {
|
||||
size_t message_len = length;
|
||||
EQ::Net::ReadOnlyPacket packet(&data[0], message_len);
|
||||
EQ::Net::StaticPacket packet(&data[0], message_len);
|
||||
|
||||
auto cb = m_message_callbacks.find(opcode);
|
||||
if (cb != m_message_callbacks.end()) {
|
||||
|
||||
@ -211,7 +211,7 @@ void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int
|
||||
bool found = false;
|
||||
while (iter != world_servers.end()) {
|
||||
if ((*iter)->GetRuntimeID() == server_id) {
|
||||
EQ::Net::WritablePacket outapp;
|
||||
EQ::Net::DynamicPacket outapp;
|
||||
outapp.Resize(sizeof(UsertoWorldRequest_Struct));
|
||||
UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct*)outapp.Data();
|
||||
utwr->worldid = server_id;
|
||||
|
||||
@ -396,7 +396,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
|
||||
Log.Out(Logs::General, Logs::Netcode, "ServerOP_LSAccountUpdate sent to world");
|
||||
is_server_trusted = true;
|
||||
|
||||
EQ::Net::WritablePacket outapp;
|
||||
EQ::Net::DynamicPacket outapp;
|
||||
connection->Send(ServerOP_LSAccountUpdate, outapp);
|
||||
}
|
||||
}
|
||||
@ -452,7 +452,7 @@ void WorldServer::Handle_NewLSInfo(ServerNewLSInfo_Struct* i)
|
||||
if(is_server_trusted) {
|
||||
Log.Out(Logs::General, Logs::Netcode, "ServerOP_LSAccountUpdate sent to world");
|
||||
is_server_trusted = true;
|
||||
EQ::Net::WritablePacket outapp;
|
||||
EQ::Net::DynamicPacket outapp;
|
||||
connection->Send(ServerOP_LSAccountUpdate, outapp);
|
||||
}
|
||||
}
|
||||
@ -501,7 +501,7 @@ void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s)
|
||||
|
||||
void WorldServer::SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id)
|
||||
{
|
||||
EQ::Net::WritablePacket outapp;
|
||||
EQ::Net::DynamicPacket outapp;
|
||||
ClientAuth_Struct client_auth;
|
||||
client_auth.lsaccount_id = account_id;
|
||||
client_auth.name = account;
|
||||
|
||||
@ -145,15 +145,6 @@ int main() {
|
||||
|
||||
worldserver->Connect();
|
||||
|
||||
EQ::Net::ServertalkClient client("127.0.0.1", 5999, false, "QueryServ", "User:Root;Password:1234567890");
|
||||
client.OnMessage(1, [&](uint16_t opcode, EQ::Net::Packet &p) {
|
||||
Log.OutF(Logs::General, Logs::Debug, "Client got message of type {0}\n{1}", opcode, p.ToString());
|
||||
|
||||
EQ::Net::WritablePacket out;
|
||||
out.PutCString(0, "Why Hello");
|
||||
client.Send(2, out);
|
||||
});
|
||||
|
||||
while(RunLoops) {
|
||||
|
||||
Timer::SetCurrentTime();
|
||||
|
||||
@ -40,13 +40,14 @@ extern uint32 numzones;
|
||||
extern uint32 numplayers;
|
||||
extern volatile bool RunLoops;
|
||||
|
||||
LoginServer::LoginServer(const char* iAddress, uint16 iPort, const char* Account, const char* Password)
|
||||
LoginServer::LoginServer(const char* iAddress, uint16 iPort, const char* Account, const char* Password, bool legacy)
|
||||
{
|
||||
strn0cpy(LoginServerAddress,iAddress,256);
|
||||
LoginServerPort = iPort;
|
||||
strn0cpy(LoginAccount,Account,31);
|
||||
strn0cpy(LoginPassword,Password,31);
|
||||
CanAccountUpdate = false;
|
||||
IsLegacy = legacy;
|
||||
Connect();
|
||||
}
|
||||
|
||||
@ -176,32 +177,65 @@ bool LoginServer::Connect() {
|
||||
return false;
|
||||
}
|
||||
|
||||
client.reset(new EQ::Net::ServertalkClient(LoginServerAddress, LoginServerPort, false, "World", ""));
|
||||
client->OnConnect([this](EQ::Net::ServertalkClient *client) {
|
||||
if (client) {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Connected to Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
if (minilogin)
|
||||
SendInfo();
|
||||
else
|
||||
SendNewInfo();
|
||||
SendStatus();
|
||||
zoneserver_list.SendLSZones();
|
||||
|
||||
statusupdate_timer.reset(new EQ::Timer(LoginServer_StatusUpdateInterval, true, [this](EQ::Timer *t) {
|
||||
if (IsLegacy) {
|
||||
legacy_client.reset(new EQ::Net::ServertalkLegacyClient(LoginServerAddress, LoginServerPort, false));
|
||||
legacy_client->OnConnect([this](EQ::Net::ServertalkLegacyClient *client) {
|
||||
if (client) {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Connected to Legacy Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
if (minilogin)
|
||||
SendInfo();
|
||||
else
|
||||
SendNewInfo();
|
||||
SendStatus();
|
||||
}));
|
||||
}
|
||||
else {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Could not connect to Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
}
|
||||
});
|
||||
zoneserver_list.SendLSZones();
|
||||
|
||||
client->OnMessage(ServerOP_UsertoWorldReq, std::bind(&LoginServer::ProcessUsertoWorldReq, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSClientAuth, std::bind(&LoginServer::ProcessLSClientAuth, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSFatalError, std::bind(&LoginServer::ProcessLSFatalError, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_SystemwideMessage, std::bind(&LoginServer::ProcessSystemwideMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSRemoteAddr, std::bind(&LoginServer::ProcessLSRemoteAddr, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSAccountUpdate, std::bind(&LoginServer::ProcessLSAccountUpdate, this, std::placeholders::_1, std::placeholders::_2));
|
||||
statusupdate_timer.reset(new EQ::Timer(LoginServer_StatusUpdateInterval, true, [this](EQ::Timer *t) {
|
||||
SendStatus();
|
||||
}));
|
||||
}
|
||||
else {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Could not connect to Legacy Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
}
|
||||
});
|
||||
|
||||
legacy_client->OnMessage(ServerOP_UsertoWorldReq, std::bind(&LoginServer::ProcessUsertoWorldReq, this, std::placeholders::_1, std::placeholders::_2));
|
||||
legacy_client->OnMessage(ServerOP_LSClientAuth, std::bind(&LoginServer::ProcessLSClientAuth, this, std::placeholders::_1, std::placeholders::_2));
|
||||
legacy_client->OnMessage(ServerOP_LSFatalError, std::bind(&LoginServer::ProcessLSFatalError, this, std::placeholders::_1, std::placeholders::_2));
|
||||
legacy_client->OnMessage(ServerOP_SystemwideMessage, std::bind(&LoginServer::ProcessSystemwideMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
legacy_client->OnMessage(ServerOP_LSRemoteAddr, std::bind(&LoginServer::ProcessLSRemoteAddr, this, std::placeholders::_1, std::placeholders::_2));
|
||||
legacy_client->OnMessage(ServerOP_LSAccountUpdate, std::bind(&LoginServer::ProcessLSAccountUpdate, this, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
}
|
||||
else {
|
||||
client.reset(new EQ::Net::ServertalkClient(LoginServerAddress, LoginServerPort, false, "World", ""));
|
||||
client->OnConnect([this](EQ::Net::ServertalkClient *client) {
|
||||
if (client) {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Connected to Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
if (minilogin)
|
||||
SendInfo();
|
||||
else
|
||||
SendNewInfo();
|
||||
SendStatus();
|
||||
zoneserver_list.SendLSZones();
|
||||
|
||||
statusupdate_timer.reset(new EQ::Timer(LoginServer_StatusUpdateInterval, true, [this](EQ::Timer *t) {
|
||||
SendStatus();
|
||||
}));
|
||||
}
|
||||
else {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Could not connect to Loginserver: %s:%d", LoginServerAddress, LoginServerPort);
|
||||
}
|
||||
});
|
||||
|
||||
client->OnMessage(ServerOP_UsertoWorldReq, std::bind(&LoginServer::ProcessUsertoWorldReq, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSClientAuth, std::bind(&LoginServer::ProcessLSClientAuth, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSFatalError, std::bind(&LoginServer::ProcessLSFatalError, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_SystemwideMessage, std::bind(&LoginServer::ProcessSystemwideMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSRemoteAddr, std::bind(&LoginServer::ProcessLSRemoteAddr, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSAccountUpdate, std::bind(&LoginServer::ProcessLSAccountUpdate, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void LoginServer::SendInfo() {
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
@ -223,7 +257,6 @@ void LoginServer::SendInfo() {
|
||||
}
|
||||
|
||||
void LoginServer::SendNewInfo() {
|
||||
uint16 port;
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
|
||||
auto pack = new ServerPacket;
|
||||
@ -243,7 +276,7 @@ void LoginServer::SendNewInfo() {
|
||||
if (Config->LocalAddress.length())
|
||||
strcpy(lsi->local_address, Config->LocalAddress.c_str());
|
||||
else {
|
||||
WorldConfig::SetLocalAddress(client->Handle()->LocalIP());
|
||||
WorldConfig::SetLocalAddress(IsLegacy ? legacy_client->Handle()->LocalIP() : client->Handle()->LocalIP());
|
||||
}
|
||||
SendPacket(pack);
|
||||
delete pack;
|
||||
|
||||
@ -25,12 +25,13 @@
|
||||
#include "../common/eq_packet_structs.h"
|
||||
#include "../common/mutex.h"
|
||||
#include "../common/net/servertalk_client_connection.h"
|
||||
#include "../common/net/servertalk_legacy_client_connection.h"
|
||||
#include "../common/event/timer.h"
|
||||
#include <memory>
|
||||
|
||||
class LoginServer{
|
||||
public:
|
||||
LoginServer(const char*, uint16, const char*, const char*);
|
||||
LoginServer(const char*, uint16, const char*, const char*, bool legacy);
|
||||
~LoginServer();
|
||||
|
||||
bool Connect();
|
||||
@ -39,9 +40,9 @@ public:
|
||||
void SendNewInfo();
|
||||
void SendStatus();
|
||||
|
||||
void SendPacket(ServerPacket* pack) { client->SendPacket(pack); }
|
||||
void SendPacket(ServerPacket* pack) { if (IsLegacy) legacy_client->SendPacket(pack); else client->SendPacket(pack); }
|
||||
void SendAccountUpdate(ServerPacket* pack);
|
||||
bool Connected() { return client->Connected(); }
|
||||
bool Connected() { return IsLegacy ? legacy_client->Connected() : client->Connected(); }
|
||||
bool MiniLogin() { return minilogin; }
|
||||
bool CanUpdate() { return CanAccountUpdate; }
|
||||
|
||||
@ -55,6 +56,7 @@ private:
|
||||
|
||||
bool minilogin;
|
||||
std::unique_ptr<EQ::Net::ServertalkClient> client;
|
||||
std::unique_ptr<EQ::Net::ServertalkLegacyClient> legacy_client;
|
||||
std::unique_ptr<EQ::Timer> statusupdate_timer;
|
||||
char LoginServerAddress[256];
|
||||
uint32 LoginServerIP;
|
||||
@ -62,5 +64,6 @@ private:
|
||||
char LoginAccount[32];
|
||||
char LoginPassword[32];
|
||||
bool CanAccountUpdate;
|
||||
bool IsLegacy;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -49,9 +49,9 @@ LoginServerList::LoginServerList() {
|
||||
LoginServerList::~LoginServerList() {
|
||||
}
|
||||
|
||||
void LoginServerList::Add(const char* iAddress, uint16 iPort, const char* Account, const char* Password)
|
||||
void LoginServerList::Add(const char* iAddress, uint16 iPort, const char* Account, const char* Password, bool Legacy)
|
||||
{
|
||||
auto loginserver = new LoginServer(iAddress, iPort, Account, Password);
|
||||
auto loginserver = new LoginServer(iAddress, iPort, Account, Password, Legacy);
|
||||
list.Insert(loginserver);
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ public:
|
||||
LoginServerList();
|
||||
~LoginServerList();
|
||||
|
||||
void Add(const char*, uint16, const char*, const char*);
|
||||
void Add(const char*, uint16, const char*, const char*, bool);
|
||||
|
||||
bool SendInfo();
|
||||
bool SendNewInfo();
|
||||
|
||||
@ -158,7 +158,7 @@ int main(int argc, char** argv) {
|
||||
// add login server config to list
|
||||
if (Config->LoginCount == 0) {
|
||||
if (Config->LoginHost.length()) {
|
||||
loginserverlist.Add(Config->LoginHost.c_str(), Config->LoginPort, Config->LoginAccount.c_str(), Config->LoginPassword.c_str());
|
||||
loginserverlist.Add(Config->LoginHost.c_str(), Config->LoginPort, Config->LoginAccount.c_str(), Config->LoginPassword.c_str(), Config->LoginLegacy);
|
||||
Log.Out(Logs::General, Logs::World_Server, "Added loginserver %s:%i", Config->LoginHost.c_str(), Config->LoginPort);
|
||||
}
|
||||
} else {
|
||||
@ -166,7 +166,8 @@ int main(int argc, char** argv) {
|
||||
LinkedListIterator<LoginConfig*> iterator(loginlist);
|
||||
iterator.Reset();
|
||||
while(iterator.MoreElements()) {
|
||||
loginserverlist.Add(iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort, iterator.GetData()->LoginAccount.c_str(), iterator.GetData()->LoginPassword.c_str());
|
||||
loginserverlist.Add(iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort, iterator.GetData()->LoginAccount.c_str(), iterator.GetData()->LoginPassword.c_str(),
|
||||
iterator.GetData()->LoginLegacy);
|
||||
Log.Out(Logs::General, Logs::World_Server, "Added loginserver %s:%i", iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort);
|
||||
iterator.Advance();
|
||||
}
|
||||
|
||||
@ -3029,11 +3029,7 @@ void Mob::CommonDamage(Mob* attacker, int32 &damage, const uint16 spell_id, cons
|
||||
if (IsValidSpell(spell_id))
|
||||
ignore_invul = spell_id == 982 || spells[spell_id].cast_not_standing; // cazic touch
|
||||
|
||||
Log.Out(Logs::Detail, Logs::Combat, "Applying damage %d done by %s with skill %d and spell %d, avoidable? %s, is %sa buff tic in slot %d",
|
||||
damage, attacker?attacker->GetName():"NOBODY", skill_used, spell_id, avoidable?"yes":"no", iBuffTic?"":"not ", buffslot);
|
||||
|
||||
if (!ignore_invul && (GetInvul() || DivineAura())) {
|
||||
Log.Out(Logs::Detail, Logs::Combat, "Avoiding %d damage due to invulnerability.", damage);
|
||||
damage = -5;
|
||||
}
|
||||
|
||||
|
||||
@ -2934,10 +2934,6 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
|
||||
if (ClientVersion() >= EQEmu::versions::ClientVersion::RoF)
|
||||
{
|
||||
ItemInst *itemOneToPush = nullptr, *itemTwoToPush = nullptr;
|
||||
|
||||
//Log.Out(Logs::DebugLevel::Moderate, Logs::Debug, "cslot: %i aslot: %i cidx: %i aidx: %i act: %i dest: %i",
|
||||
// in_augment->container_slot, in_augment->augment_slot, in_augment->container_index, in_augment->augment_index, in_augment->augment_action, in_augment->dest_inst_id);
|
||||
|
||||
ItemInst *tobe_auged = nullptr, *old_aug = nullptr, *new_aug = nullptr, *aug = nullptr, *solvent = nullptr;
|
||||
Inventory& user_inv = GetInv();
|
||||
|
||||
|
||||
@ -435,7 +435,7 @@ int main(int argc, char** argv) {
|
||||
bool eqsf_open = false;
|
||||
std::unique_ptr<EQ::Net::EQStreamManager> eqsm;
|
||||
|
||||
EQ::Timer process_timer(33, true, [&eqsf_open, &eqsm, &stream_identifier, &eqsi, &worldwasconnected,
|
||||
EQ::Timer process_timer(50, true, [&eqsf_open, &eqsm, &stream_identifier, &eqsi, &worldwasconnected,
|
||||
&zoneupdate_timer, &IDLEZONEUPDATE, &ZONEUPDATE, &quest_timers, &InterserverTimer](EQ::Timer* t) {
|
||||
//Advance the timer to our current point in time
|
||||
Timer::SetCurrentTime();
|
||||
@ -445,7 +445,7 @@ int main(int argc, char** argv) {
|
||||
if (!eqsf_open && Config->ZonePort != 0) {
|
||||
Log.Out(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort);
|
||||
|
||||
EQ::Net::EQStreamManagerOptions opts(Config->ZonePort, false, true);
|
||||
EQ::Net::EQStreamManagerOptions opts(Config->ZonePort, false, false);
|
||||
eqsm.reset(new EQ::Net::EQStreamManager(opts));
|
||||
eqsf_open = true;
|
||||
|
||||
|
||||
@ -484,11 +484,8 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f): Jumping pure Z.", x, y, z);
|
||||
return true;
|
||||
}
|
||||
// Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f) inWater=%d: We are there.", x, y, z, inWater);
|
||||
return false;
|
||||
} else if ((std::abs(m_Position.x - x) < 0.1) && (std::abs(m_Position.y - y) < 0.1)) {
|
||||
Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f): X/Y difference <0.1, Jumping to target.", x, y, z);
|
||||
|
||||
if(IsNPC()) {
|
||||
entity_list.ProcessMove(CastToNPC(), x, y, z);
|
||||
}
|
||||
@ -514,8 +511,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.y = new_y;
|
||||
m_Position.z = new_z;
|
||||
|
||||
Log.Out(Logs::Detail, Logs::AI, "Calculating new position2 to (%.3f, %.3f, %.3f), old vector (%.3f, %.3f, %.3f)", x, y, z, m_TargetV.x, m_TargetV.y, m_TargetV.z);
|
||||
|
||||
uint8 NPCFlyMode = 0;
|
||||
|
||||
if(IsNPC()) {
|
||||
@ -533,8 +528,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
|
||||
float newz = zone->zonemap->FindBestZ(dest, nullptr) + 2.0f;
|
||||
|
||||
Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.x,m_Position.y,m_Position.z);
|
||||
|
||||
if ((newz > -2000) &&
|
||||
std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check.
|
||||
{
|
||||
@ -578,11 +571,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
{
|
||||
animation = speed / 2;
|
||||
}
|
||||
//pRunAnimSpeed = (int8)(speed*NPC_RUNANIM_RATIO);
|
||||
//speed *= NPC_SPEED_MULTIPLIER;
|
||||
|
||||
Log.Out(Logs::Detail, Logs::AI, "Calculating new position2 to (%.3f, %.3f, %.3f), new vector (%.3f, %.3f, %.3f) rate %.3f, RAS %d", x, y, z, m_TargetV.x, m_TargetV.y, m_TargetV.z, speed, pRunAnimSpeed);
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// 2: get unit vector
|
||||
// --------------------------------------------------------------------------
|
||||
@ -616,7 +605,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.z = new_z;
|
||||
m_Position.w = CalculateHeadingToTarget(x, y);
|
||||
tar_ndx = 20 - numsteps;
|
||||
Log.Out(Logs::Detail, Logs::AI, "Next position2 (%.3f, %.3f, %.3f) (%d steps)", m_Position.x, m_Position.y, m_Position.z, numsteps);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -627,9 +615,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.x = x;
|
||||
m_Position.y = y;
|
||||
m_Position.z = z;
|
||||
|
||||
Log.Out(Logs::Detail, Logs::AI, "Only a single step to get there... jumping.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -652,7 +637,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
m_Position.y = new_y;
|
||||
m_Position.z = new_z;
|
||||
m_Position.w = CalculateHeadingToTarget(x, y);
|
||||
Log.Out(Logs::Detail, Logs::AI, "Next position2 (%.3f, %.3f, %.3f) (%d steps)", m_Position.x, m_Position.y, m_Position.z, numsteps);
|
||||
}
|
||||
|
||||
uint8 NPCFlyMode = 0;
|
||||
@ -672,8 +656,6 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed, boo
|
||||
|
||||
float newz = zone->zonemap->FindBestZ(dest, nullptr);
|
||||
|
||||
Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.x, m_Position.y, m_Position.z);
|
||||
|
||||
if ((newz > -2000) &&
|
||||
std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check.
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user