//------------------------------------------------------------------------------------- void Proxy::giveClientTo(Proxy* proxy) { if(clientMailbox_ == NULL || clientMailbox_->getChannel() == NULL) { char err[255]; kbe_snprintf(err, 255, "Proxy[%s]::giveClientTo: no has client.", getScriptName()); PyErr_SetString(PyExc_TypeError, err); PyErr_PrintEx(0); onGiveClientToFailure(); return; } Mercury::Channel* lpChannel = clientMailbox_->getChannel(); if(proxy) { EntityMailbox* mb = proxy->getClientMailbox(); if(mb != NULL) { ERROR_MSG(boost::format("Proxy::giveClientTo: %1%[%2%] give client to %3%[%4%], %5% have clientMailbox.\n") % getScriptName() % getID() % proxy->getScriptName() % proxy->getID() % proxy->getScriptName()); onGiveClientToFailure(); return; } if(getCellMailbox()) { // 通知cell丢失客户端 Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(CellappInterface::onResetWitness); (*pBundle) << this->getID(); getCellMailbox()->postMail((*pBundle)); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } entitiesEnabled_ = false; getClientMailbox()->addr(Mercury::Address::NONE); Py_DECREF(getClientMailbox()); proxy->onGiveClientTo(lpChannel); setClientMailbox(NULL); addr(Mercury::Address::NONE); if(proxy->getClientMailbox() != NULL) { // 通知client销毁当前entity Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(ClientInterface::onEntityDestroyed); (*pBundle) << this->getID(); proxy->getClientMailbox()->postMail((*pBundle)); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } } }
//------------------------------------------------------------------------------------- void Proxy::onGiveClientTo(Mercury::Channel* lpChannel) { setClientMailbox(new EntityMailbox(this->scriptModule_, &lpChannel->addr(), 0, id_, MAILBOX_TYPE_CLIENT)); addr(lpChannel->addr()); Baseapp::getSingleton().createClientProxies(this); if(getCellMailbox()) { // 通知cell获得客户端 Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(CellappInterface::onGetWitness); getCellMailbox()->postMail((*pBundle)); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } }
//------------------------------------------------------------------------------------- void Proxy::giveClientTo(Proxy* proxy) { Mercury::Channel* lpChannel = clientMailbox_->getChannel(); if(lpChannel == NULL) { char err[255]; kbe_snprintf(err, 255, "Proxy[%s]::giveClientTo: no has client.\n", getScriptName()); PyErr_SetString(PyExc_TypeError, err); PyErr_PrintEx(0); onGiveClientToFailure(); return; } if(proxy) { EntityMailbox* mb = proxy->getClientMailbox(); if(mb != NULL) { ERROR_MSG("Proxy::giveClientTo: %s[%ld] give client to %s[%ld], %s have clientMailbox.", getScriptName(), getID(), proxy->getScriptName(), proxy->getID(), proxy->getScriptName()); onGiveClientToFailure(); return; } if(getCellMailbox()) { // 通知cell丢失客户端 Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject(); (*pBundle).newMessage(CellappInterface::onLoseWitness); getCellMailbox()->postMail((*pBundle)); Mercury::Bundle::ObjPool().reclaimObject(pBundle); } getClientMailbox()->addr(Mercury::Address::NONE); Py_DECREF(getClientMailbox()); proxy->onGiveClientTo(lpChannel); setClientMailbox(NULL); addr(Mercury::Address::NONE); } }
//------------------------------------------------------------------------------------- PyObject* Entity::pyGetCellMailbox() { EntityMailbox* mailbox = getCellMailbox(); if(mailbox == NULL) S_Return; Py_INCREF(mailbox); return mailbox; }
//------------------------------------------------------------------------------------- PyObject* Base::pyGetCellMailbox() { if(isDestroyed()) { PyErr_Format(PyExc_Exception, "%s: %d is destroyed!\n", getScriptName(), getID()); PyErr_PrintEx(0); S_Return; } EntityMailbox* mailbox = getCellMailbox(); if(mailbox == NULL) S_Return; Py_INCREF(mailbox); return mailbox; }