src/server.c

changeset 9949
377cd65fab3d
parent 9944
71ef020ec4b0
child 9976
5fceb5de48b8
equal deleted inserted replaced
9948:2642975ffb85 9949:377cd65fab3d
259 } 259 }
260 260
261 int serv_send_im(GaimConnection *gc, const char *name, const char *message, 261 int serv_send_im(GaimConnection *gc, const char *name, const char *message,
262 GaimConvImFlags imflags) 262 GaimConvImFlags imflags)
263 { 263 {
264 GaimConversation *c; 264 GaimConversation *conv;
265 GaimAccount *account;
266 GaimPresence *presence;
267 GaimPluginProtocolInfo *prpl_info = NULL;
265 int val = -EINVAL; 268 int val = -EINVAL;
266 GaimPluginProtocolInfo *prpl_info = NULL;
267 const gchar *auto_reply_pref; 269 const gchar *auto_reply_pref;
268 270
269 if (gc != NULL && gc->prpl != NULL) 271 if (gc != NULL && gc->prpl != NULL)
270 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 272 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
271 273
272 c = gaim_find_conversation_with_account(name, gc->account); 274 account = gaim_connection_get_account(gc);
275 presence = gaim_account_get_presence(account);
276
277 conv = gaim_find_conversation_with_account(name, gc->account);
273 278
274 if (prpl_info && prpl_info->send_im) 279 if (prpl_info && prpl_info->send_im)
275 val = prpl_info->send_im(gc, name, message, imflags); 280 val = prpl_info->send_im(gc, name, message, imflags);
276 281
277 if (!(imflags & GAIM_CONV_IM_AUTO_RESP)) 282 if (!(imflags & GAIM_CONV_IM_AUTO_RESP))
280 /* 285 /*
281 * XXX - If "only auto-reply when away & idle" is set, then shouldn't 286 * XXX - If "only auto-reply when away & idle" is set, then shouldn't
282 * this only reset lar->sent if we're away AND idle? 287 * this only reset lar->sent if we're away AND idle?
283 */ 288 */
284 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply"); 289 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply");
285 if (gc->away && (gc->flags & GAIM_CONNECTION_AUTO_RESP) && 290 if ((gc->flags & GAIM_CONNECTION_AUTO_RESP) &&
286 strcmp(auto_reply_pref, "never")) { 291 !gaim_presence_is_available(presence) &&
292 strcmp(auto_reply_pref, "never")) {
287 293
288 struct last_auto_response *lar; 294 struct last_auto_response *lar;
289 lar = get_last_auto_response(gc, name); 295 lar = get_last_auto_response(gc, name);
290 lar->sent = time(NULL); 296 lar->sent = time(NULL);
291 } 297 }
292 298
293 if (c && gaim_conv_im_get_type_again_timeout(GAIM_CONV_IM(c))) 299 if (conv && gaim_conv_im_get_type_again_timeout(GAIM_CONV_IM(conv)))
294 gaim_conv_im_stop_type_again_timeout(GAIM_CONV_IM(c)); 300 gaim_conv_im_stop_type_again_timeout(GAIM_CONV_IM(conv));
295 301
296 return val; 302 return val;
297 } 303 }
298 304
299 void serv_get_info(GaimConnection *gc, const char *name) 305 void serv_get_info(GaimConnection *gc, const char *name)
303 if (gc != NULL && gc->prpl != NULL) 309 if (gc != NULL && gc->prpl != NULL)
304 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 310 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
305 311
306 if (gc && prpl_info && prpl_info->get_info) 312 if (gc && prpl_info && prpl_info->get_info)
307 prpl_info->get_info(gc, name); 313 prpl_info->get_info(gc, name);
308 }
309
310 void serv_set_away(GaimConnection *gc, const char *state, const char *message)
311 {
312 GaimPluginProtocolInfo *prpl_info = NULL;
313 GaimAccount *account;
314
315 if (gc->away_state == NULL && state == NULL &&
316 gc->away == NULL && message == NULL) {
317
318 return;
319 }
320
321 if ((gc->away_state != NULL && state != NULL &&
322 !strcmp(gc->away_state, state) &&
323 !strcmp(gc->away_state, GAIM_AWAY_CUSTOM)) &&
324 (gc->away != NULL && message != NULL && !strcmp(gc->away, message))) {
325
326 return;
327 }
328
329 if (gc != NULL && gc->prpl != NULL)
330 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
331
332 account = gaim_connection_get_account(gc);
333
334 if (prpl_info && prpl_info->set_away) {
335 if (gc->away_state) {
336 g_free(gc->away_state);
337 gc->away_state = NULL;
338 }
339
340 prpl_info->set_away(gc, state, message);
341
342 if (gc->away && state) {
343 gc->away_state = g_strdup(state);
344 }
345
346 gaim_signal_emit(gaim_accounts_get_handle(), "account-away",
347 account, state, message);
348 }
349
350 /* LOG system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON); */
351 /* New away message... Clear out the record of sent autoresponses */
352 flush_last_auto_responses(gc);
353 }
354
355 void serv_set_away_all(const char *message)
356 {
357 GList *c;
358 GaimConnection *g;
359
360 for (c = gaim_connections_get_all(); c != NULL; c = c->next) {
361 g = (GaimConnection *)c->data;
362
363 serv_set_away(g, GAIM_AWAY_CUSTOM, message);
364 }
365 } 314 }
366 315
367 void serv_set_info(GaimConnection *gc, const char *info) 316 void serv_set_info(GaimConnection *gc, const char *info)
368 { 317 {
369 GaimPluginProtocolInfo *prpl_info = NULL; 318 GaimPluginProtocolInfo *prpl_info = NULL;
445 394
446 void serv_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) 395 void serv_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
447 { 396 {
448 GaimPluginProtocolInfo *prpl_info = NULL; 397 GaimPluginProtocolInfo *prpl_info = NULL;
449 398
450 if (buddy->idle > 0) 399 if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
451 remove_idle_buddy(buddy); 400 remove_idle_buddy(buddy);
452 401
453 if (gc != NULL && gc->prpl != NULL) 402 if (gc != NULL && gc->prpl != NULL)
454 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 403 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
455 404
470 if (prpl_info && g_list_find(gaim_connections_get_all(), gc)) { 419 if (prpl_info && g_list_find(gaim_connections_get_all(), gc)) {
471 if (prpl_info->remove_buddies) { 420 if (prpl_info->remove_buddies) {
472 GList *curb; 421 GList *curb;
473 for (curb = buddies; curb != NULL; curb = curb->next) { 422 for (curb = buddies; curb != NULL; curb = curb->next) {
474 GaimBuddy *buddy = curb->data; 423 GaimBuddy *buddy = curb->data;
475 if (buddy->idle > 0) 424 if (gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
476 remove_idle_buddy(buddy); 425 remove_idle_buddy(buddy);
477 } 426 }
478 prpl_info->remove_buddies(gc, buddies, groups); 427 prpl_info->remove_buddies(gc, buddies, groups);
479 } else { 428 } else {
480 GList *curb = buddies; 429 GList *curb = buddies;
906 * Alright. Two cases for how to handle this. Either we're away or 855 * Alright. Two cases for how to handle this. Either we're away or
907 * we're not. If we're not, then it's easy. If we are, then there 856 * we're not. If we're not, then it's easy. If we are, then there
908 * are three or four different ways of handling it and different 857 * are three or four different ways of handling it and different
909 * things we have to do for each. 858 * things we have to do for each.
910 */ 859 */
911 if (gc->away) { 860 if (!gaim_presence_is_available(presence))
861 {
912 time_t t = time(NULL); 862 time_t t = time(NULL);
913 char *tmpmsg; 863 char *tmpmsg;
914 GaimBuddy *b = gaim_find_buddy(gc->account, name); 864 GaimBuddy *b = gaim_find_buddy(gc->account, name);
915 const char *alias = b ? gaim_buddy_get_alias(b) : name; 865 const char *alias = b ? gaim_buddy_get_alias(b) : name;
916 int row;
917 struct last_auto_response *lar; 866 struct last_auto_response *lar;
918 const gchar *auto_reply_pref; 867 const gchar *auto_reply_pref;
868 const char *away_msg;
869 #if 0
870 int row;
871 #endif
919 872
920 /* 873 /*
921 * Either we're going to queue it or not. Because of the way 874 * Either we're going to queue it or not. Because of the way
922 * awayness currently works, this is fucked up. It's possible 875 * awayness currently works, this is fucked up. It's possible
923 * for an account to be away without the imaway dialog being 876 * for an account to be away without the imaway dialog being
999 * - or it's disabled 952 * - or it's disabled
1000 * - or we're not idle and the 'only auto respond if idle' pref 953 * - or we're not idle and the 'only auto respond if idle' pref
1001 * is set 954 * is set
1002 */ 955 */
1003 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply"); 956 auto_reply_pref = gaim_prefs_get_string("/core/away/auto_reply");
957 status = gaim_presence_get_active_status(presence);
958 away_msg = gaim_value_get_string(
959 gaim_status_get_attr_value(status, "message"));
960
1004 if (!(gc->flags & GAIM_CONNECTION_AUTO_RESP) || 961 if (!(gc->flags & GAIM_CONNECTION_AUTO_RESP) ||
1005 *gc->away == '\0' || 962 away_msg == NULL || *away_msg == '\0' ||
1006 !strcmp(auto_reply_pref, "never") || 963 !strcmp(auto_reply_pref, "never") ||
1007 (!gc->is_idle && 964 (!gaim_presence_is_idle(presence) &&
1008 !strcmp(auto_reply_pref, "awayidle"))) { 965 !strcmp(auto_reply_pref, "awayidle"))) {
1009 966
1010 g_free(name); 967 g_free(name);
1011 g_free(message); 968 g_free(message);
1012 return; 969 return;
1013 } 970 }
1126 { 1083 {
1127 GaimBuddy *buddy = (GaimBuddy *)l->data; 1084 GaimBuddy *buddy = (GaimBuddy *)l->data;
1128 1085
1129 l_next = l->next; 1086 l_next = l->next;
1130 1087
1131 if (!GAIM_BUDDY_IS_ONLINE(buddy) || buddy->idle <= 0) 1088 if (!GAIM_BUDDY_IS_ONLINE(buddy) ||
1089 gaim_presence_is_idle(gaim_buddy_get_presence(buddy)))
1132 { 1090 {
1133 remove_idle_buddy(buddy); 1091 remove_idle_buddy(buddy);
1134 } 1092 }
1135 else 1093 else
1136 { 1094 {
1169 /* 1127 /*
1170 * @param idle The time at which the buddy became idle, in seconds 1128 * @param idle The time at which the buddy became idle, in seconds
1171 * since the epoch. 1129 * since the epoch.
1172 */ 1130 */
1173 void serv_got_update(GaimConnection *gc, const char *name, gboolean loggedin, 1131 void serv_got_update(GaimConnection *gc, const char *name, gboolean loggedin,
1174 int evil, time_t signon, time_t idle, int type) 1132 time_t signon)
1175 { 1133 {
1134 GaimPresence *presence;
1176 GaimAccount *account; 1135 GaimAccount *account;
1177 GaimConversation *c; 1136 GaimConversation *c;
1178 GaimBuddy *b; 1137 GaimBuddy *b;
1179 char *alias; 1138 char *alias;
1180 GSList *buddies; 1139 GSList *buddies;
1181 int old_idle;
1182 time_t current_time = time(NULL); 1140 time_t current_time = time(NULL);
1183 int signing_on = 0; 1141 int signing_on = 0;
1184 int signing_off = 0; 1142 int signing_off = 0;
1185 1143
1186 account = gaim_connection_get_account(gc); 1144 account = gaim_connection_get_account(gc);
1219 1177
1220 gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM, 1178 gaim_conversation_write(c, NULL, tmp, GAIM_MESSAGE_SYSTEM,
1221 time(NULL)); 1179 time(NULL));
1222 g_free(tmp); 1180 g_free(tmp);
1223 } 1181 }
1182 #if 0
1224 else if (awayqueue && find_queue_total_by_name(b->name)) { 1183 else if (awayqueue && find_queue_total_by_name(b->name)) {
1225 struct queued_message *qm = g_new0(struct queued_message, 1); 1184 struct queued_message *qm = g_new0(struct queued_message, 1);
1226 g_snprintf(qm->name, sizeof(qm->name), "%s", b->name); 1185 g_snprintf(qm->name, sizeof(qm->name), "%s", b->name);
1227 qm->message = g_strdup_printf(_("%s logged in."), alias); 1186 qm->message = g_strdup_printf(_("%s logged in."), alias);
1228 qm->account = gc->account; 1187 qm->account = gc->account;
1229 qm->tm = time(NULL); 1188 qm->tm = time(NULL);
1230 qm->flags = GAIM_MESSAGE_SYSTEM; 1189 qm->flags = GAIM_MESSAGE_SYSTEM;
1231 message_queue = g_slist_append(message_queue, qm); 1190 message_queue = g_slist_append(message_queue, qm);
1232 } 1191 }
1192 #endif
1233 gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); 1193 gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE);
1234 1194
1235 if(gaim_prefs_get_bool("/core/logging/log_system") && 1195 if(gaim_prefs_get_bool("/core/logging/log_system") &&
1236 gaim_prefs_get_bool("/core/logging/log_signon_signoff")) { 1196 gaim_prefs_get_bool("/core/logging/log_signon_signoff")) {
1237 GaimAccount *account = gaim_connection_get_account(gc); 1197 GaimAccount *account = gaim_connection_get_account(gc);
1238 GaimLog *log = gaim_account_get_log(account); 1198 GaimLog *log = gaim_account_get_log(account);
1239 char *tmp = g_strdup_printf(_("%s signed on"), alias); 1199 char *tmp = g_strdup_printf(_("%s signed on"), alias);
1240
1241 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name),
1242 current_time, tmp);
1243 g_free(tmp);
1244 }
1245 }
1246
1247 if(gaim_prefs_get_bool("/core/logging/log_system") &&
1248 gaim_prefs_get_bool("/core/logging/log_away_state")) {
1249 GaimAccount *account = gaim_connection_get_account(gc);
1250 GaimLog *log = gaim_account_get_log(account);
1251 char *tmp = NULL;
1252
1253 if((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE))
1254 tmp = g_strdup_printf(_("%s came back"), alias);
1255 else if(!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE))
1256 tmp = g_strdup_printf(_("%s went away"), alias);
1257
1258 if(tmp){
1259 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name),
1260 current_time, tmp);
1261 g_free(tmp);
1262 }
1263 }
1264
1265 if (!old_idle && idle) {
1266 if(gaim_prefs_get_bool("/core/logging/log_system") &&
1267 gaim_prefs_get_bool("/core/logging/log_idle_state")) {
1268 GaimAccount *account = gaim_connection_get_account(gc);
1269 GaimLog *log = gaim_account_get_log(account);
1270 char *tmp = g_strdup_printf(_("%s became idle"), alias);
1271
1272 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name),
1273 current_time, tmp);
1274 g_free(tmp);
1275 }
1276 } else if (old_idle && !idle) {
1277 if(gaim_prefs_get_bool("/core/logging/log_system") &&
1278 gaim_prefs_get_bool("/core/logging/log_idle_state")) {
1279 GaimAccount *account = gaim_connection_get_account(gc);
1280 GaimLog *log = gaim_account_get_log(account);
1281 char *tmp = g_strdup_printf(_("%s became unidle"), alias);
1282 1200
1283 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name), 1201 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, (alias ? alias : name),
1284 current_time, tmp); 1202 current_time, tmp);
1285 g_free(tmp); 1203 g_free(tmp);
1286 } 1204 }
1290 if (c != NULL) { 1208 if (c != NULL) {
1291 char *tmp = g_strdup_printf(_("%s logged out."), alias); 1209 char *tmp = g_strdup_printf(_("%s logged out."), alias);
1292 gaim_conversation_write(c, NULL, tmp, 1210 gaim_conversation_write(c, NULL, tmp,
1293 GAIM_MESSAGE_SYSTEM, time(NULL)); 1211 GAIM_MESSAGE_SYSTEM, time(NULL));
1294 g_free(tmp); 1212 g_free(tmp);
1295 } else if (awayqueue && find_queue_total_by_name(b->name)) { 1213 }
1214 #if 0
1215 else if (awayqueue && find_queue_total_by_name(b->name)) {
1296 struct queued_message *qm = g_new0(struct queued_message, 1); 1216 struct queued_message *qm = g_new0(struct queued_message, 1);
1297 g_snprintf(qm->name, sizeof(qm->name), "%s", b->name); 1217 g_snprintf(qm->name, sizeof(qm->name), "%s", b->name);
1298 qm->message = g_strdup_printf(_("%s logged out."), alias); 1218 qm->message = g_strdup_printf(_("%s logged out."), alias);
1299 qm->account = gc->account; 1219 qm->account = gc->account;
1300 qm->tm = time(NULL); 1220 qm->tm = time(NULL);
1301 qm->flags = GAIM_MESSAGE_SYSTEM; 1221 qm->flags = GAIM_MESSAGE_SYSTEM;
1302 message_queue = g_slist_append(message_queue, qm); 1222 message_queue = g_slist_append(message_queue, qm);
1303 } 1223 }
1224 #endif
1304 serv_got_typing_stopped(gc, name); /* obviously not typing */ 1225 serv_got_typing_stopped(gc, name); /* obviously not typing */
1305 gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); 1226 gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE);
1306 1227
1307 if(gaim_prefs_get_bool("/core/logging/log_system") && 1228 if(gaim_prefs_get_bool("/core/logging/log_system") &&
1308 gaim_prefs_get_bool("/core/logging/log_signon_signoff")) { 1229 gaim_prefs_get_bool("/core/logging/log_signon_signoff")) {
1316 } 1237 }
1317 } 1238 }
1318 1239
1319 if (gc->login_time_official && gc->login_time && signon > 0) 1240 if (gc->login_time_official && gc->login_time && signon > 0)
1320 signon += gc->login_time_official - gc->login_time; 1241 signon += gc->login_time_official - gc->login_time;
1242
1321 gaim_blist_update_buddy_signon(b, signon); 1243 gaim_blist_update_buddy_signon(b, signon);
1322 gaim_blist_update_buddy_idle(b, idle);
1323 gaim_blist_update_buddy_evil(b, evil);
1324 gaim_blist_update_buddy_status(b, type);
1325
1326 if (!old_idle && idle)
1327 {
1328 gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", b);
1329
1330 add_idle_buddy(b);
1331 }
1332 else if (old_idle && !idle)
1333 {
1334 gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", b);
1335
1336 remove_idle_buddy(b);
1337 }
1338 1244
1339 if (c != NULL) 1245 if (c != NULL)
1340 gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY); 1246 gaim_conversation_update(c, GAIM_CONV_UPDATE_AWAY);
1341 1247
1342 gaim_blist_update_buddy_presence(b, loggedin); 1248 gaim_blist_update_buddy_presence(b, loggedin);
1343 1249
1344 for (buddies = gaim_find_buddies(account, name); buddies; buddies = g_slist_remove(buddies, buddies->data)) { 1250 for (buddies = gaim_find_buddies(account, name); buddies; buddies = g_slist_remove(buddies, buddies->data)) {
1345 b = buddies->data; 1251 b = buddies->data;
1346 gaim_blist_update_buddy_presence(b, loggedin); 1252 gaim_blist_update_buddy_presence(b, loggedin);
1347 gaim_blist_update_buddy_idle(b, idle);
1348 gaim_blist_update_buddy_evil(b, evil);
1349 gaim_blist_update_buddy_status(b, type);
1350 } 1253 }
1351 g_free(alias); 1254 g_free(alias);
1352 }
1353
1354
1355 void serv_got_eviled(GaimConnection *gc, const char *name, int lev)
1356 {
1357 char buf2[1024];
1358 GaimAccount *account;
1359
1360 account = gaim_connection_get_account(gc);
1361
1362 gaim_signal_emit(gaim_accounts_get_handle(), "account-warned",
1363 account, name, lev);
1364
1365 if (gc->evil >= lev) {
1366 gc->evil = lev;
1367 return;
1368 }
1369
1370 gc->evil = lev;
1371
1372 g_snprintf(buf2, sizeof(buf2),
1373 _("%s has just been warned by %s.\n"
1374 "Your new warning level is %d%%"),
1375 gaim_account_get_username(gaim_connection_get_account(gc)),
1376 ((name == NULL) ? _("an anonymous person") : name), lev);
1377
1378 gaim_notify_info(NULL, NULL, buf2, NULL);
1379 } 1255 }
1380 1256
1381 void serv_got_typing(GaimConnection *gc, const char *name, int timeout, 1257 void serv_got_typing(GaimConnection *gc, const char *name, int timeout,
1382 GaimTypingState state) { 1258 GaimTypingState state) {
1383 1259

mercurial