-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleavedesk.cpp
More file actions
113 lines (101 loc) · 4.72 KB
/
leavedesk.cpp
File metadata and controls
113 lines (101 loc) · 4.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
#include "Comm/ITableGame.h"
#include "common/macros.h"
#include "common/nndef.h"
#include "gameroot.h"
#include "logic/gamelogic/core/leavedesk.h"
#include "message/sendroommessage.h"
#include "logic/gamelogic/core/begintimer.h"
#include "logic/gamelogic/core/endtimer.h"
#include "utils/tarslog.h"
#include "context/context.h"
#include "config/gameconfig.h"
#include "process/process.h"
#include "CommonCode.pb.h"
#include "message/sendclientmessage.h"
#include "ddz.pb.h"
using namespace nndef;
namespace game
{
namespace logic
{
namespace gamelogic
{
using namespace context;
using namespace process;
using namespace gamelogic;
using namespace config;
using namespace nninvalid;
using namespace RoomSo;
using namespace message;
int LeaveDesk(GameRoot *root, bool bTimeOut)
{
if(root->pro->getProcess() != nil_nnstate || root->con->isGameBegin())
{
DLOG_TRACE("roomid:" << root->roomid() << ",process err. process : " << root->pro->getProcess());
return 0;
}
//检查离开状态
std::vector<long> vdelUser;
std::map<cid_t, User> &usermap = root->con->refUserMap();
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
if(it->second.isLeft() || it->second.isTuoGuan())
{
DLOG_TRACE("roomid:" << root->roomid() << ",user. uid: " << it->second.getUid() << ", cid: "<< it->first<< ", left: "<< it->second.isLeft() << ", tuoguan: "<<it->second.isTuoGuan() );
vdelUser.push_back(it->second.getUid());
XGameDDZProto::DDZ_msg2cLeaveNotify leave_notify;
leave_notify.set_icid(it->first);
sendAllClientMessage<XGameDDZProto::DDZ_msg2cLeaveNotify>(XGameDDZProto::DDZ_msg2cLeaveNotify_E, leave_notify, root);
}
}
RemoveUser(root, vdelUser);
if(vdelUser.size() > 0 || bTimeOut)
{
std::vector<long> vrematchUser;
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
if(it->second.isReady())
{
DLOG_TRACE("roomid:" << root->roomid() << ",user left. uid: " << it->second.getUid() << ", cid: "<< it->first << ", ready: "<< it->second.isReady());
vrematchUser.push_back(it->second.getUid());
XGameDDZProto::DDZ_msg2cLeaveNotify leave_notify;
leave_notify.set_icid(it->first);
sendAllClientMessage<XGameDDZProto::DDZ_msg2cLeaveNotify>(XGameDDZProto::DDZ_msg2cLeaveNotify_E, leave_notify, root);
}
}
for(auto uid : vrematchUser)
{
DLOG_TRACE("roomid:" << root->roomid() << ",user rematch. uid: " << uid);
XGameDDZProto::DDZ_msg2cReMatchGame rematch_notify;
sendClientMessage<XGameDDZProto::DDZ_msg2cReMatchGame>(uid, XGameDDZProto::DDZ_msg2cReMatchGame_E, rematch_notify, root);
}
RemoveUser(root, vrematchUser);
}
return 0;
}
int RemoveUser(GameRoot *root, std::vector<long> vdelUser)
{
root->con->clearCalInfo();
for (auto iter = vdelUser.begin(); iter != vdelUser.end(); iter++)
{
User* user = root->con->getUserByUid(*iter);
if(user)
{
//DLOG_TRACE("roomid:" << root->roomid() << ", del, uid: " << *iter << ", left: " << user->isLeft() << ", ready: "<< user->isReady());
root->con->delUser(*iter);
//站起消息
TGAME_Stand tmm;
tmm.lPlayerID = *iter;
tmm.iType = user->isSelfLevel() ? 1 : 0;
sendRoomMessage<TGAME_Stand>(TGAME_Stand_E, tmm, root);
}
else
{
DLOG_TRACE("roomid:" << root->roomid() << ", del user err, uid: " << *iter);
}
}
return 0;
}
}
}
}