Esempio n. 1
0
bool MailService::sendMail(DWORD h,Cmd::Session::t_sendMail_SceneSession & sm)
{
  if (0==sm.mail.toID && 0==strncmp("",sm.mail.toName,MAX_NAMESIZE))
  {
    Zebra::logger->error("[邮件]sendMoneyMail 收件人为空 fromName=%s money=%u text=%s type=%u",sm.mail.fromName,sm.mail.sendMoney,sm.mail.text,sm.mail.type);
    return false;
  }

  connHandleID handle = (connHandleID)h;
  if ((connHandleID)-1 == handle)
  {               
    Zebra::logger->error("[邮件]sendMail: 无效的数据库句柄");
    Zebra::logger->error("[邮件]%s->%s 丢失 money=%u item=%s",sm.mail.fromName,sm.mail.toName,sm.mail.sendMoney,sm.item.object.strName);
    return false;
  }
  DWORD retcode = SessionService::dbConnPool->exeInsert(handle,"`MAIL`",mail_define,(const BYTE *)&sm.mail);

  if ((DWORD)-1 == retcode)
  {
    Zebra::logger->error("[邮件]sendMail: 插入新邮件数据库出错 retcode=%d",retcode);
    Zebra::logger->error("[邮件]%s->%s 丢失 money=%u item=%s",sm.mail.fromName,sm.mail.toName,sm.mail.sendMoney,sm.item.object.strName);
    return false;
  }

  newMailMap[sm.mail.toID].insert(retcode);

  UserSession * toUser = UserSessionManager::getInstance()->getUserSessionByName(sm.mail.toName);
  if (toUser)
  {
    Cmd::stNotifyNewMail n;
    toUser->sendCmdToMe(&n,sizeof(n));
  }

  return true;
}
Esempio n. 2
0
bool MailService::sendMail(Cmd::Session::t_sendMail_SceneSession & sm)
{
  connHandleID handle = SessionService::dbConnPool->getHandle();
  if ((connHandleID)-1 == handle)
  {               
    Zebra::logger->error("[邮件]sendMail: 得到数据库句柄失败");
    Zebra::logger->error("[邮件]%s->%s 丢失 money=%u item=%s",sm.mail.fromName,sm.mail.toName,sm.mail.sendMoney,sm.item.object.strName);
    return false;
  }
  DWORD retcode = SessionService::dbConnPool->exeInsert(handle,"`MAIL`",mail_define,(const BYTE *)&sm.mail);
  SessionService::dbConnPool->putHandle(handle);

  if ((DWORD)-1 == retcode)
  {
    Zebra::logger->error("[邮件]sendMail: 插入新邮件数据库出错 retcode=%d",retcode);
    Zebra::logger->error("[邮件]%s->%s 丢失 money=%u item=%s",sm.mail.fromName,sm.mail.toName,sm.mail.sendMoney,sm.item.object.strName);
    return false;
  }

  newMailMap[sm.mail.toID].insert(retcode);

  UserSession * toUser = UserSessionManager::getInstance()->getUserSessionByName(sm.mail.toName);
  if (toUser)
  {
    Cmd::stNotifyNewMail n;
    toUser->sendCmdToMe(&n,sizeof(n));
  }

  return true;
}
Esempio n. 3
0
/**
* \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();
}
Esempio n. 4
0
void GamesInsert::handleRequest(GlobalContext *pGlobalContext, QSqlDatabase *db, QHttpRequest *req, QJsonObject &response) {
	UserSession *pUserSession = pGlobalContext->userSession(req->url(), db);
	if (pUserSession == NULL) {
		setErrorResponse(response, 1021, "token are not found");
		return;
	} else if (!pUserSession->isAdmin()) {
		setErrorResponse(response, 1022, "this method only for admin");
		return;
	}

	QUrlQuery urlQuery(req->url());
	QString name = urlQuery.queryItemValue("name");

	if (name.isEmpty()) {
		setErrorResponse(response, 1055, "Parameter name are not found or it is empty");
		return;
	}

	QSqlQuery query(*db);
	query.prepare("INSERT INTO backend_games(name) VALUES(:name)");
	query.bindValue(":name", name);
	if (query.exec()) {
		response["result"] = QString("ok");
		response["id"] = query.lastInsertId().toInt();
	} else {
		setErrorResponse(response, 1056, query.lastError().text());
		return;
	}	
};
Esempio n. 5
0
/**
* \brief 发送聊天消息给自己的所有简单社会关系,如果不在线则存为离线消息
* \param pCmd 聊天消息
* \param cmdLen 消息长度
*/
void CRelationManager::sendChatToMyFriend(const Cmd::stChannelChatUserCmd *pCmd,const DWORD cmdLen)
{
  //rwlock.rdlock();
  user->sendCmdToMe(pCmd,cmdLen);  // 转发一条消息给自己,以免看不到自己的聊天记录
  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_BAD)&& (temp->type != Cmd::RELATION_TYPE_ENEMY))
    {
      if (temp->online)
      {
        UserSession *pUser = UserSessionManager::getInstance()->getUserByID(temp->id);
        if (pUser) pUser->sendCmdToMe(pCmd,cmdLen);
      }
      else
      {
        if (Cmd::CHAT_TYPE_FRIEND_AFFICHE == pCmd->dwChannelID)
        {
          COfflineMessage::writeOfflineMessage(pCmd->dwType,user->id,pCmd,cmdLen);
        }
      }
    }
  }
  //rwlock.unlock();
}
Esempio n. 6
0
/*****************************************************
    MSG_Handler_CalledBank_REQ
*****************************************************/
void MSG_Handler_Reminder_REQ ( ServerSession * pServerSession, MSG_BASE * pMsg, WORD wSize )
{
    UserSession * pSession = ( UserSession * ) pServerSession;
    {
        UserPacket & user = pSession->GetUserPacket();
        user.GetProtocol() = MAKEDWORD( Games_Protocol, Reminder_REQ );
        user.ToPrint();
        g_AgentServer->SendToGameServer( (BYTE*)&user, user.GetPacketSize() );
    }
}
Esempio n. 7
0
void AdminUserUpdate::handleRequest(GlobalContext *pGlobalContext, QSqlDatabase *db, QHttpRequest *req, QJsonObject &response) {
	UserSession *pUserSession = pGlobalContext->userSession(req->url(), db);
	if (pUserSession == NULL) {
		setErrorResponse(response, 1074, "token are not found");
		return;
	} else if (!pUserSession->isAdmin()) {
		setErrorResponse(response, 1075, "this method only for admin");
		return;
	}
};
Esempio n. 8
0
/************************************************
    FromClientToAgent_StartGame_REQ
************************************************/
void FromClientToAgent_StartGame_REQ ( ServerSession * pServerSession, MSG_BASE * pMsg, WORD wSize ) {

    UserSession * pSession = ( UserSession * ) pServerSession;
    {
        UserPacket pack = pSession->GetUserPacket();
        pack.GetProtocol() = MAKEDWORD( Games_Protocol, StartGame_REQ );
        pack.GetReady() = 1;
        pack.ToPrint();
        g_AgentServer->SendToGameServer( (BYTE*)&pack, pack.GetPacketSize() );
    }
}
Esempio n. 9
0
// 客户端
NetworkObject * CreateClientSideAcceptedObject() {
	printf("[LoginServer::CreateClientSideAcceptedObject]: Alloc UserSession.\n");
	
	UserSession * obj = LoginFactory::Instance()->AllocUserSession();
	if ( obj == NULL) {
		printf("\nLoginFactory::Instance()->AllocTempUserSession() Fail.\n");
		return NULL;
	}
	
	obj->Init();
	return (NetworkObject *)(obj);
}
Esempio n. 10
0
void MSG_Handler_QuitTable_REQ ( ServerSession * pServerSession, MSG_BASE * pMsg, WORD wSize )
{
    DEBUG_MSG( LVL_DEBUG, "QuitTable_REQ to recv: %s \n", (char*) pMsg );

    UserSession * pSession = ( UserSession * ) pServerSession;
    {
        UserPacket & user = pSession->GetUserPacket();
        user.GetProtocol() = MAKEDWORD( Games_Protocol, QuitTable_REQ );
        user.ToPrint();
        g_AgentServer->SendToGameServer( (BYTE*)&user, user.GetPacketSize() );
    }
}
Esempio n. 11
0
bool SessionChannel::sendCmdToAll(const void *cmd,int len)
{
  UserSession * user = 0;
  for (std::list<DWORD>::iterator it=userList.begin(); it!=userList.end(); it++)
  {
    user = UserSessionManager::getInstance()->getUserByTempID(*it);
    if (user)
    {
      user->sendCmdToMe(cmd,len);
    }
  }
  return true;
}
Esempio n. 12
0
bool SessionChannel::sendToOthers(UserSession *pUser,const Cmd::stChannelChatUserCmd *cmd,DWORD len)
{
  UserSession * user = 0;
  for (std::list<DWORD>::iterator it=userList.begin(); it!=userList.end(); it++)
  {
    user = UserSessionManager::getInstance()->getUserByTempID(*it);
    if (user && user!=pUser)
    {
      user->sendCmdToMe(cmd,len);
    }
  }
  return true;
}
Esempio n. 13
0
void GateGameClient::parseChangeGS(google::protobuf::Message* p, pb_flag_type flag)
{
	message::MsgDB2GTChangeGS* msg = static_cast<message::MsgDB2GTChangeGS*>(p);
	UserSession* pksession = gGTUserMgr.getUserSession(flag);
	
	if (msg && pksession)
	{
		GateGameClient* pkNew = gGTGameMgr.getGameClient(msg->gameserverid());
		if (!pkNew)
		{
			pksession->setClose();
			Mylog::log_server(LOG_ERROR, "change server not found the gmae server [%u]", msg->gameserverid());
		}else
		{
			//切换到目标图的GS上
			removePlayer( pksession->getTrans());
			account_type a = gGTUserMgr.getAccount(pksession->getTrans());
			if (a != INVALID_ACCOUNT)
			{
				pksession->setGSid(msg->gameserverid());
				pkNew->addNewPlayer(pksession->getTrans(), gGTUserMgr.getAccount(pksession->getTrans()));
			}else
			{
				pksession->setClose();
				Mylog::log_server(LOG_ERROR, "change server not found the Account ");
			}
		}
	}
}
Esempio n. 14
0
void GateGameClient::parseGameMsg(google::protobuf::Message* p, pb_flag_type flag)
{
	UserSession* pksession = gGTUserMgr.getUserSession(flag);
	if (pksession)
	{
		pksession->sendPBMessage(p, flag);
        //Mylog::log_player(LOG_DEBUG, "Game Server Send Msg[%s] to user [%u]", p->GetTypeName().c_str(), flag);
	}
	else
	{
		//Mylog::log_server(LOG_DEBUG, "send[%s] msg failed, can not find session id[%u]", p->GetTypeName().c_str(), flag);
	}
    
}
Esempio n. 15
0
    void BooterServer::OnError(UserSession &sender)
    {
        LogEvent("BooterServer: OnError()!");

        // Mark the failed User Session as out-of-date
        sender.setSessionOutdated();
    }
Esempio n. 16
0
    void BooterServer::OnClientDisconnected(UserSession &sender)
    {
        LogEvent("BooterServer: OnClientDisconnected()");

        // Mark the disconnected User Session as out-of-date
        sender.setSessionOutdated();
    }
Esempio n. 17
0
// User Server;
BOOL LoginServer::SendToClient( BYTE * pMsg, WORD wSize )
{
	MSG_BASE_FORWARD * pBase = (MSG_BASE_FORWARD *) pMsg;
	
	WORD wIndex = pBase->m_wParameter;
	if ( wIndex == 0 ) {
		return FALSE;	
	}
	
	UserSession * pSession = m_pUserSession[wIndex];
	if ( pSession != NULL ) {
		WORD sendSize =  wSize - sizeof(MSG_BASE_FORWARD);
		BYTE * sendMsg = (BYTE *) ( pBase);
		sendMsg += sizeof(MSG_BASE_FORWARD);
		pSession->Send(sendMsg, sendSize);
	}
}
Esempio n. 18
0
/*****************************************************
    FromAgentToGame_Offline_BRD
*****************************************************/
void FromAgentToGame_Offline_BRD ( TemplateServerSession * pServerSession, MSG_BASE * pMsg, WORD wSize )
{
    DEBUG_MSG( LVL_DEBUG, "Offline_BRD to recv: %s \n", pMsg );

    JsonMap js_map;
    if ( js_map.set_json( (char *) pMsg ) == -1 ) {
        return;
    }

    int _userkey(0);
    js_map.ReadInteger( "userkey",  _userkey );

    UserSession * pSession = NULL;
    pSession = g_AgentServer->GetUserSession( _userkey );
    if ( pSession ) {
        pSession->LeaveGame();
    }
}
Esempio n. 19
0
void Seq::attachAndDetachThread()
{
	LOG_INFO("Attach and detach thread");
	JNIEnv* env;
	UserSession* us = UserSession::getInstance();
	int getEnvStat = (us->getVM())->GetEnv((void **)&env, JNI_VERSION_1_6);
	if(getEnvStat == JNI_EDETACHED)
	{
		LOG_INFO("GetEnv: not attached");
		if((us->getVM())->AttachCurrentThread(&env, NULL) != 0){
			LOG_INFO("Failed to attach");
		}
	}else if(getEnvStat == JNI_OK){
		
	}else if(getEnvStat == JNI_EVERSION){
		LOG_INFO("GetEnv: version not supported");
	}
	for(int i = 0; i < NUMBER_OF_PADS; ++i)
	{
		if(p[i].note[seqI]){
			env->CallStaticVoidMethod(sampleTriggerMethodClass, sampleTriggerMethodID, i);
			if(padState[i].state){
				padState[i].increment = 0;
			}else if(!padState[i].state){
				padState[i].state = true;
				padState[i].increment = 0;
			}
		}	
		if(padState[i].state){
			if(padState[i].increment >= PAD_STATE_INCR){
				padState[i].increment = 0;
				padState[i].state = false;
			}else{
				++padState[i].increment; 
			}
		}
	}
	if(sequencerRunning)
		env->CallStaticVoidMethod(sampleTriggerMethodClass, metronomeMethodID, seqI);
	if(env->ExceptionCheck()){
		env->ExceptionDescribe();
	}
	(us->getVM())->DetachCurrentThread();
}
Esempio n. 20
0
/*******************************************************
	FromLobbyToAgent_Onlines_ANC
******************************************************/
void FromLobbyToAgent_Onlines_ANC ( ServerSession * pServerSession, MSG_BASE * pMsg, WORD wSize ) {

    DEBUG_MSG( LVL_DEBUG, "Onlines_ANC to client: %s \n",(char *) pMsg );

    JsonMap js_map;
    if ( js_map.set_json( (char*) pMsg ) == -1 ) {
        return;
    }

    int _userkey(0), _userid(0);
    js_map.ReadInteger( "userkey", _userkey );

    if ( _userkey!=0 )
    {
        UserSession * pSession = g_AgentServer->GetUserSession( _userkey );
        if ( pSession ) {
            _userid = pSession->GetUserid();
            User_Login_Query_Relogin( _userkey , _userid );
        }
        g_AgentServer->SendToClient( _userkey, (BYTE*) pMsg, wSize );
    }
}
Esempio n. 21
0
// 重连控制连接还是数据连接
void PasClient::ConnectServer( UserSession &user, bool tcp )
{
	// 更新最后一次登陆的时间
	user.Update( PCC_USER_LOGIN, tcp ) ;

	PccUser &pccuser = user.GetUser( tcp ) ;
	// 如果TCP连接
	if ( tcp ) {
		pccuser._fd = _tcp_handle.connect_nonb( pccuser._srv_ip.c_str(), pccuser._srv_port, 10 ) ;
		if ( pccuser._fd > 0 ) {
			pccuser.SetWaitResp() ;
		}
	} /**else { // 数据通道
		pccuser._fd = _udp_handle.connect_nonb( pccuser._srv_ip.c_str(), pccuser._srv_port, 10 ) ;
		if ( pccuser._fd == -1 )
			return ;
		pccuser.SetWaitResp() ;
	}*/

	PccUser &udpuser = user.GetUser( false ) ;
	udpuser.SetOffline() ;
	if(udpuser._fd != NULL) {
		CloseSocket(udpuser._fd);
		udpuser._fd = NULL;
	}

	// 通过TCP通道发送注册数据通道信息
	if ( ! tcp ) {
		PccUser &tcpuser = user.GetUser(true) ;

		char buf[1024] = {0};
		sprintf( buf, "SZ P %s|%s|%d\r\n", user.GetKey(true), _ip.c_str(), _port ) ;
		// 发送数据通道连接请求
		SendData( tcpuser._fd, buf, strlen(buf) ) ;

		//OUT_SEND( pccuser._srv_ip.c_str(), pccuser._srv_port, pccuser._username.c_str(), "fd %d, Tcp fd %d Send %s",
		//		pccuser._fd->_fd, tcpuser._fd->_fd, buf ) ;
	}
}
Esempio n. 22
0
/**
* \brief 发送消息给自己的所有简单社会关系
* \param pCmd 消息
* \param cmdLen 消息长度
* \param sendMe 是否发给自己
*/
void CRelationManager::sendCmdToMyFriendExcept(const void *pCmd,const DWORD cmdLen,bool sendMe,const char * except)
{
  //rwlock.rdlock();
  if (sendMe)
    user->sendCmdToMe(pCmd,cmdLen);  // 转发一条消息给自己
  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_BAD) && (temp->type != Cmd::RELATION_TYPE_ENEMY))
    {
      if (temp->online)
      {
        UserSession *pUser = UserSessionManager::getInstance()->getUserByID(temp->id);
        if (pUser && strncmp(pUser->name,except,MAX_NAMESIZE))
        {
          pUser->sendCmdToMe(pCmd,cmdLen);
        }
      }
    }
  }
  //rwlock.unlock();
}
Esempio n. 23
0
void GamesDelete::handleRequest(GlobalContext *pGlobalContext, QSqlDatabase *db, QHttpRequest *req, QJsonObject &response) {
	UserSession *pUserSession = pGlobalContext->userSession(req->url(), db);
	if (pUserSession == NULL) {
		setErrorResponse(response, 1025, "token are not found");
		return;
	} else if (!pUserSession->isAdmin()) {
		setErrorResponse(response, 1026, "this method only for admin");
		return;
	}
	
	QUrlQuery urlQuery(req->url());
	QString sId = urlQuery.queryItemValue("id");

	if (sId.isEmpty()) {
		setErrorResponse(response, 1057, "Parameter id are not found or it is empty");
		return;
	}
	
	bool bConvert;
	int nId = sId.toInt(&bConvert, 10);
	if (!bConvert) {
		setErrorResponse(response, 1058, "Parameter id must be integer");
		return;
	}
	
	// TODO check exists game

	QSqlQuery query(*db);
	query.prepare("DELETE FROM backend_games WHERE id = :id");
	query.bindValue(":id", nId);
	if (query.exec()) {
		response["result"] = QString("ok");
	} else {
		setErrorResponse(response, 1059, query.lastError().text());
		return;
	}
};
Esempio n. 24
0
BOOL LoginServer::OvertimeClear( DWORD dwDeltaTick )
{
	printf(" [ LoginServer::OvertimeClear dwDeltaTick= %d ] \n", dwDeltaTick);
	printf(" [ LoginServer::OvertimeClear size = %d ] \n", m_lsOvertimeTable.size());
	
	WORD wIndex = 0;
	UserSession * pSession = NULL;
	for (int i = 0; i< m_lsOvertimeTable.size(); ++i) {	
		wIndex = m_lsOvertimeTable.front();
		if ( wIndex==0 ) {
			m_lsOvertimeTable.pop_front();
			continue;
		}		
		printf(" [ LoginServer::OvertimeClear wIndex = %d ] \n", wIndex);
		pSession = m_pUserSession[wIndex];
		if ( pSession != NULL ) {
			printf(" [ LoginServer::OvertimeClear pSession = %d ] \n", pSession);
			if ( pSession->Update( dwDeltaTick ) ) {
				pSession->CloseSession();
			}
		}
		m_lsOvertimeTable.pop_front();
	}
}
Esempio n. 25
0
// 检测用户心跳
void PasClient::CheckUserLoop( UserSession &user )
{
	// 控制通道的链路维护
	PccUser &tcpuser = user.GetUser( true ) ;
	if ( tcpuser.IsOnline() ) {
		if ( tcpuser.Check( 30, PCC_USER_LOOP ) && user.IsKey(true) ) {
			char buf[1024] = {0};
			sprintf( buf, "SZ N %s\r\n", tcpuser._srv_key.c_str() ) ;
			SendData( tcpuser._fd, buf, strlen(buf) ) ;
			tcpuser.Update( PCC_USER_LOOP ) ;

			OUT_SEND( tcpuser._srv_ip.c_str(), tcpuser._srv_port, tcpuser._username.c_str(), "fd %d, Send TCP NOOP: %s",
					tcpuser._fd->_fd, buf ) ;
		}
		// 如果超时需要处理重连操作
		if ( tcpuser.Check( 180, PCC_USER_ACTVIE ) ) {
			tcpuser.SetOffline() ;
			user.GetUser(false).SetOffline() ;
			OUT_ERROR( tcpuser._srv_ip.c_str(), tcpuser._srv_port, tcpuser._username.c_str(), "tcp  actvie time timeout") ;
		}
	} else if ( ! tcpuser.IsOffline() ) {
		if ( tcpuser.Check( 120, PCC_USER_LOGIN ) ) {
			tcpuser.SetOffline() ;
			OUT_PRINT( tcpuser._srv_ip.c_str(), tcpuser._srv_port, tcpuser._username.c_str(), "connect server tcp timeout") ;
		}
	}

	// 数据通道链路维护
	PccUser &udpuser = user.GetUser(false) ;
	if ( udpuser.IsOnline() ) {
		if ( udpuser.Check( 30, PCC_USER_LOOP ) && user.IsKey(false) ) {
			char buf[1024] = {0};
			sprintf( buf, "*%s|NOOP|%s#", user.GetSrvId(), udpuser._srv_key.c_str() ) ;
			SendData( udpuser._fd, buf, strlen(buf) ) ;
			// _udp_handle.deliver_data( udpuser._fd, udpuser._srv_ip.c_str(), udpuser._srv_port, buf, strlen(buf) ) ;
			udpuser.Update( PCC_USER_LOOP ) ;

			OUT_SEND( udpuser._srv_ip.c_str(), udpuser._srv_port, udpuser._username.c_str(), "fd %d, Send UDP NOOP: %s",
					udpuser._fd->_fd, buf ) ;
		}
		// 如果UDP心跳没有应答就直接处理重连了
		if ( udpuser.Check(180, PCC_USER_ACTVIE) ) {
			udpuser.SetOffline() ;
			OUT_ERROR( udpuser._srv_ip.c_str(), udpuser._srv_port, udpuser._username.c_str(), "udp active time timeout" ) ;
			tcpuser.SetOffline() ;
		}
	} else {
		if ( udpuser.Check( 120, PCC_USER_LOGIN) ) {
			udpuser.SetOffline() ;
			OUT_PRINT( udpuser._srv_ip.c_str(), udpuser._srv_port, udpuser._username.c_str(), "connect server udp timeout") ;
			tcpuser.SetOffline() ;
		}
	}
}
Esempio n. 26
0
// 检测用户状态
void PasClient::CheckUserState( UserSession &user )
{
	// 如果当前TCP用户不在线
	if ( user.IsOffline(true) ) {
		// 如果当前用户还没有超时就允许重新连接
		if ( !user.Check( 30, PCC_USER_LOGIN , true ) )
			return ;
		ConnectServer( user, true ) ;
	} else if ( user.IsOffline(false) && user.IsOnline(true) ){
		// 如果当前TCP用户鉴权码为空也不能登陆数据链路
		if ( ! user.IsKey(true) )
			return ;
		if ( ! user.Check( 30, PCC_USER_LOGIN, false ) )
			return ;

		ConnectServer( user, false ) ;
	}
}
Esempio n. 27
0
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;
}
Esempio n. 28
0
VOID DestroyClientSideAcceptedObject( NetworkObject * pObjs ) {
	printf("[LoginServer::DestroyClientSideAcceptedObject]: Function\n");
	UserSession * pSession = (UserSession *)pObjs;
	pSession->Release();
}
Esempio n. 29
0
/**
 * \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;
}
Esempio n. 30
0
/* \brief 退回一封邮件
 *  \param mailID 邮件ID
 *
 */
bool MailService::turnBackMail(DWORD mailID)
{
  using namespace Cmd::Session;

  connHandleID handle = SessionService::dbConnPool->getHandle();
  if ((connHandleID)-1 == handle)
  {               
    Zebra::logger->error("[邮件]turnBackMail: 得到数据库句柄失败");
    return false;
  }

  char where[128];
  bzero(where,sizeof(where));
  _snprintf(where,sizeof(where) - 1,"ID=%u",mailID);

  mailTurnBackInfo mail;
  DWORD retcode = SessionService::dbConnPool->exeSelectLimit(handle,"`MAIL`",mail_turnback_define,where,NULL,1,(BYTE*)&mail);
  if (1 != retcode
      || mail.state==MAIL_STATE_DEL
      || mail.type!=MAIL_TYPE_MAIL
      || mail.accessory!=1
      || mail.itemGot!=0
      || (0==mail.fromID && 0==strncmp("",mail.fromName,MAX_NAMESIZE)))
      //|| 0==strncmp("",mail.fromName,MAX_NAMESIZE)
      //|| 0==mail.fromID)
  {
    Zebra::logger->error("[邮件]不能退还邮件 mailID=%u retCode=%d",mailID,retcode);
    SessionService::dbConnPool->putHandle(handle);
    return false;
  }

  char temp[MAX_NAMESIZE];
  mail.state = MAIL_STATE_NEW;
  strncpy(temp,mail.fromName,MAX_NAMESIZE);
  strncpy(mail.fromName,mail.toName,MAX_NAMESIZE);
  strncpy(mail.toName,temp,MAX_NAMESIZE);
  strncpy(mail.title,"退回的物品",MAX_NAMESIZE);
  mail.type = MAIL_TYPE_RETURN;
  zRTime ct;
  mail.createTime = ct.sec();
  mail.delTime = mail.createTime + 60*60*24*7;
  _snprintf(mail.text,255-1,"%s 谢绝了你发送的物品",mail.fromName);
  mail.recvMoney = 0;
  mail.recvGold = 0;
  DWORD t = mail.fromID;
  mail.fromID = mail.toID;
  mail.toID = t;

  retcode = SessionService::dbConnPool->exeUpdate(handle,"`MAIL`",mail_turnback_define,(BYTE*)&mail,where);
  SessionService::dbConnPool->putHandle(handle);
  if (1 != retcode)
  {
    Zebra::logger->error("[邮件]返还邮件Update失败:mailID=%u,retcode=%d",mailID,retcode);
    return false;
  }

  UserSession * toUser = UserSessionManager::getInstance()->getUserSessionByName(mail.toName);
  if (toUser)
  {
    Cmd::stNotifyNewMail n;
    toUser->sendCmdToMe(&n,sizeof(n));
  }
  return true;
}