-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_net.h
73 lines (49 loc) · 1.6 KB
/
robot_net.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
#pragma once
#include "robot_define.h"
class RobotNet {
public:
explicit RobotNet(const UserID& userid);
public:
// 游戏 连接
int Connect(const std::string& game_ip, const int& game_port, const ThreadID& game_notify_thread_id);
// 游戏 断开
int OnDisconnect();
// 游戏 连接状态
int IsConnected(BOOL& is_connected) const;
// 进入游戏
int SendEnterGame(const RoomID& roomid, const TableNO& tableno);
// 连接保活
int KeepConnection();
public:
// 属性接口
UserID GetUserID() const;
int GetTokenID(TokenID& token) const; //允许脏读
TimeStamp GetTimeStamp() const;
void SetTimeStamp(const TimeStamp& val);
private:
// 辅助函数 WithLock 标识调用前需要获得此对象的数据锁mutex
int SendGameRequestWithLock(const RequestID& requestid, const google::protobuf::Message &val, REQUEST& response, const bool& need_echo = true) const;
int ResetDataWithLock();
int InitDataWithLock();
public:
// 对象状态快照
int SnapShotObjectStatus() const;
private:
// 配置机器人ID 初始化后不在改变,不需要锁保护
UserID userid_{0};
// 机器人游戏服务器连接
CDefSocketClientPtr connection_;
// 游戏服 IP
std::string game_ip_;
// 游戏服 PORT
int game_port_{InvalidPort};;
// Manager中所有机器人通知消息处理线程id
ThreadID game_notify_thread_id_{0};
// 心跳超时计数
int timeout_count_{0};
// 心跳时间戳
TimeStamp timestamp_{std::time(nullptr)};
// 重连标签
bool need_reconnect_{false};
};
using RobotPtr = std::shared_ptr<RobotNet>;