-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNetBase.h
More file actions
73 lines (65 loc) · 1.33 KB
/
NetBase.h
File metadata and controls
73 lines (65 loc) · 1.33 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
#ifndef _NET_BASE_H_
#define _NET_BASE_H_
#include "MsgHead.h"
#include <google/protobuf/message_lite.h>
using namespace google::protobuf;
struct HttpDetail
{
char* head;
int headLen;
char* message;
int messageLen;
};
class ServerKey
{
private:
int m_serverid;
int m_gameid;
public:
ServerKey(int id, int gameid)
{
m_serverid = id;
m_gameid = gameid;
}
int getServerId() const
{
return m_serverid;
}
int getGameId() const
{
return m_gameid;
}
bool operator <(const ServerKey& other) const
{
if (this->getGameId()<other.getGameId())
{
return true;
}
else if (this->getGameId() == other.getGameId())
{
return (this->getServerId()<other.getServerId());
}
return false;
}
bool operator == (const ServerKey& other) const
{
return (getGameId()==other.getGameId()) && (getServerId()==other.getServerId());
}
};
class ISvrNetEvent
{
public:
//协议消息
virtual void onGameserverMsg(MsgHead msgHead, MessageLite *pMessage) = 0;
//协议解析失败
virtual void onDecodeError(MsgHead msgHead) = 0;
//网络链接消息,true成功,false失败
virtual void onNetConnect(bool connectRet) = 0;
//网络异常,socket断开
virtual void onNetClose() = 0;
//错误协议
virtual void onError(MsgHead msgHead, const char *buffer, int len) = 0;
//心跳请求
virtual void onHeartReq() = 0;
};
#endif