This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
/
ClusterManager.h
84 lines (61 loc) · 2.44 KB
/
ClusterManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Arctic MMORPG Software
* Copyright (c) 2008-2014 Arctic
* See COPYING for license details.
*/
#pragma once
#define MAX_WORKER_SERVERS 100
#define MAX_SINGLE_MAPID 600
struct Instance
{
uint32 InstanceId;
uint32 MapId;
uint32 MapCount; //used for load balancing for things like battleground servers
WServer * Server;
};
#define IS_INSTANCE(a) (((a)>1)&&((a)!=530))
#define IS_MAIN_MAP(a) (((a)<2)||((a)==530))
class ClusterMgr : public Singleton<ClusterMgr>
{
typedef map<uint32, Instance*> InstanceMap;
RWLock m_lock;
WServer * WorkerServers[MAX_WORKER_SERVERS];
Instance * SingleInstanceMaps[MAX_SINGLE_MAPID];
InstanceMap Instances;
uint32 m_maxInstanceId;
uint32 m_maxWorkerServer;
public:
ClusterMgr();
//this is the prototype for instanced maps that haven't been created yet
//yes, its a multimap, you can have multiple servers per map (battleground servers)
std::multimap<uint32, Instance*> InstancedMaps;
WServer * GetServerByInstanceId(uint32 InstanceId);
WServer * GetServerByMapId(uint32 MapId);
Instance * GetInstanceByInstanceId(uint32 InstanceId);
Instance * GetInstanceByMapId(uint32 MapId);
Instance * GetAnyInstance();
Instance * GetPrototypeInstanceByMapId(uint32 MapId);
void OnServerDisconnect(WServer* s);
WServer * CreateWorkerServer(WSSocket * s);
ARCTIC_INLINE WServer * GetWorkerServer(uint32 Id) { return (Id < MAX_WORKER_SERVERS) ? WorkerServers[Id] : 0; }
void AllocateInitialInstances(WServer * server, vector<uint32>& preferred);
// find the worker server with the least load for the new instance
WServer * GetWorkerServerForNewInstance();
/* create new instance, or a main map */
Instance * CreateInstance(uint32 MapId, WServer * server);
/* create new instance based on template, or a saved instance */
Instance * CreateInstance(uint32 InstanceId, uint32 MapId);
/* gets the instance struct by instance id */
Instance * GetInstance(uint32 InstanceId)
{
InstanceMap::iterator itr = Instances.find(InstanceId);
return (itr == Instances.end()) ? 0 : itr->second;
}
/* distribute packet to all worker servers */
ARCTIC_INLINE void DistributePacketToAll(WorldPacket * data) { DistributePacketToAll(data, 0); }
/* distribute packet to all worker server excluding one */
void DistributePacketToAll(WorldPacket * data, WServer * exclude);
/* loop */
void Update();
};
#define sClusterMgr ClusterMgr::getSingleton()