|
Atrinik Client 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #include <global.h> 00031 00033 static ignore_list_struct *ignore_list = NULL; 00034 00039 static void ignore_entry_add(const char *name, const char *type) 00040 { 00041 ignore_list_struct *tmp = (ignore_list_struct *) malloc(sizeof(ignore_list_struct)); 00042 00043 strncpy(tmp->name, name, sizeof(tmp->name) - 1); 00044 tmp->name[sizeof(tmp->name) - 1] = '\0'; 00045 strncpy(tmp->type, type, sizeof(tmp->type) - 1); 00046 tmp->type[sizeof(tmp->type) - 1] = '\0'; 00047 00048 tmp->next = ignore_list; 00049 ignore_list = tmp; 00050 } 00051 00057 static int ignore_entry_remove(const char *name, const char *type) 00058 { 00059 ignore_list_struct *tmp, *prev = NULL; 00060 00061 for (tmp = ignore_list; tmp; prev = tmp, tmp = tmp->next) 00062 { 00063 if (!strcasecmp(name, tmp->name) && !strcasecmp(type, tmp->type)) 00064 { 00065 if (prev) 00066 { 00067 prev->next = tmp->next; 00068 } 00069 else 00070 { 00071 ignore_list = tmp->next; 00072 } 00073 00074 free(tmp); 00075 return 1; 00076 } 00077 } 00078 00079 return 0; 00080 } 00081 00084 void ignore_list_clear() 00085 { 00086 ignore_list_struct *tmp, *tmp2; 00087 00088 for (tmp = ignore_list; tmp; tmp = tmp2) 00089 { 00090 tmp2 = tmp->next; 00091 free(tmp); 00092 } 00093 00094 ignore_list = NULL; 00095 } 00096 00099 void ignore_list_load() 00100 { 00101 char buf[MAX_BUF], name[MAX_BUF], type[MAX_BUF], filename[MAX_BUF]; 00102 FILE *fp; 00103 00104 snprintf(filename, sizeof(filename), "settings/%s.ignorelist", cpl.name); 00105 ignore_list_clear(); 00106 00107 if (!(fp = fopen_wrapper(filename, "r"))) 00108 { 00109 return; 00110 } 00111 00112 while (fgets(buf, sizeof(buf), fp)) 00113 { 00114 if (sscanf(buf, "%s %s\n", name, type) == 2) 00115 { 00116 ignore_entry_add(name, type); 00117 } 00118 } 00119 00120 fclose(fp); 00121 } 00122 00125 static void ignore_list_save() 00126 { 00127 ignore_list_struct *tmp; 00128 char filename[MAX_BUF]; 00129 FILE *fp; 00130 00131 snprintf(filename, sizeof(filename), "settings/%s.ignorelist", cpl.name); 00132 00133 if (!(fp = fopen_wrapper(filename, "w"))) 00134 { 00135 return; 00136 } 00137 00138 for (tmp = ignore_list; tmp; tmp = tmp->next) 00139 { 00140 fprintf(fp, "%s %s\n", tmp->name, tmp->type); 00141 } 00142 00143 fclose(fp); 00144 } 00145 00151 int ignore_check(const char *name, const char *type) 00152 { 00153 ignore_list_struct *tmp; 00154 00155 for (tmp = ignore_list; tmp; tmp = tmp->next) 00156 { 00157 if ((tmp->name[0] == '*' || !strcasecmp(name, tmp->name)) && (tmp->type[0] == '*' || !strcasecmp(type, tmp->type))) 00158 { 00159 return 1; 00160 } 00161 } 00162 00163 return 0; 00164 } 00165 00169 void ignore_command(const char *cmd) 00170 { 00171 char name[64], type[64]; 00172 00173 if (cmd[0] == '\0') 00174 { 00175 ignore_list_struct *tmp; 00176 00177 draw_info(COLOR_WHITE, "\nIGNORE LIST"); 00178 draw_info(COLOR_WHITE, "--------------------------"); 00179 00180 for (tmp = ignore_list; tmp; tmp = tmp->next) 00181 { 00182 draw_info_format(COLOR_WHITE, "Name: %s Type: %s", tmp->name, tmp->type); 00183 } 00184 } 00185 else 00186 { 00187 cmd++; 00188 00189 if (sscanf(cmd, "%s %s", name, type) != 2) 00190 { 00191 draw_info_format(COLOR_WHITE, "Syntax: /ignore <name> <type>"); 00192 } 00193 else 00194 { 00195 if (ignore_entry_remove(name, type)) 00196 { 00197 draw_info_format(COLOR_WHITE, "Removed %s (%s) from ignore list.", name, type); 00198 } 00199 else 00200 { 00201 ignore_entry_add(name, type); 00202 draw_info_format(COLOR_WHITE, "Added %s (%s) to ignore list.", name, type); 00203 } 00204 00205 ignore_list_save(); 00206 } 00207 } 00208 }
1.7.4