Skip to content

Commit e89fa58

Browse files
committed
继续完善billing系统
1 parent af198f1 commit e89fa58

17 files changed

Lines changed: 264 additions & 95 deletions

‎kbe/src/kbengine_vs90.sln‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ EndProject
219219
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zip", "lib\third_party\zip\zip2008.vcproj", "{1ABB1158-909C-4AD4-9F81-CB38BBA5D950}"
220220
EndProject
221221
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "billingsystem", "server\tools\billing_system\billingsystem90.vcproj", "{7817D13F-1FAA-47D8-8C9F-B790FE2D6B0A}"
222+
ProjectSection(ProjectDependencies) = postProject
223+
{863B8043-533C-499D-B48E-F5EC91A6CB9B} = {863B8043-533C-499D-B48E-F5EC91A6CB9B}
224+
{F67B2C56-D1B1-4EA7-B16E-EF8E7F1B6C5F} = {F67B2C56-D1B1-4EA7-B16E-EF8E7F1B6C5F}
225+
{3F8B2057-492F-4332-99DE-3E12F20ED489} = {3F8B2057-492F-4332-99DE-3E12F20ED489}
226+
{E6367B97-92C8-4DAE-992E-4A88178319EF} = {E6367B97-92C8-4DAE-992E-4A88178319EF}
227+
{5EF24499-4F74-4AF6-8048-650BE7BD7808} = {5EF24499-4F74-4AF6-8048-650BE7BD7808}
228+
{A04109A7-46C9-42F9-AB29-8E3D84450172} = {A04109A7-46C9-42F9-AB29-8E3D84450172}
229+
{56D453A7-787B-49E3-84BC-465EED38DE8A} = {56D453A7-787B-49E3-84BC-465EED38DE8A}
230+
{0E032FA8-BB7B-40F6-8CB1-15F204113B24} = {0E032FA8-BB7B-40F6-8CB1-15F204113B24}
231+
{2992ABDB-0853-4C43-B9E2-98D4211192EE} = {2992ABDB-0853-4C43-B9E2-98D4211192EE}
232+
EndProjectSection
222233
EndProject
223234
Global
224235
GlobalSection(SolutionConfigurationPlatforms) = preSolution

‎kbe/src/lib/network/channel.cpp‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Channel::Channel(NetworkInterface & networkInterface,
9090
isCondemn_(false),
9191
proxyID_(0),
9292
isHandshake_(false),
93-
channelType_(CHANNEL_NORMAL)
93+
channelType_(CHANNEL_NORMAL),
94+
componentID_(UNKNOWN_COMPONENT_TYPE)
9495
{
9596
this->incRef();
9697
this->clearBundle();
@@ -140,7 +141,8 @@ Channel::Channel():
140141
isCondemn_(false),
141142
proxyID_(0),
142143
isHandshake_(false),
143-
channelType_(CHANNEL_NORMAL)
144+
channelType_(CHANNEL_NORMAL),
145+
componentID_(UNKNOWN_COMPONENT_TYPE)
144146
{
145147
this->incRef();
146148
this->clearBundle();
@@ -186,14 +188,24 @@ Channel * get(NetworkInterface & networkInterface,
186188
//-------------------------------------------------------------------------------------
187189
void Channel::startInactivityDetection( float period, float checkPeriod )
188190
{
189-
inactivityTimerHandle_.cancel();
191+
stopInactivityDetection();
190192

191-
inactivityExceptionPeriod_ = uint64( period * stampsPerSecond() );
192-
lastReceivedTime_ = timestamp();
193+
// 如果周期为负数则不检查
194+
if(period > 0.f)
195+
{
196+
inactivityExceptionPeriod_ = uint64( period * stampsPerSecond() );
197+
lastReceivedTime_ = timestamp();
198+
199+
inactivityTimerHandle_ =
200+
this->dispatcher().addTimer( int( checkPeriod * 1000000 ),
201+
this, (void *)TIMEOUT_INACTIVITY_CHECK );
202+
}
203+
}
193204

194-
inactivityTimerHandle_ =
195-
this->dispatcher().addTimer( int( checkPeriod * 1000000 ),
196-
this, (void *)TIMEOUT_INACTIVITY_CHECK );
205+
//-------------------------------------------------------------------------------------
206+
void Channel::stopInactivityDetection()
207+
{
208+
inactivityTimerHandle_.cancel();
197209
}
198210

199211
//-------------------------------------------------------------------------------------
@@ -275,7 +287,7 @@ void Channel::clearState( bool warnOnDiscard /*=false*/ )
275287
MemoryStream::ObjPool().reclaimObject(pFragmentStream_);
276288
pFragmentStream_ = NULL;
277289

278-
inactivityTimerHandle_.cancel();
290+
stopInactivityDetection();
279291
this->endpoint(NULL);
280292
}
281293

‎kbe/src/lib/network/channel.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Channel : public TimerHandler, public RefCountable, public PoolObject
107107
void startInactivityDetection( float inactivityPeriod,
108108
float checkPeriod = 1.f );
109109

110+
void stopInactivityDetection();
111+
110112
PacketFilterPtr pFilter() const { return pFilter_; }
111113
void pFilter(PacketFilterPtr pFilter) { pFilter_ = pFilter; }
112114

@@ -169,6 +171,9 @@ class Channel : public TimerHandler, public RefCountable, public PoolObject
169171
ENTITY_ID proxyID()const { return proxyID_; }
170172
void proxyID(ENTITY_ID pid){ proxyID_ = pid; }
171173

174+
COMPONENT_ID componentID()const{ return componentID_; }
175+
void componentID(COMPONENT_ID cid){ componentID_ = cid; }
176+
172177
virtual void handshake();
173178
private:
174179
enum TimeOutType
@@ -234,6 +239,8 @@ class Channel : public TimerHandler, public RefCountable, public PoolObject
234239

235240
// 通道类别
236241
ChannelTypes channelType_;
242+
243+
COMPONENT_ID componentID_;
237244
};
238245

239246
typedef SmartPointer<Channel> ChannelPtr;

‎kbe/src/lib/network/common.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ const ChannelID CHANNEL_ID_NULL = 0;
4646
extern float g_channelInternalTimeout;
4747
extern float g_channelExternalTimeout;
4848

49+
// 不做频道超时检查
50+
#define CLOSE_CHANNEL_INACTIVITIY_DETECTION() \
51+
{ \
52+
Mercury::g_channelExternalTimeout = Mercury::g_channelInternalTimeout = -1.0f; \
53+
} \
54+
55+
4956
namespace udp{
5057
}
5158

‎kbe/src/lib/server/components.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void Components::addComponent(int32 uid, const char* username,
128128
componentInfos.pChannel = pChannel;
129129
componentInfos.componentType = componentType;
130130

131+
if(pChannel)
132+
pChannel->componentID(componentID);
133+
131134
strncpy(componentInfos.username, username, MAX_NAME);
132135

133136
if(cinfos == NULL)
@@ -253,6 +256,7 @@ int Components::connectComponent(COMPONENT_TYPE componentType, int32 uid, COMPON
253256
if(ret == 0)
254257
{
255258
pComponentInfos->pChannel = new Mercury::Channel(*_pNetworkInterface, pEndpoint, Mercury::Channel::INTERNAL);
259+
pComponentInfos->pChannel->componentID(componentID);
256260
if(!_pNetworkInterface->registerChannel(pComponentInfos->pChannel))
257261
{
258262
ERROR_MSG(boost::format("Components::connectComponent: registerChannel(%1%) is failed!\n") %

‎kbe/src/lib/server/serverapp.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ void ServerApp::onRegisterNewApp(Mercury::Channel* pChannel, int32 uid, std::str
334334
Components::ComponentInfos* cinfos = Componentbridge::getComponents().findComponent((
335335
KBEngine::COMPONENT_TYPE)componentType, uid, componentID);
336336

337+
pChannel->componentID(componentID);
338+
337339
if(cinfos == NULL)
338340
{
339341
Componentbridge::getComponents().addComponent(uid, username.c_str(),

‎kbe/src/server/dbmgr/billinghandler.cpp‎

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2828
#include "network/channel.hpp"
2929
#include "network/bundle.hpp"
3030

31+
#include "tools/billing_system/billingsystem_interface.hpp"
32+
3133
namespace KBEngine{
3234

3335
//-------------------------------------------------------------------------------------
@@ -71,25 +73,35 @@ BillingHandler_Normal::~BillingHandler_Normal()
7173
}
7274

7375
//-------------------------------------------------------------------------------------
74-
bool BillingHandler_Normal::createAccount(Mercury::Channel* pChannel, std::string& accountName,
76+
bool BillingHandler_Normal::createAccount(Mercury::Channel* pChannel, std::string& registerName,
7577
std::string& password, std::string& datas)
7678
{
7779
dbThreadPool_.addTask(new DBTaskCreateAccount(pChannel->addr(),
78-
accountName, password, datas));
80+
registerName, registerName, password, datas));
7981

8082
return true;
8183
}
8284

85+
//-------------------------------------------------------------------------------------
86+
void BillingHandler_Normal::onCreateAccountCB(KBEngine::MemoryStream& s)
87+
{
88+
}
89+
8390
//-------------------------------------------------------------------------------------
8491
bool BillingHandler_Normal::loginAccount(Mercury::Channel* pChannel, std::string& loginName,
8592
std::string& password, std::string& datas)
8693
{
8794
dbThreadPool_.addTask(new DBTaskAccountLogin(pChannel->addr(),
88-
loginName, password, datas));
95+
loginName, loginName, password, datas));
8996

9097
return true;
9198
}
9299

100+
//-------------------------------------------------------------------------------------
101+
void BillingHandler_Normal::onLoginAccountCB(KBEngine::MemoryStream& s)
102+
{
103+
}
104+
93105
//-------------------------------------------------------------------------------------
94106
BillingHandler_ThirdParty::BillingHandler_ThirdParty(thread::ThreadPool& threadPool, DBThreadPool& dbThreadPool):
95107
BillingHandler_Normal(threadPool, dbThreadPool),
@@ -105,33 +117,91 @@ BillingHandler_ThirdParty::~BillingHandler_ThirdParty()
105117
}
106118

107119
//-------------------------------------------------------------------------------------
108-
bool BillingHandler_ThirdParty::createAccount(Mercury::Channel* pChannel, std::string& accountName,
120+
bool BillingHandler_ThirdParty::createAccount(Mercury::Channel* pChannel, std::string& registerName,
109121
std::string& password, std::string& datas)
110122
{
111123
KBE_ASSERT(pBillingChannel_);
112124

113-
Mercury::Bundle bundle;
114-
bundle << accountName << password;
115-
bundle.appendBlob(datas);
125+
Mercury::Bundle::SmartPoolObjectPtr bundle = Mercury::Bundle::createSmartPoolObj();
126+
127+
(*(*bundle)).newMessage(BillingSystemInterface::reqCreateAccount);
128+
(*(*bundle)) << pChannel->componentID();
129+
(*(*bundle)) << registerName << password;
130+
(*(*bundle)).appendBlob(datas);
116131

117-
bundle.send(Dbmgr::getSingleton().getNetworkInterface(), pBillingChannel_);
132+
(*(*bundle)).send(Dbmgr::getSingleton().getNetworkInterface(), pBillingChannel_);
118133
return true;
119134
}
120135

136+
//-------------------------------------------------------------------------------------
137+
void BillingHandler_ThirdParty::onCreateAccountCB(KBEngine::MemoryStream& s)
138+
{
139+
std::string registerName, accountName, password, datas;
140+
COMPONENT_ID cid;
141+
bool success = false;
142+
143+
s >> cid >> registerName >> accountName >> password >> success;
144+
s.readBlob(datas);
145+
146+
if(!success)
147+
{
148+
accountName = "";
149+
}
150+
151+
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(LOGINAPP_TYPE, cid);
152+
if(cinfos == NULL || cinfos->pChannel == NULL)
153+
{
154+
ERROR_MSG("BillingHandler_ThirdParty::onCreateAccountCB: loginapp not found!\n");
155+
return;
156+
}
157+
158+
dbThreadPool_.addTask(new DBTaskCreateAccount(cinfos->pChannel->addr(),
159+
registerName, accountName, password, datas));
160+
}
161+
121162
//-------------------------------------------------------------------------------------
122163
bool BillingHandler_ThirdParty::loginAccount(Mercury::Channel* pChannel, std::string& loginName,
123164
std::string& password, std::string& datas)
124165
{
125166
KBE_ASSERT(pBillingChannel_);
126167

127-
Mercury::Bundle bundle;
128-
bundle << loginName << password;
129-
bundle.appendBlob(datas);
168+
Mercury::Bundle::SmartPoolObjectPtr bundle = Mercury::Bundle::createSmartPoolObj();
169+
170+
(*(*bundle)).newMessage(BillingSystemInterface::onAccountLogin);
171+
(*(*bundle)) << pChannel->componentID();
172+
(*(*bundle)) << loginName << password;
173+
(*(*bundle)).appendBlob(datas);
130174

131-
bundle.send(Dbmgr::getSingleton().getNetworkInterface(), pBillingChannel_);
175+
(*(*bundle)).send(Dbmgr::getSingleton().getNetworkInterface(), pBillingChannel_);
132176
return true;
133177
}
134178

179+
//-------------------------------------------------------------------------------------
180+
void BillingHandler_ThirdParty::onLoginAccountCB(KBEngine::MemoryStream& s)
181+
{
182+
std::string loginName, accountName, password, datas;
183+
COMPONENT_ID cid;
184+
bool success = false;
185+
186+
s >> cid >> loginName >> accountName >> password >> success;
187+
s.readBlob(datas);
188+
189+
if(!success)
190+
{
191+
accountName = "";
192+
}
193+
194+
Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(LOGINAPP_TYPE, cid);
195+
if(cinfos == NULL || cinfos->pChannel == NULL)
196+
{
197+
ERROR_MSG("BillingHandler_ThirdParty::onCreateAccountCB: loginapp not found!\n");
198+
return;
199+
}
200+
201+
dbThreadPool_.addTask(new DBTaskAccountLogin(cinfos->pChannel->addr(),
202+
loginName, accountName, password, datas));
203+
}
204+
135205
//-------------------------------------------------------------------------------------
136206
bool BillingHandler_ThirdParty::initialize()
137207
{
@@ -202,6 +272,8 @@ bool BillingHandler_ThirdParty::reconnect()
202272
}
203273
}
204274

275+
// ²»¼ì²é³¬Ê±
276+
pBillingChannel_->stopInactivityDetection();
205277
return true;
206278
}
207279

‎kbe/src/server/dbmgr/billinghandler.hpp‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ class BillingHandler
4949

5050
virtual bool initialize() = 0;
5151

52-
virtual bool createAccount(Mercury::Channel* pChannel, std::string& accountName,
52+
virtual bool createAccount(Mercury::Channel* pChannel, std::string& registerName,
5353
std::string& password, std::string& datas) = 0;
5454

55+
5556
virtual bool loginAccount(Mercury::Channel* pChannel, std::string& loginName,
5657
std::string& password, std::string& datas) = 0;
58+
59+
virtual void onCreateAccountCB(KBEngine::MemoryStream& s) = 0;
60+
61+
virtual void onLoginAccountCB(KBEngine::MemoryStream& s) = 0;
5762
protected:
5863
DBThreadPool& dbThreadPool_;
5964
thread::ThreadPool& threadPool_;
@@ -67,11 +72,15 @@ class BillingHandler_Normal : public BillingHandler
6772

6873
virtual bool initialize(){ return true; }
6974

70-
virtual bool createAccount(Mercury::Channel* pChannel, std::string& accountName,
75+
virtual bool createAccount(Mercury::Channel* pChannel, std::string& registerName,
7176
std::string& password, std::string& datas);
7277

7378
virtual bool loginAccount(Mercury::Channel* pChannel, std::string& loginName,
7479
std::string& password, std::string& datas);
80+
81+
virtual void onCreateAccountCB(KBEngine::MemoryStream& s);
82+
83+
virtual void onLoginAccountCB(KBEngine::MemoryStream& s);
7584
protected:
7685
};
7786

@@ -83,12 +92,16 @@ class BillingHandler_ThirdParty : public BillingHandler_Normal, public thread::T
8392

8493
virtual bool initialize();
8594

86-
virtual bool createAccount(Mercury::Channel* pChannel, std::string& accountName,
95+
virtual bool createAccount(Mercury::Channel* pChannel, std::string& registerName,
8796
std::string& password, std::string& datas);
8897

8998
virtual bool loginAccount(Mercury::Channel* pChannel, std::string& loginName,
9099
std::string& password, std::string& datas);
91100

101+
virtual void onCreateAccountCB(KBEngine::MemoryStream& s);
102+
103+
virtual void onLoginAccountCB(KBEngine::MemoryStream& s);
104+
92105
bool reconnect();
93106

94107
virtual bool process();

0 commit comments

Comments
 (0)