Skip to content

Commit

Permalink
poprawki
Browse files Browse the repository at this point in the history
  • Loading branch information
darkjames committed Oct 21, 2008
1 parent 49621b0 commit 0415752
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -12,5 +12,5 @@ dirs:
touch passwd

clean:
rm -f *.o core *~
rm -f usg *.o core *~

20 changes: 17 additions & 3 deletions protocol.c
Expand Up @@ -263,7 +263,6 @@ static int gg_notify_handler(client_t *c, void *data, uint32_t len) {

static int gg_notify_end_handler(client_t *c, void *data, uint32_t len) {
struct gg_notify *n = data;
list_t l;
int i;

printf("received notify list from %d\n", c->uin);
Expand Down Expand Up @@ -293,6 +292,11 @@ static int gg_notify_add_handler(client_t *c, void *data, uint32_t len) {
if (len < sizeof(struct gg_add_remove))
return -1;

if (c->state != STATE_LOGIN_OK) {
printf("gg_notify_add_handler() c->state = %d\n", c->state);
return -3;
}

printf("adding notify on %d for %d\n", ar->uin, c->uin);

if (ar->uin == 0) {
Expand All @@ -314,11 +318,21 @@ static int gg_notify_add_handler(client_t *c, void *data, uint32_t len) {
}

static int gg_notify_remove_handler(client_t *c, void *data, uint32_t len) {
struct gg_add_remove *ar = data;
struct gg_add_remove *ar = (struct gg_add_remove *) data;
list_t l;

if (len < sizeof(struct gg_add_remove))
return -1;

if (c->state != STATE_LOGIN_OK) {
printf("gg_notify_remove_handler() c->state = %d\n", c->state);
return -3;
}

printf("removing notify from %d for %d\n", c->uin, ar->uin);

/* XXX, tak samo czy moze wystepowac wiecej niz 1 numerek w pakiecie? */

for (l = c->friends; l; l = l->next) {
friend_t *f = l->data;

Expand Down Expand Up @@ -440,7 +454,7 @@ static const gg_handlers[] =
{ GG_NOTIFY_LAST, gg_notify_end_handler },
{ GG_LIST_EMPTY, gg_list_empty_handler },
{ GG_ADD_NOTIFY, gg_notify_add_handler }, /* ok */
{ GG_REMOVE_NOTIFY, gg_notify_remove_handler },
{ GG_REMOVE_NOTIFY, gg_notify_remove_handler }, /* ok */

/* statusy.. */
{ GG_NEW_STATUS, gg_new_status_handler },
Expand Down
1 change: 1 addition & 0 deletions protocol.h
Expand Up @@ -115,6 +115,7 @@ struct gg_login70 {
#define GG_STATUS_INVISIBLE_DESCR 0x0016 /* niewidoczny z opisem (4.9) */

#define GG_STATUS_FRIENDS_MASK 0x8000 /* tylko dla znajomych (4.6) */
#define GG_STATUS_VOICE_MASK 0x20000 /* czy ma wlaczone audio (7.7) */

struct gg_new_status {
uint32_t status; /* na jaki zmieniæ? */
Expand Down
39 changes: 22 additions & 17 deletions usg.c
Expand Up @@ -114,18 +114,16 @@ static void gg77_status_write(client_t *ten, client_t *c) {
h.type = GG_STATUS77;
h.length = sizeof(s) + ((c->status_descr) ? strlen(c->status_descr) : 0);

memset(&s, 0, sizeof(s));

if (status == GG_STATUS_INVISIBLE)
status = GG_STATUS_NOT_AVAIL;

if (status == GG_STATUS_INVISIBLE_DESCR)
status = GG_STATUS_NOT_AVAIL_DESCR;

/* XXX, remote_ip, remote_port */

s.uin = c->uin;
s.status = status;
s.remote_ip = c->ip; /* XXX */
s.remote_port = c->port; /* XXX */
s.version = c->version;
s.image_size = c->image_size;
s.dunno1 = 0x00; /* ? */
Expand All @@ -148,22 +146,24 @@ client_t *get_client(client_t *c, int uin) {
/* je¶li nie jest po³±czony, zobacz, czy nie zostawi³ opisu */
if (!(f = find_client(uin))) {
static client_t dummy;
static char buf[100];

char fbuf[100];
FILE *fd;

memset(&dummy, 0, sizeof(dummy));

f = &dummy;
f->status = GG_STATUS_NOT_AVAIL;
f->uin = uin;
f->status = GG_STATUS_NOT_AVAIL;
f->status_descr = NULL;

snprintf(buf, sizeof(buf), "reasons/%d", uin);
snprintf(fbuf, sizeof(fbuf), "reasons/%d", uin);

if ((fd = fopen(buf, "r"))) {
if (fgets(buf, sizeof(buf), fd)) {
if ((fd = fopen(fbuf, "r"))) {
static char descr_buf[300];

if (fgets(descr_buf, sizeof(descr_buf), fd)) {
f->status = GG_STATUS_NOT_AVAIL_DESCR;
f->status_descr = buf;
f->status_descr = descr_buf;
}
fclose(fd);
}
Expand All @@ -188,28 +188,33 @@ static void gg77_notify_reply_data(client_t *ten, int uid) {
if (c->status == GG_STATUS_NOT_AVAIL_DESCR || c->status == GG_STATUS_INVISIBLE_DESCR) {
ten->status_write(ten, c);
return;

}

h.type = GG_NOTIFY_REPLY77;
h.length = sizeof(n) + ((c->status_descr) ? strlen(c->status_descr) : 0);
h.length = sizeof(n) + ((c->status_descr) ? 1+strlen(c->status_descr)+1 : 0);

n.uin = c->uin;
n.status = c->status;
n.remote_ip = c->ip;
n.remote_port = c->port;
n.image_size = c->image_size;
n.version = c->version;
n.image_size = c->image_size;
n.dunno1 = 0x00; /* ? */
n.dunno2 = c->port; /* ? */
n.dunno2 = 0x00; /* ? */

write_client(ten, &h, sizeof(h));
write_client(ten, &n, sizeof(n));
if (c->status_descr)
if (c->status_descr) {
unsigned char ile = strlen(c->status_descr);
unsigned char nul = '\0';

write_client(c, &ile, 1);
write_client(c, c->status_descr, strlen(c->status_descr));
write_client(c, &nul, 1);
}
}

static void gg77_notify_reply(client_t *c, int uid) {
client_t *a;
list_t l;

if (!uid) {
Expand Down

0 comments on commit 0415752

Please sign in to comment.