void CSSLClientAsync::OnConnect(BOOL bConnected) { //无论是否连接成功,都认为已经判断结束 SetCheckConnect(FALSE); //连接完毕,则删除写/错误事件的注册,改成读事件 m_pio->Remove_WriteEvent(this); if (TRUE == bConnected) { SOCKET_IO_INFO("socket connect successed, remote ip: %s, port: %d.", GetRemoteIP(), GetRemotePort()); DoConnect(GetSocketID()); SSL_set_mode(GetSSL(), SSL_MODE_AUTO_RETRY); if (SSL_set_fd(GetSSL(), GetSocket()) != 1) { SOCKET_IO_ERROR("ssl set fd failed"); DoException(GetSocketID(), SOCKET_IO_SSL_CONNECT_FAILED); return; } SSLConnect(); } else { SOCKET_IO_ERROR("socket connect failed, remote ip: %s, port: %d.", GetRemoteIP(), GetRemotePort()); DoException(GetSocketID(), SOCKET_IO_TCP_CONNECT_FAILED); } }
void CUser::SelCharToAgent(Packet & pkt) { Packet result(WIZ_SEL_CHAR); std::string strUserID, strAccountID; uint8 bInit; pkt >> strAccountID >> strUserID >> bInit; if (strAccountID.empty() || strAccountID.size() > MAX_ID_SIZE || strUserID.empty() || strUserID.size() > MAX_ID_SIZE ||strAccountID != m_strAccountID) { Disconnect(); return; } // Disconnect any currently logged in sessions. CUser *pUser = g_pMain->GetUserPtr(strUserID.c_str(), TYPE_CHARACTER); if (pUser && (pUser->GetSocketID() != GetSocketID())) { pUser->Disconnect(); // And reject the login attempt (otherwise we'll probably desync char data) result << uint8(0); Send(&result); return; } result << m_strAccountID << strUserID << bInit; g_pMain->m_LoggerSendQueue.PutData(&result, GetSocketID()); }
void CUser::UserInOut(BYTE Type) { if (GetMap() == NULL) return; Packet result(WIZ_USER_INOUT); result << Type << uint8(0) << uint16(GetSocketID()); if (Type == USER_OUT) GetMap()->RegionUserRemove(m_RegionX, m_RegionZ, GetSocketID()); else GetMap()->RegionUserAdd(m_RegionX, m_RegionZ, GetSocketID()); if (Type != USER_OUT) GetUserInfo(result); m_pMain->Send_Region(&result, GetMap(), m_RegionX, m_RegionZ, this ); if (Type == USER_OUT || m_bAbnormalType != ABNORMAL_BLINKING) { result.Initialize(AG_USER_INOUT); result.SByte(); result << Type << uint16(GetSocketID()) << m_pUserData->m_id << m_pUserData->m_curx << m_pUserData->m_curz; m_pMain->Send_AIServer(&result); } }
void CUser::MoveProcess(Packet & pkt) { ASSERT(GetMap() != nullptr); if (m_bWarp || isDead()) return; uint16 will_x, will_z, will_y; int16 speed=0; float real_x, real_z, real_y; uint8 echo; pkt >> will_x >> will_z >> will_y >> speed >> echo; real_x = will_x/10.0f; real_z = will_z/10.0f; real_y = will_y/10.0f; if (!isGM()) { // TO-DO: Handle proper speed checks against server-side amounts. // We should also avoid relying on what the client has sent us. if (speed > 200) // What is the signifance of this number? Considering 90 is light feet... // We shouldn't be using magic numbers at all here. { Disconnect(); return; } } if (!GetMap()->IsValidPosition(real_x, real_z, real_y)) return; if (m_oldx != GetX() || m_oldz != GetZ()) { m_oldx = GetX(); m_oldy = GetY(); m_oldz = GetZ(); } // TO-DO: Ensure this is checked properly to prevent speedhacking SetPosition(real_x, real_y, real_z); if (RegisterRegion()) { g_pMain->RegionNpcInfoForMe(this); g_pMain->RegionUserInOutForMe(this); g_pMain->MerchantUserInOutForMe(this); } if (m_bInvisibilityType == INVIS_DISPEL_ON_MOVE) CMagicProcess::RemoveStealth(this, INVIS_DISPEL_ON_MOVE); Packet result(WIZ_MOVE); result << GetSocketID() << will_x << will_z << will_y << speed << echo; SendToRegion(&result); GetMap()->CheckEvent(real_x, real_z, this); result.Initialize(AG_USER_MOVE); result << GetSocketID() << m_curx << m_curz << m_cury << speed; Send_AIServer(&result); }
bool CClient::addRelay( const CServerDef * pServ ) { ADDTOCALLSTACK("CClient::addRelay"); EXC_TRY("addRelay"); // Tell the client to play on this server. if ( !pServ ) return false; CSocketAddressIP ipAddr = pServ->m_ip; if ( ipAddr.IsLocalAddr()) // local server address not yet filled in. { ipAddr = m_net->m_socket.GetSockName(); DEBUG_MSG(( "%x:Login_Relay to %s\n", GetSocketID(), ipAddr.GetAddrStr() )); } if ( GetPeer().IsLocalAddr() || GetPeer().IsSameIP( ipAddr )) // weird problem with client relaying back to self. { DEBUG_MSG(( "%x:Login_Relay loopback to server %s\n", GetSocketID(), ipAddr.GetAddrStr() )); ipAddr.SetAddrIP( SOCKET_LOCAL_ADDRESS ); } EXC_SET("customer id"); dword dwAddr = ipAddr.GetAddrIP(); dword dwCustomerId = 0x7f000001; if ( g_Cfg.m_fUseAuthID ) { CSString sCustomerID(pServ->GetName()); sCustomerID.Add(GetAccount()->GetName()); dwCustomerId = z_crc32(0L, Z_NULL, 0); dwCustomerId = z_crc32(dwCustomerId, reinterpret_cast<const z_Bytef *>(sCustomerID.GetPtr()), (z_uInt)sCustomerID.GetLength()); GetAccount()->m_TagDefs.SetNum("customerid", dwCustomerId); } DEBUG_MSG(( "%x:Login_Relay to server %s with AuthId %u\n", GetSocketID(), ipAddr.GetAddrStr(), dwCustomerId )); EXC_SET("server relay packet"); new PacketServerRelay(this, dwAddr, pServ->m_ip.GetPort(), dwCustomerId); m_Targ_Mode = CLIMODE_SETUP_RELAY; return true; EXC_CATCH; EXC_DEBUG_START; g_Log.EventDebug("account '%s'\n", GetAccount() ? GetAccount()->GetName() : ""); EXC_DEBUG_END; return false; }
void CUser::MoveProcess(Packet & pkt) { ASSERT(GetMap() != nullptr); if (m_bWarp || isDead()) return; uint16 will_x, will_z, will_y; int16 speed=0; float real_x, real_z, real_y; uint8 echo; pkt >> will_x >> will_z >> will_y >> speed >> echo; real_x = will_x/10.0f; real_z = will_z/10.0f; real_y = will_y/10.0f; m_sSpeed = speed; SpeedHackUser(); if (!GetMap()->IsValidPosition(real_x, real_z, real_y)) return; if (m_oldx != GetX() || m_oldz != GetZ()) { m_oldx = GetX(); m_oldy = GetY(); m_oldz = GetZ(); } // TODO: Ensure this is checked properly to prevent speedhacking SetPosition(real_x, real_y, real_z); if (RegisterRegion()) { g_pMain->RegionNpcInfoForMe(this); g_pMain->RegionUserInOutForMe(this); g_pMain->MerchantUserInOutForMe(this); } if (m_bInvisibilityType == INVIS_DISPEL_ON_MOVE) CMagicProcess::RemoveStealth(this, INVIS_DISPEL_ON_MOVE); Packet result(WIZ_MOVE); result << GetSocketID() << will_x << will_z << will_y << speed << echo; SendToRegion(&result); GetMap()->CheckEvent(real_x, real_z, this); result.Initialize(AG_USER_MOVE); result << GetSocketID() << m_curx << m_curz << m_cury << speed; Send_AIServer(&result); }
void CSSLClientAsync::OnRecv() { if (GetSSLConnectStatus() == TRUE) { char szBuf[TCP_RECV_SIZE] = {0}; int32_t nRet = SSL_read(GetSSL(), szBuf, TCP_RECV_SIZE); if (nRet > 0) { int32_t nBufSize = nRet; char szIP[32] = {0}; int32_t nPort = 0; S_GetPeerName(GetSocket(), szIP, &nPort); DoRecv(GetSocketID(), szBuf, nBufSize, szIP, nPort); } else if (nRet == 0) { int32_t nErrorCode = SSL_get_error(GetSSL(), nRet); if (SSL_ERROR_ZERO_RETURN == nErrorCode) { //对方关闭socket SOCKET_IO_WARN("recv ssl data error, peer closed."); DoException(GetSocketID(), SOCKET_IO_SSL_RECV_FAILED); } else { SOCKET_IO_ERROR("recv ssl data error."); DoException(GetSocketID(), SOCKET_IO_SSL_RECV_FAILED); } } else { int32_t nErrorCode = SSL_get_error(GetSSL(), nRet); if (SSL_ERROR_WANT_READ == nErrorCode || SSL_ERROR_WANT_WRITE == nErrorCode) { //用select/epoll/iocp的方式应该很少会有这个情况出现 SOCKET_IO_DEBUG("recv ssl data error, buffer is blocking."); } else { SOCKET_IO_ERROR("recv ssl data error, errno: %d.", nErrorCode); DoException(GetSocketID(), SOCKET_IO_SSL_RECV_FAILED); } } } else { SSLConnect(); } }
/** @fn void CTCPSession::OnRecv() * @brief * @return */ void CTCPSession::OnRecv() { char szBuf[RECV_MAX_BUF_SIZE] = {0}; HPR_INT32 nRet = HPR_Recv(GetSocket(), szBuf, RECV_MAX_BUF_SIZE); if (nRet > 0) { HPR_INT32 nBufSize = nRet; if (m_phandler != NULL) { HPR_ADDR_T addr; memset(&addr, 0, sizeof(HPR_ADDR_T)); HPR_GetAddrBySockFd(GetSocket(), NULL, &addr); if (m_phandler != NULL) { m_phandler->OnRecv(GetSocketID(), szBuf, nBufSize, HPR_GetAddrString(&addr), HPR_GetAddrPort(&addr)); } } } else if (nRet == 0) { // close socket if (m_phandler != NULL) { m_phandler->OnException(GetSocketID(), LIB_DEV_ANALYSIS_ERROR_RECV); } DEV_ANALYSIS_DEBUG(0, "DEV ANALYSIS Debug", 0, 0, "dev analysis recv tcp data error, peer closed."); } else { #if (defined(_WIN32) || defined(_WIN64)) HPR_INT32 nErrorCode = ::GetLastError(); if (nErrorCode != WSAEWOULDBLOCK) #elif defined(__linux__) HPR_INT32 nErrorCode = errno; if (nErrorCode != EAGAIN) #endif { DEV_ANALYSIS_DEBUG(0, "DEV ANALYSIS Debug", 0, 0, "dev analysis recv tcp data error, errno: %d.", nErrorCode); if (m_phandler != NULL) { m_phandler->OnException(GetSocketID(), LIB_DEV_ANALYSIS_ERROR_RECV); } } } }
void CUser::BuyingMerchantList(Packet & pkt) { if (m_sMerchantsSocketID >= 0) RemoveFromMerchantLookers(); //This check should never be hit... uint16 uid = pkt.read<uint16>(); CUser *pMerchant = g_pMain->GetUserPtr(uid); if (pMerchant == nullptr || !pMerchant->isMerchanting()) return; m_sMerchantsSocketID = uid; pMerchant->m_arMerchantLookers.push_front(GetSocketID()); Packet result(WIZ_MERCHANT, uint8(MERCHANT_BUY_LIST)); result << uint8(1) << uint16(uid); for (int i = 0; i < MAX_MERCH_ITEMS; i++) { _MERCH_DATA *pMerch = &pMerchant->m_arMerchantItems[i]; result << pMerch->nNum << pMerch->sCount << pMerch->sDuration << pMerch->nPrice; } Send(&result); }
void CUser::UserInOut(uint8 bType) { if (GetRegion() == nullptr) return; Packet result; if (bType != INOUT_OUT) ResetGMVisibility(); GetInOut(result, bType); if (bType == INOUT_OUT) GetRegion()->Remove(this); else GetRegion()->Add(this); SendToRegion(&result, this, GetEventRoom()); if (bType == INOUT_OUT || !isBlinking()) { result.Initialize(AG_USER_INOUT); result.SByte(); result << bType << GetSocketID() << GetName() << m_curx << m_curz; Send_AIServer(&result); } }
void CUser::LoginProcess(Packet & pkt) { // Enforce only one login request per session // It's common for players to spam this at the server list when a response isn't received immediately. if (!m_strAccountID.empty()) return; Packet result(WIZ_LOGIN); CUser * pUser; std::string strAccountID, strPasswd; pkt >> strAccountID >> strPasswd; if (strAccountID.empty() || strAccountID.size() > MAX_ID_SIZE || strPasswd.empty() || strPasswd.size() > MAX_PW_SIZE) goto fail_return; pUser = g_pMain->GetUserPtr(strAccountID, TYPE_ACCOUNT); if (pUser && (pUser->GetSocketID() != GetSocketID())) { pUser->Disconnect(); goto fail_return; } result << strPasswd; m_strAccountID = strAccountID; g_pMain->AddDatabaseRequest(result, this); return; fail_return: result << uint8(-1); Send(&result); }
bool CClient::Login_Relay( uint iRelay ) // Relay player to a selected IP { ADDTOCALLSTACK("CClient::Login_Relay"); // Client wants to be relayed to another server. XCMD_ServerSelect // iRelay = 0 = this local server. // Sometimes we get an extra 0x80 ??? if ( iRelay >= 0x80 ) { iRelay -= 0x80; } // >= 1.26.00 clients list Gives us a 1 based index for some reason. if ( iRelay > 0 ) iRelay --; CServerRef pServ; if ( iRelay <= 0 ) { pServ = &g_Serv; // we always list ourself first. } else { iRelay --; pServ = g_Cfg.Server_GetDef(iRelay); if ( pServ == NULL ) { DEBUG_ERR(( "%x:Login_Relay BAD index! %u\n", GetSocketID(), iRelay )); return false; } } return addRelay( pServ ); }
void CUser::NewCharToAgent(Packet & pkt) { Packet result(WIZ_NEW_CHAR); uint32 nHair; uint16 sClass; uint8 bCharIndex, bRace, bFace, str, sta, dex, intel, cha, errorCode = 0; std::string strUserID; pkt >> bCharIndex >> strUserID >> bRace >> sClass >> bFace >> nHair >> str >> sta >> dex >> intel >> cha; _CLASS_COEFFICIENT* p_TableCoefficient = g_pMain->m_CoefficientArray.GetData(sClass); if (!IsValidName(strUserID.c_str())) errorCode = NEWCHAR_INVALID_NAME; else if (bCharIndex > 2) errorCode = NEWCHAR_NO_MORE; else if (p_TableCoefficient == NULL || (str + sta + dex + intel + cha) > 300) errorCode = NEWCHAR_INVALID_DETAILS; else if (str < 50 || sta < 50 || dex < 50 || intel < 50 || cha < 50) errorCode = NEWCHAR_STAT_TOO_LOW; if (errorCode != 0) { result << errorCode; Send(&result); return; } result << m_strAccountID << bCharIndex << strUserID << bRace << sClass << bFace << nHair << str << sta << dex << intel << cha; g_pMain->m_LoggerSendQueue.PutData(&result, GetSocketID()); }
void CUser::MerchantItemList(Packet & pkt) { if (m_sMerchantsSocketID >= 0) RemoveFromMerchantLookers(); //This check should never be hit... uint16 uid; pkt >> uid; if (uid >= MAX_USER) return; CUser *pMerchantUser = g_pMain->GetUserPtr(uid); if(!pMerchantUser || !pMerchantUser->isMerchanting()) return; m_sMerchantsSocketID = uid; pMerchantUser->m_arMerchantLookers.push_front(GetSocketID()); Packet result(WIZ_MERCHANT, uint8(MERCHANT_ITEM_LIST)); result << uint16(1) << uint16(uid); for(int i = 0; i < MAX_MERCH_ITEMS; i++) { result << pMerchantUser->m_arSellingItems[i].nNum << pMerchantUser->m_arSellingItems[i].sCount << pMerchantUser->m_arSellingItems[i].sDuration << pMerchantUser->m_arSellingItems[i].nPrice << uint32(0); //Not sure what this one is, maybe serial? } Send(&result); }
long CMessage::DefaultRun() { switch( GetType() ) { case BASEMSG_Socket_Accept: { } break; case BASEMSG_Socket_Close: { NetFlag flag = (NetFlag)GetNetFlag(); if (flag & NF_GAME_SERVER) { GetNetHandler().OnClientLost(GetGSID()); CMessage::UnMapGSIDSocket(GetSocketID()); } else { GetNetHandler().OnServerLost(flag); } } break; } return 0; }
//关闭连接 VOID CTCPSocket::CloseSocket(BYTE bNotify) { //关闭连接 bool bClose = (m_hSocket != INVALID_SOCKET); m_cbSocketStatus = SOCKET_STATUS_IDLE; if (m_hSocket != INVALID_SOCKET) { WSAAsyncSelect(m_hSocket, GetSafeHwnd(), WM_SOCKET_NOTIFY, 0); closesocket(m_hSocket); m_hSocket = INVALID_SOCKET; m_cbSocketStatus = SOCKET_STATUS_IDLE; } if ((bClose == true) && (m_pITCPSocketSink != NULL)) { ASSERT(m_pITCPSocketSink != NULL); try { m_pITCPSocketSink->OnEventTCPSocketShut(GetSocketID(), bNotify); } catch (...) {} } //恢复数据 m_wRecvSize = 0; m_cbSendRound = 0; m_cbRecvRound = 0; m_dwSendXorKey = 0; m_dwRecvXorKey = 0; m_dwSendTickCount = 0; m_dwRecvTickCount = 0; m_dwSendPacketCount = 0; m_dwRecvPacketCount = 0; m_hSocket = INVALID_SOCKET; m_cbSocketStatus = SOCKET_STATUS_IDLE; }
void CGameSocket::RecvServerConnect(Packet & pkt) { uint8 byReconnect = pkt.read<uint8>(); printf("[GameServer connected - %s]\n", GetRemoteIP().c_str()); Packet result(AI_SERVER_CONNECT, byReconnect); Send(&result); if (byReconnect == 1) TRACE("**** ReConnect - server=%s, socket = %d ****\n ", GetRemoteIP().c_str(), GetSocketID()); else TRACE("**** Connect - server=%s, socket = %d ****\n ", GetRemoteIP().c_str(), GetSocketID()); g_pMain->m_bFirstServerFlag = true; g_pMain->AllNpcInfo(); }
long CMessage::DefaultRun() { switch( GetType() ) { case BASEMSG_Socket_Accept: break; case BASEMSG_Socket_Close: { // 日志服务器断了,重新建立连接线程 if( GetNetFlag()&NF_LOGSERVER_CLIENT ) { //GetGame()->OnLostLogServer(); //GetGame()->CreateConnectLogThread(); } else if( GetNetFlag()&NF_SERVER_CLIENT ) { // GameServer断开了 GetGame()->OnGSLost(GetGSID()); CMessage::UnMapGSIDSocket(GetSocketID()); } } break; } return true; }
void CUser::RemoveFromMerchantLookers() { CUser *pPreviousMerchantUser = g_pMain->GetUserPtr(m_sMerchantsSocketID); if (pPreviousMerchantUser == nullptr) return; pPreviousMerchantUser->m_arMerchantLookers.remove(GetSocketID()); m_sMerchantsSocketID = -1; }
void CUser::Rotate(Packet & pkt) { if (isDead()) return; Packet result(WIZ_ROTATE); pkt >> m_sDirection; result << GetSocketID() << m_sDirection; SendToRegion(&result, this); }
void CSSLClientAsync::_Close() { if (m_ssl) { UnInitSSL(); } if (GetSocket() != S_INVALID_SOCKET) { if (m_pio) { m_pio->Remove_Handler(this); } SetSSLConnectStatus(FALSE); S_CloseSocket(GetSocket()); SOCKET_IO_WARN("close ssl socket, sock %d, real sock: %d.", GetSocketID(), GetSocket()); m_socket = S_INVALID_SOCKET; DoClose(GetSocketID()); _ClearSendBuffer(); } }
void CAISocket::LoginProcess(Packet & pkt) { uint8 bReconnect = pkt.read<uint8>(); DEBUG_LOG("AI Server Connect Success!!"); if (bReconnect == 1) TRACE("**** ReConnect - socket = %d ****\n ", GetSocketID()); g_pMain->m_bServerCheckFlag = TRUE; g_pMain->SendAllUserInfo(); }
void CUser::MerchantClose() { if (!isMerchanting()) return; m_bMerchantState = MERCHANT_STATE_NONE; GiveMerchantItems(); // Give back to the user that which hasn't been sold, if any. Packet result(WIZ_MERCHANT, uint8(MERCHANT_CLOSE)); result << GetSocketID(); SendToRegion(&result); }
void CAISocket::LoginProcess(Packet & pkt) { uint8 bReconnect = pkt.read<uint8>(); TRACE("Connected to the AI server\n"); if (bReconnect == 1) TRACE("**** ReConnect - socket = %d ****\n ", GetSocketID()); g_pMain->m_bServerCheckFlag = TRUE; g_pMain->SendAllUserInfo(); }
void CUser::MoveProcess(Packet & pkt) { ASSERT(GetMap() != NULL); if (m_bWarp || isDead()) return; uint16 will_x, will_z, will_y, speed=0; float real_x, real_z, real_y; uint8 echo; pkt >> will_x >> will_z >> will_y >> speed >> echo; real_x = will_x/10.0f; real_z = will_z/10.0f; real_y = will_y/10.0f; if (!GetMap()->IsValidPosition(real_x, real_z, real_y)) return; // TO-DO: Ensure this is checked properly to prevent speedhacking m_curx = real_x; m_curz = real_z; m_cury = real_y; if (RegisterRegion()) { g_pMain->RegionNpcInfoForMe(this); g_pMain->RegionUserInOutForMe(this); g_pMain->MerchantUserInOutForMe(this); } if (m_bInvisibilityType == INVIS_DISPEL_ON_MOVE) StateChangeServerDirect(7, INVIS_NONE); Packet result(WIZ_MOVE); result << GetSocketID() << will_x << will_z << will_y << speed << echo; SendToRegion(&result); GetMap()->CheckEvent(real_x, real_z, this); result.Initialize(AG_USER_MOVE); result << GetSocketID() << m_curx << m_curz << m_cury << speed; Send_AIServer(&result); }
CClient::CClient(NetState* state) { // This may be a web connection or Telnet ? m_net = state; SetConnectType( CONNECT_UNK ); // don't know what sort of connect this is yet. // update ip history #ifndef _MTNETWORK HistoryIP& history = g_NetworkIn.getIPHistoryManager().getHistoryForIP(GetPeer()); #else HistoryIP& history = g_NetworkManager.getIPHistoryManager().getHistoryForIP(GetPeer()); #endif history.m_connecting++; history.m_connected++; m_Crypt.SetClientVer( g_Serv.m_ClientVersion ); m_pAccount = NULL; m_pChar = NULL; m_pGMPage = NULL; m_timeLogin.Init(); m_timeLastSend = m_timeLastEvent = CServTime::GetCurrentTime(); m_timeLastEventWalk = CServTime::GetCurrentTime(); m_iWalkStepCount = 0; m_iWalkTimeAvg = 100; m_timeWalkStep = GetTickCount(); m_Targ_Timeout.Init(); m_Targ_Mode = CLIMODE_SETUP_CONNECTING; m_Prompt_Mode = CLIMODE_NORMAL; m_tmSetup.m_dwIP = 0; m_tmSetup.m_iConnect = 0; m_tmSetup.m_bNewSeed = false; m_Env.SetInvalid(); g_Log.Event(LOGM_CLIENTS_LOG, "%lx:Client connected [Total:%lu] ('%s' %ld/%ld)\n", GetSocketID(), g_Serv.StatGet(SERV_STAT_CLIENTS), GetPeerStr(), history.m_connecting, history.m_connected); m_zLastMessage[0] = 0; m_zLastObjMessage[0] = 0; m_tNextPickup.Init(); m_BfAntiCheat.lastvalue = m_BfAntiCheat.count = 0x0; m_ScreenSize.x = m_ScreenSize.y = 0x0; m_pPopupPacket = NULL; m_pHouseDesign = NULL; m_fUpdateStats = 0; }
void CUser::BuyingMerchantInsertRegion() { Packet result(WIZ_MERCHANT, uint8(MERCHANT_BUY_REGION_INSERT)); result << GetSocketID(); for (int i = 0; i < 4; i++) { result << m_arMerchantItems[i].nNum; } SendToRegion(&result); }
void CUser::HandleStoreClose() { char send_buff[256]; int send_index = 0; m_bStoreOpen = false; // Tell Aujard we're closing the PUS so that we can call LOAD_WEB_ITEMMALL and load the extra items. SetByte(send_buff, WIZ_SHOPPING_MALL, send_index); SetByte(send_buff, STORE_CLOSE, send_index); SetShort(send_buff, GetSocketID(), send_index); m_pMain->m_LoggerSendQueue.PutData(send_buff, send_index); }
void CUser::BuyingMerchantClose() { if (isMerchanting()) m_bMerchantState = MERCHANT_STATE_NONE; else if (m_sMerchantsSocketID >= 0) RemoveFromMerchantLookers(); else return; Packet result(WIZ_MERCHANT, uint8(MERCHANT_BUY_CLOSE)); result << GetSocketID(); SendToRegion(&result); }
int32_t CSSLClientAsync::SSLConnect() { int32_t nErrorCode = SOCKET_IO_SSL_CONNECT_FAILED; //阻塞的ssl_connect可能会有一个问题,服务端如果不对此处理,可能会一直卡在SSL_connect这个接口 //此处采用非阻塞的ssl_connect int32_t nRet = SSL_connect(GetSSL()); if (nRet == 1) { nErrorCode = SOCKET_IO_RESULT_OK; SOCKET_IO_INFO("ssl connect successed, remote ip: %s, port: %d.", GetRemoteIP(), GetRemotePort()); SetSSLConnectStatus(TRUE); DoSSLConnect(GetSocket()); } else if (nRet == 0) { int32_t ssl_error_code = SSL_get_error(GetSSL(), nRet); SOCKET_IO_ERROR("ssl connect was shut down, remote ip: %s, port: %d, error code: %d.", GetRemoteIP(), GetRemotePort(), ssl_error_code); DoException(GetSocketID(), SOCKET_IO_SSL_CONNECT_FAILED); } else { int32_t ssl_error_code = SSL_get_error(GetSSL(), nRet); if (SSL_ERROR_WANT_READ == ssl_error_code || SSL_ERROR_WANT_WRITE == ssl_error_code) { SOCKET_IO_WARN("ssl connect is blocking, remote ip: %s, port: %d, error code: %d.", GetRemoteIP(), GetRemotePort(), ssl_error_code); } else { SOCKET_IO_ERROR("ssl connect failed, remote ip: %s, port: %d, error code: %d.", GetRemoteIP(), GetRemotePort(), ssl_error_code); DoException(GetSocketID(), SOCKET_IO_SSL_CONNECT_FAILED); } } return nErrorCode; }