Changes in root_commands.c [ad9ac5d:9f03c47]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
root_commands.c
rad9ac5d r9f03c47 143 143 } 144 144 145 if (load) { 145 status = auth_check_pass(irc, irc->user->nick, password); 146 if (load && (status == STORAGE_OK)) { 146 147 status = storage_load(irc, password); 147 } else {148 status = storage_check_pass(irc->user->nick, password);149 148 } 150 149 … … 159 158 irc_rootmsg(irc, "Password accepted%s", 160 159 load ? ", settings and accounts loaded" : ""); 161 irc_setpass(irc, password);162 160 irc->status |= USTATUS_IDENTIFIED; 163 161 irc_umode_set(irc, "+R", 1); … … 268 266 storage_status_t status; 269 267 270 status = storage_remove(irc->user->nick, cmd[1]); 268 status = auth_check_pass(irc, irc->user->nick, cmd[1]); 269 if (status == STORAGE_OK) { 270 status = storage_remove(irc->user->nick); 271 } 272 271 273 switch (status) { 272 274 case STORAGE_NO_SUCH_USER: … … 340 342 int st; 341 343 344 if (s && s->flags & SET_LOCKED) { 345 irc_rootmsg(irc, "This setting can not be changed"); 346 return 0; 347 } 342 348 if (s && checkflags && checkflags(irc, s) == 0) { 343 349 return 0; … … 388 394 irc_rootmsg(irc, "This setting can only be changed when the account is %s-line", "on"); 389 395 return 0; 396 } else if (a->flags & ACC_FLAG_LOCKED && s && s->flags & ACC_SET_LOCKABLE) { 397 irc_rootmsg(irc, "This setting can not be changed for locked accounts"); 398 return 0; 390 399 } 391 400 … … 409 418 410 419 MIN_ARGS(3); 420 421 if (!global.conf->allow_account_add) { 422 irc_rootmsg(irc, "This server does not allow adding new accounts"); 423 return; 424 } 411 425 412 426 if (cmd[4] == NULL) { … … 456 470 irc_rootmsg(irc, "No need to enter a password for this " 457 471 "account since it's using OAuth"); 472 } else if (prpl->options & PRPL_OPT_NO_PASSWORD) { 473 *a->pass = '\0'; 474 } else if (prpl->options & PRPL_OPT_PASSWORD_OPTIONAL) { 475 *a->pass = '\0'; 476 irc_rootmsg(irc, "Passwords are optional for this account. " 477 "If you wish to enter the password with /OPER, do " 478 "account %s set -del password", a->tag); 458 479 } else { 459 480 irc_rootmsg(irc, "You can now use the /OPER command to " … … 465 486 } 466 487 } 488 } else if (prpl->options & PRPL_OPT_NO_PASSWORD) { 489 irc_rootmsg(irc, "Note: this account doesn't use password for login"); 467 490 } 468 491 … … 547 570 548 571 if (len >= 1 && g_strncasecmp(cmd[2], "del", len) == 0) { 549 if (a->ic) { 572 if (a->flags & ACC_FLAG_LOCKED) { 573 irc_rootmsg(irc, "Account is locked, can't delete"); 574 } 575 else if (a->ic) { 550 576 irc_rootmsg(irc, "Account is still logged in, can't delete"); 551 577 } else { … … 1090 1116 } 1091 1117 1118 static gint prplcmp(gconstpointer a, gconstpointer b) 1119 { 1120 const struct prpl *pa = a; 1121 const struct prpl *pb = b; 1122 1123 return g_strcasecmp(pa->name, pb->name); 1124 } 1125 1126 static void prplstr(GList *prpls, GString *gstr) 1127 { 1128 const char *last = NULL; 1129 GList *l; 1130 struct prpl *p; 1131 1132 prpls = g_list_copy(prpls); 1133 prpls = g_list_sort(prpls, prplcmp); 1134 1135 for (l = prpls; l; l = l->next) { 1136 p = l->data; 1137 1138 if (last && g_strcasecmp(p->name, last) == 0) { 1139 /* Ignore duplicates (mainly for libpurple) */ 1140 continue; 1141 } 1142 1143 if (gstr->len != 0) { 1144 g_string_append(gstr, ", "); 1145 } 1146 1147 g_string_append(gstr, p->name); 1148 last = p->name; 1149 } 1150 1151 g_list_free(prpls); 1152 } 1153 1154 static void cmd_plugins(irc_t *irc, char **cmd) 1155 { 1156 GList *prpls; 1157 GString *gstr; 1158 1159 #ifdef WITH_PLUGINS 1160 GList *l; 1161 struct plugin_info *info; 1162 1163 for (l = get_plugins(); l; l = l->next) { 1164 info = l->data; 1165 irc_rootmsg(irc, "%s:", info->name); 1166 irc_rootmsg(irc, " Version: %s", info->version); 1167 1168 if (info->description) { 1169 irc_rootmsg(irc, " Description: %s", info->description); 1170 } 1171 1172 if (info->author) { 1173 irc_rootmsg(irc, " Author: %s", info->author); 1174 } 1175 1176 if (info->url) { 1177 irc_rootmsg(irc, " URL: %s", info->url); 1178 } 1179 1180 irc_rootmsg(irc, ""); 1181 } 1182 #endif 1183 1184 gstr = g_string_new(NULL); 1185 prpls = get_protocols(); 1186 1187 if (prpls) { 1188 prplstr(prpls, gstr); 1189 irc_rootmsg(irc, "Enabled Protocols: %s", gstr->str); 1190 g_string_truncate(gstr, 0); 1191 } 1192 1193 prpls = get_protocols_disabled(); 1194 1195 if (prpls) { 1196 prplstr(prpls, gstr); 1197 irc_rootmsg(irc, "Disabled Protocols: %s", gstr->str); 1198 } 1199 1200 g_string_free(gstr, TRUE); 1201 } 1202 1092 1203 static void cmd_qlist(irc_t *irc, char **cmd) 1093 1204 { … … 1116 1227 1117 1228 if (g_strcasecmp(cmd[1], "add") == 0) { 1118 char *channel, *s; 1229 bee_chat_info_t *ci; 1230 char *channel, *room, *s; 1119 1231 struct irc_channel *ic; 1232 guint i; 1120 1233 1121 1234 MIN_ARGS(3); … … 1129 1242 } 1130 1243 1244 if (cmd[3][0] == '!') { 1245 if (!acc->ic || !(acc->ic->flags & OPT_LOGGED_IN)) { 1246 irc_rootmsg(irc, "Not logged in to account."); 1247 return; 1248 } else if (!acc->prpl->chat_list) { 1249 irc_rootmsg(irc, "Listing chatrooms not supported on that account."); 1250 return; 1251 } 1252 1253 i = g_ascii_strtoull(cmd[3] + 1, NULL, 10); 1254 ci = g_slist_nth_data(acc->ic->chatlist, i - 1); 1255 1256 if (ci == NULL) { 1257 irc_rootmsg(irc, "Invalid chatroom index"); 1258 return; 1259 } 1260 1261 room = ci->title; 1262 } else { 1263 room = cmd[3]; 1264 } 1265 1131 1266 if (cmd[4] == NULL) { 1132 channel = g_strdup( cmd[3]);1267 channel = g_strdup(room); 1133 1268 if ((s = strchr(channel, '@'))) { 1134 1269 *s = 0; … … 1150 1285 set_setstr(&ic->set, "chat_type", "room") && 1151 1286 set_setstr(&ic->set, "account", cmd[2]) && 1152 set_setstr(&ic->set, "room", cmd[3])) {1287 set_setstr(&ic->set, "room", room)) { 1153 1288 irc_rootmsg(irc, "Chatroom successfully added."); 1154 1289 } else { … … 1160 1295 } 1161 1296 g_free(channel); 1297 } else if (g_strcasecmp(cmd[1], "list") == 0) { 1298 MIN_ARGS(2); 1299 1300 if (!(acc = account_get(irc->b, cmd[2]))) { 1301 irc_rootmsg(irc, "Invalid account"); 1302 return; 1303 } else if (!acc->ic || !(acc->ic->flags & OPT_LOGGED_IN)) { 1304 irc_rootmsg(irc, "Not logged in to account."); 1305 return; 1306 } else if (!acc->prpl->chat_list) { 1307 irc_rootmsg(irc, "Listing chatrooms not supported on that account."); 1308 return; 1309 } 1310 1311 acc->prpl->chat_list(acc->ic, cmd[3]); 1162 1312 } else if (g_strcasecmp(cmd[1], "with") == 0) { 1163 1313 irc_user_t *iu; … … 1174 1324 irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]); 1175 1325 } 1176 } else if (g_strcasecmp(cmd[1], "list") == 0 || 1177 g_strcasecmp(cmd[1], "set") == 0 || 1326 } else if (g_strcasecmp(cmd[1], "set") == 0 || 1178 1327 g_strcasecmp(cmd[1], "del") == 0) { 1179 1328 irc_rootmsg(irc, … … 1185 1334 cmd[1]); 1186 1335 } 1336 } 1337 1338 /* some arbitrary numbers */ 1339 #define CHAT_TITLE_LEN_MIN 20 1340 #define CHAT_TITLE_LEN_MAX 100 1341 1342 void cmd_chat_list_finish(struct im_connection *ic) 1343 { 1344 account_t *acc = ic->acc; 1345 bee_chat_info_t *ci; 1346 char *hformat, *iformat, *topic, *padded; 1347 GSList *l; 1348 guint i = 0; 1349 long title_len, new_len; 1350 irc_t *irc = ic->bee->ui_data; 1351 1352 if (ic->chatlist == NULL) { 1353 irc_rootmsg(irc, "No existing chatrooms"); 1354 return; 1355 } 1356 1357 /* find a reasonable width for the table */ 1358 title_len = CHAT_TITLE_LEN_MIN; 1359 1360 for (l = ic->chatlist; l; l = l->next) { 1361 ci = l->data; 1362 new_len = g_utf8_strlen(ci->title, -1); 1363 1364 if (new_len >= CHAT_TITLE_LEN_MAX) { 1365 title_len = CHAT_TITLE_LEN_MAX; 1366 break; 1367 } else if (title_len < new_len) { 1368 title_len = new_len; 1369 } 1370 } 1371 1372 if (strchr(irc->umode, 'b') != NULL) { 1373 hformat = "%s\t%s\t%s"; 1374 iformat = "%u\t%s\t%s"; 1375 } else { 1376 hformat = "%s %s %s"; 1377 iformat = "%5u %s %s"; 1378 } 1379 1380 padded = str_pad_and_truncate("Title", title_len, NULL); 1381 irc_rootmsg(irc, hformat, "Index", padded, "Topic"); 1382 g_free(padded); 1383 1384 for (l = ic->chatlist; l; l = l->next) { 1385 ci = l->data; 1386 topic = ci->topic ? ci->topic : ""; 1387 1388 padded = str_pad_and_truncate(ci->title, title_len, "[...]"); 1389 irc_rootmsg(irc, iformat, ++i, padded, topic); 1390 g_free(padded); 1391 } 1392 1393 irc_rootmsg(irc, "%u %s chatrooms", i, acc->tag); 1187 1394 } 1188 1395 … … 1238 1445 { 1239 1446 GSList *files = irc->file_transfers; 1447 GSList *next; 1240 1448 1241 1449 enum { LIST, REJECT, CANCEL }; … … 1255 1463 } 1256 1464 1257 for (; files; files = g_slist_next(files)) { 1465 for (; files; files = next) { 1466 next = files->next; 1258 1467 file_transfer_t *file = files->data; 1259 1468 … … 1339 1548 { "nick", 1, cmd_nick, 0 }, 1340 1549 { "no", 0, cmd_yesno, 0 }, 1550 { "plugins", 0, cmd_plugins, 0 }, 1341 1551 { "qlist", 0, cmd_qlist, 0 }, 1342 1552 { "register", 0, cmd_register, 0 },
Note: See TracChangeset
for help on using the changeset viewer.