📄 ops.c
字号:
/* Send to Purple */ serv_got_im(gc, sender->nickname ? sender->nickname : "<unknown>", tmp, 0, time(NULL)); g_free(tmp); }}/* Notify message to the client. The notify arguments are sent in the same order as servers sends them. The arguments are same as received from the server except for ID's. If ID is received application receives the corresponding entry to the ID. For example, if Client ID is received application receives SilcClientEntry. Also, if the notify type is for channel the channel entry is sent to application (even if server does not send it because client library gets the channel entry from the Channel ID in the packet's header). */static voidsilc_notify(SilcClient client, SilcClientConnection conn, SilcNotifyType type, ...){ va_list va; PurpleConnection *gc = client->application; SilcPurple sg = gc->proto_data; PurpleConversation *convo; SilcClientEntry client_entry, client_entry2; SilcChannelEntry channel; SilcServerEntry server_entry; SilcIdType idtype; void *entry; SilcUInt32 mode; SilcHashTableList htl; SilcChannelUser chu; char buf[512], buf2[512], *tmp, *name; SilcNotifyType notify; PurpleBuddy *b; int i; va_start(va, type); memset(buf, 0, sizeof(buf)); switch (type) { case SILC_NOTIFY_TYPE_NONE: break; case SILC_NOTIFY_TYPE_INVITE: { GHashTable *components; va_arg(va, SilcChannelEntry); name = va_arg(va, char *); client_entry = va_arg(va, SilcClientEntry); components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_insert(components, strdup("channel"), strdup(name)); serv_got_chat_invite(gc, name, client_entry->nickname, NULL, components); } break; case SILC_NOTIFY_TYPE_JOIN: client_entry = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); /* If we joined channel, do nothing */ if (client_entry == conn->local_entry) break; convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; /* Join user to channel */ g_snprintf(buf, sizeof(buf), "%s@%s", client_entry->username, client_entry->hostname); purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), g_strdup(client_entry->nickname), buf, PURPLE_CBFLAGS_NONE, TRUE); break; case SILC_NOTIFY_TYPE_LEAVE: client_entry = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; /* Remove user from channel */ purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), client_entry->nickname, NULL); break; case SILC_NOTIFY_TYPE_SIGNOFF: client_entry = va_arg(va, SilcClientEntry); tmp = va_arg(va, char *); if (!client_entry->nickname) break; /* Remove from all channels */ silc_hash_table_list(client_entry->channels, &htl); while (silc_hash_table_get(&htl, NULL, (void *)&chu)) { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chu->channel->channel_name, sg->account); if (!convo) continue; purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), client_entry->nickname, tmp); } silc_hash_table_list_reset(&htl); break; case SILC_NOTIFY_TYPE_TOPIC_SET: { char *esc, *tmp2; idtype = va_arg(va, int); entry = va_arg(va, void *); tmp = va_arg(va, char *); channel = va_arg(va, SilcChannelEntry); convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; if (!tmp) break; esc = g_markup_escape_text(tmp, -1); tmp2 = purple_markup_linkify(esc); g_free(esc); if (idtype == SILC_ID_CLIENT) { client_entry = (SilcClientEntry)entry; g_snprintf(buf, sizeof(buf), _("%s has changed the topic of <I>%s</I> to: %s"), client_entry->nickname, channel->channel_name, tmp2); purple_conv_chat_write(PURPLE_CONV_CHAT(convo), client_entry->nickname, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), client_entry->nickname, tmp); } else if (idtype == SILC_ID_SERVER) { server_entry = (SilcServerEntry)entry; g_snprintf(buf, sizeof(buf), _("%s has changed the topic of <I>%s</I> to: %s"), server_entry->server_name, channel->channel_name, tmp2); purple_conv_chat_write(PURPLE_CONV_CHAT(convo), server_entry->server_name, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), server_entry->server_name, tmp); } else if (idtype == SILC_ID_CHANNEL) { channel = (SilcChannelEntry)entry; g_snprintf(buf, sizeof(buf), _("%s has changed the topic of <I>%s</I> to: %s"), channel->channel_name, channel->channel_name, tmp2); purple_conv_chat_write(PURPLE_CONV_CHAT(convo), channel->channel_name, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), channel->channel_name, tmp); } else { purple_conv_chat_set_topic(PURPLE_CONV_CHAT(convo), NULL, tmp); } g_free(tmp2); break; } case SILC_NOTIFY_TYPE_NICK_CHANGE: client_entry = va_arg(va, SilcClientEntry); client_entry2 = va_arg(va, SilcClientEntry); if (!strcmp(client_entry->nickname, client_entry2->nickname)) break; /* Change nick on all channels */ silc_hash_table_list(client_entry2->channels, &htl); while (silc_hash_table_get(&htl, NULL, (void *)&chu)) { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chu->channel->channel_name, sg->account); if (!convo) continue; if (purple_conv_chat_find_user(PURPLE_CONV_CHAT(convo), client_entry->nickname)) purple_conv_chat_rename_user(PURPLE_CONV_CHAT(convo), client_entry->nickname, client_entry2->nickname); } silc_hash_table_list_reset(&htl); break; case SILC_NOTIFY_TYPE_CMODE_CHANGE: idtype = va_arg(va, int); entry = va_arg(va, void *); mode = va_arg(va, SilcUInt32); (void)va_arg(va, char *); (void)va_arg(va, char *); (void)va_arg(va, char *); (void)va_arg(va, SilcPublicKey); (void)va_arg(va, SilcBuffer); channel = va_arg(va, SilcChannelEntry); convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; if (idtype == SILC_ID_CLIENT) name = ((SilcClientEntry)entry)->nickname; else if (idtype == SILC_ID_SERVER) name = ((SilcServerEntry)entry)->server_name; else name = ((SilcChannelEntry)entry)->channel_name; if (!name) break; if (mode) { silcpurple_get_chmode_string(mode, buf2, sizeof(buf2)); g_snprintf(buf, sizeof(buf), _("<I>%s</I> set channel <I>%s</I> modes to: %s"), name, channel->channel_name, buf2); } else { g_snprintf(buf, sizeof(buf), _("<I>%s</I> removed all channel <I>%s</I> modes"), name, channel->channel_name); } purple_conv_chat_write(PURPLE_CONV_CHAT(convo), channel->channel_name, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); break; case SILC_NOTIFY_TYPE_CUMODE_CHANGE: { PurpleConvChatBuddyFlags flags = PURPLE_CBFLAGS_NONE; idtype = va_arg(va, int); entry = va_arg(va, void *); mode = va_arg(va, SilcUInt32); client_entry2 = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; if (idtype == SILC_ID_CLIENT) name = ((SilcClientEntry)entry)->nickname; else if (idtype == SILC_ID_SERVER) name = ((SilcServerEntry)entry)->server_name; else name = ((SilcChannelEntry)entry)->channel_name; if (!name) break; if (mode) { silcpurple_get_chumode_string(mode, buf2, sizeof(buf2)); g_snprintf(buf, sizeof(buf), _("<I>%s</I> set <I>%s's</I> modes to: %s"), name, client_entry2->nickname, buf2); if (mode & SILC_CHANNEL_UMODE_CHANFO) flags |= PURPLE_CBFLAGS_FOUNDER; if (mode & SILC_CHANNEL_UMODE_CHANOP) flags |= PURPLE_CBFLAGS_OP; } else { g_snprintf(buf, sizeof(buf), _("<I>%s</I> removed all <I>%s's</I> modes"), name, client_entry2->nickname); } purple_conv_chat_write(PURPLE_CONV_CHAT(convo), channel->channel_name, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); purple_conv_chat_user_set_flags(PURPLE_CONV_CHAT(convo), client_entry2->nickname, flags); break; } case SILC_NOTIFY_TYPE_MOTD: tmp = va_arg(va, char *); silc_free(sg->motd); sg->motd = silc_memdup(tmp, strlen(tmp)); break; case SILC_NOTIFY_TYPE_KICKED: client_entry = va_arg(va, SilcClientEntry); tmp = va_arg(va, char *); client_entry2 = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, channel->channel_name, sg->account); if (!convo) break; if (client_entry == conn->local_entry) { /* Remove us from channel */ g_snprintf(buf, sizeof(buf), _("You have been kicked off <I>%s</I> by <I>%s</I> (%s)"), channel->channel_name, client_entry2->nickname, tmp ? tmp : ""); purple_conv_chat_write(PURPLE_CONV_CHAT(convo), client_entry->nickname, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo))); } else { /* Remove user from channel */ g_snprintf(buf, sizeof(buf), _("Kicked by %s (%s)"), client_entry2->nickname, tmp ? tmp : ""); purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), client_entry->nickname, buf); } break; case SILC_NOTIFY_TYPE_KILLED: client_entry = va_arg(va, SilcClientEntry); tmp = va_arg(va, char *); idtype = va_arg(va, int); entry = va_arg(va, SilcClientEntry); if (!client_entry->nickname) break; if (client_entry == conn->local_entry) { if (idtype == SILC_ID_CLIENT) { client_entry2 = (SilcClientEntry)entry; g_snprintf(buf, sizeof(buf), _("You have been killed by %s (%s)"), client_entry2->nickname, tmp ? tmp : ""); } else if (idtype == SILC_ID_SERVER) { server_entry = (SilcServerEntry)entry; g_snprintf(buf, sizeof(buf), _("You have been killed by %s (%s)"), server_entry->server_name, tmp ? tmp : ""); } else if (idtype == SILC_ID_CHANNEL) { channel = (SilcChannelEntry)entry; g_snprintf(buf, sizeof(buf), _("You have been killed by %s (%s)"), channel->channel_name, tmp ? tmp : ""); } /* Remove us from all channels */ silc_hash_table_list(client_entry->channels, &htl); while (silc_hash_table_get(&htl, NULL, (void *)&chu)) { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chu->channel->channel_name, sg->account); if (!convo) continue; purple_conv_chat_write(PURPLE_CONV_CHAT(convo), client_entry->nickname, buf, PURPLE_MESSAGE_SYSTEM, time(NULL)); serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo))); } silc_hash_table_list_reset(&htl); } else { if (idtype == SILC_ID_CLIENT) { client_entry2 = (SilcClientEntry)entry; g_snprintf(buf, sizeof(buf), _("Killed by %s (%s)"), client_entry2->nickname, tmp ? tmp : ""); } else if (idtype == SILC_ID_SERVER) { server_entry = (SilcServerEntry)entry; g_snprintf(buf, sizeof(buf), _("Killed by %s (%s)"), server_entry->server_name, tmp ? tmp : ""); } else if (idtype == SILC_ID_CHANNEL) { channel = (SilcChannelEntry)entry; g_snprintf(buf, sizeof(buf), _("Killed by %s (%s)"), channel->channel_name, tmp ? tmp : ""); } /* Remove user from all channels */ silc_hash_table_list(client_entry->channels, &htl); while (silc_hash_table_get(&htl, NULL, (void *)&chu)) { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chu->channel->channel_name, sg->account); if (!convo) continue; purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), client_entry->nickname, tmp); } silc_hash_table_list_reset(&htl); } break; case SILC_NOTIFY_TYPE_CHANNEL_CHANGE: break; case SILC_NOTIFY_TYPE_SERVER_SIGNOFF: { int i; SilcClientEntry *clients; SilcUInt32 clients_count; (void)va_arg(va, void *); clients = va_arg(va, SilcClientEntry *); clients_count = va_arg(va, SilcUInt32); for (i = 0; i < clients_count; i++) { if (!clients[i]->nickname) break; /* Remove from all channels */ silc_hash_table_list(clients[i]->channels, &htl); while (silc_hash_table_get(&htl, NULL, (void *)&chu)) { convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, chu->channel->channel_name, sg->account);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -