krystian11102 Temat założony przez niniejszego użytkownika |
[Libgadu/Protokół GG/C++] Program nie zmienia statusu i nie wysyła wiadomości. » 2013-03-31 16:33:10 Witam. Mam problem dotyczący "czystego" protokołu GG oraz Libgadu. Otóż program niby się łączy, wszystko jest dobrze.. Do momentu gdy chcę zmienić status lub wysłać wiadomość. Powiecie mi co jest źle? - Nie odsyłajcie do google, całą noc siedziałem do teraz. Już mam po prostu dość, więc pytam... "Czysty" protokół: #include <cstdlib> #include <iostream> #include <windows.h> #include <winsock.h>
using namespace std;
int gg_login_hash( char * password, unsigned int seed ) { unsigned int x, y, z; y = seed; for( x = 0; * password; password++ ) { x =( x & 0xffffff00 ) | * password; y ^= x; y += x; x <<= 8; y ^= x; x <<= 8; y -= x; x <<= 8; y ^= x; z = y & 0x1f; y =( y << z ) |( y >>( 32 - z ) ); } return y; }
struct gg_welcome { int typ, size, seed; };
struct gg_login { int typ, size; int uin; int hash; int status; int version; char unknown1; int local_ip; short local_port; int external_ip; short external_port; char image_size; char unknown2; };
struct set_status { int typ, size, status; char desc[ 2000 ]; };
struct gg_new_status80 { int status; int flags; int description_size; char description[ 1000 ]; };
int main() { WSADATA wd; WSAStartup( 0x101, & wd ); while( 1 ) { int s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); sockaddr_in ad; ad.sin_family = AF_INET; ad.sin_port = ntohs( 8074 ); ad.sin_addr.s_addr = inet_addr( "91.214.237.24" ); if( connect( s,( SOCKADDR * ) & ad, 16 ) == 0 ) { printf( "Polaczono sie z serwerem\n" ); gg_welcome welcome; recv( s,( char * ) & welcome, 12, 0 ); printf( "seed: %d\n", welcome.seed ); gg_login log = { 0x15, sizeof( gg_login ) - 8, # moj_numer #, gg_login_hash( "#haslo#", welcome.seed ), 2, 0x20, 0, 0, 0, 0, 0, 256, 0xbe }; send( s,( char * ) & log, sizeof( log ), 0 ); int loginstatus; recv( s,( char * ) & loginstatus, 4, 0 ); printf( "status logowania: %d\n", loginstatus ); } else { printf( "Nie mozna sie polaczyc z serwerem\n" ); } char status[ 100 ]; strcpy( status, "status" ); set_status stat; stat.typ = 2; stat.size = strlen( status ) + 4; stat.status = 4; strcpy( stat.desc, status ); send( s,( char * ) & stat, strlen( status ) + 12, 0 ); } system( "pause >nul" ); }
A Tutaj libgadu:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include "libgadu.h"
int main( int argc, char ** argv ) { struct gg_session * sess; struct gg_event * e; struct gg_login_params p; if( argc < 5 ) { fprintf( stderr, "użycie: %s <mójnumerek> <mojehasło> <numerek> <wiadomość>\n", argv[ 0 ] ); return 1; } gg_debug_level = 255; memset( & p, 0, sizeof( p ) ); p.uin = atoi( argv[ 2 ] ); p.password = argv[ 1 ]; if( !( sess = gg_login( & p ) ) ) { printf( "Nie udało się połączyć: %s\n", strerror( errno ) ); gg_free_session( sess ); return 1; } printf( "Połączono.\n" ); if( gg_notify( sess, NULL, 0 ) == - 1 ) { printf( "Połączenie przerwane: %s\n", strerror( errno ) ); gg_free_session( sess ); return 1; } if( gg_send_message( sess, GG_CLASS_MSG, atoi( argv[ 3 ] ),( unsigned char * ) argv[ 4 ] ) == - 1 ) { printf( "Połączenie przerwane: %s\n", strerror( errno ) ); gg_free_session( sess ); return 1; } while( 0 ) { if( !( e = gg_watch_fd( sess ) ) ) { printf( "Połączenie przerwane: %s\n", strerror( errno ) ); gg_logoff( sess ); gg_free_session( sess ); return 1; } if( e->type == GG_EVENT_ACK ) { printf( "Wysłano.\n" ); gg_free_event( e ); break; } gg_free_event( e ); } gg_logoff( sess ); gg_free_session( sess ); return 0; }
Ten pierwszy znaleziony w internecie. Drugi z folderu "examlpes" z biblioteki libgadu. Korzystam z Microsoft Visual C++ 2010. Wszystko co potrzebne linkuje.. DLL dodaje do folderu, ip serwera też jest ok... Już nie mam pomysłów ;/ |