mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 11:31:30 +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
|
||||
timer.cpp
|
||||
unix.cpp
|
||||
uuid.cpp
|
||||
worldconn.cpp
|
||||
XMLParser.cpp
|
||||
platform.cpp
|
||||
@ -185,6 +186,7 @@ SET(common_headers
|
||||
timer.h
|
||||
types.h
|
||||
unix.h
|
||||
uuid.h
|
||||
useperl.h
|
||||
version.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
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef WI_WEBINTUTIL_H
|
||||
#define WI_WEBINTUTIL_H
|
||||
#ifndef COMMON_WEBINTUTIL_H
|
||||
#define COMMON_WEBINTUTIL_H
|
||||
|
||||
#include "../common/debug.h"
|
||||
#include "rapidjson/writer.h"
|
||||
|
||||
@ -20,6 +20,7 @@ TARGET_LINK_LIBRARIES(web_interface common debug ${MySQL_LIBRARY_DEBUG} optimize
|
||||
IF(MSVC)
|
||||
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 rpcrt4)
|
||||
ENDIF(MSVC)
|
||||
|
||||
IF(MINGW)
|
||||
|
||||
@ -7,25 +7,29 @@
|
||||
#include "../common/crash.h"
|
||||
#include "../common/EQEmuConfig.h"
|
||||
#include "../common/web_interface_utils.h"
|
||||
#include "../common/uuid.h"
|
||||
#include "worldserver.h"
|
||||
#include "lib/libwebsockets.h"
|
||||
#include <signal.h>
|
||||
#include <list>
|
||||
#include "rapidjson/writer.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;
|
||||
TimeoutManager timeout_manager;
|
||||
const EQEmuConfig *config = nullptr;
|
||||
WorldServer *worldserver = nullptr;
|
||||
libwebsocket_context *context = nullptr;
|
||||
|
||||
struct per_session_data_eqemu {
|
||||
bool auth;
|
||||
std::list<std::string> *send_queue;
|
||||
};
|
||||
|
||||
per_session_data_eqemu *globalsession = NULL;
|
||||
std::map<std::string, per_session_data_eqemu*> sessions;
|
||||
|
||||
void CatchSignal(int sig_num) {
|
||||
run = false;
|
||||
@ -55,7 +59,10 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
||||
switch (reason) {
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session->auth = false;
|
||||
session->uuid = CreateUUID();
|
||||
session->send_queue = new std::list<std::string>();
|
||||
sessions[session->uuid] = session;
|
||||
printf("Create session %s\n", session->uuid.c_str());
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE: {
|
||||
|
||||
@ -66,31 +73,21 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
||||
std::string command;
|
||||
command.assign((const char*)in, len);
|
||||
|
||||
globalsession = session;
|
||||
if(command.compare("get_version") == 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;
|
||||
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) {
|
||||
|
||||
//out_message
|
||||
size_t sz = LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + (*iter).size();
|
||||
unsigned char *buf = new unsigned char[sz];
|
||||
memset(buf, 0, sz);
|
||||
memcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING], &(*iter)[0], (*iter).size());
|
||||
auto n = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], (*iter).size(), LWS_WRITE_TEXT);
|
||||
delete[] buf;
|
||||
memset(out_message, 0, sz);
|
||||
memcpy(&out_message[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);
|
||||
if (n < (*iter).size()) {
|
||||
//couldn't write the message
|
||||
return -1;
|
||||
@ -98,9 +95,19 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
||||
}
|
||||
session->send_queue->clear();
|
||||
break;
|
||||
}
|
||||
case LWS_CALLBACK_PROTOCOL_DESTROY:
|
||||
//clean stuff up here
|
||||
delete session->send_queue;
|
||||
//clean up sessions here
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -34,7 +34,6 @@ struct per_session_data_eqemu {
|
||||
std::list<std::string> *send_queue;
|
||||
};
|
||||
|
||||
extern per_session_data_eqemu *globalsession;
|
||||
WorldServer::WorldServer(std::string shared_key)
|
||||
: WorldConnection(EmuTCPConnection::packetModeWebInterface, shared_key.c_str()){
|
||||
pTryReconnect = true;
|
||||
@ -60,9 +59,6 @@ void WorldServer::Process(){
|
||||
case 0: { break; }
|
||||
case ServerOP_KeepAlive: { break; }
|
||||
case ServerOP_WIWorldResponse: {
|
||||
char pos_update[255];
|
||||
pack->ReadString(pos_update);
|
||||
globalsession->send_queue->push_back(pos_update);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user