CSDPipeChannel* CPKApplication::OnPipeChannelConnected(UINT32 dwPipeID) { CSDPipeChannel* poPipeChannel = NULL; CSDServerID oServerID(dwPipeID); switch(oServerID.GetServerType()) { case TYPE_GM_SERVER: { break; } case TYPE_GAME_SERVER: { poPipeChannel = SDNew CGSPipeChannel; poPipeChannel->SetPacketProcessor(CGSProcessor::Instance()); m_mapGSPipeChannel[oServerID.GetAreaID()] = poPipeChannel; printf(_SDT("PKServer: recv gameserver「zoneid=%u」pipe connect\n"), oServerID.GetAreaID()); USR_INFO(_SDT("[%s: %d]: recv gameserver「zoneid=%u」pipe connect\n"), MSG_MARK, oServerID.GetAreaID()); break; } default: printf(_SDT("PKServer:recv unknown pipe connect(Type:%d)\n"), oServerID.GetServerType()); USR_INFO(_SDT("[%s: %d]:recv unknown pipe connect(Type:%d)\n"), MSG_MARK, oServerID.GetServerType()); break; } return poPipeChannel; }
static bool accept_ctx(i32 net, u32 wait_secs) { struct client_ctx *cl_ctx; cl_ctx = cl_ctx_alloc(); if(NULL == cl_ctx) { USR_INFO("S: No free cl_ctx, max # of clients reached \n\r"); return true; } cl_ctx->net = net_ops->accept(net, cl_ctx->remote_ip, &cl_ctx->ip_length); if(0 > cl_ctx->net) { cl_ctx_free(cl_ctx); USR_INFO("S: Fatal, couldn't accept new incoming conn \n\r"); return false; } DBG_INFO("Accepted new connection (fd) %d\n\r", (i32)cl_ctx->net); /* Timeout to receive MQTT_CONNECT */ cl_ctx->timeout = wait_secs + net_ops->time(); used_ctxs_insert(cl_ctx); return true; }
static struct mqtt_packet *server_mqp_alloc(u8 msg_type, u32 buf_sz, u8 offset) { u32 mqp_sz = sizeof(struct mqtt_packet); struct mqtt_packet *mqp = NULL; buf_sz += offset; if((mqp_sz + buf_sz) > MQP_SERVER_TX_LEN) { USR_INFO("S: fatal, buf alloc len > MQP_SERVER_TX_LEN\n\r"); return NULL; } mqp = my_malloc(MQP_SERVER_TX_LEN); if(NULL != mqp) { mqp_init(mqp, offset); mqp->msg_type = msg_type; mqp->maxlen = buf_sz; mqp->buffer = (u8*)mqp + mqp_sz; mqp->free = my_pkt_free; } else { USR_INFO("S: fatal, failed to alloc Server MQP\n\r"); } return mqp; }
void CGvGVideoMgr::AddVideo(SGvGVideo &stVideo) { if(0 == stVideo.stGvGInfo.qwVideoID) { return; } if(GetVideo(stVideo.stGvGInfo.qwVideoID)) { USR_INFO(_SDT("CGvGVideoMgr::AddVideo[%llu], [%s] vs [%s] %s, round = [%u:%u], PKVideoCnt = %u, found exist video, skip."), stVideo.stGvGInfo.qwVideoID, stVideo.stGvGInfo.stG1.aszFactionName, stVideo.stGvGInfo.stG2.aszFactionName, gvgvideoutil::EchoBattleResult(stVideo.stGvGInfo.byBattleResult).c_str(), stVideo.stGvGInfo.stRound.byBigRound, stVideo.stGvGInfo.stRound.bySmallRound, stVideo.stGvGInfo.byPKVideoCnt ); return; } m_mapVideo[stVideo.stGvGInfo.qwVideoID] = stVideo; if(stVideo.IsAllPKVideoHere()) { USR_INFO(_SDT("CGvGVideoMgr::AddVideo[%llu], [%s] vs [%s] %s, round = [%u:%u], all pk video is here, PKVideoCnt = %u"), stVideo.stGvGInfo.qwVideoID, stVideo.stGvGInfo.stG1.aszFactionName, stVideo.stGvGInfo.stG2.aszFactionName, gvgvideoutil::EchoBattleResult(stVideo.stGvGInfo.byBattleResult).c_str(), stVideo.stGvGInfo.stRound.byBigRound, stVideo.stGvGInfo.stRound.bySmallRound, stVideo.stGvGInfo.byPKVideoCnt ); m_setNotSavedVideoID.insert(stVideo.stGvGInfo.qwVideoID); } else { USR_INFO(_SDT("CGvGVideoMgr::AddVideo[%llu], [%s] vs [%s] %s, round = [%u:%u], not all pk video is here, PKVideoCnt = %u"), stVideo.stGvGInfo.qwVideoID, stVideo.stGvGInfo.stG1.aszFactionName, stVideo.stGvGInfo.stG2.aszFactionName, gvgvideoutil::EchoBattleResult(stVideo.stGvGInfo.byBattleResult).c_str(), stVideo.stGvGInfo.stRound.byBigRound, stVideo.stGvGInfo.stRound.bySmallRound, stVideo.stGvGInfo.byPKVideoCnt ); } }
VOID CEatBread::Enter(PKT_CLIGS_OPNE_EAT_BREAD_ACK& pstAck) { memset(&m_stDT_EAT_BREAD_DATA, 0, sizeof(m_stDT_EAT_BREAD_DATA)); m_stDT_EAT_BREAD_DATA.byHaveDataFlag = 1; USR_INFO(_SDT("[%s: %d]: Player[%u] Enter EatBread!"), MSG_MARK, m_poOwner->GetID()); const SEatBreadActivityTimeProp* pstActivityTimeProp = CEatBreadPropMgr::Instance()->GetActivityTimeProp(); if(pstActivityTimeProp) //当前时间在活动内,进入活动 { pstAck.byHaveObtainPhyStrengthen = 0; pstAck.dwHaveObtainCoin = 0; pstAck.wHaveUseTime = 0; //进入活动 memset(&m_stDT_EAT_BREAD_DATA, 0, sizeof(m_stDT_EAT_BREAD_DATA)); m_stDT_EAT_BREAD_DATA.byHaveDataFlag = 1; m_stDT_EAT_BREAD_DATA.qwEnterTime = SDTimeSecs(); m_poOwner->GetLocale().OnEatBread(); UINT32 dwCurSecond = GetDayPassSecond(); if((dwCurSecond >= pstActivityTimeProp->dwStartTime) && (dwCurSecond < pstActivityTimeProp->dwEndTime)) { pstAck.wEndCountDown = (UINT16)(pstActivityTimeProp->dwEndTime - dwCurSecond); } } else //不在活动时间段 { pstAck.byHaveObtainPhyStrengthen = 0; pstAck.dwHaveObtainCoin = 0; pstAck.wHaveUseTime = 0; m_poOwner->GetLocale().OnEatBreadEnd(); } }
static i32 subtop_read(const c8 *topstr, c8 *subtop_buf, u16 buf_length, c8 const **next_subtop) { i32 idx = 0, len = buf_length; *next_subtop = topstr; while(idx < (len - 1)) { subtop_buf[idx++] = *topstr; if(is_end_of_subtop(topstr, next_subtop)) break; topstr++; } if(idx == len) { USR_INFO("S: Fatal, insufficient buffer for sub-str\n\r"); return -1; /* zero or insufficient buffer provided */ } /* NUL terminated buffer: unless '\0' ended copy, make one */ if('\0' == subtop_buf[idx - 1]) idx--; /* A fix up */ else subtop_buf[idx] = '\0'; return idx; }
//去掉过期礼包 VOID CGvGGiftMgr::RemoveOverGift() { UINT8 byOver = 12; UINT16 wCurSession = CGvGBuild::Instance()->GetCurSession(); UINT16 wOverSession = wCurSession < byOver ? 0 : wCurSession - byOver; UINT64 qwOverKey = GetGiftKey(0, wOverSession, 0, 0); UINT64 qwKey = GetGiftKey(0, 0xFFFF, 0, 0); for ( CMapGvGGiftRewardItr itr = m_mapGiftReward.begin(); itr != m_mapGiftReward.end(); ) { if ( (itr->first & qwKey) == qwOverKey) { m_mapGiftReward.erase(itr++); } else { itr++; } } //数据库删除数据 CBaseDBCMD* poDBCmd = gsapi::GetDBMgr()->CreateCmd(EDBCT_DELETE_GVG_GIFT); if ( NULL == poDBCmd ) { USR_INFO("[%s : %d] Delete GvG Gift Failed", MSG_MARK); return ; } poDBCmd->SetUserData( &wOverSession); gsapi::GetDBMgr()->AddCommand(poDBCmd); }
//添加礼包进DB VOID CGvGGiftMgr::AddGiftTODB() { UINT8 byDBIdx = 0; for ( CVecGiftRewardDataItr itr = m_vecAddToDBGift.begin(); itr != m_vecAddToDBGift.end(); ) { UINT64 qwKey = GetGiftKey(itr->dwPlayerID, itr->wSessionID, itr->byGvGRound, itr->byBattleIdx); CMapGvGGiftRewardItr mapItr = m_mapGiftReward.find(qwKey); if ( mapItr == m_mapGiftReward.end()) { AddGiftReward(*itr); byDBIdx++; itr++; } else { itr = m_vecAddToDBGift.erase(itr); } } if ( 0 != byDBIdx) { //数据库删除数据 CBaseDBCMD* poDBCmd = gsapi::GetDBMgr()->CreateCmd(EDBCT_ADD_GVG_GIFT); if ( NULL == poDBCmd ) { USR_INFO("[%s : %d] Delete GvG Gift Failed", MSG_MARK); return ; } poDBCmd->SetUserData( &m_vecAddToDBGift); gsapi::GetDBMgr()->AddCommand(poDBCmd); } m_vecAddToDBGift.clear(); }
void CGvGVideoMgr::AddPKVideo(PKT_PKGS_RET_VIDEO_ACK &stAck) { SGvGVideo *pstVideo = CGvGVideoMgr::Instance()->GetVideo(stAck.qwVideoID); if(NULL == pstVideo) { return; } if(pstVideo->IsAllPKVideoHere()) { return; } pstVideo->vecPvPVideo.resize(stAck.byStartSlot + stAck.wPvPVideoCnt); for(UINT16 i = 0; i < stAck.wPvPVideoCnt; i++) { pstVideo->vecPvPVideo[stAck.byStartSlot + i] = stAck.astPvPVideoList[i]; } if(pstVideo->IsAllPKVideoHere()) { USR_INFO(_SDT("CGvGVideoMgr::AddPKVideo[%llu], [%s] vs [%s] %s, round = [%u:%u], all pk video is here, PKVideoCnt = %u"), pstVideo->stGvGInfo.qwVideoID, pstVideo->stGvGInfo.stG1.aszFactionName, pstVideo->stGvGInfo.stG2.aszFactionName, gvgvideoutil::EchoBattleResult(pstVideo->stGvGInfo.byBattleResult).c_str(), pstVideo->stGvGInfo.stRound.byBigRound, pstVideo->stGvGInfo.stRound.bySmallRound, pstVideo->stGvGInfo.byPKVideoCnt ); m_setNotSavedVideoID.insert(stAck.qwVideoID); } }
VOID CSDPipeChannel::OnRecv(UINT16 wBusinessID, const CHAR *pData, UINT32 dwLen) { if (m_poPacketProcessor) { CSDProtocol* poProtocol = m_poPacketProcessor->GetProtocol(); if (poProtocol) { SDPipeMsgHeader* pHeader = (SDPipeMsgHeader*)pData; pHeader->dwTransID = SGDP::SDNtohl(pHeader->dwTransID); pHeader->wMsgID = SGDP::SDNtohs(pHeader->wMsgID); static CHAR DecodeData[PACKET_LENGTH] = {0}; INT32 nDecodeLen = poProtocol->Decode( pHeader->wMsgID, (CHAR*)(pData + sizeof(SDPipeMsgHeader) ) , dwLen - sizeof(SDPipeMsgHeader), DecodeData, PACKET_LENGTH); if ( nDecodeLen > 0) { m_poPacketProcessor->ProcessPacket(this, pHeader, DecodeData, nDecodeLen); } else { CSDServerID servierid(GetPipeID()); USR_INFO(_SDT("decode packet error: pipeid=%s, ip=%s, msgid=%u"), SDServerIDUtoa(GetPipeID()).c_str(), GetRemoteIPStr().c_str(), pHeader->wMsgID); } } } }
BOOL CPKApplication::Init(const TCHAR* pszConfigFilename) { if (FALSE == CPKApplication::Init(pszConfigFilename)) { return FALSE; } PrintScreen(_SDT("PKApplication::Init successful")); if(FALSE == CPKConfig::CreateInstance()) { return FALSE; } if(!CPKConfig::Instance()->Init(pszConfigFilename)) { USR_INFO(_SDT("CPKConfig::Init failed!")); return FALSE; } if(!m_oSQLMemoryPool.Create(MAX_SQL_LEN , MAX_SQL_LEN * 4)) { return FALSE; } //初始化db模块 if(FALSE == m_oDBMgr.Init()) { USR_INFO(_SDT("[%s: %d]:CDBMgr init failed"), MSG_MARK); return FALSE; } //初始化游戏逻辑模块 if (FALSE == CLogicModel::CreateInstance()) { USR_INFO(_SDT("[%s: %d]:Create CLogicModel failed"), MSG_MARK); return FALSE; } if(FALSE == CLogicModel::Instance()->Init()) { USR_INFO(_SDT("[%s: %d]:Create CLogicModel Init failed"), MSG_MARK); return FALSE; } return TRUE; }
static bool process_recv(struct client_ctx *cl_ctx, struct mqtt_packet *mqp_raw) { u8 msg_type = mqp_raw->msg_type; bool rv = false; USR_INFO("S: Rcvd msg Fix-Hdr (Byte1) 0x%02x from net %d [@ %u]\n\r", mqp_raw->fh_byte1, cl_ctx->net, net_ops->time()); if((MQTT_CONNECT != msg_type) ^ had_rcvd_conn_msg(cl_ctx)) goto process_recv_exit1; /* Proto Violation */ rx_timeout_update(cl_ctx); switch(msg_type) { case MQTT_CONNECT: rv = proc_connect_rx(cl_ctx, mqp_raw); break; case MQTT_DISCONNECT: rv = proc_disconn_rx(cl_ctx); break; case MQTT_SUBSCRIBE: rv = proc_sub_msg_rx(cl_ctx, mqp_raw); break; case MQTT_UNSUBSCRIBE: rv = proc_unsub_msg_rx(cl_ctx, mqp_raw); break; case MQTT_PINGREQ: rv = proc_pingreq_rx(cl_ctx); break; case MQTT_PUBLISH: rv = proc_pub_msg_rx(cl_ctx, mqp_raw); break; case MQTT_PUBACK: case MQTT_PUBREC: case MQTT_PUBREL: case MQTT_PUBCOMP: rv = proc_ack_msg_rx(cl_ctx, mqp_raw); break; default: break; } process_recv_exit1: DBG_INFO("S: Processing of MSG ID 0x%02x: %s\n\r", mqp_raw->msg_id, rv? "Good" : "Fail"); return rv; }
BOOL CSkillMgr::Init() { //读取配置文件 // 初始化CSkillPropMgr管理器 if(FALSE == CSkillPropMgr::CreateInstance()) { USR_INFO(_SDT("[%s: %d]: CSkillPropMgr::CreateInstance failed!"), MSG_MARK); return FALSE; } if(FALSE == CSkillPropMgr::Instance()->Init()) { USR_INFO(_SDT("[%s: %d]: CSkillPropMgr Init failed!"), MSG_MARK); return FALSE; } return TRUE; }
static i32 cl_ctx_send(struct client_ctx *cl_ctx, u8 *buf, u32 len) { i32 rv = net_ops->send(cl_ctx->net, buf, len, NULL); if(rv <= 0) { do_net_close_tx(cl_ctx, true); rv = MQP_ERR_NETWORK; } USR_INFO("S: FH-B1 0x%02x, len %u to net %d: %s [@ %u]\n\r", *buf, len, cl_ctx->net, rv? "Sent" : "Fail", net_ops->time()); return rv; }
BOOL CGSConfig::Init(const TCHAR* pszConfig) { CSDXMLFile oSDXMLFile; if (FALSE == oSDXMLFile.Load(_SDTT2A(pszConfig))) { return FALSE; } SDStrcpy(m_szConfigFile,_SDTT2A(pszConfig)); if(!_LoadCfg(&oSDXMLFile)) { USR_INFO(_SDT("[%s: %d]: _LoadCfg failed!"), MSG_MARK); return FALSE; } if(!_LoadGateListenerInfo(&oSDXMLFile)) { USR_INFO(_SDT("[%s: %d]: _LoadGateListenerInfo failed!"), MSG_MARK); return FALSE; } return TRUE; }
BOOL CLoginExHttpCMD::OnExecuted() { if (FALSE == m_bError) { USR_INFO( _SDT( "Player:%u url error, msg:%s" ), stLoginInfo.stReq.dwPlayerID, m_szErrorBuff ); OnLoginExAck_Failed(ERR_LOGIN::ID_LOGIN_TIME_OUT ); } else { ProcessResult(); } return TRUE; }
static bool can_delete_node(const struct topic_node *node) { if(node->up_nhbr && node->up_hier) { USR_INFO("S: fatal, node w/ up-nhbr & up-hier.\n\r"); return false; } if(node->dn_nhbr || node->dn_hier) return false; return true; }
static struct client_ctx *net_cl_ctx_find(i32 net) { struct client_ctx *cl_ctx = used_ctxs; while(cl_ctx) { if(net == cl_ctx->net) break; cl_ctx = cl_ctx->next; } if(NULL == cl_ctx) USR_INFO("Did not find ctx for net %d\n\r", net); return cl_ctx; }
VOID CSDPipeChannelMgr::OnReport(INT32 nErrCode, UINT32 dwID) { if(SGDP::PIPE_SUCCESS == nErrCode) { _OnConnected(dwID); CSDPipeChannel* poPipeChannel = FindPipeChannel(dwID); if (poPipeChannel) { poPipeChannel->OnEstablish(); } } else { USR_INFO(_SDT("PipeID, %s, Pipe report: %d\n"), SGDP::SDServerIDUtoa(dwID).c_str(), nErrCode); _OnDisconnected(dwID); } }
static bool topbuf_cpy(struct topbuf_desc *buf_desc, const c8 *subtop) { const c8 *next_subtop; c8 *buf = buf_desc->buffer + buf_desc->offset; u16 len = buf_desc->maxlen - buf_desc->offset; i32 rv = subtop_read(subtop, buf, len, &next_subtop); if(rv < 0) return false; if(NULL != next_subtop) { USR_INFO("S: topstr_copy fatal, bad subtop.\n\r"); return false; } buf_desc->offset += rv; return true; }
/** * @brief 同步执行SQL命令相关的逻辑部分 * @return VOID */ VOID SDAPI CSetAppPayProcessed::OnExecuted() { if( !m_bSuccess ) { return; } //数据处理成功,增加元宝,通知客户端(如果接收元宝的玩家和接收通知的玩家不是同一个,那么则需要分开取数据) CPlayer *pPlayer = CPlayerMgr::Instance()->FindPlayer( m_stAppPayProcessed.dwPlayerID ); if( NULL == pPlayer ) { //如果玩家不在线,则调出玩家,以设置数据 CGetPlayerDataMgr::Instance()->GetPlayerData(0 , GET_PLAYERDATATYPE_EXCHANGE, m_stAppPayProcessed.dwPlayerID, m_stAppPayProcessed.dwQueryPlayer, m_stAppPayProcessed.dwGold, m_stAppPayProcessed.dwRMB, (char *)m_stAppPayProcessed.strOrderID.c_str() ); return; } //玩家在线,则增加元宝 pPlayer->AddGold( m_stAppPayProcessed.dwGold, CRecordMgr::EGGT_ADDFLAGEXCHANGE, 0, 0, 0, 0, m_stAppPayProcessed.strOrderID, m_stAppPayProcessed.dwRMB); _SDTStrcpy( pPlayer->GetLastOrderID(), m_stAppPayProcessed.strOrderID.c_str() ); //并且通知玩家 CPlayer *pNotifyPlayer = CPlayerMgr::Instance()->FindPlayer( m_stAppPayProcessed.dwQueryPlayer ); if( !pNotifyPlayer ) { //被通知玩家不在线,则不通知 USR_INFO( _SDT("[%s:%d]Query player pay, but can't find query player:%u in memory"), MSG_MARK, m_stAppPayProcessed.dwQueryPlayer ); return; } UINT32 dwMsgID = INVALID_MSGID; //基础数据(如果被通知玩家和充值玩家不是同一个,那么这么做也没关系,因为如果不是同一个,那么客户端不提示具体的充值情况,所以可以随便赋值) DT_PLAYER_BASE_DATA stDT_PLAYER_BASE_DATA = pNotifyPlayer->GetDT_PLAYER_BASE_DATA(); dwMsgID = CGTPktBuilder::Instance()->OnAppPaySuccess( stDT_PLAYER_BASE_DATA.byVipLevel, stDT_PLAYER_BASE_DATA.dwTotalAmount, stDT_PLAYER_BASE_DATA.qwGold, m_stAppPayProcessed.dwGold, m_stAppPayProcessed.strOrderID, stDT_PLAYER_BASE_DATA.dwID); if( dwMsgID == INVALID_MSGID ) { return; } pNotifyPlayer->SendMsg( CGTPktBuilder::Instance()->GetPacketBuffer(), dwMsgID ); }
CSpecialEffect* CSpecialEffectPropMgr::CreateSpecialEffect(CPlayer* poPlayer, CBattleAttrObj* poMySelf, DT_SPECIAL_EFFECT_DATA& stSpecialData, UINT8 bySelectIdx) { CSpecialEffect* poEffect = NULL; switch (stSpecialData.abyEffectSmallType[bySelectIdx]) { case EBSE_CONTINUE_ATTACK: poEffect = CContinueAttackEffectPoolMgr::Instance()->Create(); break; case EBSE_SUCK_BLOOD: poEffect = CSuckBloodEffectPoolMgr::Instance()->Create(); break; case EBSE_PHYSICAL_IMMUNITY: poEffect = CPhysicalImmunityEffectPoolMgr::Instance()->Create(); break; case EBSE_MAGIC_IMMUNITY: poEffect = CMagicImmunityEffectPoolMgr::Instance()->Create(); break; case EBSE_ADD_BLOOD: poEffect = CAddBloodEffectPoolMgr::Instance()->Create(); break; case EBSE_REBOUND: poEffect = CReboundEffectPoolMgr::Instance()->Create(); break; case EBSE_BEAT_BACK: poEffect = CBeatBackPoolMgr::Instance()->Create(); break; case EBSE_DODGE: poEffect = CDodgeEffectPoolMgr::Instance()->Create(); break; default: return NULL; } if( !poEffect->Init(poPlayer, poMySelf, stSpecialData, bySelectIdx)) { FreeSpecialEffect(stSpecialData.abyEffectSmallType[bySelectIdx], poEffect); USR_INFO(_SDT("[%s:%u] SpecialEffect Init Failed, ID = %u "), MSG_MARK, stSpecialData.wEffectID); return NULL; } return poEffect; }
i32 mqtt_server_run(u32 wait_secs) // TBD break into two functions { USR_INFO("S: MQTT Server Run invoked 123....\n\r"); if(NULL == net_ops) return MQP_ERR_NET_OPS; if(loopback_port) { loopb_net = net_ops->open(DEV_NETCONN_OPT_UDP, NULL, loopback_port, NULL); if(-1 == loopb_net) return MQP_ERR_LIBQUIT; } listen_net = net_ops->listen(0, listener_port, NULL); if(-1 == listen_net) return MQP_ERR_LIBQUIT; return net_hnds_mon_loop(wait_secs); }
BOOL CTimeMedal::IsOverTime() { if ( !IsActivate() ) { return FALSE; } const SMedalProp* poProp = NULL; if( CMedalPropMgr::Instance()->GetMedalProp(m_stMedalData.wMedalID, poProp) ) { //当前时间 UINT64 qwCurTime = SGDP::SDTimeSecs(); UINT64 qwOverTime = m_stMedalData.qwActivateTime + poProp->dwOverTime; if( qwCurTime <= qwOverTime ) { USR_INFO("[%s:%d] LeftTime=%llu, MedalID = %u", MSG_MARK, qwOverTime - qwCurTime, m_stMedalData.wMedalID); return FALSE; } } SetActivateState(FALSE); // USR_INFO("[%s:%d] IsOver Time ", MSG_MARK); return TRUE; }
i32 mqtt_server_init(const struct mqtt_server_lib_cfg *lib_cfg, const struct mqtt_server_app_cfg *app_cfg) { /* If mutex is specified, then the following set of callbacks are invoked in the locked state - enumerated by 'locked' */ struct mqtt_server_msg_cbs pkts_cbs = {proc_connect_rx_locked, proc_sub_msg_rx_locked, proc_un_sub_msg_locked, proc_pub_msg_rx_locked, proc_notify_ack_locked, on_cl_net_close_locked, on_connack_send_locked }; struct plugin_core_msg_cbs core_cbs = {proc_topic_enroll_locked, proc_topic_cancel_locked, proc_app_pub_send_locked }; util_params_set(lib_cfg->debug_printf, lib_cfg->mutex, lib_cfg->mutex_lockin, lib_cfg->mutex_unlock); USR_INFO("Version: Server LIB %s, Common LIB %s.\n\r", MQTT_SERVER_VERSTR, MQTT_COMMON_VERSTR); topic_node_init(); cl_mgmt_init(); plugin_init(&core_cbs); mqtt_server_lib_init(lib_cfg, &pkts_cbs); return 0; }
BOOL CSDPipeChannel::SendMsg(UINT32 dwTransID, UINT32 dwMsgID ,const CHAR* pData) { CSDProtocol* pProtocol = m_poPacketProcessor->GetProtocol(); if ( NULL == pProtocol ) { return FALSE; } static CHAR MsgData[PACKET_LENGTH]={0}; CHAR* pMsgBody = MsgData + sizeof(SDPipeMsgHeader); INT32 nBodyLength = PACKET_LENGTH - sizeof(SDPipeMsgHeader); INT32 nEncodeRet = pProtocol->Encode(dwMsgID,(VOID*) pData, pMsgBody, nBodyLength); if ( nEncodeRet < 0) { USR_INFO(_SDT(" Encode failed! MsgID[%d]." ) ,dwMsgID); return FALSE; } SDPipeMsgHeader* pTempHeader = (SDPipeMsgHeader *)(MsgData); if ( 3043 == dwMsgID)//CLIGS_OPEN_PLAYER_PANEL_ACK_OLD//°æ±¾¼æÈÝÎÊÌâ { dwMsgID = 2823;//CLIGS_OPEN_PLAYER_PANEL_ACK; } INT32 nTotalLen = nEncodeRet + SDBuildPipeMsgHeader(pTempHeader,dwMsgID,dwTransID); return Send(MsgData, nTotalLen); }
VOID CSDPipeChannel::OnError(const INT32 nErrCode) { USR_INFO(_SDT("pipe(%s) has error: %d, ip: %s" ) ,SDServerIDUtoa(GetPipeID()).c_str(), nErrCode, GetRemoteIPStr().c_str()); }
VOID CLoginExHttpCMD::ProcessResult() { USR_INFO( _SDT( "ack:%s" ), SDUTF82Local(m_strResult.c_str()).c_str()); CC_LOOP_DO Json::Value root; Json::Reader reader; if( !reader.parse( m_strResult, root ) ) { break; } //检测数据个数,如果为零刚为出错,防止崩溃 if (!root.isObject()) { break; } //解析返回的状态码 if (!root["errcode"].isInt()) { break; } stAck.wErrCode = root["errcode"].asInt(); if (!root["datas"].isObject()) { break; } Json::Value datas = root["datas"]; UINT32 dwUserID = 0; if (!datas["userid"].isInt()) { break; } dwUserID = datas["userid"].asInt(); Json::Value jsVersionInfo; if (!datas["versioninfo"].isObject()) { break; } jsVersionInfo = datas["versioninfo"]; if (!jsVersionInfo["versionid"].isInt()) { break; } stAck.stVersionInfo.dwVersionID = jsVersionInfo["versionid"].asInt(); if (!jsVersionInfo["forceupdateflag"].isInt()) { break; } stAck.stVersionInfo.byForceUpdateFlag = jsVersionInfo["forceupdateflag"].asInt(); if (!jsVersionInfo["updatecontent"].isString()) { break; } SDStrncpy(stAck.stVersionInfo.aszUpdateContent, jsVersionInfo["updatecontent"].asCString(), MAX_CONTENT_SIZE); if (!jsVersionInfo["updateurl"].isString()) { break; } SDStrncpy(stAck.stVersionInfo.aszUpdateURL, jsVersionInfo["updateurl"].asCString(), MAX_CONTENT_SIZE); //通知 Json::Value jsNoticeInfo; if (!datas["noticeinfo"].isObject()) { break; } jsNoticeInfo = datas["noticeinfo"]; if (!jsNoticeInfo["noticeid"].isInt()) { break; } stAck.stNoticeInfo.dwNoticeID = jsVersionInfo["noticeid"].asInt(); if (!jsNoticeInfo["forcepopflag"].isInt()) { break; } stAck.stNoticeInfo.byForcePopFlag = jsVersionInfo["forcepopflag"].asInt(); if (!jsNoticeInfo["urlflag"].isInt()) { break; } stAck.stNoticeInfo.byUrlFlag = jsVersionInfo["urlflag"].asInt(); if (!jsNoticeInfo["noticecontent"].isString()) { break; } SDStrncpy(stAck.stNoticeInfo.aszNoticeContent, jsNoticeInfo["noticecontent"].asCString(), MAX_CONTENT_SIZE); //////////////////////////////////////////////////////////////////////// if (!datas["otherdeviceloginflag"].isInt()) { break; } stAck.byOtherDeviceLoginFlag = datas["otherdeviceloginflag"].asInt(); if (!datas["authtype"].isInt()) { break; } stAck.byAuthType = datas["authtype"].asInt(); if (!datas["deviceid"].isString()) { break; } SDStrncpy((char*)stAck.aszDeviceID, datas["deviceid"].asCString(), DEVICEID_LEN); if (!datas["notifyid"].isString()) { break; } SDStrncpy((char*)stAck.aszNotifyID, datas["notifyid"].asCString(), NOTIFYID_LEN); if (!datas["username"].isString()) { break; } SDStrncpy((char*)stAck.aszUserName, datas["username"].asCString(), USERNAME_LEN); if (!datas["zoneid"].isInt()) { break; } stAck.wZoneID = datas["zoneid"].asInt(); if (!datas["oldzoneid"].isInt()) { break; } m_wOriZoneID = datas["oldzoneid"].asInt(); if (!datas["zonename"].isString()) { break; } SDStrncpy(stAck.aszZoneName, datas["zonename"].asCString(), ZONENAME_LEN); if (!datas["playerid"].isInt()) { break; } stAck.dwPlayerID = datas["playerid"].asInt(); if (!datas["careerid"].isInt()) { break; } stAck.wCareerID = datas["careerid"].asInt(); if (datas["minresver"].isInt()) { stAck.stExtFuncParamLst.astExtFuncParaInfo[0].dwParam3 = datas["minresver"].asInt(); } stAck.stExtFuncParamLst.byFuncNum = 1; UINT8 byDaiChong = 0; if (datas["daichong"].isInt()) { byDaiChong = datas["daichong"].asInt(); } stAck.stExtFuncParamLst.byFuncNum = 1; OnLoginExAck_Success(dwUserID, byDaiChong); return; CC_LOOP_WHILE(0) SYS_CRITICAL( _SDT( "json parse error, result:%s" ), SDUTF82Local(m_strResult.c_str()).c_str() ); OnLoginExAck_Failed( ERR_LOGIN::ID_LS_SERVER_NOT_STARTUP); }
VOID CSDPipeChannel::OnTerminate() { USR_INFO(_SDT("pipe(%s) has terminated, ip: %s" ) ,SDServerIDUtoa(GetPipeID()).c_str(), GetRemoteIPStr().c_str()); }
BOOL CGSConfig::_LoadCfg(CSDXMLFile* poConfig) { CSDXMLNode oRootNode = poConfig->GetRootNode() ; string strValue; m_dwOnlineSaveTimeInterval = oRootNode["TimerCfg"]("OnlineSaveTimeInterval").AsInteger(); m_dwOfflineSaveCkInterval = oRootNode["TimerCfg"]("OfflineSaveCkInterval").AsInteger(); m_dwOfflineCacheTime = oRootNode["TimerCfg"]("OfflineCacheTime").AsInteger(); m_dwPvpSaveCkInterval = oRootNode["TimerCfg"]("PvpSaveCkInterval").AsInteger(); m_dwPvpSaveNum = oRootNode["TimerCfg"]("PvpSaveNum").AsInteger(); m_dwPlayerSaveInterval=oRootNode["SavePlayerCfg"]("SavePlayerInterval").AsInteger(); m_dwFillePlayerQueueInterval=oRootNode["SavePlayerCfg"]( "FillePlayerQueueInterval" ).AsInteger(); m_strRechargeIP=oRootNode["Recharge"]( "ip" ).AsString(); m_dwRechargePort=oRootNode["Recharge"]( "port" ).AsInteger(); m_nPayType=oRootNode["PayConfig"]("paytype").AsInteger(); m_strAppPayUrl=oRootNode["APPPay"]("Url").AsString(); m_strAppPayTableName=oRootNode["APPPay"]( "PayTableName" ).AsString(); if((0 == m_dwOnlineSaveTimeInterval) || (0 == m_dwOfflineSaveCkInterval) || (0 == m_dwOfflineCacheTime) || (0 == m_dwPvpSaveCkInterval) || (0 == m_dwPvpSaveNum) ) { USR_INFO(_SDT("[%s: %d]: TimerCfg invalid!"), MSG_MARK); return FALSE; } m_dwTimerNotice = oRootNode["TimerNotice"]("OnTimerNotice").AsInteger(); if (m_dwTimerNotice < 0 || m_dwTimerNotice > 24) { USR_INFO(_SDT("[%s: %d]: TimerNotice invalid!"), MSG_MARK); return FALSE; } m_dwChatSyncTime = oRootNode["Chat"]("SyncTimer").AsInteger(); if (m_dwChatSyncTime < 60) { m_dwChatSyncTime = 60; } m_dwChatSendNotice = oRootNode["Chat"]("SendTimer").AsInteger(); if (m_dwChatSendNotice < 10) { m_dwChatSendNotice = 10; } m_strSpeCfgTablePrefix = oRootNode["SpeCfgTablePrefix"]( "Prefix" ).AsString(); CSDDateTime stDateTime; if(SDTimeFromString(oRootNode["ServerOpenTime"]( "Time" ).AsString(), stDateTime)) { m_qwServerOpentTime = stDateTime.GetTimeValue(); } CSDXMLNode oSettingNode=oRootNode["DBMS"]; LoadDBConnInfo( oSettingNode, m_oDBAccount ); m_dwPoolCoreSize = oSettingNode(ELEM_POOLCORESIZE).AsInteger(); m_dwPoolMaxSize = oSettingNode(ELEM_POOLMAXSIZE).AsInteger(); CSDXMLNode oRecordDBSettingNode=oRootNode["RecordDBMS"]; LoadDBConnInfo( oRecordDBSettingNode, m_oRecordDBAccount ); m_dwRecordPoolCoreSize = oRecordDBSettingNode(ELEM_POOLCORESIZE).AsInteger(); m_dwRecordPoolMaxSize = oRecordDBSettingNode(ELEM_POOLMAXSIZE).AsInteger(); CSDXMLNode oPayDBSettingNode=oRootNode["PayDBMS"]; LoadDBConnInfo( oPayDBSettingNode, m_oPayDBAccount ); m_dwPayPoolCoreSize = oPayDBSettingNode(ELEM_POOLCORESIZE).AsInteger(); m_dwPayPoolMaxSize = oPayDBSettingNode(ELEM_POOLMAXSIZE).AsInteger(); CSDXMLNode oCfgBSettingNode=oRootNode["ConfigureDBMS"]; LoadDBConnInfo( oCfgBSettingNode, m_oCfgDBAccount ); return TRUE; }