diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 13ae065be..eaf1bc7ce 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -2051,3 +2051,27 @@ void SharedDatabase::SetBotInspectMessage(uint32 botid, const InspectMessage_Str std::string query = StringFormat("UPDATE bots SET BotInspectMessage = '%s' WHERE BotID = %i", msg.c_str(), botid); QueryDatabase(query); } + +bool SharedDatabase::VerifyToken(std::string token, int& status) { + status = 0; + if (token.length() > 64) { + token = token.substr(0, 64); + } + + token = EscapeString(token); + std::string query = StringFormat("SELECT status FROM tokens WHERE token='%s'", token.c_str()); + auto results = QueryDatabase(query); + if (!results.Success()) + { + std::cerr << "Error in SharedDatabase::VerifyToken query '" << query << "' " << results.ErrorMessage() << std::endl; + return false; + } + + if (results.RowCount() != 1) { + return false; + } + + auto row = results.begin(); + status = atoi(row[0]); + return true; +} \ No newline at end of file diff --git a/common/web_interface_utils.cpp b/common/web_interface_utils.cpp index 18f332af7..89786db86 100644 --- a/common/web_interface_utils.cpp +++ b/common/web_interface_utils.cpp @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "../common/debug.h" +#include "../common/global_define.h" #include "web_interface_utils.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" diff --git a/common/web_interface_utils.h b/common/web_interface_utils.h index c4c88e4c3..3dbda5dcb 100644 --- a/common/web_interface_utils.h +++ b/common/web_interface_utils.h @@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #ifndef COMMON_WEBINTUTIL_H #define COMMON_WEBINTUTIL_H -#include "../common/debug.h" +#include "../common/global_define.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" #include diff --git a/web_interface/web_interface.cpp b/web_interface/web_interface.cpp index 5f39558ad..17f2d9ac0 100644 --- a/web_interface/web_interface.cpp +++ b/web_interface/web_interface.cpp @@ -1,13 +1,16 @@ +#include "../common/eqemu_logsys.h" #include "web_interface.h" #include "method_handler.h" #include "remote_call.h" +EQEmuLogSys Log; volatile bool run = true; TimeoutManager timeout_manager; const EQEmuConfig *config = nullptr; WorldServer *worldserver = nullptr; libwebsocket_context *context = nullptr; SharedDatabase *db = nullptr; + std::map sessions; std::map> authorized_methods; std::map unauthorized_methods; @@ -135,18 +138,20 @@ static struct libwebsocket_protocols protocols[] = { int main() { RegisterExecutablePlatform(ExePlatformWebInterface); + Log.LoadLogSettingsDefaults(); + set_exception_handler(); register_methods(); Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect - _log(WEB_INTERFACE__INIT, "Starting EQEmu Web Server."); + Log.Out(Logs::General, Logs::WebInterface_Server, "Starting EQEmu Web Server."); if (signal(SIGINT, CatchSignal) == SIG_ERR) { - _log(WEB_INTERFACE__ERROR, "Could not set signal handler"); + Log.Out(Logs::General, Logs::Error, "Could not set signal handler"); return 1; } if (signal(SIGTERM, CatchSignal) == SIG_ERR) { - _log(WEB_INTERFACE__ERROR, "Could not set signal handler"); + Log.Out(Logs::General, Logs::Error, "Could not set signal handler"); return 1; } @@ -162,15 +167,15 @@ int main() { context = libwebsocket_create_context(&info); if (context == NULL) { - _log(WEB_INTERFACE__ERROR, "Could not create websocket handler."); + Log.Out(Logs::General, Logs::Error, "Could not create websocket handler."); return 1; } db = new SharedDatabase(); - _log(WEB_INTERFACE__TRACE, "Connecting to database..."); + Log.Out(Logs::General, Logs::WebInterface_Server, "Connecting to database..."); if(!db->Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(), config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) { - _log(WEB_INTERFACE__TRACE, "Unable to connect to the database, cannot continue without a database connection"); + Log.Out(Logs::General, Logs::WebInterface_Server, "Unable to connect to the database, cannot continue without a database connection"); return 1; } diff --git a/web_interface/web_interface.h b/web_interface/web_interface.h index 19cba376d..83007d287 100644 --- a/web_interface/web_interface.h +++ b/web_interface/web_interface.h @@ -18,7 +18,7 @@ #ifndef WI_WEB_INTERFACE_H #define WI_WEB_INTERFACE_H -#include "../common/debug.h" +#include "../common/global_define.h" #include "../common/opcodemgr.h" #include "../common/eq_stream_factory.h" #include "../common/rulesys.h" diff --git a/web_interface/worldserver.cpp b/web_interface/worldserver.cpp index f28bd7a03..4a1762d38 100644 --- a/web_interface/worldserver.cpp +++ b/web_interface/worldserver.cpp @@ -15,7 +15,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "../common/debug.h" +#include "../common/global_define.h" #include #include #include @@ -44,7 +44,7 @@ WorldServer::~WorldServer(){ } void WorldServer::OnConnected(){ - _log(WEB_INTERFACE__INIT, "Connected to World."); + Log.Out(Logs::General, Logs::WebInterface_Server, "Connected to World."); WorldConnection::OnConnected(); } @@ -55,7 +55,7 @@ void WorldServer::Process(){ ServerPacket *pack = nullptr; while((pack = tcpc.PopPacket())){ - _log(WEB_INTERFACE__TRACE, "Received Opcode: %4X", pack->opcode); + Log.Out(Logs::General, Logs::Netcode, "Received Opcode: %4X", pack->opcode); switch(pack->opcode) { case 0: { break; } case ServerOP_KeepAlive: { break; } diff --git a/world/console.cpp b/world/console.cpp index 99a1bab9c..a34492c0a 100644 --- a/world/console.cpp +++ b/world/console.cpp @@ -268,7 +268,7 @@ bool Console::Process() { } else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeWebInterface) { - _log(WORLD__CONSOLE, "New WI Connection from %s:%d", inet_ntoa(in), GetPort()); + Log.Out(Logs::Detail, Logs::World_Server, "New WI Connection from %s:%d", inet_ntoa(in), GetPort()); WILink.SetConnection(tcpc); tcpc = 0; } diff --git a/world/net.cpp b/world/net.cpp index d388d5cb4..6f4b8213e 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -108,6 +108,8 @@ uint32 numclients = 0; uint32 numzones = 0; bool holdzones = false; +EQEmuLogSys Log; + extern ConsoleList console_list; void CatchSignal(int sig_num); diff --git a/world/remote_call.cpp b/world/remote_call.cpp index 40b0666de..e150b03f7 100644 --- a/world/remote_call.cpp +++ b/world/remote_call.cpp @@ -1,8 +1,7 @@ #include -#include "../common/debug.h" -#include "../common/logsys.h" -#include "../common/logtypes.h" +#include "../common/global_define.h" +#include "../common/eqemu_logsys.h" #include "../common/md5.h" #include "../common/emu_tcp_connection.h" #include "../common/packet_dump.h" diff --git a/world/web_interface.cpp b/world/web_interface.cpp index da6a5c955..2da12c48f 100644 --- a/world/web_interface.cpp +++ b/world/web_interface.cpp @@ -1,12 +1,11 @@ -#include "../common/debug.h" +#include "../common/global_define.h" #include "web_interface.h" #include "world_config.h" #include "clientlist.h" #include "zonelist.h" #include "zoneserver.h" #include "remote_call.h" -#include "../common/logsys.h" -#include "../common/logtypes.h" +#include "../common/eqemu_logsys.h" #include "../common/md5.h" #include "../common/emu_tcp_connection.h" #include "../common/packet_dump.h" @@ -25,7 +24,7 @@ void WebInterfaceConnection::SetConnection(EmuTCPConnection *inStream) { if(stream) { - _log(WEB_INTERFACE__ERROR, "Incoming WebInterface Connection while we were already connected to a WebInterface."); + Log.Out(Logs::General, Logs::WebInterface_Server, "Incoming WebInterface Connection while we were already connected to a WebInterface."); stream->Disconnect(); } @@ -59,7 +58,7 @@ bool WebInterfaceConnection::Process() { struct in_addr in; in.s_addr = GetIP(); - _log(WEB_INTERFACE__ERROR, "WebInterface authorization failed."); + Log.Out(Logs::General, Logs::Error, "WebInterface authorization failed."); ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed); SendPacket(pack); delete pack; @@ -71,7 +70,7 @@ bool WebInterfaceConnection::Process() { struct in_addr in; in.s_addr = GetIP(); - _log(WEB_INTERFACE__ERROR, "WebInterface authorization failed."); + Log.Out(Logs::General, Logs::Error, "WebInterface authorization failed."); ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed); SendPacket(pack); delete pack; @@ -81,7 +80,7 @@ bool WebInterfaceConnection::Process() } else { - _log(WEB_INTERFACE__ERROR, "**WARNING** You have not configured a world shared key in your config file. You should add a STRING element to your element to prevent unauthorized zone access."); + Log.Out(Logs::General, Logs::Error, "**WARNING** You have not configured a world shared key in your config file. You should add a STRING element to your element to prevent unauthorized zone access."); authenticated = true; } delete pack; @@ -99,7 +98,7 @@ bool WebInterfaceConnection::Process() } case ServerOP_ZAAuth: { - _log(WEB_INTERFACE__ERROR, "Got authentication from WebInterface when they are already authenticated."); + Log.Out(Logs::General, Logs::Error, "Got authentication from WebInterface when they are already authenticated."); break; } case ServerOP_WIRemoteCall: @@ -159,7 +158,7 @@ bool WebInterfaceConnection::Process() } default: { - _log(WEB_INTERFACE__ERROR, "Unknown ServerOPcode from WebInterface 0x%04x, size %d", pack->opcode, pack->size); + Log.Out(Logs::General, Logs::Error, "Unknown ServerOPcode from WebInterface 0x%04x, size %d", pack->opcode, pack->size); DumpPacket(pack->pBuffer, pack->size); break; } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 7fe4a41c8..4e216c35f 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -4362,7 +4362,7 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) params.push_back(std::to_string(ppu->x_pos)); params.push_back(std::to_string(ppu->y_pos)); params.push_back(std::to_string(ppu->z_pos)); - params.push_back(std::to_string(heading)); + params.push_back(std::to_string(m_Position.w)); params.push_back(std::to_string(GetClass())); params.push_back(std::to_string(GetRace())); RemoteCallSubscriptionHandler::Instance()->OnEvent("Client.Position", params); diff --git a/zone/mob.cpp b/zone/mob.cpp index f7d620cb2..b7d447349 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -1233,10 +1233,10 @@ void Mob::MakeSpawnUpdateNoDelta(PlayerPositionUpdateServer_Struct *spu){ std::vector params; params.push_back(std::to_string((long)GetID())); params.push_back(GetCleanName()); - params.push_back(std::to_string((double)x_pos)); - params.push_back(std::to_string((double)y_pos)); - params.push_back(std::to_string((double)z_pos)); - params.push_back(std::to_string((double)heading)); + params.push_back(std::to_string((double)m_Position.x)); + params.push_back(std::to_string((double)m_Position.y)); + params.push_back(std::to_string((double)m_Position.z)); + params.push_back(std::to_string((double)m_Position.w)); params.push_back(std::to_string((double)GetClass())); params.push_back(std::to_string((double)GetRace())); RemoteCallSubscriptionHandler::Instance()->OnEvent("NPC.Position", params); diff --git a/zone/remote_call.cpp b/zone/remote_call.cpp index e58fcbd6d..61ab17994 100644 --- a/zone/remote_call.cpp +++ b/zone/remote_call.cpp @@ -1,7 +1,6 @@ -#include "../common/debug.h" +#include "../common/global_define.h" #include "../common/emu_tcp_connection.h" -#include "../common/logsys.h" -#include "../common/logtypes.h" +#include "../common/eqemu_logsys.h" #include "../common/md5.h" #include "../common/packet_dump.h" #include "../common/packet_functions.h" @@ -184,10 +183,10 @@ void handle_rc_get_initial_entity_positions(const std::string &method, const std res["ent_id"] = itoa(c->GetEntityID()); res["type"] = "Door"; res["name"] = c->GetDoorName(); - res["x"] = itoa(c->GetX()); - res["y"] = itoa(c->GetY()); - res["z"] = itoa(c->GetZ()); - res["h"] = itoa(c->GetHeading()); + res["x"] = itoa(c->GetPosition().x); + res["y"] = itoa(c->GetPosition().y); + res["z"] = itoa(c->GetPosition().z); + res["h"] = itoa(c->GetPosition().w); RemoteCallResponse(connection_id, request_id, res, error); } std::list object_list; diff --git a/zone/remote_call_subscribe.cpp b/zone/remote_call_subscribe.cpp index 336669ae8..ba19ad999 100644 --- a/zone/remote_call_subscribe.cpp +++ b/zone/remote_call_subscribe.cpp @@ -1,6 +1,5 @@ -#include "../common/debug.h" -#include "../common/logsys.h" -#include "../common/logtypes.h" +#include "../common/global_define.h" +#include "../common/eqemu_logsys.h" #include "../common/md5.h" #include "../common/emu_tcp_connection.h" #include "../common/packet_functions.h"