-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_config.h
executable file
·128 lines (108 loc) · 2.3 KB
/
server_config.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* server_config.h
*
* Created on: 2014年5月12日
* Author: jimm
*/
#ifndef SERVER_CONFIG_H_
#define SERVER_CONFIG_H_
#include "../frame/frame_impl.h"
#include "../frame/frame.h"
#include "../common/common_api.h"
#include "server_typedef.h"
#include <string.h>
using namespace FRAME;
class CServerConfig : public IConfig
{
public:
CServerConfig(const char *pConfigName)
{
strcpy(m_szConfigFile, CONFIG_SERVER);
m_nGroupID = 0;
m_nListenPort = 0;
m_nServerType = 0;
m_nServerID = 0;
m_nNetNodeCount = 0;
m_nMaxConnCount = 0;
}
virtual ~CServerConfig(){};
//初始化配置
virtual int32_t Init();
//卸载配置
virtual int32_t Uninit();
int32_t GetGroupID()
{
return m_nGroupID;
}
int32_t GetListenPort()
{
return m_nListenPort;
}
int32_t GetServerType()
{
return m_nServerType;
}
int32_t GetServerID()
{
return m_nServerID;
}
int32_t GetAllNetNode(NetNode arrNetNode[], int32_t nSize)
{
int32_t nCount = 0;
for(int32_t i = 0; i < m_nNetNodeCount; ++i)
{
if(nCount >= nSize)
{
break;
}
arrNetNode[i] = m_arrNetNode[i];
++nCount;
}
return nCount;
}
NetNode *FindNetNode(char *szAddress, uint16_t nPort)
{
for(int32_t i = 0; i < m_nNetNodeCount; ++i)
{
if((strcmp(m_arrNetNode[i].m_szPeerAddress, szAddress) == 0) &&
(m_arrNetNode[i].m_nPeerPort == nPort))
{
return &m_arrNetNode[i];
}
}
return NULL;
}
//随机获取一个服务类型的结点
NetNode *GetOneNetNode(int32_t nEntityType)
{
int32_t nCount = 0;
int32_t arrNetNodeIndex[enmMaxNetNodeCount];
for(int32_t i = 0; i < m_nNetNodeCount; ++i)
{
if(m_arrNetNode[i].m_nPeerType == nEntityType)
{
arrNetNodeIndex[nCount++] = i;
}
}
if(nCount <= 0)
{
return NULL;
}
int32_t nIndex = Random(nCount);
return &m_arrNetNode[arrNetNodeIndex[nIndex]];
}
int32_t GetMaxConnCount()
{
return m_nMaxConnCount;
}
protected:
char m_szConfigFile[enmMaxConfigFileNameSize];
int32_t m_nGroupID;
int32_t m_nListenPort;
int32_t m_nServerType;
int32_t m_nServerID;
int32_t m_nNetNodeCount;
NetNode m_arrNetNode[enmMaxNetNodeCount];
int32_t m_nMaxConnCount;
};
#endif /* SERVER_CONFIG_H_ */