Skip to content

Commit daa6e33

Browse files
committed
added proxy::entitiesEnabled。
1 parent 06689b8 commit daa6e33

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎kbe/src/server/baseapp/proxy.cpp‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SCRIPT_GET_DECLARE("roundTripTime", pyGetRoundTripTime, 0, 0)
4848
SCRIPT_GET_DECLARE("timeSinceHeardFromClient", pyGetTimeSinceHeardFromClient, 0, 0)
4949
SCRIPT_GET_DECLARE("clientAddr", pyClientAddr, 0, 0)
5050
SCRIPT_GET_DECLARE("hasClient", pyHasClient, 0, 0)
51+
SCRIPT_GET_DECLARE("entitiesEnabled", pyGetEntitiesEnabled, 0, 0)
5152
SCRIPT_GETSET_DECLARE_END()
5253
BASE_SCRIPT_INIT(Proxy, 0, 0, 0, 0, 0)
5354

@@ -132,7 +133,7 @@ void Proxy::initClientCellPropertys()
132133
void Proxy::onEntitiesEnabled(void)
133134
{
134135
SCOPED_PROFILE(SCRIPTCALL_PROFILE);
135-
136+
entitiesEnabled_ = true;
136137
SCRIPT_OBJECT_CALL_ARGS0(this, const_cast<char*>("onEntitiesEnabled"));
137138
}
138139

@@ -176,6 +177,7 @@ void Proxy::onClientDeath(void)
176177
addr(Mercury::Address::NONE);
177178
}
178179

180+
entitiesEnabled = false;
179181
SCRIPT_OBJECT_CALL_ARGS0(this, const_cast<char*>("onClientDeath"));
180182
}
181183

@@ -248,6 +250,7 @@ void Proxy::giveClientTo(Proxy* proxy)
248250
Mercury::Bundle::ObjPool().reclaimObject(pBundle);
249251
}
250252

253+
entitiesEnabled_ = false;
251254
getClientMailbox()->addr(Mercury::Address::NONE);
252255
Py_DECREF(getClientMailbox());
253256
proxy->onGiveClientTo(lpChannel);
@@ -280,13 +283,13 @@ void Proxy::onGiveClientTo(Mercury::Channel* lpChannel)
280283
}
281284

282285
//-------------------------------------------------------------------------------------
283-
uint32 Proxy::getRoundTripTime()const
286+
double Proxy::getRoundTripTime()const
284287
{
285288
if(getClientMailbox() == NULL || getClientMailbox()->getChannel() == NULL ||
286289
getClientMailbox()->getChannel()->endpoint() == NULL)
287-
return 0;
290+
return 0.0;
288291

289-
return getClientMailbox()->getChannel()->endpoint()->getRTT();
292+
return double(getClientMailbox()->getChannel()->endpoint()->getRTT()) / 1000000.0;
290293
}
291294

292295
//-------------------------------------------------------------------------------------
@@ -300,7 +303,7 @@ PyObject* Proxy::pyGetRoundTripTime()
300303
return 0;
301304
}
302305

303-
return PyLong_FromUnsignedLong(this->getRoundTripTime());
306+
return PyFloat_FromDouble(this->getRoundTripTime());
304307
}
305308

306309
//-------------------------------------------------------------------------------------
@@ -385,6 +388,25 @@ PyObject* Proxy::pyClientAddr()
385388
return pyobj;
386389
}
387390

391+
//-------------------------------------------------------------------------------------
392+
PyObject* Proxy::pyGetEntitiesEnabled()
393+
{
394+
if(isDestroyed())
395+
{
396+
PyErr_Format(PyExc_AssertionError, "%s: %d is destroyed!\n",
397+
getScriptName(), getID());
398+
PyErr_PrintEx(0);
399+
return 0;
400+
}
401+
402+
if(this->entitiesEnabled())
403+
{
404+
Py_RETURN_TRUE;
405+
}
406+
407+
Py_RETURN_FALSE;
408+
}
409+
388410
//-------------------------------------------------------------------------------------
389411
PyObject* Proxy::__py_pyStreamFileToClient(PyObject* self, PyObject* args)
390412
{

‎kbe/src/server/baseapp/proxy.hpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Proxy : public Base
6161
/**
6262
脚本请求获取连接的rtt值
6363
*/
64-
uint32 getRoundTripTime()const;
64+
double getRoundTripTime()const;
6565
DECLARE_PY_GET_MOTHOD(pyGetRoundTripTime);
6666

6767
/**
@@ -81,6 +81,12 @@ class Proxy : public Base
8181
*/
8282
DECLARE_PY_GET_MOTHOD(pyClientAddr);
8383

84+
/**
85+
脚本请求获取连接的rtt值
86+
*/
87+
INLINE bool entitiesEnabled()const;
88+
DECLARE_PY_GET_MOTHOD(pyGetEntitiesEnabled);
89+
8490
/**
8591
这个entity被激活了, 在客户端初始化好对应的entity后, 这个方法被调用
8692
*/

‎kbe/src/server/baseapp/proxy.ipp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ INLINE const Mercury::Address& Proxy::addr()const
4040
{
4141
return addr_;
4242
}
43-
43+
44+
INLINE bool Proxy::entitiesEnabled()const
45+
{
46+
return entitiesEnabled_;
47+
}
48+
4449
}

0 commit comments

Comments
 (0)