dll_game.cpp
2.1 KB
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
#include <common.h>
#include "client_proto_head.h"
#include "statisitcs.h"
#include "sys.h"
#ifdef EL_ASYNC_USE_THREAD
#error "EL_ASYNC_USE_THREAD"
#endif // EL_ASYNC_USE_THREAD
extern "C"{
int on_init(){
if(el_async::is_parent()){
DEBUG_LOG("======daemon start======");
DEBUG_LOG("Compiled at [%s-%s]", __DATE__, __TIME__);
}else{
DEBUG_LOG("======server start======");
::srand(el_async::get_now_sec());
g_statisitcs = new statisitcs_t;
if(SUCC != g_statisitcs->init()){
ALERT_LOG("game init failed...");
return ERR;
}
}
return 0;
}
int on_fini(){
if (el_async::is_parent()) {
DEBUG_LOG("======daemon done======");
}else{
DEBUG_LOG("======server done======");
SAFE_DELETE(g_statisitcs);
}
return 0;
}
void on_events(){
if (el_async::is_parent()){
}else{
// g_timer->handle_timer();
}
}
int on_get_pkg_len(el::lib_tcp_peer_info_t* peer_fd_info,
const void* data, uint32_t len){
if (len < proto_head_t::PROTO_HEAD_LEN){
return 0;
}
g_proto_head.unpack(data);
PROTO_LEN pkg_len = g_proto_head.length;
if (pkg_len < proto_head_t::PROTO_HEAD_LEN || pkg_len >= g_bench_conf->page_size_max){
ERROR_LOG("server head len err [len=%u]", len);
return -1;
}
if (len < pkg_len){
return 0;
}
return pkg_len;
}
int on_cli_pkg(const void* data, uint32_t len, el::lib_tcp_peer_info_t* peer_fd_info){
g_proto_head.unpack(data);
return g_statisitcs->on_recv(peer_fd_info, ((char*)data)+proto_head_t::PROTO_HEAD_LEN , len-proto_head_t::PROTO_HEAD_LEN);
}
void on_srv_pkg(const void* data, uint32_t len, el::lib_tcp_peer_info_t* peer_fd_info){
}
void on_cli_conn(el::lib_tcp_peer_info_t* peer_fd_info){
}
void on_cli_conn_closed(int fd){
}
void on_svr_conn_closed(int fd){
CRIT_LOG("[fd:%d]", fd);
}
void on_svr_conn(int fd){
TRACE_LOG("[fd:%d]", fd);
}
void on_mcast_pkg(const void* data, int len){
}
void on_addr_mcast_pkg(uint32_t id, const char* name, const char* ip, uint16_t port, const char* data, int flag){
}
void on_udp_pkg(int fd, const void* data, int len ,struct sockaddr_in* from, socklen_t fromlen){
}
};