Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Libgadu/Protokół GG/C++] Program nie zmienia statusu i nie wysyła wiadomości.

Ostatnio zmodyfikowano 2013-03-31 16:42
Autor Wiadomość
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ół:
C/C++
#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; /* nowy status */
    int flags; /* nowe flagi */
    int description_size; /* rozmiar opisu */
    char description[ 1000 ]; /* opis (nie musi wystąpić, bez \0) */
};

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:
C/C++
/*
* przykład prostego programu łączącego się z serwerem i wysyłającego
* jedną wiadomość.
*/

#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 ) { /* serwery gg nie pozwalaja wysylac wiadomosci bez powiadomienia o userliscie (przetestowane p.protocol_version [0x15; def] */
        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;
    }
   
    /* poniższą część można olać, ale poczekajmy na potwierdzenie */
   
    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 ;/
P-79661
MrPoxipol
» 2013-03-31 16:42:48
Też próbowałem zrobić coś wg tych przykładów z libgadu, miałem taki sam problem-wszystko łączyło, ale wiadomości nie mogłem wysłać. Możesz zainteresować się biblioteką libpurple(https://developer.pidgin.im/wiki/WhatIsLibpurple).

** gg_login(0022FEE6: [uin=NUMER_gg, async=0, ...]);
// gg_login() host "appmsg.gadu-gadu.pl" not found
Nie uda┼éo si─Ö po┼é─ůczy─ç: No error
Po ustawieniu
async = 1
** gg_login(0022FEE6: [uin=NUMER_GG, async=1, ...]);
** gg_resolver_win32_start(003E25D8, 003E265E, "appmsg.gadu-gadu.pl");
// gg_resolver_win32_start() unable to create pipes (errno=5, Input/output error
)
// gg_login() resolving failed (errno=5, Input/output error)
Nie uda┼éo si─Ö po┼é─ůczy─ç: Input/output error
P-79663
« 1 »
  Strona 1 z 1