void closeFile (uint8_t channel) { struct channelTableStruct *channelStruct = &channelTable[channel]; if ((channelStruct->readDirState == NOT_READ_DIR) && (channelStruct->fileState == WRITE_FILE)) { struct dirEntryStruct *entry; /* save last block */ writeFile (channel); channelStruct->dirEntry.bytesInLastBlock = channelStruct->bufferPtr; getBlock (channelStruct->dirBlock); if (!(entry = getEntryByName (channelStruct->dirEntry.fileName))) { return; /* FIXME, cleanup */ } /* write inode */ ataPutBlock (channelStruct->inodeBlock, (uint8_t *)(channelStruct->inode)); /* copy back direntry */ memcpy (entry, &channelStruct->dirEntry, sizeof (struct dirEntryStruct)); entry->splat = FALSE; dirBufferChanged = TRUE; flushDirBuffer(); /* flush free block list */ flushFreeBlockList(); } channelStruct->fileState = NO_FILE; }
/** * \brief 发送私聊消息给好友,如果对方不在则存为离线消息 * \param pCmd 聊天消息 * \param cmdLen 消息长度 * \return */ void CRelationManager::sendPrivateChatToFriend(const Cmd::stChannelChatUserCmd *pCmd,const DWORD cmdLen) { //rwlock.rdlock(); CRelation *rel = (CRelation *)getEntryByName(pCmd->pstrName); if (rel) { BYTE buf[x_socket::MAX_DATASIZE]; Cmd::stChannelChatUserCmd *chatCmd; chatCmd = (Cmd::stChannelChatUserCmd *)buf; memcpy(chatCmd,pCmd,cmdLen,sizeof(buf)); strncpy(chatCmd->pstrName,user->name,MAX_NAMESIZE); if (rel->isOnline()) { UserSession *pUser = UserSessionManager::getInstance()->getUserByID(rel->id); if (pUser) pUser->sendCmdToMe(chatCmd,cmdLen); } else { COfflineMessage::writeOfflineMessage(chatCmd->dwType,rel->id,chatCmd,cmdLen); } } //rwlock.unlock(); }
/** * \brief 改变社会关系类型,发送通知并更新数据库记录 * \param name 对端名称 * \param type 社会关系类型 */ void CRelationManager::changeRelationType(const char * name,const BYTE type) { CRelation *relation = NULL; relation = (CRelation *)getEntryByName(name); if (relation) { zRTime ctv; //rwlock.wrlock(); if (Cmd::RELATION_TYPE_BAD == relation->type) { sendBlackListToGateway(name,Cmd::Session::BLACK_LIST_REMOVE); relation->level = 0; } if (Cmd::RELATION_TYPE_BAD == type) { sendBlackListToGateway(name,Cmd::Session::BLACK_LIST_ADD); relation->level = 0; relation->lasttime = ctv.sec(); } relation->type = type; relation->sendNotifyToScene(); sendStatusChange(relation,Cmd::RELATION_TYPECHANGE); updateDBRecord(relation); //rwlock.unlock(); } }
inline extern bool_t renameEntry (char *newName, char *oldNamePattern) { struct dirEntryStruct *entry; getBlock (currentDir); if ((entry = getEntryByName (oldNamePattern))) { block_t blockWithEntry = dirBufferBlock; if (!getEntryByName (newName)) { getBlock (blockWithEntry); memcpy (entry->fileName, newName, FILE_NAME_SIZE); dirBufferChanged = TRUE; flushDirBuffer(); return TRUE; } } return FALSE; }
bool Zips::read(const char* name, file::buffer& bf) { MutexAutoLock al(_lock); const file_entry* entry = getEntryByName(name); if (!entry) return false; return readEntry(entry, bf); }
bool CFormDfn::getEntryDfnByName (const std::string &name, UFormDfn **dfn) { CFormDfn::CEntry *entry; if (getEntryByName (name, &entry)) { *dfn=entry->getDfnPtr(); return true; } *dfn=NULL; return false; }
/** * \brief 删除简单社会关系 * \param name 被删除者的名字 */ void CRelationManager::removeRelation(const char * name) { CRelation *pRelation = NULL; //rwlock.rdlock(); pRelation = (CRelation *)getEntryByName(name); //rwlock.unlock(); if (pRelation) { //rwlock.wrlock(); deleteDBRecord(pRelation->id); removeEntry(pRelation); //rwlock.unlock(); sendStatusChange(pRelation,Cmd::RELATION_REMOVE); if (Cmd::RELATION_TYPE_BAD == pRelation->type) sendBlackListToGateway(name,Cmd::Session::BLACK_LIST_REMOVE); if (Cmd::RELATION_TYPE_BAD != pRelation->type) pRelation->sendNotifyToScene(); SAFE_DELETE(pRelation); } }
inline extern bool_t createDir (char *name) { struct dirEntryStruct *entry; getBlock (currentDir); if (nameValid (name)) { if ((entry = getUnusedEntry())) {// nicht mehr als 256 , da dir nicht mehr ausgibt! if (!getEntryByName (name)) { //alle entrys auch files! if ((entry->startBlock = allocateBlock())) { dirBufferChanged = TRUE; /* set entry */ memcpy (entry->fileName, name, FILE_NAME_SIZE); entry->fileSize = 0; entry->fileType = DIR; entry->readOnly = FALSE; entry->splat = FALSE; { /* init new directory block */ getBlock (entry->startBlock); memset (&dirBuffer, '\0', BLOCKSIZE); dirBuffer.dirEntry[0].startBlock = currentDir; memcpy_P (dirBuffer.dirEntry[0].fileName, PSTR ("."), 3); dirBuffer.dirEntry[0].fileSize = 0; dirBuffer.dirEntry[0].fileType = DIR; dirBuffer.dirEntry[0].readOnly = TRUE; dirBuffer.dirEntry[0].splat = FALSE; dirBufferChanged = TRUE; } flushDirBuffer(); flushFreeBlockList(); return TRUE; } } } } return FALSE; }
bool_t setCurrentDir (char *path) { struct dirEntryStruct *entry; block_t nextCurrentDir = 0; if (*path == '/') { path++; nextCurrentDir = ROOTBLOCK; getBlock (ROOTBLOCK); } else { getBlock (currentDir); } while (TRUE) { if (!(*path)) { currentDir = nextCurrentDir; dirBufferBlockNumber = ~0; return TRUE; } if (!(entry = getEntryByName (path))) { /* can't find dir */ return FALSE; } if (entry->fileType != DIR) { /* not a dir */ return FALSE; } nextCurrentDir = entry->startBlock; if (!(path = strchr (path, '/'))) { /* no more elements in path */ currentDir = nextCurrentDir; dirBufferBlockNumber = ~0; return TRUE; } path++; /* skip '/' */ getBlock (entry->startBlock); } }
inline extern bool_t openWrite (char *name, uint8_t fileType, uint8_t channel) { struct dirEntryStruct *entry; struct channelTableStruct *channelStruct = &channelTable[channel]; if (nameValid (name)) { if (channelStruct->fileState == NO_FILE) { getBlock (currentDir); if (!getEntryByName (name)) { if ((entry = getUnusedEntry())) { /* create first inode */ memset (&(channelStruct->inode), '\0', BLOCKSIZE); if ((channelStruct->inodeBlock = allocateBlock())) { /* set entry */ entry->startBlock = channelStruct->inodeBlock; memcpy (entry->fileName, name, FILE_NAME_SIZE); entry->fileSize = 0; entry->fileType = fileType; entry->splat = TRUE; /* set channel struct */ memcpy (&channelStruct->dirEntry, entry, sizeof (struct dirEntryStruct)); channelStruct->dirBlock = currentDir; channelStruct->inodePtr = 0; /* save entry to disk */ dirBufferChanged = TRUE; flushDirBuffer(); return TRUE; } } } } } return FALSE; }
inline extern bool_t openRead (char *pattern, uint8_t fileType, uint8_t channel) { struct dirEntryStruct *entry; struct channelTableStruct *channelStruct = &channelTable[channel]; if (channelStruct->fileState == NO_FILE) { getBlock (currentDir); if ((entry = getEntryByName (pattern))) { if ((fileType == ANY) || (entry->fileType == fileType)) { /* TODO: should perhaps have some kind of file lock here */ /* set channel struct */ memcpy (&channelStruct->dirEntry, entry, sizeof (struct dirEntryStruct)); channelStruct->inodePtr = 0; channelStruct->dirBlock = currentDir; /* read first inode block into mem */ ataGetBlock (entry->startBlock,(uint8_t *)(channelStruct->inode)); return TRUE; } } } return FALSE; }
bool Zips::isExists(const char* name) { MutexAutoLock al(_lock); return getEntryByName(name) != 0; }
/** * \brief 增加一个黑名单类型的关系 * \param name 上黑名单者 */ void CRelationManager::addEnemyRelation(const char *name) { int iCount=0; CRelation *lastPoint = NULL; zRTime ctv; DWORD dwLastTime = ctv.sec(); for(zEntryName::hashmap::iterator it=zEntryName::ets.begin();it!=zEntryName::ets.end();it++) { CRelation *temp = (CRelation *)it->second; if (temp && (temp->type == Cmd::RELATION_TYPE_ENEMY)) { iCount++; if (dwLastTime >= temp->lasttime) { dwLastTime = temp->lasttime; lastPoint = temp; } } } if (iCount>=5 && lastPoint) { this->deleteDBRecord(lastPoint->id); this->removeEntry(lastPoint); } CRelation *relation = NULL; relation = (CRelation *)getEntryByName(name); if (relation) { } else { UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(name); if (otherUser) { CRelation *relation = NULL; zRTime ctv; relation = new CRelation(); if (relation) { relation->id = otherUser->id; relation->level = 0; strncpy(relation->name,otherUser->name,MAX_NAMESIZE); relation->type = Cmd::RELATION_TYPE_ENEMY; relation->lasttime = ctv.sec(); relation->occupation = otherUser->occupation; //rwlock.wrlock(); addEntry(relation); //rwlock.unlock(); insertDBRecord(relation); sendStatusChange(relation,Cmd::RELATION_ADD); } if (user) user->sendSysChat(Cmd::INFO_TYPE_GAME,"将 %s 加入了仇人列表",name); } } }
/** * \brief 增加一个黑名单类型的关系 * \param name 上黑名单者 */ void CRelationManager::addBadRelation(const char *name) { CRelation *relation = NULL; relation = (CRelation *)getEntryByName(name); if (relation) { if (Cmd::RELATION_TYPE_BAD == relation->type) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方已经在黑名单列表中"); } else { if (Cmd::RELATION_TYPE_LOVE == relation->type) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"必须先离婚才能将其加入黑名单!"); return; } UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(name); if (otherUser) { otherUser->relationManager.removeRelation(user->name); otherUser->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"%s选择和你恩断义绝",user->name); } else { CRelation *relation = NULL; relation = (CRelation *)getEntryByName(name); if (relation) writeOfflineNotify(relation); } changeRelationType(name,Cmd::RELATION_TYPE_BAD); } } else { UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(name); if (otherUser) { CRelation *relation = NULL; zRTime ctv; relation = new CRelation(); if (relation) { relation->id = otherUser->id; relation->level = 0; strncpy(relation->name,otherUser->name,MAX_NAMESIZE); relation->type = Cmd::RELATION_TYPE_BAD; relation->lasttime = ctv.sec(); relation->occupation = otherUser->occupation; //if (insertDBRecord(relation)) //{ //rwlock.wrlock(); addEntry(relation); //rwlock.unlock(); insertDBRecord(relation); sendStatusChange(relation,Cmd::RELATION_ADD); sendBlackListToGateway(name,Cmd::Session::BLACK_LIST_ADD); //} //else //{ // if (user) user->sendSysChat(Cmd::INFO_TYPE_GAME,"将 %s 加入黑名单失败",name); // SAFE_DELETE(relation); //} } if (user) user->sendSysChat(Cmd::INFO_TYPE_GAME,"将 %s 加入了黑名单",name); } else { if (user) user->sendSysChat(Cmd::INFO_TYPE_FAIL,"人不在线无法确认"); } } }
/** * \brief 根据对端关系名获取关系对象 * \param name 对端关系名 * \return 简单社会关系对象 */ CRelation * CRelationManager::getRelationByName(const char *name) { return (CRelation *)getEntryByName(name); }
/** * \brief 处理Gateway转发过来的客户端消息 * \param pNullCmd 消息体 * \param cmdLen 消息长度 * \return true 处理完毕,false 不在处理范围之中 */ bool CRelationManager::processUserMessage(const Cmd::stNullUserCmd *pNullCmd,const DWORD cmdLen) { switch(pNullCmd->byCmd) { case Cmd::RELATION_USERCMD: { switch(pNullCmd->byParam) { case UNMARRY_PARA: { CRelation* relation = NULL; relation = getMarryRelation(); if (relation) { UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(relation->name); if (otherUser) { removeRelation(relation->name); otherUser->relationManager.removeRelation(user->name); otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"%s选择和你离婚",user->name); otherUser->updateConsort(); } else { CRelation *tRelation = NULL; tRelation = (CRelation *)getEntryByName(relation->name); if (tRelation) writeOfflineNotify(tRelation); removeRelation(relation->name); } user->updateConsort(); } } break; case Cmd::RELATION_STATUS_PARA: { Cmd::stRelationStatusCmd *rev = (Cmd::stRelationStatusCmd *)pNullCmd; switch(rev->byState) { case Cmd::RELATION_ADD: { if (!strncmp(rev->name,user->name,MAX_NAMESIZE)) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"不能把自己加入名单中?"); return true; } if (300>size()) { if (rev->type == Cmd::RELATION_TYPE_BAD) { addBadRelation(rev->name); } else { addEnemyRelation(rev->name); } } else { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"名单列表已满!"); } return true; } break; case Cmd::RELATION_ANSWER_NO: { UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserByID(rev->userid); if (otherUser) { switch(rev->type) { case Cmd::RELATION_TYPE_FRIEND: { otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不同意与你结为好友"); return true; } break; case Cmd::RELATION_TYPE_LOVE: { otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不同意与你结为夫妻"); } break; default: break; } } } break; case Cmd::RELATION_ANSWER_YES: { UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserByID(rev->userid); if (otherUser) { if (300>otherUser->relationManager.size()|| rev->type == Cmd::RELATION_TYPE_LOVE) { if (300>size() || rev->type == Cmd::RELATION_TYPE_LOVE) { addRelation(rev->userid,rev->type); otherUser->relationManager.addRelation(user->id,rev->type); if (rev->type != Cmd::RELATION_TYPE_LOVE) { otherUser->sendSysChat(Cmd::INFO_TYPE_ADDFRIEND,"你与 %s 义结金兰,成为好友",user->name); user->sendSysChat(Cmd::INFO_TYPE_ADDFRIEND,"你与 %s 义结金兰,成为好友",otherUser->name); } } else { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"我的好友列表已满"); otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方好友列表已满"); } } else { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方好友列表已满"); otherUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的好友列表已满"); } } } break; case Cmd::RELATION_QUESTION: //free 禁止好友功能 // user->sendSysChat(Cmd::INFO_TYPE_FAIL, "好友系统正在开 发中!"); // break; //#if 0 { if (!strncmp(rev->name,user->name,MAX_NAMESIZE)) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"你在开玩笑吗?加自己为好友!"); return true; } CRelation *relation = NULL; relation = (CRelation *)getEntryByName(rev->name); if (relation) { if (!strncmp(rev->name,relation->name,MAX_NAMESIZE) && Cmd::RELATION_TYPE_BAD != relation->type) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方已经在你的好友列表中了,无需再添加!"); return true; } } UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(rev->name); if (otherUser) { if (isset_state(otherUser->sysSetting,Cmd::USER_SETTING_FRIEND)) { user->sendSysChat(Cmd::INFO_TYPE_GAME,"好友请求已发送,等待对方应答!"); rev->userid = user->id; strncpy(rev->name,user->name,MAX_NAMESIZE); otherUser->sendCmdToMe(rev,sizeof(Cmd::stRelationStatusCmd)); } else user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方添加好友未开启"); } else { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"对方不在线不能响应你的邀请"); } //#endif break; } case Cmd::RELATION_REMOVE: { CRelation *rel = NULL; rel = (CRelation *)getEntryByName(rev->name); if (!rel) return true; int type = rel->type; if (Cmd::RELATION_TYPE_BAD == type || Cmd::RELATION_TYPE_ENEMY == type) { removeRelation(rev->name); // 删除黑名单成员 } else { if (Cmd::RELATION_TYPE_LOVE == type) { user->sendSysChat(Cmd::INFO_TYPE_FAIL,"你必须到民政官那里去办理离婚手续!"); return true; } UserSession *otherUser = NULL; otherUser = UserSessionManager::getInstance()->getUserSessionByName(rev->name); if (otherUser) { removeRelation(rev->name); otherUser->relationManager.removeRelation(user->name); otherUser->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"%s选择与你割席断交",user->name); user->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"你选择与 %s 割席断交",otherUser->name); otherUser->updateConsort(); } else { user->sendSysChat(Cmd::INFO_TYPE_BREAKFRIEND,"你选择与 %s 割席断交",rev->name); CRelation *relation = NULL; relation = (CRelation *)getEntryByName(rev->name); if (relation) writeOfflineNotify(relation); removeRelation(rev->name); } user->updateConsort(); } } break; } return true; } break; default: break; } } break; default: break; } return false; }