//------------------------------------------------------------------------------------- PyObject* BaseRemoteMethod::tp_call(PyObject* self, PyObject* args, PyObject* kwds) { BaseRemoteMethod* rmethod = static_cast<BaseRemoteMethod*>(self); MethodDescription* methodDescription = rmethod->getDescription(); EntityMailboxAbstract* mailbox = rmethod->getMailbox(); if (!mailbox->isClient() || mailbox->type() == MAILBOX_TYPE_CLIENT_VIA_CELL /* 需要先经过cell */ ) { return RemoteEntityMethod::tp_call(self, args, kwds); } Base* pEntity = Baseapp::getSingleton().findEntity(mailbox->id()); if(pEntity == NULL) { //WARNING_MSG(fmt::format("BaseRemoteMethod::callClientMethod: not found entity({}).\n", // mailbox->id())); return RemoteEntityMethod::tp_call(self, args, kwds); } // 如果是调用客户端方法, 我们记录事件并且记录带宽 if(methodDescription->checkArgs(args)) { Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); mailbox->newMail((*pBundle)); MemoryStream* mstream = MemoryStream::ObjPool().createObject(); methodDescription->addToStream(mstream, args); if(mstream->wpos() > 0) (*pBundle).append(mstream->data(), (int)mstream->wpos()); // 记录这个事件产生的数据量大小 g_privateClientEventHistoryStats.trackEvent(pEntity->scriptName(), methodDescription->getName(), pBundle->currMsgLength(), "::"); static_cast<Proxy*>(pEntity)->sendToClient(ClientInterface::onRemoteMethodCall, pBundle); MemoryStream::ObjPool().reclaimObject(mstream); } S_Return; }
//------------------------------------------------------------------------------------- PyObject* EntityMailboxAbstract::__py_reduce_ex__(PyObject* self, PyObject* protocol) { EntityMailboxAbstract* emailbox = static_cast<EntityMailboxAbstract*>(self); PyObject* args = PyTuple_New(2); PyObject* unpickleMethod = script::Pickler::getUnpickleFunc("Mailbox"); PyTuple_SET_ITEM(args, 0, unpickleMethod); PyObject* args1 = PyTuple_New(4); PyTuple_SET_ITEM(args1, 0, PyLong_FromLong(emailbox->id())); PyTuple_SET_ITEM(args1, 1, PyLong_FromUnsignedLongLong(emailbox->componentID())); PyTuple_SET_ITEM(args1, 2, PyLong_FromUnsignedLong(emailbox->utype())); int16 mbType = static_cast<int16>(emailbox->type()); PyTuple_SET_ITEM(args1, 3, PyLong_FromLong(mbType)); PyTuple_SET_ITEM(args, 1, args1); if(unpickleMethod == NULL){ Py_DECREF(args); return NULL; } return args; }