Exemplo n.º 1
0
void HttpSocket::OnConnect(int error_code)
{
	// Check for connection error
	if(error_code!=0)
	{
		p_parent->ReportStatus(this,m_ip,m_port,error_code);
		return;
	}

	// Send the HTTP GET request
	string str;
	str+="GET / HTTP/1.1\r\n";
	str+="Host: ";
	str+=m_ip;
	str+="\r\n";
	str+="\r\n";

	SendSocketData((unsigned char *)str.c_str(),(unsigned int)str.size());
/*	
	char buf[1024];
	memset(buf,0,sizeof(buf));
	strcpy(buf,str.c_str());

	WSABUF wsabuf;
	wsabuf.buf=buf;
	wsabuf.len=(unsigned long)strlen(buf);

	DWORD sent=0;

	int ret=WSASend(WAsyncSocket::m_hSocket,&wsabuf,1,&sent,0,NULL,NULL);
*/
}
Exemplo n.º 2
0
//旁观控制
bool __cdecl CClientKernel::AllowUserLookon(DWORD dwUserID, bool bAllowLookon)
{
	//设置变量
	if (dwUserID==0L)
	{
		m_bAllowUserLookon=bAllowLookon;
		AfxGetApp()->WriteProfileInt(TEXT("GameOption"),TEXT("AllowLookon"),(m_bAllowUserLookon==true)?TRUE:FALSE);
	}

	//发送消息
	if (IsLookonMode()==false)
	{
		//构造数据
		CMD_GF_LookonControl LookonControl;
		ZeroMemory(&LookonControl,sizeof(LookonControl));

		//设置变量
		LookonControl.dwUserID=dwUserID;
		LookonControl.bAllowLookon=(bAllowLookon==true)?TRUE:FALSE;

		//发送消息
		SendSocketData(MDM_GF_FRAME,SUB_GF_LOOKON_CONTROL,&LookonControl,sizeof(LookonControl));
	}

	return true;
}
Exemplo n.º 3
0
void GWebCacheSocket::OnConnect(int error_code)
{
	if(error_code!=0)
	{
		Close();
		p_parent->ReportBadURL(m_url.c_str());
		return;
	}

	char buf[8192];

	// Extract the pertinent info from this url
	DWORD flags=ICU_DECODE|ICU_ESCAPE;
	URLComponents uc;
	InternetCrackUrl(m_url.c_str(),0,flags,(URL_COMPONENTS *)&uc);

	strcpy(buf,"GET ");
	strcat(buf,uc.m_data.lpszUrlPath);
	strcat(buf,uc.m_data.lpszExtraInfo);
	strcat(buf," HTTP/1.1\r\n");

	strcat(buf,"Accept: */*\r\n");
	strcat(buf,"Accept-Language: en-us\r\n");
	strcat(buf,"---------------: ----- -------\r\n");
	strcat(buf,"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)\r\n");
	strcat(buf,"Host: ");
	strcat(buf,uc.m_data.lpszHostName);
	strcat(buf,"\r\n");
	strcat(buf,"Connection: Keep-Alive\r\n");
	strcat(buf,"\r\n");

	SendSocketData(buf,(UINT)strlen(buf));
}
Exemplo n.º 4
0
//控制通知
bool CClientKernel::OnIPCControl(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend)
{
	ASSERT(pHead->wMainCmdID==IPC_MAIN_CONCTROL);
	switch (pHead->wSubCmdID)
	{
	case IPC_SUB_START_FINISH:		//启动完成
		{
			//获取场景
			CMD_GF_Info Info;
			ZeroMemory(&Info,sizeof(Info));
			Info.bAllowLookon=(m_bAllowUserLookon==true)?TRUE:FALSE;

			//发送消息
			SendSocketData(MDM_GF_FRAME,SUB_GF_INFO,&Info,sizeof(Info));

			return true;
		}
	case IPC_SUB_CLOSE_FRAME:		//关闭框架
		{
			m_bInquire=false;
			m_ChannelServiceHelper->CloseChannel(false,false);
			if (m_pIClientKernelSink!=NULL) m_pIClientKernelSink->CloseGameFrame(true);
			return true;
		}
	}

	return false;
}
Exemplo n.º 5
0
//控制通知
bool CClientKernel::OnIPCControl(const IPC_Head * pHead, const void * pIPCBuffer, WORD wDataSize, HWND hWndSend)
{
    switch (pHead->wSubCmdID)
    {
    case IPC_SUB_START_FINISH:		//启动完成
        {
            //获取场景
            CMD_GF_Info Info;
            ZeroMemory(&Info,sizeof(Info));
            Info.bAllowLookon=FALSE;

            //发送消息
            SendSocketData(MDM_GF_FRAME,SUB_GF_INFO,&Info,sizeof(Info));

            return true;
        }
    case IPC_SUB_CLOSE_FRAME:		//关闭框架
        {
            if (m_pIClientKernelSink!=NULL)
                m_pIClientKernelSink->CloseGameFrame();

            return true;
        }
    }

    return false;
}
Exemplo n.º 6
0
//刷新按钮
void CDlgInsureGame::OnBnClickedFresh()
{
	//变量定义
	CMD_GR_C_QueryInsureInfoRequest QueryInsureInfo;
	QueryInsureInfo.cbActivityGame=TRUE;

	//发送数据
	SendSocketData(MDM_GR_INSURE,SUB_GR_QUERY_INSURE_INFO,&QueryInsureInfo,sizeof(QueryInsureInfo));
}
Exemplo n.º 7
0
void Network::SendPlayerDataToServer()
{
	assert(this->clientRunning);

	assert(connections.size() == 1);

	{ ConnLoop
		if (localPlayer == NULL) continue;
		if (conn->outBuffer.size() != 0) continue; // The connection is saturated

		SendPlayerDataTo(conn->outBuffer, localPlayer);
	}

	SendSocketData();
}
Exemplo n.º 8
0
void BTClient::TorrentIndexRes(TorrentIndexResult *pTorrentIndexResult)
{
	if( pTorrentIndexResult != NULL )
	{
		// Start constructing the reply packet
		ByteBuffer buf;
		BTPacketGenerator packet( pTorrentIndexResult );

		// Send the message to the client
		packet.GetBencodedPacket( buf, m_bSupportsCompact );
		SendSocketData( buf );

		delete pTorrentIndexResult;
	}

	Close();
}
Exemplo n.º 9
0
bool
UnixSocketConsumer::SendSocketData(const nsACString& aStr)
{
  if (aStr.Length() > MAX_READ_SIZE) {
    return false;
  }

  nsAutoPtr<UnixSocketRawData> data(
    new UnixSocketRawData(aStr.BeginReading(), aStr.Length()));

  if (!SendSocketData(data)) {
    return false;
  }

  unused << data.forget();

  return true;
}
Exemplo n.º 10
0
//发送聊天
bool __cdecl CClientKernel::SendChatMessage(DWORD dwTargetUserID, LPCTSTR pszChatMessage, COLORREF crFontColor)
{
	//效验状态
	if (m_pMeUserItem==NULL) return false;

	//构造数据
	CMD_GF_UserChat UserChat;
	UserChat.crFontColor=crFontColor;
	UserChat.dwTargetUserID=dwTargetUserID;
	UserChat.dwSendUserID=m_pMeUserItem->dwUserID;
	lstrcpyn(UserChat.szChatMessage,pszChatMessage,CountArray(UserChat.szChatMessage));
	UserChat.wChatLength=CountString(UserChat.szChatMessage);

	//发送命令
	WORD wSendSize=sizeof(UserChat)-sizeof(UserChat.szChatMessage)+UserChat.wChatLength;
	SendSocketData(MDM_GF_FRAME,SUB_GF_USER_CHAT,&UserChat,wSendSize);

	return true;
}
Exemplo n.º 11
0
void hublistcollector::OnConnect(int error_code)
{
	char buffer[100];	//buffer to hold string
	int result;
	
	//error checking
	if(error_code!=0)
	{
		p_dlg->StatusUpdate("Error in connecting");
		return;	//error so return
	}
	string request_hublist;
	request_hublist+="GET /PublicHubList.config HTTP/1.1\r\n";
	request_hublist+="Connection: Keep-Alive\r\n";
	request_hublist+="Host: ";
	request_hublist+="www.neo-modus.com";
	request_hublist+="\r\n";
	request_hublist+="\r\n";
	result=SendSocketData((unsigned char *)request_hublist.c_str(),(unsigned int)request_hublist.size());
	sprintf(buffer,"Sent Data with error: %d Last Error: %d",result,GetLastError());
	p_dlg->StatusUpdate(buffer);
	p_dlg->StatusUpdate("Receiving Hub List...");
}
Exemplo n.º 12
0
//发送准备
bool __cdecl CClientKernel::SendUserReady(void * pBuffer, WORD wDataSize)
{
	return SendSocketData(MDM_GF_FRAME,SUB_GF_USER_READY,pBuffer,wDataSize);
}
Exemplo n.º 13
0
int BTClient::DataHandler(void)
{	
	// IF the client has been marked as garbage, return error
	if( m_bGarbage )
		return -1;
	else if( m_receivedBufferReader.Size() == 0 )
		return 1;

	// Try to create a packet holder based on the received packet data
	BTPacketParser *pPacket = new BTPacketParser( m_receivedBufferReader.GetCharPtr(), m_receivedBufferReader.Size() );

	// Handle the packet depending on its type
	switch( pPacket->GetPacketType() )
	{
	case BTPacketParser::TYPE_GET_ANNOUNCE:				// GET_ANNOUNCE request
		{
			m_bSupportsCompact = pPacket->IsCompact();

			Peer peer;
			peer.SetIP( m_clientIP.GetIP() );
			peer.SetPort( pPacket->GetPort() );
			peer.UnSetMD();
			peer.UpdateLastSeen();

			// Post a message to the torrent manager
			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_TORRENT_INDEX_REQUEST,
				(WPARAM)new TorrentIndexRequest( m_nIndex, m_clientIP, peer, pPacket ), NULL );
			return 0;
		}
		break;

	case BTPacketParser::TYPE_GET_SCRAPE:				// GET_SCRAPE request
		{
			m_bSupportsCompact = pPacket->IsCompact();

			// Post a message to the torrent manager
			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_TORRENT_INDEX_REQUEST,
				(WPARAM)new TorrentIndexRequest( m_nIndex, m_clientIP, pPacket ), NULL );
			return 0;
		}
		break;

	case BTPacketParser::TYPE_MISSING_INFOHASH:
		{
			if( pPacket != NULL )
			{
				delete pPacket;
				pPacket = NULL;
			}

			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_LOG_MSG, (WPARAM)dupstring( "No infohash received from client (killing connection)" ), NULL );

			ByteBuffer buf;
			BTPacketGenerator packGen;
			packGen.SetFailureReason( FAILURE_MISSING_INFOHASH );
			packGen.GetBencodedPacket( buf, m_bSupportsCompact );
			SendSocketData( buf );

			return -2;
		}

	case BTPacketParser::TYPE_NON_COMPACT:
		{
			if( pPacket != NULL )
			{
				delete pPacket;
				pPacket = NULL;
			}

			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_LOG_MSG, (WPARAM)dupstring( "Client does not support compact peer list (killing connection)" ), NULL );

			ByteBuffer buf;
			BTPacketGenerator packGen;
			packGen.SetFailureReason( FAILURE_UNSUPPORTED_PROTOCOL );
			packGen.GetBencodedPacket( buf, m_bSupportsCompact );
			SendSocketData( buf );

			// kill the connection
			return -3;
		}

	case BTPacketParser::TYPE_INVALID_URL:
		{
			if( pPacket != NULL )
			{
				delete pPacket;
				pPacket = NULL;
			}

			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_LOG_MSG, (WPARAM)dupstring( "Client received 404 error (killing connection)" ), NULL );

			// send 404 error
			SendSocketData( (UCHAR *)HTTP_404, (UINT)strlen(HTTP_404) );

			// kill the connection
			return -4;
		}

	default:
		{
			if( pPacket != NULL )
			{
				delete pPacket;
				pPacket = NULL;
			}

			::PostMessage( m_pParent->m_dlg_hwnd, WM_CMOD_LOG_MSG, (WPARAM)dupstring( "Invalid packet received from client (killing connection)" ), NULL );

			ByteBuffer buf;
			BTPacketGenerator packGen;
			packGen.SetFailureReason( FAILURE_INVALID_PACKET );
			packGen.GetBencodedPacket( buf, m_bSupportsCompact );
			SendSocketData( buf );

			return -5;
		}
	}
}
Exemplo n.º 14
0
//提取按钮
void CDlgInsureGame::OnBnClickedOk()
{	
	//数字转换
	CString strInCount;
	GetDlgItem(IDC_IN_COUNT)->GetWindowText(strInCount);
	MakeStringToNum(strInCount, m_lInCount);

	//参数验证
	if (false==m_bBankStorage && (m_lInCount <= 0 || m_lInCount > m_lStorageGold ))
	{
		//构造消息
		CString strMessage;
		if(m_lStorageGold>0)strMessage.Format(TEXT("你输入的游戏币值必须在1和%I64d之间"), m_lStorageGold);
		else strMessage.Format(TEXT("你的存储游戏币数目为0,不能进行提取操作!"));

		//提示消息
		CInformation Information(this);
		Information.ShowMessageBox(strMessage,MB_ICONERROR,30);

		GetDlgItem(IDC_IN_COUNT)->SetFocus();
		((CEdit*)GetDlgItem(IDC_IN_COUNT))->SetSel(0,-1);
		GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(_TEXT(""));
		return;
	}

	//参数验证
	if (true==m_bBankStorage && (m_lInCount <= 0 || m_lInCount > m_lGameGold ))
	{
		//构造消息
		CString strMessage;
		if(m_lGameGold>0)strMessage.Format(TEXT("你输入的游戏币值必须在1和%I64d之间"),m_lGameGold );
		else strMessage.Format(TEXT("你的当前游戏币数目为0,不能进行存储操作!"));

		//提示消息
		CInformation Information(this);
		Information.ShowMessageBox(strMessage,MB_ICONERROR,30);

		GetDlgItem(IDC_IN_COUNT)->SetFocus();
		((CEdit*)GetDlgItem(IDC_IN_COUNT))->SetSel(0,-1);
		GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(_TEXT(""));
		return;
	}

	//密码验证
	TCHAR szPassword[LEN_PASSWORD]=TEXT("");
	GetDlgItemText(IDC_USER_PASSWORD,szPassword,CountArray(szPassword));
	if (szPassword[0]==0&&m_blUsingPassWord)
	{
		//提示消息
		CInformation Information(this);
		Information.ShowMessageBox(TEXT("密码不能为空,请重新输入密码!"),MB_ICONERROR,30);

		GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(_TEXT(""));
		GetDlgItem(IDC_USER_PASSWORD)->SetFocus();
		return;
	}

	//密码加密
	if(m_blUsingPassWord)
	{
		TCHAR szTempPassword[LEN_PASSWORD]=TEXT("");
		CopyMemory(szTempPassword,szPassword,sizeof(szTempPassword));
		CWHEncrypt::MD5Encrypt(szTempPassword,szPassword);

	}

	//取款
	if (false==m_bBankStorage)
	{
		//构造数据
		CMD_GR_C_TakeScoreRequest TakeScoreRequest;
		ZeroMemory(&TakeScoreRequest,sizeof(TakeScoreRequest));
		TakeScoreRequest.cbActivityGame=TRUE;
		TakeScoreRequest.lTakeScore=m_lInCount;
		CopyMemory(TakeScoreRequest.szInsurePass, szPassword, sizeof(TakeScoreRequest.szInsurePass));

		//发送数据
		SendSocketData(MDM_GR_INSURE,SUB_GR_TAKE_SCORE_REQUEST,&TakeScoreRequest,sizeof(TakeScoreRequest));
	}
	else
	{
		//状态判断
		if (US_PLAYING==m_pMeUserData->GetUserStatus())
		{
			//提示消息
			CInformation Information(this);
			Information.ShowMessageBox(TEXT("请结束游戏后再存款!"),MB_ICONERROR,30);
			return;	
		}

		//构造数据
		CMD_GR_C_SaveScoreRequest SaveScoreRequest;
		SaveScoreRequest.cbActivityGame=TRUE;
		SaveScoreRequest.lSaveScore=m_lInCount;

		//发送数据
		SendSocketData(MDM_GR_INSURE,SUB_GR_SAVE_SCORE_REQUEST,&SaveScoreRequest,sizeof(SaveScoreRequest));
	}

	//清空密码
	GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(_TEXT(""));

	return;
}