forked from deeptexas-ai/online-holdem-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgamestation.cpp
More file actions
153 lines (133 loc) · 6.48 KB
/
gamestation.cpp
File metadata and controls
153 lines (133 loc) · 6.48 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "common/macros.h"
#include "common/nndef.h"
#include "common/nnlogic.h"
#include "gameroot.h"
#include "logic/clientlogic/core/gamestation.h"
#include "utils/tarslog.h"
#include "context/context.h"
#include "config/gameconfig.h"
#include "ddz.pb.h"
#include "process/process.h"
#include "message/sendclientmessage.h"
#include "logic/gamelogic/core/endtimer.h"
#include "CommonCode.pb.h"
using namespace nndef;
namespace game
{
namespace logic
{
namespace clientlogic
{
void GameStation(long uid, const vector<char> &vecMsgData, GameRoot *root)
{
PERFSTATS_ENTRY();
__TRY__
using namespace context;
using namespace process;
using namespace config;
using namespace message;
using namespace nnlogic;
DLOG_TRACE("roomid:" << root->roomid() << ", game station. uid: " << uid);
XGameDDZProto::DDZ_msg2csGameStation shcm;
shcm.set_iresultid(0);
shcm.set_ibankercid(root->con->getBankerCid());
shcm.set_itokencid(root->con->getTokenCid());
shcm.set_lbasescore(root->cfg->getBaseScore());
shcm.set_ibetid(root->cfg->getBlindLevel());
shcm.set_imultiple(root->con->getBankerScore());
if(root->pro->getProcess() == NN_STATE_DAPAI)
{
for(auto card : root->con->getVecCommCard())
{
shcm.add_scommcards(card);
}
}
(*shcm.mutable_mcalinfo()).set_bdismiss(root->pro->getProcess() == nil_nnstate);
XGameDDZProto::DDZ_msg2sActNotify cm;
cm.set_icid(root->con->getTokenCid());
cm.set_iacttype(root->pro->getProcess() - 1);
cm.set_bfirstdapai(root->con->isFirstDaPai());
int cfg_time = root->cfg->getDecisionTime(root->pro->getProcess() - 1);
int remain_time = cfg_time - (time(nullptr) - root->con->getOptionTime());
remain_time = remain_time < 0 || remain_time > cfg_time ? 0 : remain_time;
DLOG_TRACE("roomid:" << root->roomid() << ", cfg_time: " << cfg_time << ", op_time: "<< root->con->getOptionTime() << ", remain_time: "<< remain_time);
cm.set_icfgoptiontime(cfg_time);
cm.set_iremainoptiontime(remain_time);
User* user = root->con->getUserByCid(root->con->getTokenCid());
if(user)
{
if(root->pro->getProcess() == NN_STATE_DAPAI)
{
cm.set_bfirstdapai(root->con->isFirstDaPai());
cm.set_bcandapai(user->isCanDaPai());
auto last_decision = root->con->getLastDecision();
for(auto decision : last_decision)
{
for(auto card : decision.second)
{
cm.add_sprecards(card);
}
}
cm.set_iprecardtype(root->con->getLastCardType());
}
}
(*shcm.mutable_maction()) = cm;
std::map<cid_t, User> const &usermap = root->con->getUserMap();
for (auto it = usermap.begin(); it != usermap.end(); it++)
{
XGameDDZProto::PlayerInfo userinfo;
userinfo.set_icid(it->first);
userinfo.set_lplayerid(it->second.getUid());
userinfo.set_snickname(it->second.getNick());
userinfo.set_sheadstr(it->second.getUrl());
userinfo.set_iplayergender(it->second.getGender());
userinfo.set_lcidscore(it->second.getWealth());
userinfo.set_ijiaodizhu(it->second.getJiaoDiZhu());
long ready_time = 30 - (time(nullptr) - it->second.getReadyGameTime());
ready_time = ready_time > 30 || ready_time < 0 ? 0 : ready_time;
userinfo.set_ireadytime(ready_time);
if(uid == it->second.getUid())
{
for(auto card : it->second.getVecCards())
{
userinfo.add_shdcards(card);
}
User* tuser = root->con->getUserByUid(uid);
if(tuser)
{
tuser->setSelfLevel(false);
tuser->setLeft(false);
if(tuser->isTuoGuan())
{
tuser->setTuoGuan(false);
tuser->setTimeOut(0);
XGameDDZProto::DDZ_msg2csTuoGuan tg;
tg.set_iresultid(0);
tg.set_btuoguan(tuser->isTuoGuan());
tg.set_icid(tuser->getCid());
sendAllClientMessage<XGameDDZProto::DDZ_msg2csTuoGuan>(XGameDDZProto::DDZ_msg2csTuoGuan_E, tg, root);
}
}
}
else
{
for(unsigned int i = 0; i < it->second.getVecCards().size(); i++)
{
userinfo.add_shdcards(-1);
}
}
userinfo.set_btuoguan(it->second.isTuoGuan());
for(auto card : it->second.getVecOutCards())
{
userinfo.add_soutcards(card);
}
(*shcm.mutable_muserinfo())[it->first] = userinfo;
}
DLOG_TRACE("roomid:" << root->roomid() << ", game station. uid: " << uid << ", shcm: "<< logPb(shcm));
sendClientMessage<XGameDDZProto::DDZ_msg2csGameStation>(uid, XGameDDZProto::DDZ_msg2csGameStation_E, shcm, root);
__CATCH__
PERFSTATS_EXIT();
}
}
}
}