|
|
@@ -35,6 +35,7 @@
|
|
|
#include <poll.h>
|
|
|
#include <signal.h>
|
|
|
|
|
|
+#include <klist.h>
|
|
|
#include <vcc/vcc.h>
|
|
|
#include <vcc/version.h>
|
|
|
#include <vcc/pretty.h>
|
|
|
@@ -63,7 +64,7 @@ int incr_score(char *username, int incr);
|
|
|
int send_msg(char *msg, char *s);
|
|
|
int encrypt(char *s);
|
|
|
|
|
|
-extern str_t banned_people[BAN_SIZE];
|
|
|
+extern struct klist_node *banned_people;
|
|
|
extern char usrname[];
|
|
|
extern int rate;
|
|
|
extern int current_sid;
|
|
|
@@ -388,45 +389,44 @@ int do_cmd_cqd(char *s) {
|
|
|
|
|
|
|
|
|
int do_cmd_ban(char *s) {
|
|
|
- char *people_name;
|
|
|
- int i;
|
|
|
+ char *people_name, people_arr[USRNAME_SIZE];
|
|
|
+ struct klist_node *i;
|
|
|
|
|
|
(void) s;
|
|
|
|
|
|
- people_name = malloc(USRNAME_SIZE + 1);
|
|
|
+ fprintf(stderr, "Enter the user to ban: ");
|
|
|
+ scanf("%s", people_arr);
|
|
|
|
|
|
- printf("Enter the user to ban: ");
|
|
|
- scanf("%s", people_name);
|
|
|
+ people_name = strdup(people_arr);
|
|
|
|
|
|
- for (i = 0; i < BAN_SIZE; ++i) {
|
|
|
- if (!banned_people[i]) {
|
|
|
- banned_people[i] = people_name;
|
|
|
- return 0;
|
|
|
- }
|
|
|
- else if (!strcmp(people_name, banned_people[i])) {
|
|
|
- printf("User %s is already banned", people_name);
|
|
|
+ for (i = banned_people->next; i != banned_people; i = i->next) {
|
|
|
+ if (!strcmp(people_name, i->usrname)) {
|
|
|
+ fprintf(stderr, "User %s is already banned", people_name);
|
|
|
+ free(people_name);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
- printf("Cannot ban the user");
|
|
|
+ i = malloc(sizeof(struct klist_node));
|
|
|
+ i->usrname = people_name;
|
|
|
+ klist_add(banned_people, i);
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
int do_cmd_unban(char *s) {
|
|
|
- char *people_name;
|
|
|
- int i;
|
|
|
+ char *people_name;
|
|
|
+ struct klist_node *i;
|
|
|
|
|
|
(void) s;
|
|
|
|
|
|
people_name = malloc(USRNAME_SIZE + 1);
|
|
|
|
|
|
- printf("Enter the user to unban: ");
|
|
|
+ fprintf(stderr, "Enter the user to unban: ");
|
|
|
scanf("%s", people_name);
|
|
|
|
|
|
- for (i = 0; i < BAN_SIZE; ++i) {
|
|
|
- if (banned_people[i] && !strcmp(people_name, banned_people[i])) {
|
|
|
- free(banned_people[i]);
|
|
|
- banned_people[i] = NULL;
|
|
|
+ for (i = banned_people->next; i != banned_people; i = i->next) {
|
|
|
+ if (!strcmp(people_name, i->usrname)) {
|
|
|
+ klist_del(banned_people, i);
|
|
|
+ free(i->usrname);
|
|
|
+ free(i);
|
|
|
break;
|
|
|
}
|
|
|
}
|