#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <time.h> #include <errno.h> #include "kernel.h" #include <gdbm.h> #include "sflags.h" Boolean tst_doublebit (DoubleLongInt * f, int b) { if (b >= 64) return XTSTBIT((f->b3), (b - 64)); else if (b >= 32) return XTSTBIT((f->b2), (b - 32)); else return XTSTBIT(f->b1, b); } void clr_doublebit (DoubleLongInt * f, int b) { if (b >= 64) XCLRBIT((f->b3), (b-64)); else if (b >= 32) XCLRBIT((f->b2), (b-32)); else XCLRBIT(f->b1, b); } void set_doublebit (DoubleLongInt *f, int b) { if (b >= 64) XSETBIT ((f->b3), (b-64)); else if (b >= 32) XSETBIT ((f->b2), (b-32)); else XSETBIT (f->b1, b); } int main(void) { PERSONA p; GDBM_FILE dbf; FILE *df; datum key; datum data; int count = 0,i; char line[1024]; if ((df = fopen("users_dump","r")) != NULL) { dbf = gdbm_open("users_data",1024,GDBM_WRCREAT,S_IRUSR|S_IWUSR,0); if (dbf != NULL) { while (!feof(df)) { fgets(line,1024,df); sscanf(line,"%s", p.p_idname); fgets(line,1024,df); sscanf(line,"%s ", p.p_name); fgets(line,1024,df); line[strlen(line)-1] = '\0'; strcpy(p.p_title,line); fgets(line,1024,df); sscanf(line,"%s ", p.p_email); fgets(line,1024,df); sscanf(line,"%s ", p.p_passwd); fgets(line,1024,df); sscanf(line,"%s ", p.p_prompt); if (strcmp(p.p_prompt,"&+MEW&+W>&*") == 0) strcpy(p.p_prompt,DEFAULT_PROMPT); fgets(line,1024,df); sscanf(line,"%s ",p.p_lasthost); fscanf(df,"%*d %d %d %d %d %d %d %d %d ", &p.p_score, &p.p_strength, &p.p_damage, &p.p_armor, &p.p_vlevel, &p.p_level, &p.p_wimpy, &p.p_pager); fscanf(df,"0x%08lx:0x%08lx:0x%08lx ", &p.p_sflags.b1, &p.p_sflags.b2, &p.p_sflags.b3); if (tst_doublebit(&p.p_sflags,42)) { clr_doublebit(&p.p_sflags,42); set_doublebit(&p.p_sflags,SFL_NOABERCHAT); } fscanf(df,"0x%08lx:0x%08lx:0x%08lx ", &p.p_pflags.b1, &p.p_pflags.b2, &p.p_pflags.b3); fscanf(df,"0x%08lx:0x%08lx:0x%08lx ", &p.p_mask.b1, &p.p_mask.b2, &p.p_mask.b3); fscanf(df,"0x%08lx:0x%08lx %ld %ld ", &p.p_quests.h, &p.p_quests.l, &p.p_last_on, &p.p_id); fscanf(df,"%d %d %d %d ", &p.p_killed, &p.p_died, &p.p_questpoints, &p.p_losses); printf("Converting %s[%s]<%d>\n",p.p_idname,p.p_name,p.p_level); key.dptr = p.p_idname; key.dsize = strlen(p.p_idname) + 1; data.dptr = (char *)&p; data.dsize = sizeof(PERSONA) + 1; for (i = 0; i < 8; i++) p.p_xflags.sect[i] = 0; switch (gdbm_store(dbf,key,data,GDBM_REPLACE)) { case 1: printf("GDBM: store(): caller is not the official writer\n"); break; case -1: printf("GDBM: store(): non-replaceable key.\n"); break; default: count++; } } printf("Total of %d players stored in database\n",count); gdbm_reorganize(dbf); gdbm_close(dbf); } else perror("GDBM: open()"); fclose(df); } else perror("FILE: open()"); return errno; }