dll_game.cpp
2.72 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <common.h>
#include <client_proto_head.h>
#include "lobby.h"
#include "gateway.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_lobby = new lobby_t;
if(SUCC != g_lobby->init()){
ALERT_LOG("lobby init failed...");
return ERR;
}
}
return 0;
}
int on_fini(){
if (el_async::is_parent()) {
DEBUG_LOG("======daemon done======");
}else{
DEBUG_LOG("======server done======");
g_lobby->release();
SAFE_DELETE(g_lobby);
}
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;
}
proto_head_t ph;
ph.unpack(data);
PROTO_LEN pkg_len = ph.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_gateway_mgr->proto_head.unpack(data);
g_gateway_mgr->on_recv(peer_fd_info,
((char*)data)+proto_head_t::PROTO_HEAD_LEN ,
len-proto_head_t::PROTO_HEAD_LEN);
return 0;
}
void on_srv_pkg(const void* data, uint32_t len, el::lib_tcp_peer_info_t* peer_fd_info){
// g_room_mgr->proto_head.unpack(data);
//
// g_room_mgr->on_recv(peer_fd_info,
// ((char*)data)+proto_head_t::PROTO_HEAD_LEN,
// len-proto_head_t::PROTO_HEAD_LEN);
}
void on_cli_conn(el::lib_tcp_peer_info_t* peer_fd_info){
g_gateway_mgr->add_gateway(peer_fd_info);
}
void on_cli_conn_closed(int fd){
CRIT_LOG("[fd:%d]", fd);
g_gateway_mgr->del_fd_gateway(fd);
}
void on_svr_conn_closed(int fd){
// CRIT_LOG("[fd:%d]", fd);
// g_room_service_mgr->do_del_service(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){
// TRACE_LOG("id:%u, name:%s, ip:%s, port:%u, data:%s, flag:%u", id, name, ip, port, data, flag);
// std::string str_name = name;
// str_name += data;
// if (0 == g_lobby->room_name.compare(str_name)){
// g_room_service_mgr->do_add_service(id, ip, port);
// }
}
void on_udp_pkg(int fd, const void* data, int len ,struct sockaddr_in* from, socklen_t fromlen){
}
};