mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-16 22:18:20 +00:00
More work on shared tasks
This commit is contained in:
@@ -15,6 +15,7 @@ SET(world_sources
|
||||
login_server_list.cpp
|
||||
net.cpp
|
||||
queryserv.cpp
|
||||
shared_tasks.cpp
|
||||
ucs.cpp
|
||||
web_interface.cpp
|
||||
web_interface_eqw.cpp
|
||||
@@ -42,6 +43,7 @@ SET(world_headers
|
||||
login_server_list.h
|
||||
net.h
|
||||
queryserv.h
|
||||
shared_tasks.h
|
||||
sof_char_create_data.h
|
||||
ucs.h
|
||||
web_interface.h
|
||||
|
||||
+3
-1
@@ -83,6 +83,7 @@ union semun {
|
||||
#include "queryserv.h"
|
||||
#include "web_interface.h"
|
||||
#include "console.h"
|
||||
#include "shared_tasks.h"
|
||||
|
||||
#include "../common/net/servertalk_server.h"
|
||||
#include "../zone/data_bucket.h"
|
||||
@@ -103,6 +104,7 @@ bool holdzones = false;
|
||||
const WorldConfig *Config;
|
||||
EQEmuLogSys LogSys;
|
||||
WebInterfaceList web_interface;
|
||||
SharedTaskManager shared_tasks;
|
||||
|
||||
void CatchSignal(int sig_num);
|
||||
void CheckForServerScript(bool force_download = false);
|
||||
@@ -622,4 +624,4 @@ void CheckForServerScript(bool force_download) {
|
||||
system("wget -N --no-check-certificate --quiet -O eqemu_server.pl https://raw.githubusercontent.com/EQEmu/Server/master/utils/scripts/eqemu_server.pl");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "shared_tasks.h"
|
||||
#include "clientlist.h"
|
||||
#include "cliententry.h"
|
||||
#include "zonelist.h"
|
||||
|
||||
extern ClientList client_list;
|
||||
extern ZSList zoneserver_list;
|
||||
|
||||
void SharedTaskManager::HandleTaskRequest(ServerPacket *pack)
|
||||
{
|
||||
if (!pack)
|
||||
return;
|
||||
|
||||
char tmp_str[64] = { 0 };
|
||||
int task_id = pack->ReadUInt32();
|
||||
pack->ReadString(tmp_str);
|
||||
std::string leader_name = tmp_str;
|
||||
int missing_count = pack->ReadUInt32();
|
||||
std::vector<std::string> missing_players;
|
||||
for (int i = 0; i < missing_count; ++i) {
|
||||
pack->ReadString(tmp_str);
|
||||
missing_players.push_back(tmp_str);
|
||||
}
|
||||
|
||||
int id = GetNextID();
|
||||
auto ret = tasks.insert({id, {id, task_id}});
|
||||
if (!ret.second) {
|
||||
auto pc = client_list.FindCharacter(leader_name.c_str());
|
||||
if (pc) {
|
||||
auto pack = new ServerPacket(ServerOP_TaskReject, leader_name.size() + 1 + 4);
|
||||
pack->WriteUInt32(0); // string ID or just generic fail message
|
||||
pack->WriteString(leader_name.c_str());
|
||||
zoneserver_list.SendPacket(pc->zone(), pc->instance(), pack);
|
||||
safe_delete(pack);
|
||||
} // oh well
|
||||
}
|
||||
|
||||
auto &task = ret.first->second;
|
||||
task.AddMember(leader_name, true);
|
||||
|
||||
if (missing_players.empty()) {
|
||||
// send instant success to leader
|
||||
auto pc = client_list.FindCharacter(leader_name.c_str());
|
||||
if (pc) {
|
||||
SerializeBuffer buf(10);
|
||||
buf.WriteInt32(id); // task's ID
|
||||
buf.WriteString(leader_name); // leader's name
|
||||
|
||||
auto pack = new ServerPacket(ServerOP_TaskGrant, buf);
|
||||
zoneserver_list.SendPacket(pc->zone(), pc->instance(), pack);
|
||||
safe_delete(pack);
|
||||
} else { // well fuck
|
||||
tasks.erase(ret.first);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
task.SetMissingCount(missing_count);
|
||||
for (auto &&name : missing_players) {
|
||||
// look up CLEs by name, tell them we need to know if they can be added
|
||||
auto pc = client_list.FindCharacter(name.c_str());
|
||||
if (pc) {
|
||||
SerializeBuffer buf(10);
|
||||
buf.WriteInt32(id);
|
||||
buf.WriteInt32(task_id);
|
||||
buf.WriteString(name);
|
||||
|
||||
auto pack = new ServerPacket(ServerOP_TaskRequest, buf);
|
||||
zoneserver_list.SendPacket(pc->zone(), pc->instance(), pack);
|
||||
safe_delete(pack);
|
||||
} else { // asked for a toon we couldn't find ABORT!
|
||||
auto pc = client_list.FindCharacter(leader_name.c_str());
|
||||
if (pc) {
|
||||
auto pack = new ServerPacket(ServerOP_TaskReject, leader_name.size() + 1 + 4);
|
||||
pack->WriteUInt32(0); // string ID or just generic fail message
|
||||
pack->WriteString(leader_name.c_str());
|
||||
zoneserver_list.SendPacket(pc->zone(), pc->instance(), pack);
|
||||
safe_delete(pack);
|
||||
} // oh well
|
||||
tasks.erase(ret.first);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef SHARED_TASKS_H
|
||||
#define SHARED_TASKS_H
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "../common/servertalk.h"
|
||||
|
||||
struct SharedTaskMember {
|
||||
std::string name;
|
||||
bool leader;
|
||||
SharedTaskMember() : leader(false) {}
|
||||
SharedTaskMember(std::string name, bool leader) : name(name), leader(leader) {}
|
||||
};
|
||||
|
||||
class SharedTask {
|
||||
public:
|
||||
SharedTask() : id(0), task_id(0), missing_count(0) {}
|
||||
SharedTask(int id, int task_id) : id(id), task_id(task_id), missing_count(0) {}
|
||||
~SharedTask() {}
|
||||
|
||||
void AddMember(std::string name, bool leader = false) { members.push_back({name, leader}); }
|
||||
inline void SetMissingCount(int in) { missing_count = in; }
|
||||
|
||||
private:
|
||||
int id; // id we have in our map
|
||||
int task_id; // ID of the task we're on
|
||||
int missing_count; // other toons waiting to verify (out of zone, etc)
|
||||
std::vector<SharedTaskMember> members;
|
||||
};
|
||||
|
||||
class SharedTaskManager {
|
||||
public:
|
||||
SharedTaskManager() {}
|
||||
~SharedTaskManager() {}
|
||||
|
||||
// IPC packet processing
|
||||
void HandleTaskRequest(ServerPacket *pack);
|
||||
|
||||
private:
|
||||
inline int GetNextID() { return ++next_id; }
|
||||
int next_id;
|
||||
std::unordered_map<int, SharedTask> tasks;
|
||||
};
|
||||
|
||||
#endif /* !SHARED_TASKS_H */
|
||||
@@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "adventure_manager.h"
|
||||
#include "ucs.h"
|
||||
#include "queryserv.h"
|
||||
#include "shared_tasks.h"
|
||||
|
||||
extern ClientList client_list;
|
||||
extern GroupLFPList LFPGroupList;
|
||||
@@ -45,6 +46,7 @@ extern volatile bool UCSServerAvailable_;
|
||||
extern AdventureManager adventure_manager;
|
||||
extern UCSConnection UCSLink;
|
||||
extern QueryServConnection QSLink;
|
||||
extern SharedTaskManager shared_tasks;
|
||||
void CatchSignal(int sig_num);
|
||||
|
||||
ZoneServer::ZoneServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection, EQ::Net::ConsoleServer *console)
|
||||
@@ -1344,6 +1346,11 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) {
|
||||
cle->ProcessTellQueue();
|
||||
break;
|
||||
}
|
||||
case ServerOP_TaskRequest:
|
||||
{
|
||||
shared_tasks.HandleTaskRequest(pack);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Log(Logs::Detail, Logs::World_Server, "Unknown ServerOPcode from zone 0x%04x, size %d", pack->opcode, pack->size);
|
||||
|
||||
Reference in New Issue
Block a user