[C++] Recv packets from webbrowser...

03/19/2012 14:52 stronka111#1
Hello guys!
I have a question to you. I want make bot as:
Code:
http://www.elitepvpers.com/forum/browsergames/1763240-release-seafight-antistealth-wartool-bot.html
and I don't know how recv packets which seafight server send to webbrowser?
I must use winsock or winpcap?
I try make serwer:
PHP Code:
#include <cstdio>
#include <winsock2.h>
#include <iostream>
using namespace std;
int main()
{
//********************START**********************************
    
WSADATA wsaData;

    
int result = WSAStartup( MAKEWORD( 2, 2 ), & wsaData );
    if( 
result != NO_ERROR )
        
printf( "Initialization error.\n" );

    
SOCKET mainSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
    if( 
mainSocket == INVALID_SOCKET )
    {
    
printf( "Error creating socket: %ld\n", WSAGetLastError() );
    
WSACleanup();
    return 
1;
    }

    
sockaddr_in service;
    
memset( & service, 0, sizeof( service ) );
    
service.sin_family = AF_INET;
    
service.sin_addr.s_addr = inet_addr( "127.0.0.1" );
    
service.sin_port = htons( 1111 );
//********************START**********************************
    
if( bind( mainSocket,( SOCKADDR * ) & service, sizeof( service )) == SOCKET_ERROR)
    {
        
printf( "bind() failed.\n" );
        
closesocket( mainSocket );
        
WSACleanup();
        return 
1;
    }
    if( 
listen( mainSocket, 1 ) == SOCKET_ERROR )
        
printf( "Error listening on socket.\n" );

    
SOCKET acceptSocket = SOCKET_ERROR;
    
printf( "Waiting for a client to connect...\n" );

    while( 
acceptSocket== SOCKET_ERROR )
        {
        
acceptSocket = accept( mainSocket, NULL, NULL );
        }

    
printf( "Client connected.\n" );
    
mainSocket = acceptSocket;
//****************END***************************

int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[ 32 ] = "answer...";
char recvbuf[ 1024 ] = "";

bytesRecv = recv( mainSocket, recvbuf, 1024, 0 );
printf( "Bytes received: %ld\n", bytesRecv );
printf( "Received text: %s\n", recvbuf );

bytesSent = send( mainSocket, sendbuf, strlen( sendbuf ), 0 );
printf( "Bytes sent: %ld\n", bytesSent );

cin.get();
    return 
0;
} 
and in webbrowser set ip: 127.0.0.1 and socket: 1111; but webbrowser can't connect to game..
I need way to make it!
Please help me:handsdown:
03/20/2012 11:54 MoepMeep#2
This looks like c&p code ;o
03/20/2012 20:12 .Infinite#3
Your "server" is not a proxy... It does not know how to answer the browsers requests. Neither does your browser know how to handle your server's packets.

First you need to know how communication between a browser and a proxy server works in order to emulate one.
03/20/2012 21:09 stronka111#4
So i must make proxy local and listen:)
03/20/2012 21:42 .Infinite#5
Quote:
but webbrowser can't connect to game..
Your "server" has to redirect the packets:

Browser ---GET---> Local Proxy(your server) ---GET---> Gameserver