mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 00:01:28 +00:00
Racism down, uuid tracking up
This commit is contained in:
parent
2dff51a4db
commit
69e90aac0a
@ -64,6 +64,7 @@ SET(common_sources
|
|||||||
timeoutmgr.cpp
|
timeoutmgr.cpp
|
||||||
timer.cpp
|
timer.cpp
|
||||||
unix.cpp
|
unix.cpp
|
||||||
|
uuid.cpp
|
||||||
worldconn.cpp
|
worldconn.cpp
|
||||||
XMLParser.cpp
|
XMLParser.cpp
|
||||||
platform.cpp
|
platform.cpp
|
||||||
@ -185,6 +186,7 @@ SET(common_headers
|
|||||||
timer.h
|
timer.h
|
||||||
types.h
|
types.h
|
||||||
unix.h
|
unix.h
|
||||||
|
uuid.h
|
||||||
useperl.h
|
useperl.h
|
||||||
version.h
|
version.h
|
||||||
worldconn.h
|
worldconn.h
|
||||||
|
|||||||
44
common/uuid.cpp
Normal file
44
common/uuid.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
EQEMu: Everquest Server Emulator
|
||||||
|
Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||||
|
are required to give you total support for your newly bought product;
|
||||||
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "uuid.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <rpc.h>
|
||||||
|
#else
|
||||||
|
#include <uuid/uuid.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string CreateUUID() {
|
||||||
|
#ifdef WIN32
|
||||||
|
UUID uuid;
|
||||||
|
UuidCreate(&uuid);
|
||||||
|
unsigned char *str = nullptr;
|
||||||
|
UuidToStringA(&uuid, &str);
|
||||||
|
std::string s((char*)str);
|
||||||
|
RpcStringFreeA(&str);
|
||||||
|
return s;
|
||||||
|
#else
|
||||||
|
char str[64] = { 0 };
|
||||||
|
uuid_t uuid;
|
||||||
|
uuid_generate_random(uuid);
|
||||||
|
uuid_unparse(uuid, str);
|
||||||
|
return str;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
27
common/uuid.h
Normal file
27
common/uuid.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
EQEMu: Everquest Server Emulator
|
||||||
|
Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net)
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; version 2 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||||
|
are required to give you total support for your newly bought product;
|
||||||
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef COMMON_UUID_H
|
||||||
|
#define COMMON_UUID_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string CreateUUID();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#ifndef WI_WEBINTUTIL_H
|
#ifndef COMMON_WEBINTUTIL_H
|
||||||
#define WI_WEBINTUTIL_H
|
#define COMMON_WEBINTUTIL_H
|
||||||
|
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
|
|||||||
@ -20,6 +20,7 @@ TARGET_LINK_LIBRARIES(web_interface common debug ${MySQL_LIBRARY_DEBUG} optimize
|
|||||||
IF(MSVC)
|
IF(MSVC)
|
||||||
SET_TARGET_PROPERTIES(web_interface PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
|
SET_TARGET_PROPERTIES(web_interface PROPERTIES LINK_FLAGS_RELEASE "/OPT:REF /OPT:ICF")
|
||||||
TARGET_LINK_LIBRARIES(web_interface "Ws2_32.lib")
|
TARGET_LINK_LIBRARIES(web_interface "Ws2_32.lib")
|
||||||
|
TARGET_LINK_LIBRARIES(web_interface rpcrt4)
|
||||||
ENDIF(MSVC)
|
ENDIF(MSVC)
|
||||||
|
|
||||||
IF(MINGW)
|
IF(MINGW)
|
||||||
|
|||||||
@ -7,25 +7,29 @@
|
|||||||
#include "../common/crash.h"
|
#include "../common/crash.h"
|
||||||
#include "../common/EQEmuConfig.h"
|
#include "../common/EQEmuConfig.h"
|
||||||
#include "../common/web_interface_utils.h"
|
#include "../common/web_interface_utils.h"
|
||||||
|
#include "../common/uuid.h"
|
||||||
#include "worldserver.h"
|
#include "worldserver.h"
|
||||||
#include "lib/libwebsockets.h"
|
#include "lib/libwebsockets.h"
|
||||||
#include <signal.h>
|
|
||||||
#include <list>
|
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#define MAX_MESSAGE_LENGTH 2048
|
||||||
|
|
||||||
|
struct per_session_data_eqemu {
|
||||||
|
bool auth;
|
||||||
|
std::string uuid;
|
||||||
|
std::list<std::string> *send_queue;
|
||||||
|
};
|
||||||
|
|
||||||
volatile bool run = true;
|
volatile bool run = true;
|
||||||
TimeoutManager timeout_manager;
|
TimeoutManager timeout_manager;
|
||||||
const EQEmuConfig *config = nullptr;
|
const EQEmuConfig *config = nullptr;
|
||||||
WorldServer *worldserver = nullptr;
|
WorldServer *worldserver = nullptr;
|
||||||
libwebsocket_context *context = nullptr;
|
libwebsocket_context *context = nullptr;
|
||||||
|
std::map<std::string, per_session_data_eqemu*> sessions;
|
||||||
struct per_session_data_eqemu {
|
|
||||||
bool auth;
|
|
||||||
std::list<std::string> *send_queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
per_session_data_eqemu *globalsession = NULL;
|
|
||||||
|
|
||||||
void CatchSignal(int sig_num) {
|
void CatchSignal(int sig_num) {
|
||||||
run = false;
|
run = false;
|
||||||
@ -55,7 +59,10 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
|||||||
switch (reason) {
|
switch (reason) {
|
||||||
case LWS_CALLBACK_ESTABLISHED:
|
case LWS_CALLBACK_ESTABLISHED:
|
||||||
session->auth = false;
|
session->auth = false;
|
||||||
|
session->uuid = CreateUUID();
|
||||||
session->send_queue = new std::list<std::string>();
|
session->send_queue = new std::list<std::string>();
|
||||||
|
sessions[session->uuid] = session;
|
||||||
|
printf("Create session %s\n", session->uuid.c_str());
|
||||||
break;
|
break;
|
||||||
case LWS_CALLBACK_RECEIVE: {
|
case LWS_CALLBACK_RECEIVE: {
|
||||||
|
|
||||||
@ -66,31 +73,21 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
|||||||
std::string command;
|
std::string command;
|
||||||
command.assign((const char*)in, len);
|
command.assign((const char*)in, len);
|
||||||
|
|
||||||
globalsession = session;
|
|
||||||
if(command.compare("get_version") == 0) {
|
if(command.compare("get_version") == 0) {
|
||||||
session->send_queue->push_back("0.8.0");
|
session->send_queue->push_back("0.8.0");
|
||||||
}
|
}
|
||||||
if (command.compare("test_json") == 0) {
|
|
||||||
session->send_queue->push_back(MakeJSON("niggers:tits"));
|
|
||||||
}
|
|
||||||
if (command.compare("stream_test") == 0) {
|
|
||||||
ServerPacket* pack = new ServerPacket(ServerOP_WIServGeneric, len + 1);
|
|
||||||
pack->WriteString(command.c_str());
|
|
||||||
worldserver->SendPacket(pack);
|
|
||||||
safe_delete(pack);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
}
|
||||||
//send stuff here
|
case LWS_CALLBACK_SERVER_WRITEABLE: {
|
||||||
|
//send messages here
|
||||||
|
char out_message[MAX_MESSAGE_LENGTH + LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + 1];
|
||||||
for (auto iter = session->send_queue->begin(); iter != session->send_queue->end(); ++iter) {
|
for (auto iter = session->send_queue->begin(); iter != session->send_queue->end(); ++iter) {
|
||||||
|
|
||||||
|
//out_message
|
||||||
size_t sz = LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + (*iter).size();
|
size_t sz = LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + (*iter).size();
|
||||||
unsigned char *buf = new unsigned char[sz];
|
memset(out_message, 0, sz);
|
||||||
memset(buf, 0, sz);
|
memcpy(&out_message[LWS_SEND_BUFFER_PRE_PADDING], &(*iter)[0], (*iter).size());
|
||||||
memcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING], &(*iter)[0], (*iter).size());
|
auto n = libwebsocket_write(wsi, (unsigned char*)&out_message[LWS_SEND_BUFFER_PRE_PADDING], (*iter).size(), LWS_WRITE_TEXT);
|
||||||
auto n = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], (*iter).size(), LWS_WRITE_TEXT);
|
|
||||||
delete[] buf;
|
|
||||||
if (n < (*iter).size()) {
|
if (n < (*iter).size()) {
|
||||||
//couldn't write the message
|
//couldn't write the message
|
||||||
return -1;
|
return -1;
|
||||||
@ -98,9 +95,19 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
|||||||
}
|
}
|
||||||
session->send_queue->clear();
|
session->send_queue->clear();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case LWS_CALLBACK_PROTOCOL_DESTROY:
|
case LWS_CALLBACK_PROTOCOL_DESTROY:
|
||||||
//clean stuff up here
|
//clean up sessions here
|
||||||
delete session->send_queue;
|
safe_delete(session->send_queue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLOSED:
|
||||||
|
printf("Closed session %s\n", session->uuid.c_str());
|
||||||
|
//Session closed but perhaps not yet destroyed, we still don't want to track it though.
|
||||||
|
sessions.erase(session->uuid);
|
||||||
|
safe_delete(session->send_queue);
|
||||||
|
session->uuid.clear();
|
||||||
|
session->auth = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -34,7 +34,6 @@ struct per_session_data_eqemu {
|
|||||||
std::list<std::string> *send_queue;
|
std::list<std::string> *send_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern per_session_data_eqemu *globalsession;
|
|
||||||
WorldServer::WorldServer(std::string shared_key)
|
WorldServer::WorldServer(std::string shared_key)
|
||||||
: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){
|
: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){
|
||||||
pTryReconnect = true;
|
pTryReconnect = true;
|
||||||
@ -60,9 +59,6 @@ void WorldServer::Process(){
|
|||||||
case 0: { break; }
|
case 0: { break; }
|
||||||
case ServerOP_KeepAlive: { break; }
|
case ServerOP_KeepAlive: { break; }
|
||||||
case ServerOP_WIWorldResponse: {
|
case ServerOP_WIWorldResponse: {
|
||||||
char pos_update[255];
|
|
||||||
pack->ReadString(pos_update);
|
|
||||||
globalsession->send_queue->push_back(pos_update);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user