Changeset b308cf9 for protocols/nogaim.c
- Timestamp:
- 2010-06-05T23:21:02Z (14 years ago)
- Branches:
- master
- Children:
- 1fdb0a4
- Parents:
- 3ab1d31 (diff), e774815 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r3ab1d31 rb308cf9 39 39 40 40 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); 41 static char *format_timestamp( irc_t *irc, time_t msg_ts ); 41 42 42 43 GSList *connections; … … 116 117 { 117 118 GList *gl; 118 for (gl = protocols; gl; gl = gl->next) 119 120 for( gl = protocols; gl; gl = gl->next ) 119 121 { 120 122 struct prpl *proto = gl->data; 121 if(!g_strcasecmp(proto->name, name)) 123 124 if( g_strcasecmp( proto->name, name ) == 0 ) 122 125 return proto; 123 126 } 127 124 128 return NULL; 125 129 } … … 132 136 extern void byahoo_initmodule(); 133 137 extern void jabber_initmodule(); 138 extern void twitter_initmodule(); 139 extern void purple_initmodule(); 134 140 135 141 #ifdef WITH_MSN … … 147 153 #ifdef WITH_JABBER 148 154 jabber_initmodule(); 155 #endif 156 157 #ifdef WITH_TWITTER 158 twitter_initmodule(); 159 #endif 160 161 #ifdef WITH_PURPLE 162 purple_initmodule(); 149 163 #endif 150 164 … … 651 665 u->away = u->status_msg = NULL; 652 666 653 if( ( flags & OPT_LOGGED_IN ) && !u->online ) 654 { 667 if( set_getbool( &ic->irc->set, "show_offline" ) && !u->online ) 668 { 669 /* always set users as online */ 655 670 irc_spawn( ic->irc, u ); 656 671 u->online = 1; 672 if( !( flags & OPT_LOGGED_IN ) ) 673 { 674 /* set away message if user isn't really online */ 675 u->away = g_strdup( "User is offline" ); 676 } 677 } 678 else if( ( flags & OPT_LOGGED_IN ) && !u->online ) 679 { 680 irc_spawn( ic->irc, u ); 681 u->online = 1; 657 682 } 658 683 else if( !( flags & OPT_LOGGED_IN ) && u->online ) … … 660 685 struct groupchat *c; 661 686 662 irc_kill( ic->irc, u ); 663 u->online = 0; 664 665 /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ 666 for( c = ic->groupchats; c; c = c->next ) 667 remove_chat_buddy_silent( c, handle ); 668 } 669 687 if( set_getbool( &ic->irc->set, "show_offline" ) ) 688 { 689 /* keep offline users in channel and set away message to "offline" */ 690 u->away = g_strdup( "User is offline" ); 691 692 /* Keep showing him/her in the control channel but not in groupchats. */ 693 for( c = ic->groupchats; c; c = c->next ) 694 { 695 if( remove_chat_buddy_silent( c, handle ) && c->joined ) 696 irc_part( c->ic->irc, u, c->channel ); 697 } 698 } 699 else 700 { 701 /* kill offline users */ 702 irc_kill( ic->irc, u ); 703 u->online = 0; 704 705 /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ 706 for( c = ic->groupchats; c; c = c->next ) 707 remove_chat_buddy_silent( c, handle ); 708 } 709 } 710 670 711 if( flags & OPT_AWAY ) 671 712 { … … 692 733 } 693 734 694 /* LISPy... */ 695 if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ 696 ( u->online ) && /* Don't touch offline people */ 697 ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ 698 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ 735 /* early if-clause for show_offline even if there is some redundant code here because this isn't LISP but C ;) */ 736 if( set_getbool( &ic->irc->set, "show_offline" ) && set_getbool( &ic->irc->set, "away_devoice" ) ) 699 737 { 700 738 char *from; … … 709 747 ic->irc->myhost ); 710 748 } 711 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 712 u->away?'-':'+', u->nick ); 713 g_free( from ); 749 750 /* if we use show_offline, we op online users, voice away users, and devoice/deop offline users */ 751 if( flags & OPT_LOGGED_IN ) 752 { 753 /* user is "online" (either really online or away) */ 754 irc_write( ic->irc, ":%s MODE %s %cv%co %s %s", from, ic->irc->channel, 755 u->away?'+':'-', u->away?'-':'+', u->nick, u->nick ); 756 } 757 else 758 { 759 /* user is offline */ 760 irc_write( ic->irc, ":%s MODE %s -vo %s %s", from, ic->irc->channel, u->nick, u->nick ); 761 } 762 } 763 else 764 { 765 /* LISPy... */ 766 if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ 767 ( u->online ) && /* Don't touch offline people */ 768 ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ 769 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ 770 { 771 char *from; 772 773 if( set_getbool( &ic->irc->set, "simulate_netsplit" ) ) 774 { 775 from = g_strdup( ic->irc->myhost ); 776 } 777 else 778 { 779 from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, 780 ic->irc->myhost ); 781 } 782 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 783 u->away?'-':'+', u->nick ); 784 g_free( from ); 785 } 714 786 } 715 787 } … … 718 790 { 719 791 irc_t *irc = ic->irc; 720 char *wrapped ;792 char *wrapped, *ts = NULL; 721 793 user_t *u; 722 794 … … 760 832 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 761 833 strip_html( msg ); 762 834 835 if( set_getbool( &ic->irc->set, "display_timestamps" ) && 836 ( ts = format_timestamp( irc, sent_at ) ) ) 837 { 838 char *new = g_strconcat( ts, msg, NULL ); 839 g_free( ts ); 840 ts = msg = new; 841 } 842 763 843 wrapped = word_wrap( msg, 425 ); 764 844 irc_msgfrom( irc, u->nick, wrapped ); 765 845 g_free( wrapped ); 846 g_free( ts ); 766 847 } 767 848 … … 805 886 806 887 return c; 888 } 889 890 void imcb_chat_name_hint( struct groupchat *c, const char *name ) 891 { 892 if( !c->joined ) 893 { 894 struct im_connection *ic = c->ic; 895 char stripped[MAX_NICK_LENGTH+1], *full_name; 896 897 strncpy( stripped, name, MAX_NICK_LENGTH ); 898 stripped[MAX_NICK_LENGTH] = '\0'; 899 nick_strip( stripped ); 900 if( set_getbool( &ic->irc->set, "lcnicks" ) ) 901 nick_lc( stripped ); 902 903 full_name = g_strdup_printf( "&%s", stripped ); 904 905 if( stripped[0] && 906 nick_cmp( stripped, ic->irc->channel + 1 ) != 0 && 907 irc_chat_by_channel( ic->irc, full_name ) == NULL ) 908 { 909 g_free( c->channel ); 910 c->channel = full_name; 911 } 912 else 913 { 914 g_free( full_name ); 915 } 916 } 807 917 } 808 918 … … 867 977 if( c && u ) 868 978 { 869 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); 979 char *ts = NULL; 980 if( set_getbool( &ic->irc->set, "display_timestamps" ) ) 981 ts = format_timestamp( ic->irc, sent_at ); 982 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped ); 983 g_free( ts ); 870 984 } 871 985 else … … 1061 1175 } 1062 1176 1063 1064 1177 char *set_eval_timezone( set_t *set, char *value ) 1178 { 1179 char *s; 1180 1181 if( strcmp( value, "local" ) == 0 || 1182 strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 ) 1183 return value; 1184 1185 /* Otherwise: +/- at the beginning optional, then one or more numbers, 1186 possibly followed by a colon and more numbers. Don't bother bound- 1187 checking them since users are free to shoot themselves in the foot. */ 1188 s = value; 1189 if( *s == '+' || *s == '-' ) 1190 s ++; 1191 1192 /* \d+ */ 1193 if( !isdigit( *s ) ) 1194 return SET_INVALID; 1195 while( *s && isdigit( *s ) ) s ++; 1196 1197 /* EOS? */ 1198 if( *s == '\0' ) 1199 return value; 1200 1201 /* Otherwise, colon */ 1202 if( *s != ':' ) 1203 return SET_INVALID; 1204 s ++; 1205 1206 /* \d+ */ 1207 if( !isdigit( *s ) ) 1208 return SET_INVALID; 1209 while( *s && isdigit( *s ) ) s ++; 1210 1211 /* EOS */ 1212 return *s == '\0' ? value : SET_INVALID; 1213 } 1214 1215 static char *format_timestamp( irc_t *irc, time_t msg_ts ) 1216 { 1217 time_t now_ts = time( NULL ); 1218 struct tm now, msg; 1219 char *set; 1220 1221 /* If the timestamp is <= 0 or less than a minute ago, discard it as 1222 it doesn't seem to add to much useful info and/or might be noise. */ 1223 if( msg_ts <= 0 || msg_ts > now_ts - 60 ) 1224 return NULL; 1225 1226 set = set_getstr( &irc->set, "timezone" ); 1227 if( strcmp( set, "local" ) == 0 ) 1228 { 1229 localtime_r( &now_ts, &now ); 1230 localtime_r( &msg_ts, &msg ); 1231 } 1232 else 1233 { 1234 int hr, min = 0, sign = 60; 1235 1236 if( set[0] == '-' ) 1237 { 1238 sign *= -1; 1239 set ++; 1240 } 1241 else if( set[0] == '+' ) 1242 { 1243 set ++; 1244 } 1245 1246 if( sscanf( set, "%d:%d", &hr, &min ) >= 1 ) 1247 { 1248 msg_ts += sign * ( hr * 60 + min ); 1249 now_ts += sign * ( hr * 60 + min ); 1250 } 1251 1252 gmtime_r( &now_ts, &now ); 1253 gmtime_r( &msg_ts, &msg ); 1254 } 1255 1256 if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday ) 1257 return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ", 1258 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1259 else 1260 return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d " 1261 "%02d:%02d:%02d\x02]\x02 ", 1262 msg.tm_year + 1900, msg.tm_mon + 1, msg.tm_mday, 1263 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1264 } 1065 1265 1066 1266 /* The plan is to not allow straight calls to prpl functions anymore, but do … … 1105 1305 { 1106 1306 char *away, *msg = NULL; 1307 1308 if( ic->acc->prpl->away_states == NULL || 1309 ic->acc->prpl->set_away == NULL ) 1310 return 0; 1107 1311 1108 1312 away = set_getstr( &ic->acc->set, "away" ) ?
Note: See TracChangeset
for help on using the changeset viewer.