//------------------------------------------------------------------------------------- void Channel::destroy() { if(isDestroyed_) { CRITICAL_MSG("is channel has Destroyed!"); return; } isDestroyed_ = true; this->decRef(); }
//------------------------------------------------------------------------------------- void Base::addPersistentsDataToStream(uint32 flags, MemoryStream* s) { std::vector<ENTITY_PROPERTY_UID> log; // 再将base中存储属性取出 PyObject* pydict = PyObject_GetAttrString(this, "__dict__"); // 先将celldata中的存储属性取出 ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule_->getPersistentPropertyDescriptions(); ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin(); for(; iter != propertyDescrs.end(); iter++) { PropertyDescription* propertyDescription = iter->second; std::vector<ENTITY_PROPERTY_UID>::const_iterator finditer = std::find(log.begin(), log.end(), propertyDescription->getUType()); if(finditer != log.end()) continue; const char* attrname = propertyDescription->getName(); if(propertyDescription->isPersistent() && (flags & propertyDescription->getFlags()) > 0) { PyObject *key = PyUnicode_FromString(attrname); if(PyDict_Contains(cellDataDict_, key) > 0) { PyObject* pyVal = PyDict_GetItemString(cellDataDict_, attrname); (*s) << propertyDescription->getUType(); log.push_back(propertyDescription->getUType()); propertyDescription->getDataType()->addToStream(s, pyVal); DEBUG_PERSISTENT_PROPERTY("addCellPersistentsDataToStream", attrname); } else if(PyDict_Contains(pydict, key) > 0) { (*s) << propertyDescription->getUType(); log.push_back(propertyDescription->getUType()); propertyDescription->getDataType()->addToStream(s, PyDict_GetItem(pydict, key)); DEBUG_PERSISTENT_PROPERTY("addBasePersistentsDataToStream", attrname); } else { CRITICAL_MSG("%s::addPersistentsDataToStream: %d not found Persistent[%s].\n", this->getScriptName(), this->getID(), attrname); } Py_DECREF(key); } } Py_XDECREF(pydict); }
void DistortionMesh::createIndexBuffer() { HRESULT hr = indexBuffer_.create( nIndices_ / 2, D3DFMT_INDEX16, D3DUSAGE_WRITEONLY, D3DPOOL_DEFAULT ); if (SUCCEEDED(hr)) { Moo::IndicesReference ir = indexBuffer_.lock( 0 ); int offset = 0; if (ir.valid()) { uint16 lastIndex = 0; for (int y = 0; y < nIndicesY_; y++) { uint16 rowIndex = y * nVertsX_; ir[offset++] = lastIndex; ir[offset++] = rowIndex + nVertsX_; for (int x = 0; x < nVertsX_; x++) { lastIndex = x + rowIndex; ir[offset++] = lastIndex + nVertsX_; ir[offset++] = lastIndex; } } indexBuffer_.unlock(); } else { CRITICAL_MSG( "DistortionMesh::createIndexBuffer: Unable to lock index buffer" ); } } else { CRITICAL_MSG( "DistortionMesh::createIndexBuffer: Unable create index buffer" ); } }
//------------------------------------------------------------------------------------- bool DBInterfaceMysql::checkEnvironment() { std::string querycmd = "SHOW VARIABLES"; if(!query(querycmd.c_str(), querycmd.size(), true)) { ERROR_MSG(fmt::format("DBInterfaceMysql::checkEnvironment: {}, query is error!\n", querycmd)); return false; } bool lower_case_table_names = false; MYSQL_RES * pResult = mysql_store_result(mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { std::string s = arow[0]; std::string v = arow[1]; if(s == "lower_case_table_names") { if(v != "1") { lower_case_table_names = true; } else { CRITICAL_MSG(fmt::format("DBInterfaceMysql::checkEnvironment: [my.cnf or my.ini]->lower_case_table_names != 0, curr={}!\n" "Windows use cmd('sc qc MySQL|find \".ini\"') to view the configuration directory.\n", v)); } } else if(s == "max_allowed_packet") { uint64 size; KBEngine::StringConv::str2value(size, v.c_str()); sql_max_allowed_packet_ = (size_t)size; } } mysql_free_result(pResult); } return lower_case_table_names; }
void EntityApp<E>::onSignalled(int sigNum) { this->ServerApp::onSignalled(sigNum); switch (sigNum) { case SIGQUIT: CRITICAL_MSG(boost::format("Received QUIT signal. This is likely caused by the " "%1%Mgr killing this %2% because it has been " "unresponsive for too long. Look at the callstack from " "the core dump to find the likely cause.\n") % COMPONENT_NAME_EX(componentType_) % COMPONENT_NAME_EX(componentType_) ); break; default: break; } }
//------------------------------------------------------------------------------------- bool NetworkInterface::registerChannel(Channel* pChannel) { const Address & addr = pChannel->addr(); KBE_ASSERT(addr.ip != 0); KBE_ASSERT(&pChannel->networkInterface() == this); ChannelMap::iterator iter = channelMap_.find(addr); Channel * pExisting = iter != channelMap_.end() ? iter->second : NULL; if(pExisting) { CRITICAL_MSG("NetworkInterface::registerChannel: channel %s is exist.\n", \ pChannel->c_str()); return false; } channelMap_[addr] = pChannel; INFO_MSG("NetworkInterface::registerChannel: new channel: %s.\n", pChannel->c_str()); return true; }
void packFooter( TYPE value ) { msgEndOffset_ -= sizeof( TYPE ); switch( sizeof( TYPE ) ) { case sizeof( uint8 ): *(TYPE*)this->back() = value; break; case sizeof( uint16 ): *(TYPE*)this->back() = BW_HTONS( value ); break; case sizeof( uint32 ): *(TYPE*)this->back() = BW_HTONL( value ); break; default: CRITICAL_MSG( "Footers of size %zu aren't supported", sizeof( TYPE ) ); } }
bool NetworkHandlerImpl::init() { assert(m_socket == INVALID_SOCKET); if(m_isIpv6) { m_socket = cocos_socket(AF_INET6, SOCK_STREAM, 0); } else { m_socket = cocos_socket(AF_INET, SOCK_STREAM, 0); } if(m_socket == INVALID_SOCKET) return false; int rtn = 0; if(m_isIpv6) { rtn = cocos_connect(m_socket, (struct sockaddr *)&m_serverAddr6, sizeof(m_serverAddr6)); } else { rtn = cocos_connect(m_socket, (struct sockaddr *)&m_serverAddr4, sizeof(m_serverAddr4)); } if(rtn != 0) { char str[256]; xy_snprintf(str, sizeof(str), "connect error: %d", cocos_get_last_error()); CRITICAL_MSG(str); cocos_close(m_socket); m_socket = INVALID_SOCKET; return false; } cocos_set_nonblocking(m_socket); cocos2d::CCDirector::sharedDirector()->getScheduler()->scheduleUpdateForTarget(this, 1, false); return true; }
//------------------------------------------------------------------------------------- bool DBInterfaceMysql::checkEnvironment() { std::string querycmd = "SHOW VARIABLES LIKE \"%lower_case_table_names%\""; if(!query(querycmd.c_str(), querycmd.size(), true)) { ERROR_MSG(boost::format("DBInterfaceMysql::checkEnvironment: %1%, query is error!\n") % querycmd); return false; } bool lower_case_table_names = false; MYSQL_RES * pResult = mysql_store_result(mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { std::string s = arow[0]; std::string v = arow[1]; if(s == "lower_case_table_names") { if(v != "1") { lower_case_table_names = true; } else { CRITICAL_MSG(boost::format("DBInterfaceMysql::checkEnvironment: [my.cnf or my.ini]->lower_case_table_names != 0, curr=%1%!\n") % v); } } break; } mysql_free_result(pResult); } return lower_case_table_names; }
//------------------------------------------------------------------------------------- bool NetworkInterface::deregisterChannel(Channel* pChannel) { const Address & addr = pChannel->addr(); KBE_ASSERT(pChannel->endpoint() != NULL); if(pChannelDeregisterHandler_) { pChannelDeregisterHandler_->onChannelDeregister(pChannel); } INFO_MSG("NetworkInterface::deregisterChannel: del channel: %s\n", pChannel->c_str()); if (!channelMap_.erase(addr)) { CRITICAL_MSG( "NetworkInterface::deregisterChannel: " "Channel not found %s!\n", pChannel->c_str() ); return false; } return true; }
//------------------------------------------------------------------------------------- void Channel::destroy() { if(isDestroyed_) { CRITICAL_MSG("is channel has Destroyed!"); return; } if(pNetworkInterface_ != NULL && pEndPoint_ != NULL) { pNetworkInterface_->onChannelGone(this); if(protocoltype_ == PROTOCOL_TCP) { pNetworkInterface_->dispatcher().deregisterFileDescriptor(*pEndPoint_); pEndPoint_->close(); } } stopInactivityDetection(); isDestroyed_ = true; this->decRef(); }
//------------------------------------------------------------------------------------- bool NetworkInterface::registerChannel(Channel* pChannel) { const Address & addr = pChannel->addr(); KBE_ASSERT(addr.ip != 0); KBE_ASSERT(&pChannel->networkInterface() == this); ChannelMap::iterator iter = channelMap_.find(addr); Channel * pExisting = iter != channelMap_.end() ? iter->second : NULL; if(pExisting) { CRITICAL_MSG(fmt::format("NetworkInterface::registerChannel: channel {} is exist.\n", pChannel->c_str())); return false; } channelMap_[addr] = pChannel; if(pChannel->isExternal()) numExtChannels_++; //INFO_MSG(fmt::format("NetworkInterface::registerChannel: new channel: {}.\n", pChannel->c_str())); return true; }
//------------------------------------------------------------------------------------- void ServerApp::reqKillServer(Network::Channel* pChannel, MemoryStream& s) { if(pChannel->isExternal()) return; COMPONENT_ID componentID; COMPONENT_TYPE componentType; std::string username; int32 uid; std::string reason; s >> componentID >> componentType >> username >> uid >> reason; INFO_MSG(fmt::format("ServerApp::reqKillServer: requester(uid:{}, username:{}, componentType:{}, " "componentID:{}, reason:{}, from {})\n", uid, username, COMPONENT_NAME_EX((COMPONENT_TYPE)componentType), componentID, reason, pChannel->c_str())); CRITICAL_MSG("The application was killed!\n"); }
//------------------------------------------------------------------------------------- void Base::addPersistentsDataToStream(uint32 flags, MemoryStream* s) { std::vector<ENTITY_PROPERTY_UID> log; // 再将base中存储属性取出 PyObject* pydict = PyObject_GetAttrString(this, "__dict__"); // 先将celldata中的存储属性取出 ScriptDefModule::PROPERTYDESCRIPTION_MAP& propertyDescrs = scriptModule_->getPersistentPropertyDescriptions(); ScriptDefModule::PROPERTYDESCRIPTION_MAP::const_iterator iter = propertyDescrs.begin(); if(scriptModule_->hasCell()) { addPositionAndDirectionToStream(*s); } for(; iter != propertyDescrs.end(); ++iter) { PropertyDescription* propertyDescription = iter->second; std::vector<ENTITY_PROPERTY_UID>::const_iterator finditer = std::find(log.begin(), log.end(), propertyDescription->getUType()); if(finditer != log.end()) continue; const char* attrname = propertyDescription->getName(); if(propertyDescription->isPersistent() && (flags & propertyDescription->getFlags()) > 0) { PyObject *key = PyUnicode_FromString(attrname); if(cellDataDict_ != NULL && PyDict_Contains(cellDataDict_, key) > 0) { PyObject* pyVal = PyDict_GetItemString(cellDataDict_, attrname); if(!propertyDescription->getDataType()->isSameType(pyVal)) { CRITICAL_MSG(fmt::format("{}::addPersistentsDataToStream: {} persistent[{}] type(curr_py: {} != {}) is error.\n", this->scriptName(), this->id(), attrname, (pyVal ? pyVal->ob_type->tp_name : "unknown"), propertyDescription->getDataType()->getName())); } else { (*s) << propertyDescription->getUType(); log.push_back(propertyDescription->getUType()); propertyDescription->addPersistentToStream(s, pyVal); DEBUG_PERSISTENT_PROPERTY("addCellPersistentsDataToStream", attrname); } } else if(PyDict_Contains(pydict, key) > 0) { PyObject* pyVal = PyDict_GetItem(pydict, key); if(!propertyDescription->getDataType()->isSameType(pyVal)) { CRITICAL_MSG(fmt::format("{}::addPersistentsDataToStream: {} persistent[{}] type(curr_py: {} != {}) is error.\n", this->scriptName(), this->id(), attrname, (pyVal ? pyVal->ob_type->tp_name : "unknown"), propertyDescription->getDataType()->getName())); } else { (*s) << propertyDescription->getUType(); log.push_back(propertyDescription->getUType()); propertyDescription->addPersistentToStream(s, pyVal); DEBUG_PERSISTENT_PROPERTY("addBasePersistentsDataToStream", attrname); } } else { CRITICAL_MSG(fmt::format("{}::addPersistentsDataToStream: {} not found Persistent[{}].\n", this->scriptName(), this->id(), attrname)); } Py_DECREF(key); } SCRIPT_ERROR_CHECK(); } Py_XDECREF(pydict); SCRIPT_ERROR_CHECK(); }
//------------------------------------------------------------------------------------- void Channel::handleMessage(KBEngine::Mercury::MessageHandlers* pMsgHandlers) { if (this->isDestroyed()) { ERROR_MSG("Channel::handleMessage(%s): channel[%p] is destroyed.\n", this->c_str(), this); return; } if(this->isCondemn()) { ERROR_MSG("Channel::handleMessage(%s): channel[%p] is condemn.\n", this->c_str(), this); //this->destroy(); return; } try { BufferedReceives::iterator packetIter = bufferedReceives_.begin(); for(; packetIter != bufferedReceives_.end(); packetIter++) { Packet* pPacket = (*packetIter); while(pPacket->totalSize() > 0) { if(fragmentDatasFlag_ == FRAGMENT_DATA_UNKNOW) { if(currMsgID_ == 0) { if(MERCURY_MESSAGE_ID_SIZE > 1 && pPacket->opsize() < MERCURY_MESSAGE_ID_SIZE) { writeFragmentMessage(FRAGMENT_DATA_MESSAGE_ID, pPacket, MERCURY_MESSAGE_ID_SIZE); break; } (*pPacket) >> currMsgID_; pPacket->messageID(currMsgID_); } Mercury::MessageHandler* pMsgHandler = pMsgHandlers->find(currMsgID_); if(pMsgHandler == NULL) { TRACE_BUNDLE_DATA(true, pPacket, pMsgHandler, pPacket->totalSize()); WARNING_MSG("Channel::handleMessage: invalide msgID=%d, msglen=%d, from %s.\n", currMsgID_, pPacket->totalSize(), c_str()); currMsgID_ = 0; currMsgLen_ = 0; condemn(); break; } TRACE_BUNDLE_DATA(true, pPacket, pMsgHandler, pPacket->totalSize()); // 如果没有可操作的数据了则退出等待下一个包处理。 //if(pPacket->opsize() == 0) // 可能是一个无参数数据包 // break; if(currMsgLen_ == 0) { if(pMsgHandler->msgLen == MERCURY_VARIABLE_MESSAGE || g_packetAlwaysContainLength) { // 如果长度信息不完整, 则等待下一个包处理 if(pPacket->opsize() < MERCURY_MESSAGE_LENGTH_SIZE) { writeFragmentMessage(FRAGMENT_DATA_MESSAGE_LENGTH, pPacket, MERCURY_MESSAGE_LENGTH_SIZE); break; } else (*pPacket) >> currMsgLen_; } else currMsgLen_ = pMsgHandler->msgLen; } if(currMsgLen_ > MERCURY_MESSAGE_MAX_SIZE / 2) { WARNING_MSG("Channel::handleMessage(%s): msglen is error! msgID=%d, msglen=(%d:%d), from %s.\n", pMsgHandler->name.c_str(), currMsgID_, currMsgLen_, pPacket->totalSize(), c_str()); currMsgLen_ = 0; condemn(); break; } if(pFragmentStream_ != NULL) { pMsgHandler->handle(this, *pFragmentStream_); MemoryStream::ObjPool().reclaimObject(pFragmentStream_); pFragmentStream_ = NULL; } else { if(pPacket->opsize() < currMsgLen_) { writeFragmentMessage(FRAGMENT_DATA_MESSAGE_BODY, pPacket, currMsgLen_); break; } // 临时设置有效读取位, 防止接口中溢出操作 size_t wpos = pPacket->wpos(); // size_t rpos = pPacket->rpos(); size_t frpos = pPacket->rpos() + currMsgLen_; pPacket->wpos(frpos); pMsgHandler->handle(this, *pPacket); // 防止handle中没有将数据导出获取非法操作 if(currMsgLen_ > 0) { if(frpos != pPacket->rpos()) { CRITICAL_MSG("Channel::handleMessage(%s): rpos(%d) invalid, expect=%d. msgID=%d, msglen=%d.\n", pMsgHandler->name.c_str(), pPacket->rpos(), frpos, currMsgID_, currMsgLen_); pPacket->rpos(frpos); } } pPacket->wpos(wpos); } currMsgID_ = 0; currMsgLen_ = 0; } else { mergeFragmentMessage(pPacket); } } if(pPacket->isTCPPacket()) TCPPacket::ObjPool().reclaimObject(static_cast<TCPPacket*>(pPacket)); else UDPPacket::ObjPool().reclaimObject(static_cast<UDPPacket*>(pPacket)); }