bool MailService::doMailCmd(const Cmd::t_NullCmd *cmd,const DWORD cmdLen) { using namespace Cmd; using namespace Cmd::Session; switch (cmd->para) { case PARA_SCENE_SENDMAIL: { t_sendMail_SceneSession * rev = (t_sendMail_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserSessionByName(rev->mail.fromName); if (!pUser) pUser = UserSessionManager::getInstance()->getUserByID(rev->mail.fromID); /*//取消这个身份确认,避免一些物品丢失 if (!pUser && rev->mail.type!=Cmd::Session::MAIL_TYPE_ACTIVITY) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_SENDMAIL): 发送邮件时未找到发送者 %s",rev->mail.fromName); return true; } */ if (sendMail(* rev)) { if (pUser) pUser->sendSysChat(Cmd::INFO_TYPE_GAME,"发送成功"); Zebra::logger->info("[邮件]邮件发送成功 %s->%s(%u)",rev->mail.fromName,rev->mail.toName,rev->mail.toID); UserSession * toUser = UserSessionManager::getInstance()->getUserSessionByName(rev->mail.toName); if (!toUser) toUser = UserSessionManager::getInstance()->getUserByID(rev->mail.toID); if (toUser) { Cmd::stNotifyNewMail n; toUser->sendCmdToMe(&n,sizeof(n)); } } return true; } break; case PARA_SCENE_GET_MAIL_LIST: { t_getMailList_SceneSession * rev = (t_getMailList_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->tempID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_LIST): 取得邮件列表时未找到玩家"); return true; } connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"取得邮件失败"); Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_LIST): 得到数据库句柄失败"); return true; } char where[128]; //得到邮件列表 bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"TOID=%u",pUser->id); mailHeadInfo *mailList; DWORD retcode = SessionService::dbConnPool->exeSelect(handle,"`MAIL`",mail_head_define,where,"DELTIME DESC",(BYTE **)&mailList); SessionService::dbConnPool->putHandle(handle); if (mailList) { for (DWORD i=0; i< retcode; i++) { if (mailList[i].state==MAIL_STATE_DEL) continue; stAddListMail al; al.id = mailList[i].id; al.state = mailList[i].state; if (MAIL_TYPE_AUCTION==mailList[i].type || MAIL_TYPE_SYS==mailList[i].type) al.type=1;//系统邮件 strncpy(al.fromName,mailList[i].fromName,MAX_NAMESIZE); if (mailList[i].accessory && !mailList[i].itemGot) al.accessory = true; else al.accessory = false; zRTime ct; al.endTime = mailList[i].delTime>ct.sec()?mailList[i].delTime-ct.sec():0; pUser->sendCmdToMe(&al,sizeof(al)); } } SAFE_DELETE_VEC(mailList); /* //得到邮件列表 std::string escapeName; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"TONAME='%s'",pUser->name); retcode = SessionService::dbConnPool->exeSelect(handle,"`MAIL`",mail_head_define,where,"DELTIME DESC",(BYTE **)&mailList); SessionService::dbConnPool->putHandle(handle); if (mailList) { for (DWORD i=0; i< retcode; i++) { if (mailList[i].state==MAIL_STATE_DEL || strncmp(mailList[i].toName,pUser->name,MAX_NAMESIZE)) continue; stAddListMail al; al.id = mailList[i].id; al.state = mailList[i].state; strncpy(al.fromName,mailList[i].fromName,MAX_NAMESIZE); if (mailList[i].accessory && !mailList[i].itemGot) al.accessory = true; else al.accessory = false; zRTime ct; al.endTime = mailList[i].delTime>ct.sec()?mailList[i].delTime-ct.sec():0; pUser->sendCmdToMe(&al,sizeof(al)); } } SAFE_DELETE_VEC(mailList); */ return true; } break; case PARA_SCENE_OPEN_MAIL: { t_openMail_SceneSession * rev = (t_openMail_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->tempID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_OPEN_MAIL): 打开邮件时未找到玩家"); return true; } connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"打开邮件失败"); Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_OPEN_MAIL): 得到数据库句柄失败"); return true; } std::string escapeName; char where[128]; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); mailContentInfo content; DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_content_define,where,NULL,1,(BYTE*)&content); if (1 != retcode ||content.state==MAIL_STATE_DEL ||(strncmp(content.toName,pUser->name,MAX_NAMESIZE) && content.toID!=pUser->id)) { SessionService::dbConnPool->putHandle(handle); return true; } if (content.state==MAIL_STATE_NEW) { mailStateInfo st; st.state = MAIL_STATE_OPENED; retcode = SessionService::dbConnPool->exeUpdate(handle,"`MAIL`",mail_state_define,(BYTE*)&st,where); newMailMap[content.toID].erase(rev->mailID);//从新邮件列表里删除 } SessionService::dbConnPool->putHandle(handle); stContentMail cm; cm.mailID = content.id; strncpy(cm.title,content.title,MAX_NAMESIZE); strncpy(cm.text,content.text,256); if (content.accessory>0 && content.itemGot==0) { cm.accessory = true; cm.sendMoney = content.sendMoney; cm.recvMoney = content.recvMoney; cm.sendGold = content.sendGold; cm.recvGold = content.recvGold; bcopy(&content.item.object,&cm.item,sizeof(t_Object),sizeof(cm.item)); } else { cm.accessory = false; } pUser->sendCmdToMe(&cm,sizeof(cm)); #ifdef _DEBUG //Zebra::logger->debug("[邮件]%s 打开邮件 id=%u 物品:thisID=%u ObjectID=%u",pUser->name,cm.mailID,cm.item.qwThisID,cm.item.dwObjectID); #endif return true; } break; case PARA_SCENE_GET_MAIL_ITEM: { t_getMailItem_SceneSession * rev = (t_getMailItem_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->tempID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_ITEM): 获取附件时未找到玩家"); return true; } connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"获取附件失败"); Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_ITEM): 得到数据库句柄失败"); return true; } std::string escapeName; char where[128]; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); mailContentInfo content; DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_content_define,where,NULL,1,(BYTE*)&content); if (1 != retcode ||content.state==MAIL_STATE_DEL ||content.accessory!=1 ||content.itemGot==1 ||(strncmp(content.toName,pUser->name,MAX_NAMESIZE) && content.toID!=pUser->id)) { //pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"不能获取附件"); SessionService::dbConnPool->putHandle(handle); return true; } if (content.item.object.qwThisID!=0 && rev->space==0) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的包裹空间不足"); SessionService::dbConnPool->putHandle(handle); return true; } if (content.sendMoney && rev->money+content.sendMoney>10000000) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的银币超过了上限,不能领取附件"); SessionService::dbConnPool->putHandle(handle); return true; } if (content.sendGold && rev->gold+content.sendGold>10000000) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的金币超过了上限,不能领取附件"); SessionService::dbConnPool->putHandle(handle); return true; } if (content.recvMoney>rev->money) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的银币不够,不能领取附件"); SessionService::dbConnPool->putHandle(handle); return true; } if (content.recvGold>rev->gold) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你的金币不够,不能领取附件"); SessionService::dbConnPool->putHandle(handle); return true; } content.itemGot = 1; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); retcode = SessionService::dbConnPool->exeUpdate(handle,"`MAIL`",mail_content_define,(BYTE*)&content,where); SessionService::dbConnPool->putHandle(handle); t_getMailItemReturn_SceneSession gmir; gmir.userID = pUser->tempid; gmir.mailID = rev->mailID; gmir.sendMoney = content.sendMoney; gmir.recvMoney = content.recvMoney; gmir.sendGold = content.sendGold; gmir.recvGold = content.recvGold; bcopy(&content.item,&gmir.item,sizeof(Cmd::Session::SessionObject),sizeof(gmir.item)); pUser->scene->sendCmd(&gmir,sizeof(gmir)); return true; } break; case PARA_SCENE_GET_MAIL_ITEM_CONFIRM: { t_getMailItemConfirm_SceneSession * rev = (t_getMailItemConfirm_SceneSession *)cmd; /* //已经收取附件成功 UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->userID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_ITEM_CONFIRM): 确认获取附件时未找到玩家"); return true; } */ connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_GET_MAIL_ITEM_CONFIRM): 得到数据库句柄失败"); return true; } char where[128]; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); mailInfo mail; DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_define,where,NULL,1,(BYTE*)&mail); if (1 != retcode) { if (retcode!=0) Zebra::logger->error("[邮件]%s 确认获取附件错误 mailID=%u retCode=%d",mail.toName,rev->mailID,retcode); SessionService::dbConnPool->putHandle(handle); return true; } if (mail.recvMoney) if (!sendMoneyMail(mail.toName,mail.toID,mail.fromName,mail.fromID,mail.recvMoney,"支付给你的银子")) { Zebra::logger->error("[邮件]%s 支付银子失败 mailID=%u",mail.toName,rev->mailID); } //BYTE i = 1; //retcode = SessionService::dbConnPool->exeUpdate(handle,"`MAIL`",mail_item_define,&i,where); SessionService::dbConnPool->putHandle(handle); //if ((DWORD)-1 == retcode || 0 == retcode) // Zebra::logger->error("[邮件]%s 确认获取附件错误 mailID=%u retCode=%d",mail.toName,rev->mailID,retcode); return true; } break; case PARA_SCENE_DEL_MAIL: { t_delMail_SceneSession * rev = (t_delMail_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->tempID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_DEL_MAIL): 删除邮件时未找到玩家"); return true; } connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_DEL_MAIL): 得到数据库句柄失败"); return true; } char where[128]; mailContentInfo st; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_content_define,where,NULL,1,(BYTE*)&st); if (1!=retcode ||st.state==MAIL_STATE_DEL ||(st.accessory==1 && st.itemGot==0) ||(strncmp(st.toName,pUser->name,MAX_NAMESIZE) && st.toID!=pUser->id)) { if (st.accessory==1 && st.itemGot==0) pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"你不能删除带附件的邮件"); SessionService::dbConnPool->putHandle(handle); return true; } st.state = MAIL_STATE_DEL; retcode = SessionService::dbConnPool->exeUpdate(handle,"`MAIL`",mail_content_define,(BYTE*)&st,where); if (1 != retcode) Zebra::logger->error("[邮件]删除邮件失败:mailID=%u,retcode=%u",rev->mailID,retcode); stDelMail dm; dm.mailID = rev->mailID; pUser->sendCmdToMe(&dm,sizeof(dm)); Zebra::logger->info("[邮件]%s 删除邮件 mailID=%u",pUser->name,rev->mailID); SessionService::dbConnPool->putHandle(handle); return true; } break; case PARA_SCENE_CHECK_NEW_MAIL: { t_checkNewMail_SceneSession * rev = (t_checkNewMail_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->userID); if (!pUser) return true; if (0==newMailMap[pUser->id].size()) return true; Cmd::stNotifyNewMail n; pUser->sendCmdToMe(&n,sizeof(n)); return true; } break; case PARA_SCENE_TURN_BACK_MAIL: { t_turnBackMail_SceneSession * rev = (t_turnBackMail_SceneSession *)cmd; UserSession * pUser = UserSessionManager::getInstance()->getUserByTempID(rev->userID); if (!pUser) { Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_TURN_BACK_MAIL): 退回邮件时未找到玩家"); return true; } connHandleID handle = SessionService::dbConnPool->getHandle(); if ((connHandleID)-1 == handle) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"退回邮件失败"); Zebra::logger->error("[邮件]doMailCmd(PARA_SCENE_TURN_BACK_MAIL): 得到数据库句柄失败"); return true; } char where[128]; bzero(where,sizeof(where)); _snprintf(where,sizeof(where) - 1,"ID=%u",rev->mailID); mailTurnBackInfo info; DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_turnback_define,where,NULL,1,(BYTE*)&info); SessionService::dbConnPool->putHandle(handle); if (1!=retcode ||info.state==MAIL_STATE_DEL ||info.type==MAIL_TYPE_RETURN ||info.accessory!=1 ||info.itemGot!=0 ||(strncmp(info.toName,pUser->name,MAX_NAMESIZE) && info.toID!=pUser->id)) { pUser->sendSysChat(Cmd::INFO_TYPE_FAIL,"不能退还该邮件"); return true; } if (turnBackMail(rev->mailID)) { stDelMail dm; dm.mailID = rev->mailID; pUser->sendCmdToMe(&dm,sizeof(dm)); Zebra::logger->info("[邮件]%s 退回 %s 的邮件 mailID=%u",pUser->name,info.fromName,rev->mailID); } return true; } break; default: break; } return false; }
/** * \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 解析来自管理服务器的指令 * * 这些指令是网关和管理服务器交互的指令<br> * 实现了虚函数<code>zSubNetService::msgParse_SuperService</code> * * \param pNullCmd 待解析的指令 * \param nCmdLen 待解析的指令长度 * \return 解析是否成功 */ bool SessionService::msgParse_SuperService(const Cmd::t_NullCmd *pNullCmd,const DWORD nCmdLen) { switch (pNullCmd->cmd) { case Cmd::Session::CMD_SCENE: { using namespace Cmd::Session; switch(pNullCmd->para) { case PARA_SCENE_FORBID_TALK: { t_forbidTalk_SceneSession * rev = (t_forbidTalk_SceneSession *)pNullCmd; UserSession *pUser = UserSessionManager::getInstance()->getUserSessionByName(rev->name); if (pUser) pUser->scene->sendCmd(rev,sizeof(t_forbidTalk_SceneSession)); else { Zebra::logger->debug("处罚玩家时没找到玩家"); break; } } break; } } break; case Cmd::Rolechange::CMD_BATTLE: { using namespace Cmd::Rolechange; switch(pNullCmd->para) { case PARA_CHECK_ZONE_STATE: { t_checkZoneState* rev = (t_checkZoneState*)pNullCmd; if(rev->isForce == 2) { UserSession *u = UserSessionManager::getInstance()->getUserByID(rev->charid); t_retCheckZoneState send; send.charid = rev->charid; send.accid = rev->accid; if(u) //玩家在线 { send.type = 5; } else { send.type = 6; } SessionChannel::sendCmdToZone(rev->fromGameID, &send, sizeof(send)); } return true; } break; case PARA_RET_CHECK_VALID: { t_Ret_Check_Valid* rev = (t_Ret_Check_Valid*)pNullCmd; UserSession *u = UserSessionManager::getInstance()->getUserByID(rev->userid); if(!u) return true; if(rev->state == BATTLE_SUCCESS) { if(u && u->scene) { Cmd::Session::t_notifyEnterZone_SceneSession send; send.toGameZone = rev->fromGameZone; send.userid = rev->userid; send.type = rev->type; u->scene->sendCmd(&send, sizeof(send)); Zebra::logger->info("[转区] 验证成功,发送t_notifyEnterZone_SceneSession到场景 send.toGameZone:%u send.userid:%u send.type:%u", send.toGameZone.zone, send.userid, send.type); return true; } else { Zebra::logger->info("[转区] 验证成功,发送t_notifyEnterZone_SceneSession到场景 时 发现玩家不在线了"); return true; } } else {//这里需要通知客户端显示 if(rev->state == BATTLE_CLOSE) { Zebra::logger->error("[转区] 验证失败, 目标区未开放"); } else if(rev->state == BATTLE_INVALID) { Zebra::logger->error("[转区] 验证失败, 不是战区不能进入"); } else if(rev->state == BATTLE_USER_REPEAT) { Zebra::logger->error("[转区] 验证失败, 目标区已经存在该账号的角色"); } else if(rev->state == BATTLE_LEVEL_INVALID) { Zebra::logger->error("[转区] 验证失败, 角色等级不符,不能进入"); } else if(rev->state == BATTLE_VERSION_INVALID) { Zebra::logger->error("[转区] 验证失败, 目标区和源区版本不符,不能进入"); } else if(rev->state == ZONE_CLOSE) { Zebra::logger->error("[转区] 验证失败, 该区已关闭"); } else if(rev->state == ZONE_SORT_INVALID) { Zebra::logger->error("[转区] 验证失败, 角色等级过高,不允许进入该区"); } else { Zebra::logger->error("[转区] 验证失败, 收到的状态是:%u 状态未定义",rev->state); } } return true; } break; case PARA_RTN_ZONE_LIST: {} break; default: break; } } break; case Cmd::GmTool::CMD_GMTOOL: { using namespace Cmd::GmTool; switch(pNullCmd->para) { case PARA_CHAT_GMTOOL: { t_Chat_GmTool * rev = (t_Chat_GmTool *)pNullCmd; UserSession *pUser = UserSessionManager::getInstance()->getUserSessionByName(rev->userName); if (!pUser) return true; SessionChannel::sendPrivate(pUser,rev->gmName,rev->content); } break; case PARA_MSG_REPLY_GMTOOL: { t_Msg_Reply_GmTool * rev = (t_Msg_Reply_GmTool *)pNullCmd; char buf[255]; snprintf(buf,sizeof(buf),"GM对您的问题做出了回复:\n\t%s\n原件:\n\t%s",rev->reply,rev->content); //MailService::getMe().sendTextMail(rev->gmName,0,rev->userName,rev->userID,buf,(DWORD)-1,Cmd::Session::MAIL_TYPE_SYS); UserSession *pUser = UserSessionManager::getInstance()->getUserSessionByName(rev->userName); if (pUser) pUser->sendSysChat(Cmd::INFO_TYPE_GAME,"GM对您提出的问题做了回复,请及时查收邮件"); return true; } break; case PARA_BROADCAST_GMTOOL: { t_Broadcast_GmTool * rev = (t_Broadcast_GmTool *)pNullCmd; Zebra::logger->debug("[GM工具]收到公告 %s:%s id=%u time=%u country=%u mapID=%u",rev->GM,rev->content,rev->id,rev->time,rev->country,rev->mapID); if (rev->id>5) return false; //置空取消公告 if (0==strcmp(rev->content,"")) { SessionService::wMsg.erase(rev->id); return true; } if (rev->time) if (rev->country) if (rev->mapID) { SceneSession *scene = SceneSessionManager::getInstance() ->getSceneByID((rev->country<<16)+rev->mapID); if (scene) { Cmd::Session::t_broadcastScene_SceneSession send; strncpy(send.info,rev->content,MAX_CHATINFO); strncpy(send.GM,rev->GM,MAX_NAMESIZE); send.mapID = scene->id; scene->sendCmd(&send,sizeof(send)); #ifdef _DEBUG Zebra::logger->debug("GM公告:%s mapID=%u mapName=%s",send.info,send.mapID,scene->name); #endif } #ifdef _DEBUG else Zebra::logger->debug("GM公告:%s mapID=%u 没找到地图",rev->content,(rev->country<<16)+rev->mapID); #endif } else SessionChannel::sendCountryInfo(Cmd::INFO_TYPE_SCROLL,rev->country,rev->content); else SessionChannel::sendAllInfo(Cmd::INFO_TYPE_SCROLL,rev->content); else { SessionService::wMsg.erase(rev->id); return true; } if (rev->time-1 && rev->id<=5) { strncpy(SessionService::wMsg[rev->id].msg,rev->content,256); strncpy(SessionService::wMsg[rev->id].GM,rev->GM,MAX_NAMESIZE); SessionService::wMsg[rev->id].time = rev->time-1; SessionService::wMsg[rev->id].interval = rev->interval; SessionService::wMsg[rev->id].count = rev->interval; SessionService::wMsg[rev->id].country = rev->country; SessionService::wMsg[rev->id].mapID = rev->mapID; } return true; } break; } } break; case Cmd::Super::CMD_COUNTRYONLINE: switch(pNullCmd->para) { case Cmd::Super::PARA_REQUEST_COUNTRYONLINE: { Cmd::Super::t_Request_CountryOnline *ptCmd = (Cmd::Super::t_Request_CountryOnline *)pNullCmd; BYTE pBuffer[zSocket::MAX_DATASIZE]; Cmd::Super::t_CountryOnline *cmd = (Cmd::Super::t_CountryOnline *)pBuffer; constructInPlace(cmd); cmd->rTimestamp = ptCmd->rTimestamp; cmd->infoTempID = ptCmd->infoTempID; std::vector<std::pair<DWORD,DWORD> > cti; UserSession::getCountryUser(cti); std::vector<std::pair<DWORD,DWORD> >::const_iterator it; for(it = cti.begin(); it != cti.end(); ++it) { if (cmd->OnlineNum < 50) { cmd->CountryOnline[cmd->OnlineNum].country = (*it).first; cmd->CountryOnline[cmd->OnlineNum].num = (*it).second; cmd->OnlineNum++; } else break; } return sendCmdToSuperServer(cmd,sizeof(Cmd::Super::t_CountryOnline) + cmd->OnlineNum * sizeof(Cmd::Super::t_CountryOnline::Online)); } break; } break; case Cmd::Super::CMD_SESSION: { switch(pNullCmd->para) { case Cmd::Super::PARA_USER_ONLINE_BROADCAST: { Cmd::Super::stUserOnlineBroadCast *rev = (Cmd::Super::stUserOnlineBroadCast *)pNullCmd; Zebra::logger->debug("[广播消息]收到来自(%u)区的玩家:%s消息", rev->dwZoneID, rev->name); return true; } break; default: break; } } break; } Zebra::logger->error("SessionService::msgParse_SuperService(%u,%u,%u)",pNullCmd->cmd,pNullCmd->para,nCmdLen); return false; }
/** * \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; }