Added fetch of all updates. Added print of service messages

This commit is contained in:
Vysheng 2013-10-21 23:27:29 +04:00
parent 1c0ba265f0
commit 6893fca713
5 changed files with 183 additions and 11 deletions

View File

@ -239,6 +239,22 @@ void interpreter (char *line UU) {
Peers[index]->id, strndup (f, len));
}
}
} else if (!memcmp (line, "send_video", 10)) {
char *q = line + 10;
int len;
char *text = get_token (&q, &len);
int index = 0;
while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) {
index ++;
}
if (index < user_num + chat_num) {
int len = 0;
char *f = get_token (&q, &len);
if (len > 0) {
do_send_photo (CODE_input_media_uploaded_video,
Peers[index]->id, strndup (f, len));
}
}
} else if (!memcmp (line, "history", 7)) {
char *q = line + 7;
int len;
@ -474,9 +490,54 @@ void print_date (long t) {
}
int our_id;
void print_service_message (struct message *M) {
print_start ();
push_color (COLOR_GREY);
print_date (M->date);
printf (" ");
print_chat_name (M->to_id, user_chat_get (M->to_id));
printf (" ");
print_user_name (M->from_id, user_chat_get (M->from_id));
switch (M->action.type) {
case CODE_message_action_empty:
printf ("\n");
break;
case CODE_message_action_chat_create:
printf (" created chat %s. %d users\n", M->action.title, M->action.user_num);
break;
case CODE_message_action_chat_edit_title:
printf (" changed title to %s\n",
M->action.new_title);
break;
case CODE_message_action_chat_edit_photo:
printf (" changed photo\n");
break;
case CODE_message_action_chat_delete_photo:
printf (" deleted photo\n");
break;
case CODE_message_action_chat_add_user:
printf (" added user ");
print_user_name (M->action.user, user_chat_get (M->action.user));
printf ("\n");
break;
case CODE_message_action_chat_delete_user:
printf (" deleted user ");
print_user_name (M->action.user, user_chat_get (M->action.user));
printf ("\n");
break;
default:
assert (0);
}
pop_color ();
print_end ();
}
void print_message (struct message *M) {
if (M->service) {
rprintf ("Service message\n");
print_service_message (M);
return;
}

View File

@ -782,6 +782,104 @@ void work_update (struct connection *c UU, long long msg_id UU) {
}
}
break;
case CODE_update_restore_messages:
{
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
print_start ();
push_color (COLOR_YELLOW);
printf ("Restored %d messages\n", n);
pop_color ();
print_end ();
fetch_skip (n);
fetch_int (); // pts
}
break;
case CODE_update_chat_participants:
{
assert (fetch_int () == CODE_chat_participants);
int chat_id = fetch_int ();
fetch_int (); // admin_id
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
fetch_skip (n * 4);
fetch_int (); // version
union user_chat *C = user_chat_get (-chat_id);
print_start ();
push_color (COLOR_YELLOW);
printf ("Chat ");
print_chat_name (-chat_id, C);
printf (" changed list: now %d members\n", n);
pop_color ();
print_end ();
}
break;
case CODE_update_contact_registered:
{
int user_id = fetch_int ();
union user_chat *U = user_chat_get (user_id);
fetch_int (); // date
print_start ();
push_color (COLOR_YELLOW);
printf ("User ");
print_user_name (user_id, U);
printf (" registered\n");
pop_color ();
print_end ();
}
break;
case CODE_update_contact_link:
{
int user_id = fetch_int ();
union user_chat *U = user_chat_get (user_id);
print_start ();
push_color (COLOR_YELLOW);
printf ("Updated link with user ");
print_user_name (user_id, U);
printf ("\n");
pop_color ();
print_end ();
unsigned t = fetch_int ();
assert (t == CODE_contacts_my_link_empty || t == CODE_contacts_my_link_requested || t == CODE_contacts_my_link_contact);
if (t == CODE_contacts_my_link_requested) {
fetch_bool (); // has_phone
}
t = fetch_int ();
assert (t == CODE_contacts_foreign_link_unknown || t == CODE_contacts_foreign_link_requested || t == CODE_contacts_foreign_link_mutual);
if (t == CODE_contacts_foreign_link_requested) {
fetch_bool (); // has_phone
}
}
break;
case CODE_update_activation:
{
int user_id = fetch_int ();
union user_chat *U = user_chat_get (user_id);
print_start ();
push_color (COLOR_YELLOW);
printf ("User ");
print_user_name (user_id, U);
printf (" activated\n");
pop_color ();
print_end ();
}
break;
case CODE_update_new_authorization:
{
fetch_long (); // auth_key_id
fetch_int (); // date
char *s = fetch_str_dup ();
char *location = fetch_str_dup ();
print_start ();
push_color (COLOR_YELLOW);
printf ("New autorization: device='%s' location='%s'\n",
s, location);
pop_color ();
print_end ();
free (s);
free (location);
}
break;
default:
logprintf ("Unknown update type %08x\n", op);
}

View File

@ -280,6 +280,10 @@ static inline char *fetch_str_dup (void) {
return s;
}
static inline void fetch_skip (int n) {
in_ptr += n;
}
static __inline__ unsigned long long rdtsc(void) {
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));

View File

@ -665,7 +665,9 @@ void send_part (struct send_file *f) {
assert (x > 0);
out_cstring (buf, x);
f->offset += x;
logprintf ("offset=%lld size=%lld\n", f->offset, f->size);
if (verbosity >= 2) {
logprintf ("offset=%lld size=%lld\n", f->offset, f->size);
}
if (f->offset == f->size) {
close (f->fd);
f->fd = -1;
@ -675,7 +677,7 @@ void send_part (struct send_file *f) {
clear_packet ();
out_int (CODE_messages_send_media);
out_peer_id (f->to_id);
assert (f->media_type == CODE_input_media_uploaded_photo);
assert (f->media_type == CODE_input_media_uploaded_photo || f->media_type == CODE_input_media_uploaded_video);
out_int (f->media_type);
out_int (CODE_input_file);
out_long (f->id);
@ -684,6 +686,11 @@ void send_part (struct send_file *f) {
while (s >= f->file_name && *s != '/') { s --;}
out_string (s + 1);
out_string ("");
if (f->media_type == CODE_input_media_uploaded_video) {
out_int (100);
out_int (100);
out_int (100);
}
out_long (-lrand48 () * (1ll << 32) - lrand48 ());
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &send_file_methods, 0);
free (f->file_name);

View File

@ -158,15 +158,17 @@ void fetch_chat (struct chat *C) {
void fetch_photo_size (struct photo_size *S) {
memset (S, 0, sizeof (*S));
unsigned x = fetch_int ();
assert (x == CODE_photo_size || x == CODE_photo_cached_size);
assert (x == CODE_photo_size || x == CODE_photo_cached_size || x == CODE_photo_size_empty);
S->type = fetch_str_dup ();
fetch_file_location (&S->loc);
S->w = fetch_int ();
S->h = fetch_int ();
if (x == CODE_photo_size) {
S->size = fetch_int ();
} else {
S->data = fetch_str_dup ();
if (x != CODE_photo_size_empty) {
fetch_file_location (&S->loc);
S->w = fetch_int ();
S->h = fetch_int ();
if (x == CODE_photo_size) {
S->size = fetch_int ();
} else {
S->data = fetch_str_dup ();
}
}
}