X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=clients%2Fgaim%2Fgaim-dolcon.c;h=c52feb65d5594db850ca95d09aad25dbfdfba21e;hb=c7f65f51c58011c1fc4ccd65a9924acf2c290c0d;hp=b04c8a01698a4587193aeabccce6e8646499110c;hpb=fbd18e0ce36db876bcbb6b56de506e1b9385d3c9;p=doldaconnect.git diff --git a/clients/gaim/gaim-dolcon.c b/clients/gaim/gaim-dolcon.c index b04c8a0..c52feb6 100644 --- a/clients/gaim/gaim-dolcon.c +++ b/clients/gaim/gaim-dolcon.c @@ -40,6 +40,7 @@ struct conndata { }; static struct conndata *inuse = NULL; +static GaimPlugin *me; static void dcfdcb(struct conndata *data, int fd, GaimInputCondition condition); @@ -89,6 +90,28 @@ static int loginconv(int type, wchar_t *text, char **resp, struct conndata *data } } +static gboolean gi_chatjoincb(GaimConversation *conv, const char *user, GaimConvChatBuddyFlags flags, void *uudata) +{ + GaimConnection *c; + + if((c = gaim_conversation_get_gc(conv)) == NULL) + return(FALSE); + if(c->prpl == me) + return(TRUE); + return(FALSE); +} + +static gboolean gi_chatleavecb(GaimConversation *conv, const char *user, const char *reason, void *uudata) +{ + GaimConnection *c; + + if((c = gaim_conversation_get_gc(conv)) == NULL) + return(FALSE); + if(c->prpl == me) + return(TRUE); + return(FALSE); +} + static void newpeercb(struct dc_fnetpeer *peer) { struct conndata *data; @@ -98,7 +121,7 @@ static void newpeercb(struct dc_fnetpeer *peer) data = peer->fn->udata; if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) { - buf = sprintf2("%s", peer->fn->id, icswcstombs(peer->nick, "UTF-8", NULL)); + buf = sprintf2("%s", icswcstombs(peer->nick, "UTF-8", NULL)); gaim_conv_chat_add_user(GAIM_CONV_CHAT(conv), buf, NULL, GAIM_CBFLAGS_NONE, TRUE); free(buf); } @@ -113,7 +136,7 @@ static void delpeercb(struct dc_fnetpeer *peer) data = peer->fn->udata; if((conv = gaim_find_chat(data->gc, peer->fn->id)) != NULL) { - buf = sprintf2("%s", peer->fn->id, icswcstombs(peer->nick, "UTF-8", NULL)); + buf = sprintf2("%s", icswcstombs(peer->nick, "UTF-8", NULL)); gaim_conv_chat_remove_user(GAIM_CONV_CHAT(conv), buf, NULL); free(buf); } @@ -170,14 +193,19 @@ static void dcfdcb(struct conndata *data, int fd, GaimInputCondition condition) } while((resp = dc_getresp()) != NULL) { if(!wcscmp(resp->cmdname, L".connect")) { - if(resp->code == 200) { - gaim_connection_update_progress(data->gc, "Authenticating", 2, 3); - dc_loginasync(NULL, 1, (int (*)(int, wchar_t *, char **, void *))loginconv, (void (*)(int, wchar_t *, void *))logincb, data); - } else { + if(resp->code != 201) { dc_disconnect(); disconnected(data); gaim_connection_error(data->gc, "Server refused connection"); return; + } else if(dc_checkprotocol(resp, DC_LATEST)) { + dc_disconnect(); + disconnected(data); + gaim_connection_error(data->gc, "Server protocol revision mismatch"); + return; + } else { + gaim_connection_update_progress(data->gc, "Authenticating", 2, 3); + dc_loginasync(NULL, 1, (int (*)(int, wchar_t *, char **, void *))loginconv, (void (*)(int, wchar_t *, void *))logincb, data); } } else if(!wcscmp(resp->cmdname, L".notify")) { dc_uimisc_handlenotify(resp); @@ -248,7 +276,7 @@ static int gi_sendchat(GaimConnection *gc, int id, const char *what, GaimMessage /* XXX: Handle chat rooms */ if((wwhat = icmbstowcs((char *)what, "UTF-8")) == NULL) return(-errno); - dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", fn->id, L"1", L"", L"%%ls", wwhat, NULL); + dc_queuecmd(NULL, NULL, L"sendchat", L"%i", fn->id, L"1", L"", L"%ls", wwhat, NULL); free(wwhat); updatewrite(data); return(0); @@ -288,7 +316,7 @@ static int gi_sendim(GaimConnection *gc, const char *who, const char *what, Gaim free(wwho); return(-en); } - dc_queuecmd(NULL, NULL, L"sendchat", L"%%i", fn->id, L"0", L"%%ls", peer->nick, L"%%ls", wwhat, NULL); + dc_queuecmd(NULL, NULL, L"sendchat", L"%i", fn->id, L"0", L"%ls", peer->nick, L"%ls", wwhat, NULL); free(wwho); free(wwhat); updatewrite(data); @@ -310,7 +338,7 @@ static char *gi_statustext(GaimBuddy *b) return(NULL); } -static void gi_tiptext(GaimBuddy *b, GString *buf, gboolean full) +static void gi_tiptext(GaimBuddy *b, GaimNotifyUserInfo *inf, gboolean full) { /* Nothing for now */ } @@ -365,7 +393,7 @@ static void gi_login(GaimAccount *act) return; } gaim_connection_update_progress(gc, "Connecting", 1, 3); - if((data->fd = dc_connect((char *)gaim_account_get_string(act, "server", "localhost"), -1)) < 0) + if((data->fd = dc_connect((char *)gaim_account_get_string(act, "server", "localhost"))) < 0) { gaim_connection_error(gc, "Could not connect to server"); return; @@ -500,12 +528,13 @@ static void init(GaimPlugin *pl) GaimAccountOption *opt; dc_init(); - opt = gaim_account_option_string_new("Server", "server", "localhost"); - protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); - opt = gaim_account_option_int_new("Port", "port", -1); + opt = gaim_account_option_string_new("Server", "server", ""); protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); opt = gaim_account_option_bool_new("Do not pop up private messages automatically", "represspm", FALSE); protinfo.protocol_options = g_list_append(protinfo.protocol_options, opt); + gaim_signal_connect(gaim_conversations_get_handle(), "chat-buddy-joining", pl, GAIM_CALLBACK(gi_chatjoincb), NULL); + gaim_signal_connect(gaim_conversations_get_handle(), "chat-buddy-leaving", pl, GAIM_CALLBACK(gi_chatleavecb), NULL); + me = pl; } GAIM_INIT_PLUGIN(dolcon, init, info);