KBEngine 是一款開源的遊戲服務端引擎,使用簡單的約定協議就可以使客戶端與服務端進行交互,
使用KBEngine插件可以快速與(Unity3D, OGRE, Cocos2d, HTML5, 等等)技術結合造成一個完整的客戶端。html
服務端底層框架使用c++編寫,遊戲邏輯層使用Python(支持熱更新),開發者無需重複的實現一些遊戲服務端通用的底層技術,
將精力真正集中到遊戲開發層面上來,快速的打造各類網絡遊戲。前端
(常常被問到承載上限,kbengine底層架構被設計爲多進程分佈式動態負載均衡方案,
理論上只須要不斷擴展硬件就可以不斷增長承載上限,單臺機器的承載上限取決於遊戲邏輯自己的複雜度。)java
cstdkbe.hpppython
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2012 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KBE_CSTDKBE_HPP
#define KBE_CSTDKBE_HPP
#include "cstdkbe/platform.hpp"
#include "cstdkbe/singleton.hpp"
#include "cstdkbe/kbeversion.hpp"
#include "cstdkbe/kbemalloc.hpp"
#include "cstdkbe/stringconv.hpp"
#include "cstdkbe/format.hpp"
namespace
KBEngine{
/** 安全的釋放一個指針內存 */
#define SAFE_RELEASE(i) \
if
(i) \
{ \
delete
i; \
i = NULL; \
}
/** 安全的釋放一個指針數組內存 */
#define SAFE_RELEASE_ARRAY(i) \
if
(i) \
{ \
delete
[] i; \
i = NULL; \
}
#ifdef CODE_INLINE
#define INLINE inline
#else
#define INLINE
#endif
/** kbe時間 */
extern
GAME_TIME g_kbetime;
/** 帳號的類別 */
enum
ACCOUNT_TYPE
{
ACCOUNT_TYPE_NORMAL = 1,
// 普通帳號
ACCOUNT_TYPE_MAIL = 2,
// email帳號(需激活)
ACCOUNT_TYPE_SMART = 3
// 智能識別
};
enum
ACCOUNT_FLAGS
{
ACCOUNT_FLAG_NORMAL = 0x00000000,
ACCOUNT_FLAG_LOCK = 0x000000001,
ACCOUNT_FLAG_NOT_ACTIVATED = 0x000000002
};
/** entity的mailbox類別 */
enum
ENTITY_MAILBOX_TYPE
{
MAILBOX_TYPE_CELL = 0,
MAILBOX_TYPE_BASE = 1,
MAILBOX_TYPE_CLIENT = 2,
MAILBOX_TYPE_CELL_VIA_BASE = 3,
MAILBOX_TYPE_BASE_VIA_CELL = 4,
MAILBOX_TYPE_CLIENT_VIA_CELL = 5,
MAILBOX_TYPE_CLIENT_VIA_BASE = 6,
};
/** mailbox的類別對換爲字符串名稱 嚴格和ENTITY_MAILBOX_TYPE索引匹配 */
const
char
ENTITY_MAILBOX_TYPE_TO_NAME_TABLE[][8] =
{
"cell"
,
"base"
,
"client"
,
"cell"
,
"base"
,
"client"
,
"client"
,
};
/** 定義服務器各組件類別 */
enum
COMPONENT_TYPE
{
UNKNOWN_COMPONENT_TYPE = 0,
DBMGR_TYPE = 1,
LOGINAPP_TYPE = 2,
BASEAPPMGR_TYPE = 3,
CELLAPPMGR_TYPE = 4,
CELLAPP_TYPE = 5,
BASEAPP_TYPE = 6,
CLIENT_TYPE = 7,
MACHINE_TYPE = 8,
CONSOLE_TYPE = 9,
MESSAGELOG_TYPE = 10,
BOTS_TYPE = 11,
WATCHER_TYPE = 12,
BILLING_TYPE = 13,
COMPONENT_END_TYPE = 14,
};
/** 當前服務器組件類別和ID */
extern
COMPONENT_TYPE g_componentType;
extern
COMPONENT_ID g_componentID;
/** 定義服務器各組件名稱 */
const
char
COMPONENT_NAME[][255] = {
"unknown"
,
"dbmgr"
,
"loginapp"
,
"baseappmgr"
,
"cellappmgr"
,
"cellapp"
,
"baseapp"
,
"client"
,
"kbmachine"
,
"console"
,
"messagelog"
,
"bots"
,
"watcher"
,
"billing"
,
};
const
char
COMPONENT_NAME_1[][255] = {
"unknown "
,
"dbmgr "
,
"loginapp "
,
"baseappmgr "
,
"cellappmgr "
,
"cellapp "
,
"baseapp "
,
"client "
,
"kbmachine "
,
"console "
,
"messagelog "
,
"bots"
,
"watcher"
,
"billing"
,
};
inline
const
char
* COMPONENT_NAME_EX(COMPONENT_TYPE CTYPE)
{
if
(CTYPE < 0 || CTYPE >= COMPONENT_END_TYPE)
{
return
COMPONENT_NAME[UNKNOWN_COMPONENT_TYPE];
}
return
COMPONENT_NAME[CTYPE];
}
inline
const
char
* COMPONENT_NAME_EX_1(COMPONENT_TYPE CTYPE)
{
if
(CTYPE < 0 || CTYPE >= COMPONENT_END_TYPE)
{
return
COMPONENT_NAME_1[UNKNOWN_COMPONENT_TYPE];
}
return
COMPONENT_NAME_1[CTYPE];
}
inline
COMPONENT_TYPE ComponentName2ComponentType(
const
char
* name)
{
for
(
int
i=0; i<(
int
)COMPONENT_END_TYPE; i++)
{
if
(kbe_stricmp(COMPONENT_NAME[i], name) == 0)
return
(COMPONENT_TYPE)i;
}
return
UNKNOWN_COMPONENT_TYPE;
}
// 全部的組件列表
const
COMPONENT_TYPE ALL_COMPONENT_TYPES[] = {BASEAPPMGR_TYPE, CELLAPPMGR_TYPE, DBMGR_TYPE, CELLAPP_TYPE,
BASEAPP_TYPE, LOGINAPP_TYPE, MACHINE_TYPE, CONSOLE_TYPE, MESSAGELOG_TYPE,
WATCHER_TYPE, BILLING_TYPE, BOTS_TYPE, UNKNOWN_COMPONENT_TYPE};
// 全部的後端組件列表
const
COMPONENT_TYPE ALL_SERVER_COMPONENT_TYPES[] = {BASEAPPMGR_TYPE, CELLAPPMGR_TYPE, DBMGR_TYPE, CELLAPP_TYPE,
BASEAPP_TYPE, LOGINAPP_TYPE, MACHINE_TYPE, MESSAGELOG_TYPE,
WATCHER_TYPE, BILLING_TYPE, BOTS_TYPE, UNKNOWN_COMPONENT_TYPE};
// 全部的後端組件列表
const
COMPONENT_TYPE ALL_GAME_SERVER_COMPONENT_TYPES[] = {BASEAPPMGR_TYPE, CELLAPPMGR_TYPE, DBMGR_TYPE, CELLAPP_TYPE,
BASEAPP_TYPE, LOGINAPP_TYPE, BILLING_TYPE, UNKNOWN_COMPONENT_TYPE};
// 全部的輔助性組件
const
COMPONENT_TYPE ALL_HELPER_COMPONENT_TYPE[] = {MESSAGELOG_TYPE, UNKNOWN_COMPONENT_TYPE};
// 返回是不是一個有效的組件
#define VALID_COMPONENT(C_TYPE) ((C_TYPE) > 0 && (C_TYPE) < COMPONENT_END_TYPE)
// 前端應用的類別, All client type
enum
COMPONENT_CLIENT_TYPE
{
UNKNOWN_CLIENT_COMPONENT_TYPE = 0,
// 移動類,手機,平板電腦
// Mobile, Phone, Pad(Allowing does not contain Python-scripts and entitydefs analysis, can be imported protocol from network)
CLIENT_TYPE_MOBILE = 1,
// 獨立的Windows/Linux/Mac應用程序(包含python腳本,entitydefs解析與檢查entitydefs的MD5,原生的)
// Windows/Linux/Mac Application program (Contains the Python-scripts, entitydefs parsing and check entitydefs-MD5, Native)
CLIENT_TYPE_PC = 2,
// 不包含Python腳本,entitydefs協議可以使用網絡導入
// Web, HTML5, Flash
CLIENT_TYPE_BROWSER = 3,
// 包含Python腳本,entitydefs解析與檢查entitydefs的MD5,原生的
// bots (Contains the Python-scripts, entitydefs parsing and check entitydefs-MD5, Native)
CLIENT_TYPE_BOTS = 4,
// 輕端類, 可不包含python腳本,entitydefs協議可以使用網絡導入
// Mini-Client(Allowing does not contain Python-scripts and entitydefs analysis, can be imported protocol from network)
CLIENT_TYPE_MINI = 5,
// End
CLIENT_TYPE_END = 6
};
/** 定義前端應用的類別名稱 */
const
char
COMPONENT_CLIENT_NAME[][255] = {
"UNKNOWN_CLIENT_COMPONENT_TYPE"
,
"CLIENT_TYPE_MOBILE"
,
"CLIENT_TYPE_PC"
,
"CLIENT_TYPE_BROWSER"
,
"CLIENT_TYPE_BOTS"
,
"CLIENT_TYPE_MINI"
,
};
// 全部前端應用的類別
const
COMPONENT_CLIENT_TYPE ALL_CLIENT_TYPES[] = {CLIENT_TYPE_MOBILE, CLIENT_TYPE_PC, CLIENT_TYPE_BROWSER,
CLIENT_TYPE_BOTS, CLIENT_TYPE_MINI, UNKNOWN_CLIENT_COMPONENT_TYPE};
typedef
int8 CLIENT_CTYPE;
// 前端是否支持浮點數
// #define CLIENT_NO_FLOAT
// 一個cell的默認的邊界或者最小大小
#define CELL_DEF_MIN_AREA_SIZE 500.0f
/** 一個空間的一個chunk大小 */
#define SPACE_CHUNK_SIZE 100
/** 檢查用戶名合法性 */
inline
bool
validName(
const
char
* name,
int
size)
{
if
(size >= 256)
return
false
;
for
(
int
i=0; i<size; i++)
{
char
ch = name[i];
if
((ch >=
'a'
&& ch <=
'z'
) || (ch >=
'A'
&& ch <=
'Z'
) || (ch >=
'0'
&& ch <=
'9'
) || (ch ==
'_'
))
continue
;
return
false
;
}
return
true
;
}
inline
bool
validName(
const
std::string& name)
{
return
validName(name.c_str(), name.size());
}
/** 檢查email地址合法性
嚴格匹配請用以下表達式
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
*/
#ifdef USE_REGEX
#include <regex>
#endif
inline
bool
email_isvalid(
const
char
*address)
{
#ifdef USE_REGEX
std::tr1::regex _mail_pattern(
"([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"
);
return
std::tr1::regex_match(accountName, _mail_pattern);
#endif
int
len =
strlen
(address);
if
(len <= 3)
return
false
;
char
ch = address[len - 1];
if
(!((ch >=
'a'
&& ch <=
'z'
) || (ch >=
'A'
&& ch <=
'Z'
) || (ch >=
'0'
&& ch <=
'9'
)))
return
false
;
int
count = 0;
const
char
*c, *domain;
static
const
char
*rfc822_specials =
"()<>@,;:\\\"[]"
;
/* first we validate the name portion (name@domain) */
for
(c = address; *c; c++) {
if
(*c ==
'\"'
&& (c == address || *(c - 1) ==
'.'
|| *(c - 1) ==
'\"'
)) {
while
(*++c) {
if
(*c ==
'\"'
)
break
;
if
(*c ==
'\\'
&& (*++c ==
' '
))
continue
;
if
(*c <=
' '
|| *c >= 127)
return
false
;
}
if
(!*c++)
return
false
;
if
(*c ==
'@'
)
break
;
if
(*c !=
'.'
)
return
false
;
continue
;
}
if
(*c ==
'@'
)
break
;
if
(*c <=
' '
|| *c >= 127)
return
false
;
if
(
strchr
(rfc822_specials, *c))
return
false
;
}
if
(c == address || *(c - 1) ==
'.'
)
return
false
;
/* next we validate the domain portion (name@domain) */
if
(!*(domain = ++c))
return
false
;
do
{
if
(*c ==
'.'
) {
if
(c == domain || *(c - 1) ==
'.'
)
return
false
;
count++;
}
if
(*c <=
' '
|| *c >= 127)
return
false
;
if
(
strchr
(rfc822_specials, *c))
return
false
;
}
while
(*++c);
return
(count >= 1);
}
}
#endif // KBE_CSTDKBE_HPP
|
以上所述就是本文的所有內容了,有須要的小夥伴能夠參考下。c++
如對本文有疑問,請提交到交流社區,廣大熱心網友會爲你解答!! 點擊進入社區redis
最新評論