#include "copyright.h"
#include "config.h"
#include <ctype.h>
#include <sys/types.h>
#include "db.h"
#include "interface.h"
#include "match.h"
#include "externs.h"
#include "commac.h"
Include dependency graph for commac.c:
Go to the source code of this file.
Functions | |
void | load_comsystem (FILE *) |
void | load_macros (FILE *) |
void | save_comsystem (FILE *) |
void | save_macros (FILE *) |
void | load_comsys_and_macros (char *filename) |
void | save_comsys_and_macros (char *filename) |
void | load_commac (FILE *fp) |
void | purge_commac (void) |
void | save_commac (FILE *fp) |
commac * | create_new_commac (void) |
commac * | get_commac (dbref which) |
void | add_commac (struct commac *c) |
void | del_commac (dbref who) |
void | destroy_commac (struct commac *c) |
void | sort_com_aliases (struct commac *c) |
void add_commac | ( | struct commac * | c | ) |
Definition at line 245 of file commac.c.
References c, commac_table, coolmenu_type::next, and NUM_COMMAC.
Referenced by get_commac(), load_commac(), and mmdb_db_read().
00246 { 00247 if(c->who < 0) 00248 return; 00249 00250 c->next = commac_table[c->who % NUM_COMMAC]; 00251 commac_table[c->who % NUM_COMMAC] = c; 00252 }
struct commac* create_new_commac | ( | void | ) |
Definition at line 204 of file commac.c.
References c, and coolmenu_type::next.
Referenced by get_commac(), load_commac(), and mmdb_db_read().
00205 { 00206 struct commac *c; 00207 int i; 00208 00209 c = (struct commac *) malloc(sizeof(struct commac)); 00210 00211 c->who = -1; 00212 c->numchannels = 0; 00213 c->maxchannels = 0; 00214 c->alias = NULL; 00215 c->channels = NULL; 00216 00217 c->curmac = -1; 00218 for(i = 0; i < 5; i++) 00219 c->macros[i] = -1; 00220 00221 c->next = NULL; 00222 return c; 00223 }
void del_commac | ( | dbref | who | ) |
Definition at line 254 of file commac.c.
References c, commac_table, destroy_commac(), coolmenu_type::next, commac::next, and NUM_COMMAC.
Referenced by purge_commac(), and toast_player().
00255 { 00256 struct commac *c; 00257 struct commac *last; 00258 00259 if(who < 0) 00260 return; 00261 00262 c = commac_table[who % NUM_COMMAC]; 00263 00264 if(c == NULL) 00265 return; 00266 00267 if(c->who == who) { 00268 commac_table[who % NUM_COMMAC] = c->next; 00269 destroy_commac(c); 00270 return; 00271 } 00272 last = c; 00273 c = c->next; 00274 while (c) { 00275 if(c->who == who) { 00276 last->next = c->next; 00277 destroy_commac(c); 00278 return; 00279 } 00280 last = c; 00281 c = c->next; 00282 } 00283 }
void destroy_commac | ( | struct commac * | c | ) |
Definition at line 225 of file commac.c.
References add_commac(), c, commac_table, create_new_commac(), coolmenu_type::next, and NUM_COMMAC.
Referenced by do_add_macro(), do_addcom(), do_allcom(), do_clear_macro(), do_clearcom(), do_comconnect(), do_comdisconnect(), do_comlist(), do_create_macro(), do_del_macro(), do_delcom(), do_edit_macro(), do_process_macro(), do_status_macro(), get_channel_from_alias(), and get_macro_set().
00226 { 00227 struct commac *c; 00228 00229 if(which < 0) 00230 return NULL; 00231 00232 c = commac_table[which % NUM_COMMAC]; 00233 00234 while (c && (c->who != which)) 00235 c = c->next; 00236 00237 if(!c) { 00238 c = create_new_commac(); 00239 c->who = which; 00240 add_commac(c); 00241 } 00242 return c; 00243 }
void load_commac | ( | FILE * | fp | ) |
Definition at line 91 of file commac.c.
References add_commac(), c, create_new_commac(), God, Going, Owner, purge_commac(), sort_com_aliases(), StringCopy, TYPE_PLAYER, and Typeof.
Referenced by load_comsys_and_macros().
00092 { 00093 int i, j; 00094 char buffer[100]; 00095 int np; 00096 struct commac *c; 00097 char *t; 00098 char in; 00099 00100 fscanf(fp, "%d\n", &np); 00101 for(i = 0; i < np; i++) { 00102 c = create_new_commac(); 00103 fscanf(fp, "%d %d %d %d %d %d %d %d\n", &(c->who), 00104 &(c->numchannels), &(c->macros[0]), &(c->macros[1]), 00105 &c->macros[2], &(c->macros[3]), &(c->macros[4]), &(c->curmac)); 00106 c->maxchannels = c->numchannels; 00107 if(c->maxchannels > 0) { 00108 c->alias = (char *) malloc(c->maxchannels * 6); 00109 c->channels = (char **) malloc(sizeof(char *) * c->maxchannels); 00110 00111 for(j = 0; j < c->numchannels; j++) { 00112 t = c->alias + j * 6; 00113 while ((in = fgetc(fp)) != ' ') 00114 *t++ = in; 00115 *t = 0; 00116 00117 fscanf(fp, "%[^\n]\n", buffer); 00118 00119 c->channels[j] = (char *) malloc(strlen(buffer) + 1); 00120 StringCopy(c->channels[j], buffer); 00121 } 00122 sort_com_aliases(c); 00123 } else { 00124 c->alias = NULL; 00125 c->channels = NULL; 00126 } 00127 if((Typeof(c->who) == TYPE_PLAYER) || (!God(Owner(c->who))) || 00128 ((!Going(c->who)))) 00129 add_commac(c); 00130 purge_commac(); 00131 } 00132 }
void load_comsys_and_macros | ( | char * | filename | ) |
Definition at line 23 of file commac.c.
References commac_table, load_commac(), load_comsystem(), load_macros(), and NUM_COMMAC.
Referenced by load_game().
00024 { 00025 FILE *fp; 00026 int i; 00027 char buffer[200]; 00028 00029 for(i = 0; i < NUM_COMMAC; i++) 00030 commac_table[i] = NULL; 00031 00032 if(!(fp = fopen(filename, "r"))) { 00033 fprintf(stderr, "Error: Couldn't find %s.\n", filename); 00034 } else { 00035 fprintf(stderr, "LOADING: %s\n", filename); 00036 if(fscanf(fp, "*** Begin %s ***\n", buffer) == 1 && 00037 !strcmp(buffer, "COMMAC")) { 00038 load_commac(fp); 00039 } else { 00040 fprintf(stderr, "Error: Couldn't find Begin COMMAC in %s.", 00041 filename); 00042 return; 00043 } 00044 00045 if(fscanf(fp, "*** Begin %s ***\n", buffer) == 1 && 00046 !strcmp(buffer, "COMSYS")) { 00047 load_comsystem(fp); 00048 } else { 00049 fprintf(stderr, "Error: Couldn't find Begin COMSYS in %s.", 00050 filename); 00051 return; 00052 } 00053 00054 if(fscanf(fp, "*** Begin %s ***\n", buffer) == 1 && 00055 !strcmp(buffer, "MACRO")) { 00056 load_macros(fp); 00057 } else { 00058 fprintf(stderr, "Error: Couldn't find Begin MACRO in %s.", 00059 filename); 00060 return; 00061 } 00062 00063 fclose(fp); 00064 fprintf(stderr, "LOADING: %s (done)\n", filename); 00065 } 00066 }
void load_comsystem | ( | FILE * | ) |
Definition at line 93 of file comsys.c.
Referenced by load_comsys_and_macros().
00094 { 00095 int i, j, k, dummy; 00096 int nc, new = 0; 00097 struct channel *ch; 00098 struct comuser *user; 00099 char temp[LBUF_SIZE]; 00100 char buf[8]; 00101 00102 num_channels = 0; 00103 00104 fgets(buf, sizeof(buf), fp); 00105 if(!strncmp(buf, "+V2", 3)) { 00106 new = 2; 00107 fscanf(fp, "%d\n", &nc); 00108 } else if(!strncmp(buf, "+V1", 3)) { 00109 new = 1; 00110 fscanf(fp, "%d\n", &nc); 00111 } else 00112 nc = atoi(buf); 00113 00114 num_channels = nc; 00115 00116 for(i = 0; i < nc; i++) { 00117 ch = (struct channel *) malloc(sizeof(struct channel)); 00118 00119 fscanf(fp, "%[^\n]\n", temp); 00120 00121 strncpy(ch->name, temp, CHAN_NAME_LEN); 00122 ch->name[CHAN_NAME_LEN - 1] = '\0'; 00123 ch->on_users = NULL; 00124 00125 hashadd(ch->name, (int *) ch, &mudstate.channel_htab); 00126 00127 ch->last_messages = NULL; 00128 00129 if(new) { /* V1 or higher */ 00130 00131 if(fscanf(fp, 00132 new == 00133 1 ? "%d %d %d %d %d %d %d %d\n" : 00134 "%d %d %d %d %d %d %d %d %d\n", &(ch->type), 00135 &(ch->temp1), &(ch->temp2), &(ch->charge), 00136 &(ch->charge_who), &(ch->amount_col), 00137 &(ch->num_messages), &(ch->chan_obj), &dummy) >= 9 && 00138 new > 1) { 00139 /* Do things with 'dummy' */ 00140 if(dummy > 0) { 00141 for(j = 0; j < dummy; j++) { 00142 chmsg *c; 00143 00144 fscanf(fp, "%d %[^\n]\n", &k, temp); 00145 Create(c, chmsg, 1); 00146 c->msg = strdup(temp); 00147 c->time = k; 00148 myfifo_push(&ch->last_messages, c); 00149 } 00150 } 00151 } 00152 } else { 00153 fscanf(fp, "%d %d %d %d %d %d %d %d %d %d\n", &(ch->type), 00154 &(dummy), &(ch->temp1), &(ch->temp2), &(dummy), 00155 &(ch->charge), &(ch->charge_who), &(ch->amount_col), 00156 &(ch->num_messages), &(ch->chan_obj)); 00157 } 00158 00159 fscanf(fp, "%d\n", &(ch->num_users)); 00160 ch->max_users = ch->num_users; 00161 if(ch->num_users > 0) { 00162 ch->users = (struct comuser **) 00163 calloc(ch->max_users, sizeof(struct comuser *)); 00164 00165 for(j = 0; j < ch->num_users; j++) { 00166 user = (struct comuser *) malloc(sizeof(struct comuser)); 00167 00168 ch->users[j] = user; 00169 00170 if(new) { 00171 fscanf(fp, "%d %d\n", &(user->who), &(user->on)); 00172 } else { 00173 fscanf(fp, "%d %d %d", &(user->who), &(dummy), &(dummy)); 00174 fscanf(fp, "%d\n", &(user->on)); 00175 } 00176 00177 fscanf(fp, "%[^\n]\n", temp); 00178 00179 user->title = strdup(temp + 2); 00180 00181 if(!(isPlayer(user->who)) && !(Going(user->who) && 00182 (God(Owner(user->who))))) { 00183 do_joinchannel(user->who, ch); 00184 user->on_next = ch->on_users; 00185 ch->on_users = user; 00186 } else { 00187 user->on_next = ch->on_users; 00188 ch->on_users = user; 00189 } 00190 } 00191 sort_users(ch); 00192 } else 00193 ch->users = NULL; 00194 } 00195 }
void load_macros | ( | FILE * | ) |
Definition at line 779 of file macro.c.
Referenced by load_comsys_and_macros().
00780 { 00781 int i, j; 00782 char *c; 00783 char *t; 00784 char buffer[LBUF_SIZE]; 00785 struct macros *m; 00786 00787 TST(fscanf(fp, "%d\n", &nummacros) != 1, "Error: Loading #macros\n"); 00788 maxmacros = nummacros; 00789 00790 if(maxmacros > 0) 00791 macros = 00792 (struct macros **) malloc(sizeof(struct macros *) * nummacros); 00793 else 00794 macros = NULL; 00795 00796 for(i = 0; i < nummacros; i++) { 00797 macros[i] = (struct macros *) malloc(sizeof(struct macros)); 00798 00799 m = macros[i]; 00800 00801 fgets(buffer, LBUF_SIZE, fp); 00802 TST(sscanf(buffer, "%d %d %d\n", &(m->player), &(m->nummacros), &j) 00803 != 3, tprintf("Reading macro set #%d\n", i)); 00804 m->status = j; 00805 00806 fgets(buffer, LBUF_SIZE, fp); 00807 if(*buffer) 00808 if(buffer[strlen(buffer) - 1] == '\n') 00809 buffer[strlen(buffer) - 1] = 0; 00810 00811 m->desc = (char *) malloc(strlen(buffer) - 1); 00812 StringCopy(m->desc, buffer + 2); 00813 00814 m->maxmacros = m->nummacros; 00815 if(m->nummacros > 0) { 00816 m->alias = (char *) malloc(5 * m->maxmacros); 00817 m->string = (char **) malloc(sizeof(char *) * m->nummacros); 00818 00819 for(j = 0; j < m->nummacros; j++) { 00820 t = m->alias + j * 5; 00821 fgets(buffer, LBUF_SIZE, fp); 00822 if(buffer[strlen(buffer) - 1] == '\n') 00823 buffer[strlen(buffer) - 1] = 0; 00824 for(c = buffer; *c && *c != ' '; c++); 00825 *c = 0; 00826 if(strlen(buffer) > 4) { 00827 fprintf(stderr, "Error reading macro set #%d!\n", i); 00828 exit(1); 00829 } 00830 if(!*buffer) { 00831 00832 /* fprintf(stderr, "Error in macro set #%d (macro %d) : Invalid macro name.\n", i, j); */ 00833 t[0] = 0; 00834 } else 00835 strcpy(t, buffer); 00836 c++; 00837 m->string[j] = (char *) malloc(strlen(c) + 1); 00838 StringCopy(m->string[j], c); 00839 } 00840 do_sort_macro_set(m); 00841 } else { 00842 m->alias = NULL; 00843 m->string = NULL; 00844 } 00845 } 00846 while (1) { 00847 for(i = 0; i < nummacros; i++) 00848 if(!isPlayer(macros[i]->player)) 00849 break; 00850 if(i >= nummacros) 00851 break; 00852 clear_macro_set(i); 00853 } 00854 }
void purge_commac | ( | void | ) |
Definition at line 134 of file commac.c.
References c, commac_table, commac::curmac, del_commac(), God, Going, commac::macros, commac::next, NUM_COMMAC, commac::numchannels, Owner, TYPE_PLAYER, Typeof, and commac::who.
Referenced by load_commac(), mmdb_db_read(), mmdb_db_write(), and save_commac().
00135 { 00136 struct commac *c; 00137 struct commac *d; 00138 int i; 00139 00140 #ifdef ABORT_PURGE_COMSYS 00141 return; 00142 #endif /* 00143 * * ABORT_PURGE_COMSYS 00144 */ 00145 00146 for(i = 0; i < NUM_COMMAC; i++) { 00147 c = commac_table[i]; 00148 while (c) { 00149 d = c; 00150 c = c->next; 00151 if(d->numchannels == 0 && d->curmac == -1 && 00152 d->macros[1] == -1 && d->macros[2] == -1 && 00153 d->macros[3] == -1 && d->macros[4] == -1 && 00154 d->macros[0] == -1) { 00155 del_commac(d->who); 00156 continue; 00157 } 00158 00159 /* 00160 * if ((Typeof(d->who) != TYPE_PLAYER) && (God(Owner(d->who))) && 00161 * * (Going(d->who))) 00162 */ 00163 if(Typeof(d->who) == TYPE_PLAYER) 00164 continue; 00165 if(God(Owner(d->who)) && Going(d->who)) { 00166 del_commac(d->who); 00167 continue; 00168 } 00169 } 00170 } 00171 }
void save_commac | ( | FILE * | fp | ) |
Definition at line 173 of file commac.c.
References c, commac_table, commac::next, NUM_COMMAC, commac::numchannels, and purge_commac().
Referenced by save_comsys_and_macros().
00174 { 00175 int np; 00176 struct commac *c; 00177 int i, j; 00178 00179 purge_commac(); 00180 np = 0; 00181 for(i = 0; i < NUM_COMMAC; i++) { 00182 c = commac_table[i]; 00183 while (c) { 00184 np++; 00185 c = c->next; 00186 } 00187 } 00188 00189 fprintf(fp, "%d\n", np); 00190 for(i = 0; i < NUM_COMMAC; i++) { 00191 c = commac_table[i]; 00192 while (c) { 00193 fprintf(fp, "%d %d %d %d %d %d %d %d\n", c->who, 00194 c->numchannels, c->macros[0], c->macros[1], c->macros[2], 00195 c->macros[3], c->macros[4], c->curmac); 00196 for(j = 0; j < c->numchannels; j++) { 00197 fprintf(fp, "%s %s\n", c->alias + j * 6, c->channels[j]); 00198 } 00199 c = c->next; 00200 } 00201 } 00202 }
void save_comsys_and_macros | ( | char * | filename | ) |
Definition at line 68 of file commac.c.
References save_commac(), save_comsystem(), and save_macros().
Referenced by dump_database_internal().
00069 { 00070 FILE *fp; 00071 char buffer[500]; 00072 00073 sprintf(buffer, "%s.#", filename); 00074 if(!(fp = fopen(buffer, "w"))) { 00075 fprintf(stderr, "Unable to open %s for writing.\n", buffer); 00076 return; 00077 } 00078 fprintf(fp, "*** Begin COMMAC ***\n"); 00079 save_commac(fp); 00080 00081 fprintf(fp, "*** Begin COMSYS ***\n"); 00082 save_comsystem(fp); 00083 00084 fprintf(fp, "*** Begin MACRO ***\n"); 00085 save_macros(fp); 00086 00087 fclose(fp); 00088 rename(buffer, filename); 00089 }
void save_comsystem | ( | FILE * | ) |
Definition at line 204 of file comsys.c.
Referenced by save_comsys_and_macros().
00205 { 00206 struct channel *ch; 00207 struct comuser *user; 00208 int j, k, player_users; 00209 00210 fprintf(fp, "+V2\n"); 00211 fprintf(fp, "%d\n", num_channels); 00212 for(ch = (struct channel *) hash_firstentry(&mudstate.channel_htab); 00213 ch; ch = (struct channel *) hash_nextentry(&mudstate.channel_htab)) { 00214 fprintf(fp, "%s\n", ch->name); 00215 k = myfifo_length(&ch->last_messages); 00216 /* 1 2 3 4 5 6 7 8 9 */ 00217 fprintf(fp, "%d %d %d %d %d %d %d %d %d\n", ch->type, ch->temp1, 00218 ch->temp2, ch->charge, ch->charge_who, ch->amount_col, 00219 ch->num_messages, ch->chan_obj, k); 00220 00221 if(k) { 00222 temp_file = fp; 00223 myfifo_trav_r(&ch->last_messages, do_save_com); 00224 } 00225 player_users = 0; 00226 for(j = 0; j < ch->num_users; j++) 00227 if(isPlayer(ch->users[j]->who) || isRobot(ch->users[j]->who)) 00228 player_users++; 00229 00230 fprintf(fp, "%d\n", player_users); 00231 for(j = 0; j < ch->num_users; j++) { 00232 user = ch->users[j]; 00233 if(!isPlayer(user->who) && !isRobot(user->who)) 00234 continue; 00235 fprintf(fp, "%d %d\n", user->who, user->on); 00236 if(strlen(user->title)) 00237 fprintf(fp, "t:%s\n", user->title); 00238 else 00239 fprintf(fp, "t:\n"); 00240 } 00241 } 00242 }
void save_macros | ( | FILE * | ) |
Definition at line 856 of file macro.c.
Referenced by save_comsys_and_macros().
00857 { 00858 int i, j; 00859 struct macros *m; 00860 00861 fprintf(fp, "%d\n", nummacros); 00862 00863 for(i = 0; i < nummacros; i++) { 00864 m = macros[i]; 00865 fprintf(fp, "%d %d %d\n", m->player, m->nummacros, (int) m->status); 00866 fprintf(fp, "D:%s\n", m->desc); 00867 for(j = 0; j < m->nummacros; j++) 00868 fprintf(fp, "%s %s\n", m->alias + j * 5, m->string[j]); 00869 } 00870 }
void sort_com_aliases | ( | struct commac * | c | ) |
Definition at line 296 of file commac.c.
References c, and StringCopy.
Referenced by load_commac(), and mmdb_db_read().
00297 { 00298 int i; 00299 int cont; 00300 char buffer[10]; 00301 char *s; 00302 00303 cont = 1; 00304 while (cont) { 00305 cont = 0; 00306 for(i = 0; i < c->numchannels - 1; i++) 00307 if(strcasecmp(c->alias + i * 6, c->alias + (i + 1) * 6) > 0) { 00308 StringCopy(buffer, c->alias + i * 6); 00309 StringCopy(c->alias + i * 6, c->alias + (i + 1) * 6); 00310 StringCopy(c->alias + (i + 1) * 6, buffer); 00311 s = c->channels[i]; 00312 c->channels[i] = c->channels[i + 1]; 00313 c->channels[i + 1] = s; 00314 cont = 1; 00315 } 00316 } 00317 }