Changeset 537d9b9 for root_commands.c
- Timestamp:
- 2016-11-20T08:40:36Z (8 years ago)
- Children:
- 3f44e43
- Parents:
- ba52ac5 (diff), 9f03c47 (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
-
root_commands.c
rba52ac5 r537d9b9 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 … … 553 576 554 577 if (len >= 1 && g_strncasecmp(cmd[2], "del", len) == 0) { 555 if (a->ic) { 578 if (a->flags & ACC_FLAG_LOCKED) { 579 irc_rootmsg(irc, "Account is locked, can't delete"); 580 } 581 else if (a->ic) { 556 582 irc_rootmsg(irc, "Account is still logged in, can't delete"); 557 583 } else { … … 1108 1134 } 1109 1135 1136 static gint prplcmp(gconstpointer a, gconstpointer b) 1137 { 1138 const struct prpl *pa = a; 1139 const struct prpl *pb = b; 1140 1141 return g_strcasecmp(pa->name, pb->name); 1142 } 1143 1144 static void prplstr(GList *prpls, GString *gstr) 1145 { 1146 const char *last = NULL; 1147 GList *l; 1148 struct prpl *p; 1149 1150 prpls = g_list_copy(prpls); 1151 prpls = g_list_sort(prpls, prplcmp); 1152 1153 for (l = prpls; l; l = l->next) { 1154 p = l->data; 1155 1156 if (last && g_strcasecmp(p->name, last) == 0) { 1157 /* Ignore duplicates (mainly for libpurple) */ 1158 continue; 1159 } 1160 1161 if (gstr->len != 0) { 1162 g_string_append(gstr, ", "); 1163 } 1164 1165 g_string_append(gstr, p->name); 1166 last = p->name; 1167 } 1168 1169 g_list_free(prpls); 1170 } 1171 1172 static void cmd_plugins(irc_t *irc, char **cmd) 1173 { 1174 GList *prpls; 1175 GString *gstr; 1176 1177 #ifdef WITH_PLUGINS 1178 GList *l; 1179 struct plugin_info *info; 1180 1181 for (l = get_plugins(); l; l = l->next) { 1182 info = l->data; 1183 irc_rootmsg(irc, "%s:", info->name); 1184 irc_rootmsg(irc, " Version: %s", info->version); 1185 1186 if (info->description) { 1187 irc_rootmsg(irc, " Description: %s", info->description); 1188 } 1189 1190 if (info->author) { 1191 irc_rootmsg(irc, " Author: %s", info->author); 1192 } 1193 1194 if (info->url) { 1195 irc_rootmsg(irc, " URL: %s", info->url); 1196 } 1197 1198 irc_rootmsg(irc, ""); 1199 } 1200 #endif 1201 1202 gstr = g_string_new(NULL); 1203 prpls = get_protocols(); 1204 1205 if (prpls) { 1206 prplstr(prpls, gstr); 1207 irc_rootmsg(irc, "Enabled Protocols: %s", gstr->str); 1208 g_string_truncate(gstr, 0); 1209 } 1210 1211 prpls = get_protocols_disabled(); 1212 1213 if (prpls) { 1214 prplstr(prpls, gstr); 1215 irc_rootmsg(irc, "Disabled Protocols: %s", gstr->str); 1216 } 1217 1218 g_string_free(gstr, TRUE); 1219 } 1220 1110 1221 static void cmd_qlist(irc_t *irc, char **cmd) 1111 1222 { … … 1134 1245 1135 1246 if (g_strcasecmp(cmd[1], "add") == 0) { 1136 char *channel, *s; 1247 bee_chat_info_t *ci; 1248 char *channel, *room, *s; 1137 1249 struct irc_channel *ic; 1250 guint i; 1138 1251 1139 1252 MIN_ARGS(3); … … 1147 1260 } 1148 1261 1262 if (cmd[3][0] == '!') { 1263 if (!acc->ic || !(acc->ic->flags & OPT_LOGGED_IN)) { 1264 irc_rootmsg(irc, "Not logged in to account."); 1265 return; 1266 } else if (!acc->prpl->chat_list) { 1267 irc_rootmsg(irc, "Listing chatrooms not supported on that account."); 1268 return; 1269 } 1270 1271 i = g_ascii_strtoull(cmd[3] + 1, NULL, 10); 1272 ci = g_slist_nth_data(acc->ic->chatlist, i - 1); 1273 1274 if (ci == NULL) { 1275 irc_rootmsg(irc, "Invalid chatroom index"); 1276 return; 1277 } 1278 1279 room = ci->title; 1280 } else { 1281 room = cmd[3]; 1282 } 1283 1149 1284 if (cmd[4] == NULL) { 1150 channel = g_strdup( cmd[3]);1285 channel = g_strdup(room); 1151 1286 if ((s = strchr(channel, '@'))) { 1152 1287 *s = 0; … … 1168 1303 set_setstr(&ic->set, "chat_type", "room") && 1169 1304 set_setstr(&ic->set, "account", cmd[2]) && 1170 set_setstr(&ic->set, "room", cmd[3])) {1305 set_setstr(&ic->set, "room", room)) { 1171 1306 irc_rootmsg(irc, "Chatroom successfully added."); 1172 1307 } else { … … 1178 1313 } 1179 1314 g_free(channel); 1315 } else if (g_strcasecmp(cmd[1], "list") == 0) { 1316 MIN_ARGS(2); 1317 1318 if (!(acc = account_get(irc->b, cmd[2]))) { 1319 irc_rootmsg(irc, "Invalid account"); 1320 return; 1321 } else if (!acc->ic || !(acc->ic->flags & OPT_LOGGED_IN)) { 1322 irc_rootmsg(irc, "Not logged in to account."); 1323 return; 1324 } else if (!acc->prpl->chat_list) { 1325 irc_rootmsg(irc, "Listing chatrooms not supported on that account."); 1326 return; 1327 } 1328 1329 acc->prpl->chat_list(acc->ic, cmd[3]); 1180 1330 } else if (g_strcasecmp(cmd[1], "with") == 0) { 1181 1331 irc_user_t *iu; … … 1192 1342 irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]); 1193 1343 } 1194 } else if (g_strcasecmp(cmd[1], "list") == 0 || 1195 g_strcasecmp(cmd[1], "set") == 0 || 1344 } else if (g_strcasecmp(cmd[1], "set") == 0 || 1196 1345 g_strcasecmp(cmd[1], "del") == 0) { 1197 1346 irc_rootmsg(irc, … … 1203 1352 cmd[1]); 1204 1353 } 1354 } 1355 1356 /* some arbitrary numbers */ 1357 #define CHAT_TITLE_LEN_MIN 20 1358 #define CHAT_TITLE_LEN_MAX 100 1359 1360 void cmd_chat_list_finish(struct im_connection *ic) 1361 { 1362 account_t *acc = ic->acc; 1363 bee_chat_info_t *ci; 1364 char *hformat, *iformat, *topic, *padded; 1365 GSList *l; 1366 guint i = 0; 1367 long title_len, new_len; 1368 irc_t *irc = ic->bee->ui_data; 1369 1370 if (ic->chatlist == NULL) { 1371 irc_rootmsg(irc, "No existing chatrooms"); 1372 return; 1373 } 1374 1375 /* find a reasonable width for the table */ 1376 title_len = CHAT_TITLE_LEN_MIN; 1377 1378 for (l = ic->chatlist; l; l = l->next) { 1379 ci = l->data; 1380 new_len = g_utf8_strlen(ci->title, -1); 1381 1382 if (new_len >= CHAT_TITLE_LEN_MAX) { 1383 title_len = CHAT_TITLE_LEN_MAX; 1384 break; 1385 } else if (title_len < new_len) { 1386 title_len = new_len; 1387 } 1388 } 1389 1390 if (strchr(irc->umode, 'b') != NULL) { 1391 hformat = "%s\t%s\t%s"; 1392 iformat = "%u\t%s\t%s"; 1393 } else { 1394 hformat = "%s %s %s"; 1395 iformat = "%5u %s %s"; 1396 } 1397 1398 padded = str_pad_and_truncate("Title", title_len, NULL); 1399 irc_rootmsg(irc, hformat, "Index", padded, "Topic"); 1400 g_free(padded); 1401 1402 for (l = ic->chatlist; l; l = l->next) { 1403 ci = l->data; 1404 topic = ci->topic ? ci->topic : ""; 1405 1406 padded = str_pad_and_truncate(ci->title, title_len, "[...]"); 1407 irc_rootmsg(irc, iformat, ++i, padded, topic); 1408 g_free(padded); 1409 } 1410 1411 irc_rootmsg(irc, "%u %s chatrooms", i, acc->tag); 1205 1412 } 1206 1413 … … 1256 1463 { 1257 1464 GSList *files = irc->file_transfers; 1465 GSList *next; 1258 1466 1259 1467 enum { LIST, REJECT, CANCEL }; … … 1273 1481 } 1274 1482 1275 for (; files; files = g_slist_next(files)) { 1483 for (; files; files = next) { 1484 next = files->next; 1276 1485 file_transfer_t *file = files->data; 1277 1486 … … 1357 1566 { "nick", 1, cmd_nick, 0 }, 1358 1567 { "no", 0, cmd_yesno, 0 }, 1568 { "plugins", 0, cmd_plugins, 0 }, 1359 1569 { "qlist", 0, cmd_qlist, 0 }, 1360 1570 { "register", 0, cmd_register, 0 },
Note: See TracChangeset
for help on using the changeset viewer.