Skip to content

Commit b325e40

Browse files
committed
增加新机制shouldAutoArchive, shouldAutoBackup
1 parent 89b9360 commit b325e40

10 files changed

Lines changed: 208 additions & 25 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,8 @@ inline uint64 secondsToStamps(float seconds)
153153
// 登录注册时附带的信息最大长度
154154
#define ACCOUNT_DATA_MAX_LENGTH 1024
155155

156+
// 被用来描述任何只做一次后自动设置为不做的选项
157+
#define KBE_NEXT_ONLY 2
158+
156159
}
157160
#endif

‎kbe/src/lib/server/entity_app.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ bool EntityApp<E>::installPyModules()
449449
ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.LOG_TYPE_WAR.\n");
450450
}
451451

452+
453+
if(PyModule_AddIntConstant(this->getScript().getModule(), "NEXT_ONLY", KBE_NEXT_ONLY))
454+
{
455+
ERROR_MSG( "EntityApp::installPyModules: Unable to set KBEngine.NEXT_ONLY.\n");
456+
}
457+
452458
onInstallPyModules();
453459
return true;
454460
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ void Archiver::tick()
7474
void Archiver::archive(Base& base)
7575
{
7676
base.writeToDB(NULL);
77+
78+
if(base.shouldAutoArchive() == KBE_NEXT_ONLY)
79+
base.shouldAutoArchive(0);
7780
}
7881

7982
//-------------------------------------------------------------------------------------
@@ -86,7 +89,9 @@ void Archiver::createArchiveTable()
8689

8790
for(; iter != Baseapp::getSingleton().pEntities()->getEntities().end(); iter++)
8891
{
89-
if(static_cast<Base*>(iter->second.get())->hasDB())
92+
Base* pBase = static_cast<Base*>(iter->second.get());
93+
94+
if(pBase->hasDB() && pBase->shouldAutoArchive() > 0)
9095
{
9196
backupEntityIDs_.push_back(iter->first);
9297
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ bool BackupSender::backup(Base& base, MemoryStream& s)
8282
{
8383
// 这里开始将需要备份的数据写入流
8484
base.writeBackupData(&s);
85+
86+
if(base.shouldAutoBackup() == KBE_NEXT_ONLY)
87+
base.shouldAutoBackup(0);
88+
8589
return true;
8690
}
8791

@@ -94,7 +98,10 @@ void BackupSender::createBackupTable()
9498

9599
for(; iter != Baseapp::getSingleton().pEntities()->getEntities().end(); iter++)
96100
{
97-
backupEntityIDs_.push_back(iter->first);
101+
Base* pBase = static_cast<Base*>(iter->second.get());
102+
103+
if(pBase->shouldAutoBackup() > 0)
104+
backupEntityIDs_.push_back(iter->first);
98105
}
99106

100107
// 随机一下序列

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

Lines changed: 83 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ SCRIPT_MEMBER_DECLARE_BEGIN(Base)
4646
SCRIPT_MEMBER_DECLARE_END()
4747

4848
ENTITY_GETSET_DECLARE_BEGIN(Base)
49-
SCRIPT_GET_DECLARE("cell", pyGetCellMailbox, 0, 0)
50-
SCRIPT_GET_DECLARE("client", pyGetClientMailbox, 0, 0)
51-
SCRIPT_GET_DECLARE("databaseID", pyGetDBID, 0, 0)
49+
SCRIPT_GET_DECLARE("cell", pyGetCellMailbox, 0, 0)
50+
SCRIPT_GET_DECLARE("client", pyGetClientMailbox, 0, 0)
51+
SCRIPT_GET_DECLARE("databaseID", pyGetDBID, 0, 0)
52+
SCRIPT_GETSET_DECLARE("shouldAutoBackup", pyGetShouldAutoBackup, pySetShouldAutoBackup, 0, 0)
53+
SCRIPT_GETSET_DECLARE("shouldAutoArchive", pyGetShouldAutoArchive, pySetShouldAutoArchive, 0, 0)
5254
ENTITY_GETSET_DECLARE_END()
5355
BASE_SCRIPT_INIT(Base, 0, 0, 0, 0, 0)
5456

@@ -64,6 +66,8 @@ hasDB_(false),
6466
DBID_(0),
6567
isGetingCellData_(false),
6668
isArchiveing_(false),
69+
shouldAutoArchive_(1),
70+
shouldAutoBackup_(1),
6771
creatingCell_(false),
6872
createdSpace_(false),
6973
inRestore_(false)
@@ -123,7 +127,7 @@ void Base::onDestroy(void)
123127
}
124128

125129
//-------------------------------------------------------------------------------------
126-
bool Base::installCellDataAttr(PyObject* dictData)
130+
bool Base::installCellDataAttr(PyObject* dictData, bool installpy)
127131
{
128132
if(dictData != NULL)
129133
{
@@ -136,15 +140,22 @@ bool Base::installCellDataAttr(PyObject* dictData)
136140
Py_INCREF(cellDataDict_);
137141
}
138142
}
139-
else if(cellDataDict_ == NULL)
140-
cellDataDict_ = PyDict_New();
141-
142-
if(PyObject_SetAttrString(this, "cellData", cellDataDict_) == -1)
143+
144+
if(installpy)
143145
{
144-
ERROR_MSG("Base::installCellDataAttr: set property cellData is error!\n");
145-
SCRIPT_ERROR_CHECK();
146-
return false;
146+
if(cellDataDict_ == NULL)
147+
{
148+
cellDataDict_ = PyDict_New();
149+
}
150+
151+
if(PyObject_SetAttrString(this, "cellData", cellDataDict_) == -1)
152+
{
153+
ERROR_MSG("Base::installCellDataAttr: set property cellData is error!\n");
154+
SCRIPT_ERROR_CHECK();
155+
return false;
156+
}
147157
}
158+
148159
return true;
149160
}
150161

@@ -456,6 +467,9 @@ void Base::onDestroyEntity(bool deleteFromDB, bool writeToDB)
456467
{
457468
this->hasDB(false);
458469
}
470+
471+
shouldAutoArchive_ = 0;
472+
shouldAutoBackup_ = 0;
459473
}
460474

461475
//-------------------------------------------------------------------------------------
@@ -510,6 +524,64 @@ PyObject* Base::pyGetClientMailbox()
510524
return mailbox;
511525
}
512526

527+
//-------------------------------------------------------------------------------------
528+
int Base::pySetShouldAutoArchive(PyObject *value)
529+
{
530+
if(isDestroyed())
531+
{
532+
PyErr_Format(PyExc_AssertionError, "%s: %d is destroyed!\n",
533+
getScriptName(), getID());
534+
PyErr_PrintEx(0);
535+
return 0;
536+
}
537+
538+
if(!PyLong_Check(value))
539+
{
540+
PyErr_Format(PyExc_AssertionError, "%s: %d set shouldAutoArchive value is not int!\n",
541+
getScriptName(), getID());
542+
PyErr_PrintEx(0);
543+
return 0;
544+
}
545+
546+
shouldAutoArchive_ = (int8)PyLong_AsLong(value);
547+
return 0;
548+
}
549+
550+
//-------------------------------------------------------------------------------------
551+
PyObject* Base::pyGetShouldAutoArchive()
552+
{
553+
return PyLong_FromLong(shouldAutoArchive_);
554+
}
555+
556+
//-------------------------------------------------------------------------------------
557+
int Base::pySetShouldAutoBackup(PyObject *value)
558+
{
559+
if(isDestroyed())
560+
{
561+
PyErr_Format(PyExc_AssertionError, "%s: %d is destroyed!\n",
562+
getScriptName(), getID());
563+
PyErr_PrintEx(0);
564+
return 0;
565+
}
566+
567+
if(!PyLong_Check(value))
568+
{
569+
PyErr_Format(PyExc_AssertionError, "%s: %d set shouldAutoBackup value is not int!\n",
570+
getScriptName(), getID());
571+
PyErr_PrintEx(0);
572+
return 0;
573+
}
574+
575+
shouldAutoBackup_ = (int8)PyLong_AsLong(value);
576+
return 0;
577+
}
578+
579+
//-------------------------------------------------------------------------------------
580+
PyObject* Base::pyGetShouldAutoBackup()
581+
{
582+
return PyLong_FromLong(shouldAutoBackup_);
583+
}
584+
513585
//-------------------------------------------------------------------------------------
514586
void Base::onCreateCellFailure(void)
515587
{

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Base : public script::ScriptObject
119119
/**
120120
cellData部分
121121
*/
122-
bool installCellDataAttr(PyObject* dictData = NULL);
122+
bool installCellDataAttr(PyObject* dictData = NULL, bool installpy = true);
123123

124124
void createCellData(void);
125125

@@ -247,6 +247,20 @@ class Base : public script::ScriptObject
247247
void reqTeleportOther(Mercury::Channel* pChannel, ENTITY_ID reqTeleportEntityID,
248248
COMPONENT_ID reqTeleportEntityCellAppID, COMPONENT_ID reqTeleportEntityBaseAppID);
249249

250+
/**
251+
设置获取是否自动存档
252+
*/
253+
INLINE int8 shouldAutoArchive()const;
254+
INLINE void shouldAutoArchive(int8 v);
255+
DECLARE_PY_GETSET_MOTHOD(pyGetShouldAutoArchive, pySetShouldAutoArchive);
256+
257+
/**
258+
设置获取是否自动备份
259+
*/
260+
INLINE int8 shouldAutoBackup()const;
261+
INLINE void shouldAutoBackup(int8 v);
262+
DECLARE_PY_GETSET_MOTHOD(pyGetShouldAutoBackup, pySetShouldAutoBackup);
263+
250264
protected:
251265
// 这个entity的客户端mailbox cellapp mailbox
252266
EntityMailbox* clientMailbox_;
@@ -265,6 +279,12 @@ class Base : public script::ScriptObject
265279
// 是否正在存档中
266280
bool isArchiveing_;
267281

282+
// 是否进行自动存档 <= 0为false, 1为true, KBE_NEXT_ONLY为执行一次后自动为false
283+
int8 shouldAutoArchive_;
284+
285+
// 是否进行自动备份 <= 0为false, 1为true, KBE_NEXT_ONLY为执行一次后自动为false
286+
int8 shouldAutoBackup_;
287+
268288
// 是否正在创建cell中
269289
bool creatingCell_;
270290

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,24 @@ INLINE bool Base::inRestore()
8383
return inRestore_;
8484
}
8585

86+
INLINE int8 Base::shouldAutoArchive()const
87+
{
88+
return shouldAutoArchive_;
89+
}
90+
91+
INLINE void Base::shouldAutoArchive(int8 v)
92+
{
93+
shouldAutoArchive_ = v;
94+
}
95+
96+
INLINE int8 Base::shouldAutoBackup()const
97+
{
98+
return shouldAutoBackup_;
99+
}
100+
101+
INLINE void Base::shouldAutoBackup(int8 v)
102+
{
103+
shouldAutoBackup_ = v;
104+
}
105+
86106
}

‎kbe/src/server/cellapp/entity.cpp‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ SCRIPT_MEMBER_DECLARE_BEGIN(Entity)
6666
SCRIPT_MEMBER_DECLARE_END()
6767

6868
ENTITY_GETSET_DECLARE_BEGIN(Entity)
69-
SCRIPT_GET_DECLARE("base", pyGetBaseMailbox, 0, 0)
70-
SCRIPT_GET_DECLARE("client", pyGetClientMailbox, 0, 0)
71-
SCRIPT_GET_DECLARE("allClients", pyGetAllClients, 0, 0)
72-
SCRIPT_GET_DECLARE("otherClients", pyGetOtherClients, 0, 0)
73-
SCRIPT_GET_DECLARE("isWitnessed", pyIsWitnessed, 0, 0)
74-
SCRIPT_GET_DECLARE("hasWitness", pyHasWitness, 0, 0)
75-
SCRIPT_GETSET_DECLARE("position", pyGetPosition, pySetPosition, 0, 0)
76-
SCRIPT_GETSET_DECLARE("direction", pyGetDirection, pySetDirection, 0, 0)
77-
SCRIPT_GETSET_DECLARE("topSpeed", pyGetTopSpeed, pySetTopSpeed, 0, 0)
78-
SCRIPT_GETSET_DECLARE("topSpeedY", pyGetTopSpeedY, pySetTopSpeedY, 0, 0)
69+
SCRIPT_GET_DECLARE("base", pyGetBaseMailbox, 0, 0)
70+
SCRIPT_GET_DECLARE("client", pyGetClientMailbox, 0, 0)
71+
SCRIPT_GET_DECLARE("allClients", pyGetAllClients, 0, 0)
72+
SCRIPT_GET_DECLARE("otherClients", pyGetOtherClients, 0, 0)
73+
SCRIPT_GET_DECLARE("isWitnessed", pyIsWitnessed, 0, 0)
74+
SCRIPT_GET_DECLARE("hasWitness", pyHasWitness, 0, 0)
75+
SCRIPT_GETSET_DECLARE("position", pyGetPosition, pySetPosition, 0, 0)
76+
SCRIPT_GETSET_DECLARE("direction", pyGetDirection, pySetDirection, 0, 0)
77+
SCRIPT_GETSET_DECLARE("topSpeed", pyGetTopSpeed, pySetTopSpeed, 0, 0)
78+
SCRIPT_GETSET_DECLARE("topSpeedY", pyGetTopSpeedY, pySetTopSpeedY, 0, 0)
79+
SCRIPT_GETSET_DECLARE("shouldAutoBackup", pyGetShouldAutoBackup, pySetShouldAutoBackup, 0, 0)
7980
ENTITY_GETSET_DECLARE_END()
8081
BASE_SCRIPT_INIT(Entity, 0, 0, 0, 0, 0)
8182

@@ -1513,5 +1514,34 @@ void Entity::onRestore()
15131514
SCRIPT_OBJECT_CALL_ARGS0(this, const_cast<char*>("onRestore"));
15141515
}
15151516

1517+
//-------------------------------------------------------------------------------------
1518+
int Entity::pySetShouldAutoBackup(PyObject *value)
1519+
{
1520+
if(isDestroyed())
1521+
{
1522+
PyErr_Format(PyExc_AssertionError, "%s: %d is destroyed!\n",
1523+
getScriptName(), getID());
1524+
PyErr_PrintEx(0);
1525+
return 0;
1526+
}
1527+
1528+
if(!PyLong_Check(value))
1529+
{
1530+
PyErr_Format(PyExc_AssertionError, "%s: %d set shouldAutoBackup value is not int!\n",
1531+
getScriptName(), getID());
1532+
PyErr_PrintEx(0);
1533+
return 0;
1534+
}
1535+
1536+
shouldAutoBackup_ = (int8)PyLong_AsLong(value);
1537+
return 0;
1538+
}
1539+
1540+
//-------------------------------------------------------------------------------------
1541+
PyObject* Entity::pyGetShouldAutoBackup()
1542+
{
1543+
return PyLong_FromLong(shouldAutoBackup_);
1544+
}
1545+
15161546
//-------------------------------------------------------------------------------------
15171547
}

‎kbe/src/server/cellapp/entity.hpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,14 @@ class Entity : public script::ScriptObject
295295
脚本请求获得AOI范围内的entities
296296
*/
297297
DECLARE_PY_MOTHOD_ARG0(pyEntitiesInAOI);
298-
public:
298+
299+
/**
300+
设置获取是否自动备份
301+
*/
302+
INLINE int8 shouldAutoBackup()const;
303+
INLINE void shouldAutoBackup(int8 v);
304+
DECLARE_PY_GETSET_MOTHOD(pyGetShouldAutoBackup, pySetShouldAutoBackup);
305+
299306
/** 网络接口
300307
远程呼叫本entity的方法
301308
*/
@@ -443,6 +450,9 @@ class Entity : public script::ScriptObject
443450

444451
Controllers* pControllers_; // 控制器管理器
445452
Controller* pMoveController_;
453+
454+
// 是否进行自动备份 <= 0为false, 1为true, KBE_NEXT_ONLY为执行一次后自动为false
455+
int8 shouldAutoBackup_;
446456
};
447457

448458

‎kbe/src/server/cellapp/entity.ipp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,15 @@ INLINE bool Entity::isOnGround()const
173173
return isOnGround_;
174174
}
175175

176+
INLINE int8 Entity::shouldAutoBackup()const
177+
{
178+
return shouldAutoBackup_;
179+
}
180+
181+
INLINE void Entity::shouldAutoBackup(int8 v)
182+
{
183+
shouldAutoBackup_ = v;
184+
}
185+
176186
//-------------------------------------------------------------------------------------
177187
}

0 commit comments

Comments
 (0)