diff --git a/src/doors/ny2008/src/fights.cpp b/src/doors/ny2008/src/fights.cpp index 521c6902d5189e96ae484e3ef2cd438a6cf696c7..5446e859036e022da98dd69384310892aed5ca74 100644 --- a/src/doors/ny2008/src/fights.cpp +++ b/src/doors/ny2008/src/fights.cpp @@ -544,19 +544,24 @@ void attack_ops(user_rec *user_on) { //readin the index ch_game_d(); justfile=ShareFileOpen(ENEMY_INDEX,"rb"); - fseek(justfile,(INT32)user_on->level*2,SEEK_SET); - ny_fread(&first,2,1,justfile); - fseek(justfile,(INT32)user_on->level*2 + 42,SEEK_SET); - ny_fread(&last,2,1,justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)user_on->level*2,SEEK_SET); + ny_fread(&first,2,1,justfile); + fseek(justfile,(INT32)user_on->level*2 + 42,SEEK_SET); + ny_fread(&last,2,1,justfile); - fclose(justfile); + fclose(justfile); + } intval=xp_random(last-first+1)+first; justfile=ShareFileOpen(ENEMY_FILENAME,"rb"); - fseek(justfile,(INT32)intval*sizeof(enemy),SEEK_SET); - ny_fread(&erec,sizeof(enemy),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)intval*sizeof(enemy),SEEK_SET); + ny_fread(&erec,sizeof(enemy),1,justfile); + fclose(justfile); + } + od_printf("\n\r\n"); @@ -835,8 +840,10 @@ fgc(INT16 *enm_num, INT16 *user_num) { sprintf(numstr,"u%07d.fgc",*user_num); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(enm_num,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(enm_num,2,1,justfile); + fclose(justfile); + } } } @@ -848,13 +855,16 @@ sfflg(INT16 user_num,char numstr[], INT16 enm_num, user_rec *erec) { sprintf(numstr,"u%07d.fgg",user_num); //set fight flag justfile = ShareFileOpen(numstr, "wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); //readin the enemy record sprintf(numstr,"u%07d.sts",enm_num); justfile=ShareFileOpen(numstr,"rb"); - ny_fread(erec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(erec,sizeof(user_rec),1,justfile); + fclose(justfile); + } } INT16 @@ -986,8 +996,10 @@ bam_ofm: sprintf(numstr,"u%07d.atk",*enm_num); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&hit_s,4,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&hit_s,4,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.atk",*enm_num); sprintf(numstr2,"u%07d.on",*enm_num); ny_line(222,2,1); @@ -1030,8 +1042,10 @@ bam_ofm: sprintf(numstr,"u%07d.sts",*enm_num); justfile=ShareFileOpen(numstr,"rb"); - ny_fread(erec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(erec,sizeof(user_rec),1,justfile); + fclose(justfile); + } intval -= erec->hitpoints; @@ -1054,9 +1068,11 @@ bam_ofm: sprintf(numstr,"u%07d.atk",*enm_num); justfile = ShareFileOpen(numstr, "wb"); - intval=-1; //user got away - ny_fwrite(&intval,4,1,justfile); - fclose(justfile); + if(justfile != NULL) { + intval=-1; //user got away + ny_fwrite(&intval,4,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.fgg",*user_num); ny_remove(numstr); if(!rip) @@ -1070,9 +1086,11 @@ bam_ofm: sprintf(numstr,"u%07d.atk",*enm_num); justfile = ShareFileOpen(numstr, "wb"); - intval=-2; ///user couldn't get away - ny_fwrite(&intval,4,1,justfile); - fclose(justfile); + if(justfile != NULL) { + intval=-2; ///user couldn't get away + ny_fwrite(&intval,4,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.atk",*enm_num); sprintf(numstr2,"u%07d.on",*enm_num); @@ -1170,8 +1188,10 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { //read atack file sprintf(numstr,"u%07d.atk",*user_num); justfile = ShareFileOpen(numstr, "rb"); - ny_fread(&en_hit_s,4,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&en_hit_s,4,1,justfile); + fclose(justfile); + } if (en_hit_s==-1) { @@ -1194,11 +1214,12 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { // od_printf("\n\r\n`bright red`Y`red`a `bright white`WON`red`!\n\r\n"); sprintf(numstr,"u%07d.atk",*user_num); justfile = ShareFileOpen(numstr, "rb"); + if(justfile != NULL) { + ny_fread(&en_hit_s,4,1,justfile); + ny_fread(&intval,4,1,justfile); - ny_fread(&en_hit_s,4,1,justfile); - ny_fread(&intval,4,1,justfile); - - fclose(justfile); + fclose(justfile); + } money_plus(intval); @@ -1246,18 +1267,22 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { if (fexist(numstr)) { sprintf(numstr,"u%07d.swp",*enm_num); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&(erec->arm),2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&(erec->arm),2,1,justfile); + fclose(justfile); + } } else { tarm=erec->arm; ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"r+b"); - fseek(justfile,*enm_num * sizeof(user_rec),SEEK_SET); - ny_fread(erec,sizeof(user_rec),1,justfile); - erec->arm=tarm; - fseek(justfile,*enm_num * sizeof(user_rec),SEEK_SET); - ny_fwrite(erec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,*enm_num * sizeof(user_rec),SEEK_SET); + ny_fread(erec,sizeof(user_rec),1,justfile); + erec->arm=tarm; + fseek(justfile,*enm_num * sizeof(user_rec),SEEK_SET); + ny_fwrite(erec,sizeof(user_rec),1,justfile); + fclose(justfile); + } ch_flag_d(); } @@ -1302,9 +1327,11 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { if (fexist(numstr)) { sprintf(numstr,"u%07d.kik",*enm_num); justfile=ShareFileOpen(numstr,"wb"); - rape=-1; - ny_fwrite(&rape,2,2,justfile); - fclose(justfile); + if(justfile != NULL) { + rape=-1; + ny_fwrite(&rape,2,2,justfile); + fclose(justfile); + } } // WaitForEnter(); } else { @@ -1312,9 +1339,11 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { if (fexist(numstr)) { sprintf(numstr,"u%07d.kik",*enm_num); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&user_on->std,2,1,justfile); - ny_fwrite(&user_on->std_percent,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&user_on->std,2,1,justfile); + ny_fwrite(&user_on->std_percent,2,1,justfile); + fclose(justfile); + } } else { strcpy(mail_idx.recver,erec->name); strcpy(mail_idx.sender,user_on->name); @@ -1330,8 +1359,10 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { mail_idx.sender_sex=user_on->sex; ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } ch_flag_d(); } user_on->since_got_laid=0; @@ -1356,9 +1387,11 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { if (fexist(numstr)) { sprintf(numstr,"u%07d.kik",*enm_num); justfile=ShareFileOpen(numstr,"wb"); - rape=-1; - ny_fwrite(&rape,2,2,justfile); - fclose(justfile); + if(justfile != NULL) { + rape=-1; + ny_fwrite(&rape,2,2,justfile); + fclose(justfile); + } } } } @@ -1399,11 +1432,13 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { ny_remove(numstr); sprintf(numstr,"u%07d.atk",*enm_num); justfile = ShareFileOpen(numstr, "wb"); - intval=-9; //user lost - ny_fwrite(&intval,4,1,justfile); - intval=user_on->money; //users money - ny_fwrite(&intval,4,1,justfile); - fclose(justfile); + if(justfile != NULL) { + intval=-9; //user lost + ny_fwrite(&intval,4,1,justfile); + intval=user_on->money; //users money + ny_fwrite(&intval,4,1,justfile); + fclose(justfile); + } od_printf("\n\r\n"); ny_send_menu(ASS_KICKED_O,""); @@ -1441,9 +1476,11 @@ o_checks(INT16 *enm_num,INT16 *user_num, user_rec *user_on, user_rec *erec) { INT16 inf; justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&ill,2,1,justfile); - ny_fread(&inf,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&ill,2,1,justfile); + ny_fread(&inf,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); //sprintf(numstr,"del u%07d.kik",*user_num); @@ -1516,8 +1553,10 @@ online_fight_a(INT16 *user_num, user_rec *user_on, INT16 enm_num) { sprintf(numstr,"u%07d.chl",enm_num); //set fight flag justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(user_num,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(user_num,2,1,justfile); + fclose(justfile); + } sprintf(numstr2,"u%07d.on",enm_num); ny_line(219,2,1); @@ -2834,15 +2873,17 @@ void p_attack_ops(user_rec *user_on,INT16 *nCurrentUserNumber) { do { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); - do { - ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); - od_kernal(); - } while ( ((unum++)==user_on->rank || - strzcmp(hand,ny_un_emu(urec.name,numstr)) || - urec.alive!=ALIVE) && - ret==1); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); + do { + ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); + od_kernal(); + } while ( ((unum++)==user_on->rank || + strzcmp(hand,ny_un_emu(urec.name,numstr)) || + urec.alive!=ALIVE) && + ret==1); + fclose(justfile); + } } while (ret==1 && askifuser(urec.name)==FALSE); } if (ret!=1) { @@ -2860,8 +2901,10 @@ void p_attack_ops(user_rec *user_on,INT16 *nCurrentUserNumber) { sprintf(numstr,"u%07d.fgg",urec.user_num); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.on",intval); if (fexist(numstr)) { @@ -2905,8 +2948,10 @@ void p_attack_ops(user_rec *user_on,INT16 *nCurrentUserNumber) { sprintf(numstr,"u%07d.bfa",urec.user_num); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.on",intval); if (fexist(numstr)) { @@ -2942,21 +2987,27 @@ void p_attack_ops(user_rec *user_on,INT16 *nCurrentUserNumber) { sprintf(numstr,"u%07d.bfo",*nCurrentUserNumber); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&urec.user_num,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&urec.user_num,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.bfa",urec.user_num); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(nCurrentUserNumber,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(nCurrentUserNumber,2,1,justfile); + fclose(justfile); + } } //readin the enemy record ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,(INT32)urec.user_num * sizeof(user_rec),SEEK_SET); - ny_fread(&erec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)urec.user_num * sizeof(user_rec),SEEK_SET); + ny_fread(&erec,sizeof(user_rec),1,justfile); + fclose(justfile); + } // WaitForEnter(); @@ -3512,8 +3563,10 @@ attack_again_p: if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&urec.user_num,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&urec.user_num,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); @@ -3532,24 +3585,30 @@ attack_again_p: ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,(INT32)urec.user_num*sizeof(user_rec),SEEK_SET); - ny_fread(&serec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)urec.user_num*sizeof(user_rec),SEEK_SET); + ny_fread(&serec,sizeof(user_rec),1,justfile); + fclose(justfile); + } scr_file=ShareFileOpen(SCR_FILENAME,"r+b"); - fseek(scr_file, (INT32)serec.rank * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&urec, sizeof(scr_rec), 1, scr_file); - fclose(scr_file); + if(justfile != NULL) { + fseek(scr_file, (INT32)serec.rank * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&urec, sizeof(scr_rec), 1, scr_file); + fclose(scr_file); + } erec.rank=serec.rank; justfile=ShareFileOpen(USER_FILENAME,"r+b"); - fseek(justfile,(INT32)urec.user_num*sizeof(user_rec),SEEK_SET); - ny_fwrite(&erec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)urec.user_num*sizeof(user_rec),SEEK_SET); + ny_fwrite(&erec,sizeof(user_rec),1,justfile); + fclose(justfile); + } // @@ -3571,8 +3630,10 @@ attack_again_p: ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } @@ -3610,8 +3671,10 @@ attack_again_p: mail_idx.sender_sex=user_on->sex; ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } user_on->sex_today--; user_on->since_got_laid=0; ny_line(339,1,0); @@ -4935,6 +4998,8 @@ ny_send_file(char filename[]) { char *keyp; phile=ShareFileOpen(filename,"rb"); + if(phile=NULL) + return; cnt=2; @@ -4993,6 +5058,8 @@ ny_get_index(void) { else phile=ShareFileOpen("menusc.dat","rb"); } + if(phile==NULL) + return; while (fgets(line,120,phile)!=NULL) { sscanf(line,"%s",numstr); @@ -5131,6 +5198,8 @@ ny_send_menu(menu_t menu,char allowed[],INT16 onscreen) { else phile=ShareFileOpen("menusc.dat","rb"); } + if(phile==0) + return(0); fseek(phile,menu_index[(INT16)menu],SEEK_SET); @@ -5231,6 +5300,8 @@ ny_stat_line(INT16 line,INT16 before,INT16 after) { else phile=ShareFileOpen("linesc.dat","rb"); } + if(phile==NULL) + return; ny_read_stat_line(38,string,phile); lines[0]=(char *)malloc(strlen(string)+1); strcpy(lines[0],string); @@ -5404,6 +5475,8 @@ ny_line(INT16 line,INT16 before,INT16 after) { phile=ShareFileOpen("linesc.dat","rb"); } + if(phile==NULL) + return; if(line == -1) { cnt2=1; diff --git a/src/doors/ny2008/src/igmsup.cpp b/src/doors/ny2008/src/igmsup.cpp index bf216c518b872857010e7745d416df124f1917c9..7a8b67773c19e236d780b6e4e91eeb448c23f24d 100644 --- a/src/doors/ny2008/src/igmsup.cpp +++ b/src/doors/ny2008/src/igmsup.cpp @@ -85,6 +85,8 @@ read_IGMs(void) { ch_flag_d(); sprintf(numstr,"mnu%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"wb"); + if(menuthing==NULL) + return; ch_game_d(); ok=0; @@ -175,6 +177,8 @@ read_fight_IGMs(void) { ch_flag_d(); sprintf(numstr,"fev%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"wb"); + if(menuthing==NULL) + return; ch_game_d(); ok=0; @@ -275,6 +279,8 @@ all_over_igm: ch_flag_d(); sprintf(numstr,"mnu%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"rb"); + if(menuthing==NULL) + return; if((where+(282*20))>=filelength(fileno(menuthing))) { maxnum=(filelength(fileno(menuthing))-where)/(INT32)282; } else { @@ -300,6 +306,8 @@ list_igm: ch_flag_d(); sprintf(numstr,"mnu%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"rb"); + if(menuthing==NULL) + return; ch_game_d(); if(found_file==FALSE) { @@ -418,6 +426,8 @@ list_igm: ch_flag_d(); sprintf(numstr,"mnu%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"rb"); + if(menuthing==NULL) + return; ch_game_d(); fseek(menuthing,where+((intval-1)*282)+31,SEEK_SET); @@ -447,6 +457,8 @@ forrest_IGM() { ch_flag_d(); sprintf(numstr,"fev%d.dat",od_control.od_node); menuthing=ShareFileOpen(numstr,"rb"); + if(menuthing==NULL) + return; maxnum=filelength(fileno(menuthing))/(INT32)282; intval=xp_random((INT16)maxnum); fseek(menuthing,intval*282,SEEK_SET); @@ -508,6 +520,8 @@ CreateDropFile(INT16 all) { else strcpy(numstr,TRDMAINT_LIST_FILENAME); justfile=ShareFileOpen(numstr,"w+t"); + if(justfile==NULL) + return; fprintf(justfile,"%s\n",od_control.info_path); fprintf(justfile,"%d\n",od_control.caller_timelimit); fprintf(justfile,"%d\n",od_control.port); @@ -539,109 +553,112 @@ CreateDropFile(INT16 all) { if(all==TRUE) { sprintf(numstr,"n%07d.sts",od_control.od_node); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); + fclose(justfile); + } sprintf(numstr,"n%07d.stt",od_control.od_node); justfile=ShareFileOpen(numstr,"wt"); + if(justfile != NULL) { + fprintf(justfile,"%s\n",cur_user.bbsname); //the BBS name of the user + fprintf(justfile,"%s\n",cur_user.name); //the name of the character + fprintf(justfile,"%s\n",cur_user.say_win); //what the user says when he wins + fprintf(justfile,"%s\n",cur_user.say_loose); // " " " " " " looses + fprintf(justfile,"%d\n",cur_user.rank); //user rank + fprintf(justfile,"%d\n",cur_user.days_not_on); //days the user has been inactive + fprintf(justfile,"%d\n",cur_user.strength); //attacking strenght of the user + fprintf(justfile,"%d\n",cur_user.defense); //defensive strenght + fprintf(justfile,"%d\n",cur_user.condoms); //condoms user has + fprintf(justfile,"%d\n",cur_user.since_got_laid); //days since the user last got laid + fprintf(justfile,"%d\n",cur_user.drug_hits); //the hist that the user has + fprintf(justfile,"%d\n",cur_user.drug_days_since); //if addicted how long the user + //has not used the drug + fprintf(justfile,"%ld\n",cur_user.hitpoints); //users hitpoints + fprintf(justfile,"%ld\n",cur_user.maxhitpoints); //maximum of the users hitpoints + fprintf(justfile,"%lu\n",cur_user.points); //users points + fprintf(justfile,"%lu\n",cur_user.money); //money in hand + fprintf(justfile,"%lu\n",cur_user.bank); //money in bank + fprintf(justfile,"%d\n",(INT16)cur_user.level); //user level + fprintf(justfile,"%d\n",(INT16)cur_user.turns); //fight the user has left today + fprintf(justfile,"%d\n",(INT16)cur_user.hunger); // % of hunger + fprintf(justfile,"%d\n",(INT16)cur_user.sex_today); //sex turns left today + fprintf(justfile,"%d\n",(INT16)cur_user.std_percent); // % of current std + fprintf(justfile,"%d\n",(INT16)cur_user.drug_addiction); // % of drug addiction + fprintf(justfile,"%d\n",(INT16)cur_user.drug_high); // % of how "high" the player is + fprintf(justfile,"%d\n",(INT16)cur_user.hotel_paid_fer); //for how many more days the hotel + //is paid for + fprintf(justfile,"%d\n",(INT16)cur_user.days_in_hospital);//how many days has the use been + //in hospital - fprintf(justfile,"%s\n",cur_user.bbsname); //the BBS name of the user - fprintf(justfile,"%s\n",cur_user.name); //the name of the character - fprintf(justfile,"%s\n",cur_user.say_win); //what the user says when he wins - fprintf(justfile,"%s\n",cur_user.say_loose); // " " " " " " looses - fprintf(justfile,"%d\n",cur_user.rank); //user rank - fprintf(justfile,"%d\n",cur_user.days_not_on); //days the user has been inactive - fprintf(justfile,"%d\n",cur_user.strength); //attacking strenght of the user - fprintf(justfile,"%d\n",cur_user.defense); //defensive strenght - fprintf(justfile,"%d\n",cur_user.condoms); //condoms user has - fprintf(justfile,"%d\n",cur_user.since_got_laid); //days since the user last got laid - fprintf(justfile,"%d\n",cur_user.drug_hits); //the hist that the user has - fprintf(justfile,"%d\n",cur_user.drug_days_since); //if addicted how long the user - //has not used the drug - fprintf(justfile,"%ld\n",cur_user.hitpoints); //users hitpoints - fprintf(justfile,"%ld\n",cur_user.maxhitpoints); //maximum of the users hitpoints - fprintf(justfile,"%lu\n",cur_user.points); //users points - fprintf(justfile,"%lu\n",cur_user.money); //money in hand - fprintf(justfile,"%lu\n",cur_user.bank); //money in bank - fprintf(justfile,"%d\n",(INT16)cur_user.level); //user level - fprintf(justfile,"%d\n",(INT16)cur_user.turns); //fight the user has left today - fprintf(justfile,"%d\n",(INT16)cur_user.hunger); // % of hunger - fprintf(justfile,"%d\n",(INT16)cur_user.sex_today); //sex turns left today - fprintf(justfile,"%d\n",(INT16)cur_user.std_percent); // % of current std - fprintf(justfile,"%d\n",(INT16)cur_user.drug_addiction); // % of drug addiction - fprintf(justfile,"%d\n",(INT16)cur_user.drug_high); // % of how "high" the player is - fprintf(justfile,"%d\n",(INT16)cur_user.hotel_paid_fer); //for how many more days the hotel - //is paid for - fprintf(justfile,"%d\n",(INT16)cur_user.days_in_hospital);//how many days has the use been - //in hospital - - if(cur_user.alive==ALIVE) - fprintf(justfile,"ALIVE\n"); - else - fprintf(justfile,"UNCONSIOUS\n"); - if(cur_user.sex==MALE) - fprintf(justfile,"M\n"); - else - fprintf(justfile,"F\n"); - - if(cur_user.nation==PUNK) - fprintf(justfile,"PUNK\n"); - else if(cur_user.nation==HEADBANGER) - fprintf(justfile,"HEADBANGER\n"); - else if(cur_user.nation==BIG_FAT_DUDE) - fprintf(justfile,"BIG FAT DUDE\n"); - else if(cur_user.nation==CRACK_ADDICT) - fprintf(justfile,"CRACK ADDICT\n"); - else - fprintf(justfile,"HIPPIE\n"); - fprintf(justfile,"%d\n",(INT16)cur_user.arm); - if(cur_user.std==CRAPS) - fprintf(justfile,"CRAPS\n"); - else if(cur_user.std==HERPES) - fprintf(justfile,"HERPES\n"); - else if(cur_user.std==SYPHILIS) - fprintf(justfile,"SYPHILIS\n"); - else if(cur_user.std==AIDS) - fprintf(justfile,"AIDS\n"); - else - fprintf(justfile,"NONE\n"); - - if(cur_user.drug==POT) - fprintf(justfile,"POT\n"); - else if(cur_user.drug==HASH) - fprintf(justfile,"HASH\n"); - else if(cur_user.drug==LSD) - fprintf(justfile,"LSD\n"); - else if(cur_user.drug==COKE) - fprintf(justfile,"COKE\n"); - else if(cur_user.drug==PCP) - fprintf(justfile,"PCP\n"); - else - fprintf(justfile,"HEROIN\n"); + if(cur_user.alive==ALIVE) + fprintf(justfile,"ALIVE\n"); + else + fprintf(justfile,"UNCONSIOUS\n"); + if(cur_user.sex==MALE) + fprintf(justfile,"M\n"); + else + fprintf(justfile,"F\n"); + + if(cur_user.nation==PUNK) + fprintf(justfile,"PUNK\n"); + else if(cur_user.nation==HEADBANGER) + fprintf(justfile,"HEADBANGER\n"); + else if(cur_user.nation==BIG_FAT_DUDE) + fprintf(justfile,"BIG FAT DUDE\n"); + else if(cur_user.nation==CRACK_ADDICT) + fprintf(justfile,"CRACK ADDICT\n"); + else + fprintf(justfile,"HIPPIE\n"); + fprintf(justfile,"%d\n",(INT16)cur_user.arm); + if(cur_user.std==CRAPS) + fprintf(justfile,"CRAPS\n"); + else if(cur_user.std==HERPES) + fprintf(justfile,"HERPES\n"); + else if(cur_user.std==SYPHILIS) + fprintf(justfile,"SYPHILIS\n"); + else if(cur_user.std==AIDS) + fprintf(justfile,"AIDS\n"); + else + fprintf(justfile,"NONE\n"); + + if(cur_user.drug==POT) + fprintf(justfile,"POT\n"); + else if(cur_user.drug==HASH) + fprintf(justfile,"HASH\n"); + else if(cur_user.drug==LSD) + fprintf(justfile,"LSD\n"); + else if(cur_user.drug==COKE) + fprintf(justfile,"COKE\n"); + else if(cur_user.drug==PCP) + fprintf(justfile,"PCP\n"); + else + fprintf(justfile,"HEROIN\n"); - if(cur_user.rest_where==NOWHERE) - fprintf(justfile,"NOWHERE\n"); - else if(cur_user.rest_where==MOTEL) - fprintf(justfile,"MOTEL\n"); - else if(cur_user.rest_where==REG_HOTEL) - fprintf(justfile,"REGULAR HOTEL\n"); - else - fprintf(justfile,"EXPENSIVE HOTEL\n"); + if(cur_user.rest_where==NOWHERE) + fprintf(justfile,"NOWHERE\n"); + else if(cur_user.rest_where==MOTEL) + fprintf(justfile,"MOTEL\n"); + else if(cur_user.rest_where==REG_HOTEL) + fprintf(justfile,"REGULAR HOTEL\n"); + else + fprintf(justfile,"EXPENSIVE HOTEL\n"); - fprintf(justfile,"%d\n",(INT16)cur_user.unhq); - fprintf(justfile,"%d\n",(INT16)cur_user.poison); - fprintf(justfile,"%d\n",(INT16)cur_user.rocks); - fprintf(justfile,"%d\n",(INT16)cur_user.throwing_ability); - fprintf(justfile,"%d\n",(INT16)cur_user.punch_ability); - fprintf(justfile,"%d\n",(INT16)cur_user.kick_ability); - fprintf(justfile,"%d\n",(INT16)cur_user.InterBBSMoves); + fprintf(justfile,"%d\n",(INT16)cur_user.unhq); + fprintf(justfile,"%d\n",(INT16)cur_user.poison); + fprintf(justfile,"%d\n",(INT16)cur_user.rocks); + fprintf(justfile,"%d\n",(INT16)cur_user.throwing_ability); + fprintf(justfile,"%d\n",(INT16)cur_user.punch_ability); + fprintf(justfile,"%d\n",(INT16)cur_user.kick_ability); + fprintf(justfile,"%d\n",(INT16)cur_user.InterBBSMoves); - /*reserved for future use 3 bytes reset to 0 - char res1; - INT16 res2;*/ + /*reserved for future use 3 bytes reset to 0 + char res1; + INT16 res2;*/ - fclose(justfile); + fclose(justfile); + } } } @@ -710,8 +727,10 @@ call_IGM(char exenam[]) { if(fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&cur_user,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&cur_user,sizeof(user_rec),1,justfile); + fclose(justfile); + } ny_remove(numstr); cur_user.rank=rankt; cur_user.days_not_on=inact; @@ -721,198 +740,199 @@ call_IGM(char exenam[]) { sprintf(numstr,"n%07d.stt",od_control.od_node); if(fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - - /* fgets(cur_user.bbsname,36,justfile); //the BBS name of the user - cur_user.bbsname[35]=0; - if((key=strchr(cur_user.bbsname,'\n'))!=NULL) - *key=0; - if((key=strchr(cur_user.bbsname,'\r'))!=NULL) - *key=0;*/ - - fgets(bbs_name,36,justfile); /*BBS name not read in no more*/ - - fgets(cur_user.name,25,justfile); //the BBS name of the user - cur_user.name[24]=0; - if((key=strchr(cur_user.name,'\n'))!=NULL) - *key=0; - if((key=strchr(cur_user.name,'\r'))!=NULL) - *key=0; - - - fgets(cur_user.say_win,41,justfile); //the BBS name of the user - cur_user.say_win[40]=0; - if((key=strchr(cur_user.say_win,'\n'))!=NULL) - *key=0; - if((key=strchr(cur_user.say_win,'\r'))!=NULL) - *key=0; - - - fgets(cur_user.say_loose,41,justfile); //the BBS name of the user - cur_user.say_loose[40]=0; - if((key=strchr(cur_user.say_loose,'\n'))!=NULL) - *key=0; - if((key=strchr(cur_user.say_loose,'\r'))!=NULL) - *key=0; - - - fgets(numstr,30,justfile); - //sscanf(numstr,"%d",&cur_user.rank); //user rank - fgets(numstr,30,justfile); - //sscanf(numstr,"%d",&cur_user.days_not_on); //days the user has been inactive - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.strength); //attacking strenght of the user - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.defense); //defensive strenght - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.condoms); //condoms user has - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.since_got_laid); //days since the user last got laid - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.drug_hits); //the hist that the user has - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&cur_user.drug_days_since); //if addicted how long the user - //has not used the drug - fgets(numstr,30,justfile); - sscanf(numstr,"%ld",&cur_user.hitpoints); //users hitpoints - fgets(numstr,30,justfile); - sscanf(numstr,"%ld",&cur_user.maxhitpoints); //maximum of the users hitpoints - fgets(numstr,30,justfile); - sscanf(numstr,"%lu",&cur_user.points); //users points - fgets(numstr,30,justfile); - sscanf(numstr,"%lu",&cur_user.money); //money in hand - fgets(numstr,30,justfile); - sscanf(numstr,"%lu",&cur_user.bank); //money in bank - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.level=intval; //user level - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.turns=intval; //fight the user has left today - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.hunger=intval; // % of hunger - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.sex_today=intval; //sex turns left today - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.std_percent=intval; // % of current std - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.drug_addiction=intval; // % of drug addiction - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.drug_high=intval; // % of how "high" the player is - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.hotel_paid_fer=intval; //for how many more days the hotel - //is paid for - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.days_in_hospital=intval;//how many days has the use been - //in hospital - - fgets(numstr,30,justfile); - if(strzcmp("ALIVE",numstr)==0) - cur_user.alive=ALIVE; - else if(strzcmp("DEAD",numstr)==0) - cur_user.alive=DEAD; - else if(strzcmp("UNCONSIOUS",numstr)==0) - cur_user.alive=UNCONCIOUS; - - - fgets(numstr,30,justfile); - if(strzcmp("M",numstr)==0) - cur_user.sex=MALE; - else if(strzcmp("F",numstr)==0) - cur_user.sex=FEMALE; - - - fgets(numstr,30,justfile); - if(strzcmp("PUNK",numstr)==0) - cur_user.nation=PUNK; - else if(strzcmp("HEADBANGER",numstr)==0) - cur_user.nation=HEADBANGER; - else if(strzcmp("BIG FAT DUDE",numstr)==0) - cur_user.nation=BIG_FAT_DUDE; - else if(strzcmp("CRACK ADDICT",numstr)==0) - cur_user.nation=CRACK_ADDICT; - else if(strzcmp("HIPPIE",numstr)==0) - cur_user.nation=HIPPIE; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.arm=(weapon)intval; - - - fgets(numstr,30,justfile); - if(strzcmp("CRAPS",numstr)==0) - cur_user.std=CRAPS; - else if(strzcmp("HERPES",numstr)==0) - cur_user.std=HERPES; - else if(strzcmp("SYPHILIS",numstr)==0) - cur_user.std=SYPHILIS; - else if(strzcmp("AIDS",numstr)==0) - cur_user.std=AIDS; - else if(strzcmp("NONE",numstr)==0) - cur_user.std=NONE; - - - fgets(numstr,30,justfile); - if(strzcmp("POT",numstr)==0) - cur_user.drug=POT; - else if(strzcmp("HASH",numstr)==0) - cur_user.drug=HASH; - else if(strzcmp("LSD",numstr)==0) - cur_user.drug=LSD; - else if(strzcmp("COKE",numstr)==0) - cur_user.drug=COKE; - else if(strzcmp("PCP",numstr)==0) - cur_user.drug=PCP; - else if(strzcmp("HEROIN",numstr)==0) - cur_user.drug=HEROIN; - - - - fgets(numstr,30,justfile); - if(strzcmp("MOTEL",numstr)==0) - cur_user.rest_where=MOTEL; - else if(strzcmp("REGULAR HOTEL",numstr)==0) - cur_user.rest_where=REG_HOTEL; - else if(strzcmp("EXPENSIVE HOTEL",numstr)==0) - cur_user.rest_where=EXP_HOTEL; - else if(strzcmp("NOWHERE",numstr)==0) - cur_user.rest_where=NOWHERE; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.unhq=intval; - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.poison=intval; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.rocks=intval; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.throwing_ability=intval; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.punch_ability=intval; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.kick_ability=intval; - - fgets(numstr,30,justfile); - sscanf(numstr,"%d",&intval); - cur_user.InterBBSMoves=intval; - - fclose(justfile); - + if(justfile != NULL) { + + /* fgets(cur_user.bbsname,36,justfile); //the BBS name of the user + cur_user.bbsname[35]=0; + if((key=strchr(cur_user.bbsname,'\n'))!=NULL) + *key=0; + if((key=strchr(cur_user.bbsname,'\r'))!=NULL) + *key=0;*/ + + fgets(bbs_name,36,justfile); /*BBS name not read in no more*/ + + fgets(cur_user.name,25,justfile); //the BBS name of the user + cur_user.name[24]=0; + if((key=strchr(cur_user.name,'\n'))!=NULL) + *key=0; + if((key=strchr(cur_user.name,'\r'))!=NULL) + *key=0; + + + fgets(cur_user.say_win,41,justfile); //the BBS name of the user + cur_user.say_win[40]=0; + if((key=strchr(cur_user.say_win,'\n'))!=NULL) + *key=0; + if((key=strchr(cur_user.say_win,'\r'))!=NULL) + *key=0; + + + fgets(cur_user.say_loose,41,justfile); //the BBS name of the user + cur_user.say_loose[40]=0; + if((key=strchr(cur_user.say_loose,'\n'))!=NULL) + *key=0; + if((key=strchr(cur_user.say_loose,'\r'))!=NULL) + *key=0; + + + fgets(numstr,30,justfile); + //sscanf(numstr,"%d",&cur_user.rank); //user rank + fgets(numstr,30,justfile); + //sscanf(numstr,"%d",&cur_user.days_not_on); //days the user has been inactive + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.strength); //attacking strenght of the user + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.defense); //defensive strenght + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.condoms); //condoms user has + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.since_got_laid); //days since the user last got laid + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.drug_hits); //the hist that the user has + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&cur_user.drug_days_since); //if addicted how long the user + //has not used the drug + fgets(numstr,30,justfile); + sscanf(numstr,"%ld",&cur_user.hitpoints); //users hitpoints + fgets(numstr,30,justfile); + sscanf(numstr,"%ld",&cur_user.maxhitpoints); //maximum of the users hitpoints + fgets(numstr,30,justfile); + sscanf(numstr,"%lu",&cur_user.points); //users points + fgets(numstr,30,justfile); + sscanf(numstr,"%lu",&cur_user.money); //money in hand + fgets(numstr,30,justfile); + sscanf(numstr,"%lu",&cur_user.bank); //money in bank + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.level=intval; //user level + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.turns=intval; //fight the user has left today + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.hunger=intval; // % of hunger + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.sex_today=intval; //sex turns left today + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.std_percent=intval; // % of current std + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.drug_addiction=intval; // % of drug addiction + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.drug_high=intval; // % of how "high" the player is + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.hotel_paid_fer=intval; //for how many more days the hotel + //is paid for + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.days_in_hospital=intval;//how many days has the use been + //in hospital + + fgets(numstr,30,justfile); + if(strzcmp("ALIVE",numstr)==0) + cur_user.alive=ALIVE; + else if(strzcmp("DEAD",numstr)==0) + cur_user.alive=DEAD; + else if(strzcmp("UNCONSIOUS",numstr)==0) + cur_user.alive=UNCONCIOUS; + + + fgets(numstr,30,justfile); + if(strzcmp("M",numstr)==0) + cur_user.sex=MALE; + else if(strzcmp("F",numstr)==0) + cur_user.sex=FEMALE; + + + fgets(numstr,30,justfile); + if(strzcmp("PUNK",numstr)==0) + cur_user.nation=PUNK; + else if(strzcmp("HEADBANGER",numstr)==0) + cur_user.nation=HEADBANGER; + else if(strzcmp("BIG FAT DUDE",numstr)==0) + cur_user.nation=BIG_FAT_DUDE; + else if(strzcmp("CRACK ADDICT",numstr)==0) + cur_user.nation=CRACK_ADDICT; + else if(strzcmp("HIPPIE",numstr)==0) + cur_user.nation=HIPPIE; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.arm=(weapon)intval; + + + fgets(numstr,30,justfile); + if(strzcmp("CRAPS",numstr)==0) + cur_user.std=CRAPS; + else if(strzcmp("HERPES",numstr)==0) + cur_user.std=HERPES; + else if(strzcmp("SYPHILIS",numstr)==0) + cur_user.std=SYPHILIS; + else if(strzcmp("AIDS",numstr)==0) + cur_user.std=AIDS; + else if(strzcmp("NONE",numstr)==0) + cur_user.std=NONE; + + + fgets(numstr,30,justfile); + if(strzcmp("POT",numstr)==0) + cur_user.drug=POT; + else if(strzcmp("HASH",numstr)==0) + cur_user.drug=HASH; + else if(strzcmp("LSD",numstr)==0) + cur_user.drug=LSD; + else if(strzcmp("COKE",numstr)==0) + cur_user.drug=COKE; + else if(strzcmp("PCP",numstr)==0) + cur_user.drug=PCP; + else if(strzcmp("HEROIN",numstr)==0) + cur_user.drug=HEROIN; + + + + fgets(numstr,30,justfile); + if(strzcmp("MOTEL",numstr)==0) + cur_user.rest_where=MOTEL; + else if(strzcmp("REGULAR HOTEL",numstr)==0) + cur_user.rest_where=REG_HOTEL; + else if(strzcmp("EXPENSIVE HOTEL",numstr)==0) + cur_user.rest_where=EXP_HOTEL; + else if(strzcmp("NOWHERE",numstr)==0) + cur_user.rest_where=NOWHERE; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.unhq=intval; + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.poison=intval; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.rocks=intval; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.throwing_ability=intval; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.punch_ability=intval; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.kick_ability=intval; + + fgets(numstr,30,justfile); + sscanf(numstr,"%d",&intval); + cur_user.InterBBSMoves=intval; + + fclose(justfile); + } sprintf(numstr,"n%07d.stt",od_control.od_node); ny_remove(numstr); } diff --git a/src/doors/ny2008/src/ny2008.cpp b/src/doors/ny2008/src/ny2008.cpp index 7266976f7f5a167fa649374a53679cca4542da2e..4e636bf4ea11ec6c5f807cd6e974fc912d316f2f 100644 --- a/src/doors/ny2008/src/ny2008.cpp +++ b/src/doors/ny2008/src/ny2008.cpp @@ -244,6 +244,9 @@ loadbadwords(void) { badwordscnt=0; fp=ShareFileOpenAR(BADWORDS_FILENAME,"rt"); + + if(fp==NULL) + return; INT32 len=filelength(fileno(fp)); @@ -618,12 +621,14 @@ main(int argc,char *argv[]) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d MAIL",ibbs_game_num); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"a+b"); - while(IBGetMail(&IBBSInfo,&ibmail) == eSuccess) { + if(justfile != NULL) { + while(IBGetMail(&IBBSInfo,&ibmail) == eSuccess) { - if(strcmp(ibmail.node_r,IBBSInfo.szThisNodeAddress)==0) - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + if(strcmp(ibmail.node_r,IBBSInfo.szThisNodeAddress)==0) + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + } + fclose(justfile); } - fclose(justfile); } } @@ -844,8 +849,10 @@ main(int argc,char *argv[]) { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"wb"); - ny_fwrite(&rec, sizeof(scr_rec), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&rec, sizeof(scr_rec), 1, justfile); + fclose(justfile); + } date today; @@ -853,14 +860,16 @@ main(int argc,char *argv[]) { ch_game_d(); justfile=ShareFileOpen(LASTMAINT_FILENAME,"wb"); - ny_fwrite(&today, sizeof(date), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&today, sizeof(date), 1, justfile); + fclose(justfile); + } justfile=ShareFileOpen(GAMEDAY_FILENAME,"wb"); - intval=1; - ny_fwrite(&intval,2,1,justfile); - fclose(justfile); - - + if(justfile != NULL) { + intval=1; + ny_fwrite(&intval,2,1,justfile); + fclose(justfile); + } } else { /*Run Maintanance if it hasn't been run yet...*/ if (do_maint==TRUE) { @@ -891,8 +900,10 @@ main(int argc,char *argv[]) { ch_game_d(); if (fexist(LASTMAINT_FILENAME)) { justfile = ShareFileOpen(LASTMAINT_FILENAME, "rb"); - ny_fread(&lastday, sizeof(date), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&lastday, sizeof(date), 1, justfile); + fclose(justfile); + } if (lastday.da_year!=today.da_year || lastday.da_mon!=today.da_mon || lastday.da_day!=today.da_day) { ch_flag_d(); sprintf(numstr,"u%07d.tdp",nCurrentUserNumber); @@ -902,20 +913,25 @@ main(int argc,char *argv[]) { getdate(&today); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&today,sizeof(date),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&today,sizeof(date),1,justfile); + fclose(justfile); + } } else { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&lastday,sizeof(date),1,justfile); - fclose(justfile); - + if(justfile != NULL) { + ny_fread(&lastday,sizeof(date),1,justfile); + fclose(justfile); + } getdate(&today); if (lastday.da_year!=today.da_year || lastday.da_mon!=today.da_mon || lastday.da_day!=today.da_day) { cur_user.days_not_on++; justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&today,sizeof(date),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&today,sizeof(date),1,justfile); + fclose(justfile); + } } } } @@ -930,20 +946,26 @@ main(int argc,char *argv[]) { getdate(&today); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&today,sizeof(date),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&today,sizeof(date),1,justfile); + fclose(justfile); + } } else { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&lastday,sizeof(date),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&lastday,sizeof(date),1,justfile); + fclose(justfile); + } getdate(&today); if (lastday.da_year!=today.da_year || lastday.da_mon!=today.da_mon || lastday.da_day!=today.da_day) { cur_user.days_not_on++; justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&today,sizeof(date),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&today,sizeof(date),1,justfile); + fclose(justfile); + } } } } @@ -958,8 +980,10 @@ main(int argc,char *argv[]) { sprintf(numstr, "u%07d.bfa",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.on",intval); if (fexist(numstr)) { ny_line(402,2,1); @@ -1108,8 +1132,10 @@ main(int argc,char *argv[]) { ch_flag_d(); sprintf(numstr,"u%07d.sts",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); + fclose(justfile); + } /*send message to all online users*/ if (glob("u???????.on",0,NULL,&ff)==0) { @@ -1121,16 +1147,19 @@ main(int argc,char *argv[]) { justfile=ShareFileOpen(numstr,"a+b"); numstr[0]=27; numstr[1]=10; - ny_fwrite(&numstr,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&numstr,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } } globfree(&ff); } /*User is now on-line!*/ sprintf(numstr,"u%07d.on",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "a+b"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); }/* else { justfile = ShareFileOpen("INUSE.FLG", "a+b"); @@ -1625,23 +1654,27 @@ ny_kernel(void) { sprintf(numstr,"u%07d.bfo",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&battled_user,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&battled_user,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); } sprintf(numstr,"u%07d.cng",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); - + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.fgg",nCurrentUserNumber); if (fexist(numstr)) { sprintf(numstr,"u%07d.fgg",intval); justfile = ShareFileOpen(numstr,"wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); sprintf(numstr,"u%07d.atk",nCurrentUserNumber); sprintf(numstr2,"u%07d.atk",intval); rename(numstr,numstr2); @@ -1657,33 +1690,40 @@ ny_kernel(void) { sprintf(numstr,"u%07d.fgc",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&intval,2,1,justfile); + fclose(justfile); + } nCurrentUserNumber=intval; /* tady se musi zmenit vsechnt flagy......*/ sprintf(numstr,"u%07d.sts",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); - fclose(justfile); - + if(justfile != NULL) { + ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.on",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "a+b"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } if(battled_user>=0) { sprintf(numstr,"u%07d.bfa",battled_user); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&nCurrentUserNumber,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&nCurrentUserNumber,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.bfo",nCurrentUserNumber); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&battled_user,2,1,justfile); - fclose(justfile); - + if(justfile != NULL) { + ny_fwrite(&battled_user,2,1,justfile); + fclose(justfile); + } } // user is in a battle with an offline user @@ -1692,8 +1732,10 @@ ny_kernel(void) { sprintf(numstr,"u%07d.rnk",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&cur_user.rank,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&cur_user.rank,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); // sprintf(numstr,"del u%07d.rnk",nCurrentUserNumber); // system(numstr); @@ -1748,69 +1790,71 @@ fig_ker(void) //waiting for user not in middle of calcs or whatever ny_line(7,2,1); // od_printf("\n\r\n\r`bright`You get a message!\n\r"); justfile=ShareFileOpen(numstr,"rb"); - do { - intval=ny_fread(&omg,51,1,justfile); - ny_fread(&nam,25,1,justfile); - - if(omg[0]==27 && intval==1 ) { - if(rip) { - ny_line(7,2,1); - od_get_answer("\n\r"); - } - if(omg[1]<10) { - type=1; + if(justfile != NULL) { + do { + intval=ny_fread(&omg,51,1,justfile); + ny_fread(&nam,25,1,justfile); - if(!rip) { - ny_disp_emu("`0"); - ny_disp_emu(nam); - } else { - ny_un_emu(nam); - od_printf("\n\r!|10000((%s",nam); + if(omg[0]==27 && intval==1 ) { + if(rip) { + ny_line(7,2,1); + od_get_answer("\n\r"); } + if(omg[1]<10) { + type=1; - ny_line(357 + omg[1],0,1); - if(rip) - od_get_answer("\n\r"); + if(!rip) { + ny_disp_emu("`0"); + ny_disp_emu(nam); + } else { + ny_un_emu(nam); + od_printf("\n\r!|10000((%s",nam); + } + ny_line(357 + omg[1],0,1); + if(rip) + od_get_answer("\n\r"); - } else { - type=2; - if(!rip) { - ny_disp_emu("`0"); - ny_disp_emu(nam); } else { - ny_un_emu(nam); - od_printf("\n\r!|10000((%s",nam); - } - ny_line(360 + omg[1]-10,0,1); - if(rip) - od_get_answer("\n\r"); - } - } else { + type=2; + if(!rip) { + ny_disp_emu("`0"); + ny_disp_emu(nam); + } else { + ny_un_emu(nam); + od_printf("\n\r!|10000((%s",nam); + } + ny_line(360 + omg[1]-10,0,1); + if(rip) + od_get_answer("\n\r"); - if (intval==1) { - if(rip) { - scr_save(); - od_disp_str("\n\r"); - od_send_file("texti.rip"); - ny_disp_emu("`%You get a message!\n\r"); } + } else { - ny_disp_emu("`0"); - ny_disp_emu(omg); - if (nam[0]!=0) { - ny_line(8,0,0); - // ny_disp_emu(" `9F`1rom: `@"); - ny_disp_emu(nam); - od_printf("\n\r"); + if (intval==1) { + if(rip) { + scr_save(); + od_disp_str("\n\r"); + od_send_file("texti.rip"); + ny_disp_emu("`%You get a message!\n\r"); + } + + ny_disp_emu("`0"); + ny_disp_emu(omg); + if (nam[0]!=0) { + ny_line(8,0,0); + // ny_disp_emu(" `9F`1rom: `@"); + ny_disp_emu(nam); + od_printf("\n\r"); + } } - } - } - } while (intval==1); - fclose(justfile); + } + } while (intval==1); + fclose(justfile); + } ny_remove(numstr); //sprintf(numstr,"del u%07d.omg",nCurrentUserNumber); //system(numstr); @@ -1841,8 +1885,10 @@ fig_ker(void) //waiting for user not in middle of calcs or whatever sprintf(numstr,"u%07d.chl",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } scr_save(); //try to store the screen online_fight(&nCurrentUserNumber,&cur_user,intval); scr_res(); //try to restore the screen @@ -1908,16 +1954,20 @@ wrt_sts(void) { sprintf(numstr,"u%07d.rnk",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&cur_user.rank,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&cur_user.rank,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); // sprintf(numstr,"del u%07d.rnk",nCurrentUserNumber); // system(numstr); } sprintf(numstr,"u%07d.sts",nCurrentUserNumber); justfile = ShareFileOpen(numstr, "w+b"); - ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&cur_user,sizeof(user_rec),1,justfile); + fclose(justfile); + } } else { ch_game_d(); WriteCurrentUser(); @@ -1937,9 +1987,11 @@ wrt_sts(void) { ch_game_d(); scr_file=ShareFileOpen(SCR_FILENAME,"r+b"); - fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec, sizeof(scr_rec), 1, scr_file); - fclose(scr_file); + if(justfile != NULL) { + fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec, sizeof(scr_rec), 1, scr_file); + fclose(scr_file); + } od_control.od_disable &=~ DIS_CARRIERDETECT; if(c_dir==1) @@ -2000,8 +2052,10 @@ exit_ops(void) { sprintf(numstr,"u%07d.bfo",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } sprintf(numstr,"u%07d.bfa",intval); ny_remove(numstr); } @@ -2009,8 +2063,10 @@ exit_ops(void) { sprintf(numstr,"u%07d.swp",nCurrentUserNumber); if (fexist(numstr)) { justfile=ShareFileOpen(numstr,"rb"); - ny_fread(&cur_user.arm,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&cur_user.arm,2,1,justfile); + fclose(justfile); + } ny_remove(numstr); } @@ -2036,9 +2092,11 @@ exit_ops(void) { justfile=ShareFileOpen(numstr,"a+b"); numstr[0]=27; numstr[1]=11; - ny_fwrite(&numstr,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&numstr,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } } globfree(&ff); } @@ -2055,9 +2113,11 @@ exit_ops(void) { /*disable online flag in the scr file*/ ch_game_d(); justfile = ShareFileOpen(SCR_FILENAME,"r+b"); - fseek(justfile, (INT32)cur_user.rank * sizeof(scr_rec),SEEK_SET); - ny_fwrite(&srec,sizeof(scr_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile, (INT32)cur_user.rank * sizeof(scr_rec),SEEK_SET); + ny_fwrite(&srec,sizeof(scr_rec),1,justfile); + fclose(justfile); + } /*create score files*/ if (do_scr_files==TRUE) { @@ -2114,25 +2174,28 @@ Maintanance(void) { ch_game_d(); if (fexist(LASTMAINT_FILENAME)) { fpUserFile = ShareFileOpen(LASTMAINT_FILENAME, "r+b"); - ny_fread(&lastday, sizeof(date), 1, fpUserFile); - if (lastday.da_year==today.da_year && lastday.da_mon==today.da_mon && lastday.da_day==today.da_day) { + if(justfile != NULL) { + ny_fread(&lastday, sizeof(date), 1, fpUserFile); + if (lastday.da_year==today.da_year && lastday.da_mon==today.da_mon && lastday.da_day==today.da_day) { + fclose(fpUserFile); + return; + } + + /* if (do_maint==FALSE) { + sprintf(numstr,"u%07d.nmt",nCurrentUserNumber); + if(!fexist(numstr)) + cur_user.days_not_on++; + fclose(fpUserFile); + return; + }*/ + ch_flag_d(); + justfile = ShareFileOpen(MAINTFLAG_FILENAME, "a+b"); + if(justfile != NULL) + fclose(justfile); + fseek(fpUserFile, (INT32)0, SEEK_SET); + ny_fwrite(&today, sizeof(date), 1, fpUserFile); fclose(fpUserFile); - return; } - - /* if (do_maint==FALSE) { - sprintf(numstr,"u%07d.nmt",nCurrentUserNumber); - if(!fexist(numstr)) - cur_user.days_not_on++; - fclose(fpUserFile); - return; - }*/ - ch_flag_d(); - justfile = ShareFileOpen(MAINTFLAG_FILENAME, "a+b"); - fclose(justfile); - fseek(fpUserFile, (INT32)0, SEEK_SET); - ny_fwrite(&today, sizeof(date), 1, fpUserFile); - fclose(fpUserFile); } else { /* if (do_maint==FALSE) { cur_user.days_not_on+=1; @@ -2140,36 +2203,46 @@ Maintanance(void) { }*/ ch_flag_d(); justfile = ShareFileOpen(MAINTFLAG_FILENAME, "wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); ch_game_d(); fpUserFile = ShareFileOpen(LASTMAINT_FILENAME, "wb"); - ny_fwrite(&today, sizeof(date), 1, fpUserFile); - fclose(fpUserFile); + if(fpUserFile != NULL) { + ny_fwrite(&today, sizeof(date), 1, fpUserFile); + fclose(fpUserFile); + } } } else { ch_flag_d(); justfile = ShareFileOpen(MAINTFLAG_FILENAME, "a+b"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); getdate(&today); ch_game_d(); fpUserFile = ShareFileOpen(LASTMAINT_FILENAME, "wb"); - ny_fwrite(&today, sizeof(date), 1, fpUserFile); - fclose(fpUserFile); + if(fpUserFile != NULL) { + ny_fwrite(&today, sizeof(date), 1, fpUserFile); + fclose(fpUserFile); + } } ch_game_d(); if (fexist(GAMEDAY_FILENAME)) { justfile=ShareFileOpen(GAMEDAY_FILENAME,"r+b"); - ny_fread(&intval,2,1,justfile); - intval++; - fseek(justfile,0,SEEK_SET); - ny_fwrite(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + intval++; + fseek(justfile,0,SEEK_SET); + ny_fwrite(&intval,2,1,justfile); + fclose(justfile); + } } else { ch_game_d(); justfile=ShareFileOpen(GAMEDAY_FILENAME,"wb"); - intval=1; - ny_fwrite(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + intval=1; + ny_fwrite(&intval,2,1,justfile); + fclose(justfile); + } } ny_line(13,0,1); @@ -2187,9 +2260,11 @@ Maintanance(void) { // ny_remove(TODNEWS_FILENAME); // } fpUserFile = ShareFileOpen(TODNEWS_FILENAME, "w+b"); - fclose(fpUserFile); + if(fpUserFile != NULL) + fclose(fpUserFile); fpUserFile = ShareFileOpen(YESNEWS_FILENAME, "a+b"); - fclose(fpUserFile); + if(fpUserFile != NULL) + fclose(fpUserFile); /* Begin with the current user record number set to 0. */ @@ -2218,103 +2293,113 @@ Maintanance(void) { /* Loop for each record in the file */ ny_line(14,0,1); // od_printf("### Packing and updating user file and creating scorefile\n\r"); - while(ny_fread(&urec, sizeof(user_rec), 1, justfile) == 1) { - if (((++urec.days_not_on)<=delete_after) && urec.alive!=DEAD) { - urec.rank=user_num_w; - - urec.bank *= 1.0+ (bank_interest/100.0); - - if (urec.alive==UNCONCIOUS && (urec.days_in_hospital++)>=2 ) { - urec.alive=ALIVE; - urec.hitpoints=urec.maxhitpoints; - urec.days_in_hospital=0; - od_printf("### %s kicked out of the hospital\n\r",ny_un_emu(urec.name,numstr)); - } - if (urec.rest_where!=NOWHERE) { - if (urec.hotel_paid_fer==0) { - urec.rest_where=NOWHERE; - od_printf("### %s was kicked out of the hotel\n\r",ny_un_emu(urec.name,numstr)); - } else { - urec.hotel_paid_fer--; + if(scr_file !=NULL && justfile != NULL && fpUserFile != NULL) { + while(scr_file != NULL && ny_fread(&urec, sizeof(user_rec), 1, justfile) == 1) { + if (((++urec.days_not_on)<=delete_after) && urec.alive!=DEAD) { + urec.rank=user_num_w; + + urec.bank *= 1.0+ (bank_interest/100.0); + + if (urec.alive==UNCONCIOUS && (urec.days_in_hospital++)>=2 ) { + urec.alive=ALIVE; + urec.hitpoints=urec.maxhitpoints; + urec.days_in_hospital=0; + od_printf("### %s kicked out of the hospital\n\r",ny_un_emu(urec.name,numstr)); } - } - fseek(fpUserFile, (INT32)user_num_w * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec, sizeof(user_rec), 1, fpUserFile); - //check if on-line - if (single_node==FALSE) { - ch_flag_d(); - sprintf(numstr, "u%07d.bfa",user_num); //user in a battle - if (fexist(numstr)) { - if (user_num!=user_num_w) { - njustfile = ShareFileOpen(numstr, "rb"); - ny_fread(&intval,2,1,njustfile); - fclose(njustfile); - ny_remove(numstr); - sprintf(numstr, "u%07d.bfo",intval); - njustfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&user_num_w,2,1,njustfile); - fclose(njustfile); - //sprintf(numstr, "del u%07d.bfa",user_num); - //system(numstr); //see above! + if (urec.rest_where!=NOWHERE) { + if (urec.hotel_paid_fer==0) { + urec.rest_where=NOWHERE; + od_printf("### %s was kicked out of the hotel\n\r",ny_un_emu(urec.name,numstr)); + } else { + urec.hotel_paid_fer--; } } - sprintf(numstr,"u%07d.on",user_num); - if (fexist(numstr)) { - scr_user.online=TRUE; - sprintf(numstr,"u%07d.sts",user_num); - njustfile = ShareFileOpen(numstr, "r+b"); - ny_fread(&urec,sizeof(user_rec),1,njustfile); - fclose(njustfile); - if (user_num!=user_num_w) { - ch_game_d(); - sprintf(numstr,"u%07d.inf",user_num); - if (fexist(numstr)) { + fseek(fpUserFile, (INT32)user_num_w * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec, sizeof(user_rec), 1, fpUserFile); + //check if on-line + if (single_node==FALSE) { + ch_flag_d(); + sprintf(numstr, "u%07d.bfa",user_num); //user in a battle + if (fexist(numstr)) { + if (user_num!=user_num_w) { + njustfile = ShareFileOpen(numstr, "rb"); + if(njustfile != NULL) { + ny_fread(&intval,2,1,njustfile); + fclose(njustfile); + } + ny_remove(numstr); + sprintf(numstr, "u%07d.bfo",intval); + if(njustfile != NULL) { + njustfile = ShareFileOpen(numstr, "wb"); + ny_fwrite(&user_num_w,2,1,njustfile); + fclose(njustfile); + } + //sprintf(numstr, "del u%07d.bfa",user_num); + //system(numstr); //see above! + } + } + sprintf(numstr,"u%07d.on",user_num); + if (fexist(numstr)) { + scr_user.online=TRUE; + sprintf(numstr,"u%07d.sts",user_num); + njustfile = ShareFileOpen(numstr, "r+b"); + if(njustfile != NULL) { + ny_fread(&urec,sizeof(user_rec),1,njustfile); + fclose(njustfile); + } + if (user_num!=user_num_w) { + ch_game_d(); sprintf(numstr,"u%07d.inf",user_num); - sprintf(numstr2,"u%07d.inf",user_num_w); - rename(numstr,numstr2); + if (fexist(numstr)) { + sprintf(numstr,"u%07d.inf",user_num); + sprintf(numstr2,"u%07d.inf",user_num_w); + rename(numstr,numstr2); + } + ch_flag_d(); + sprintf(numstr,"u%07d.cng",user_num); + njustfile = ShareFileOpen(numstr, "a+b"); + if(njustfile != NULL) { + ny_fwrite(&user_num_w,2,1,njustfile); + fclose(njustfile); + } } - ch_flag_d(); - sprintf(numstr,"u%07d.cng",user_num); - njustfile = ShareFileOpen(numstr, "a+b"); - ny_fwrite(&user_num_w,2,1,njustfile); - fclose(njustfile); + } else { + scr_user.online=FALSE; } } else { scr_user.online=FALSE; } - } else { - scr_user.online=FALSE; - } - strcpy(scr_user.name,urec.name); - scr_user.nation=urec.nation; - scr_user.level=urec.level; - scr_user.points=urec.points; - scr_user.alive=urec.alive; - scr_user.sex=urec.sex; - scr_user.user_num=user_num_w; + strcpy(scr_user.name,urec.name); + scr_user.nation=urec.nation; + scr_user.level=urec.level; + scr_user.points=urec.points; + scr_user.alive=urec.alive; + scr_user.sex=urec.sex; + scr_user.user_num=user_num_w; - ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); + ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); - user_num_w++; - } else { - od_printf("### Deleting (%s)\n\r",ny_un_emu(urec.name,numstr)); - ny_remove(SENTLIST_FILENAME); - /*ch_game_d(); - delfile=ShareFileOpen(DELUSER_FILENAME,"a+b"); - ny_fwrite(&urec.bbsname,36,1,delfile); - fclose(delfile);*/ - } + user_num_w++; + } else { + od_printf("### Deleting (%s)\n\r",ny_un_emu(urec.name,numstr)); + ny_remove(SENTLIST_FILENAME); + /*ch_game_d(); + delfile=ShareFileOpen(DELUSER_FILENAME,"a+b"); + ny_fwrite(&urec.bbsname,36,1,delfile); + fclose(delfile);*/ + } - /* Move user record number to next user record. */ - user_num++; + /* Move user record number to next user record. */ + user_num++; + } + fclose(fpUserFile); + fclose(justfile); + fclose(scr_file); } - fclose(fpUserFile); - fclose(justfile); - fclose(scr_file); ny_line(15,0,1); // od_printf("### User file done...\n\r"); ny_line(16,0,1); @@ -2343,23 +2428,25 @@ Maintanance(void) { fpUserFile=ShareFileOpen(USER_FILENAME,"rb"); ny_line(19,0,1); // od_printf("### Deleting messages for dead users...\n\r"); - while (ny_fread(&mail_idx,sizeof(mail_idx_type),1,justfile)==1) { - fseek(fpUserFile,(INT32)0,SEEK_SET); - mail_idx.deleted=TRUE; - while(ny_fread(&urec,sizeof(user_rec),1,fpUserFile)==1) { - if (strcmp(urec.bbsname,mail_idx.recverI)==0) { - mail_idx.deleted=FALSE; - break; + if(justfile != NULL && fpUserFile != NULL) { + while (ny_fread(&mail_idx,sizeof(mail_idx_type),1,justfile)==1) { + fseek(fpUserFile,(INT32)0,SEEK_SET); + mail_idx.deleted=TRUE; + while(ny_fread(&urec,sizeof(user_rec),1,fpUserFile)==1) { + if (strcmp(urec.bbsname,mail_idx.recverI)==0) { + mail_idx.deleted=FALSE; + break; + } } + if(mail_idx.deleted==TRUE) { + fseek(justfile,(INT32)cnt*sizeof(mail_idx_type),SEEK_SET); + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + } + cnt++; } - if(mail_idx.deleted==TRUE) { - fseek(justfile,(INT32)cnt*sizeof(mail_idx_type),SEEK_SET); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - } - cnt++; + fclose(justfile); + fclose(fpUserFile); } - fclose(justfile); - fclose(fpUserFile); //ny_remove(DELUSER_FILENAME); //} ch_game_d(); @@ -2378,33 +2465,35 @@ Maintanance(void) { // fileposw=0; ny_line(20,0,1); // od_printf("### Deleting read messages...\n\r"); - while (ny_fread(&mail_idx,sizeof(mail_idx_type),1,rdonly1)==1) { - if (mail_idx.deleted==FALSE) { - mail_idx.location=mlinew; - // fseek(justfile,fileposw,SEEK_SET); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - cnt=0; - - fseek(rdonly2,mliner*80,SEEK_SET); - while (cnt<mail_idx.length) { - ny_fread(&line,80,1,rdonly2); - // fseek(njustfile,mlinew,SEEK_SET); - ny_fwrite(&line,80,1,njustfile); - cnt++; - } - mlinew+=mail_idx.length; - // fileposw+=sizeof(mail_idx_type); - }// else { - // od_printf("."); - //} - mliner+=mail_idx.length; - // fileposr+=sizeof(mail_idx_type); - // fseek(justfile,fileposr,SEEK_SET); + if(rdonly1 != NULL && rdonly2 != NULL && justfile != NULL && njustfile != NULL) { + while (ny_fread(&mail_idx,sizeof(mail_idx_type),1,rdonly1)==1) { + if (mail_idx.deleted==FALSE) { + mail_idx.location=mlinew; + // fseek(justfile,fileposw,SEEK_SET); + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + cnt=0; + + fseek(rdonly2,mliner*80,SEEK_SET); + while (cnt<mail_idx.length) { + ny_fread(&line,80,1,rdonly2); + // fseek(njustfile,mlinew,SEEK_SET); + ny_fwrite(&line,80,1,njustfile); + cnt++; + } + mlinew+=mail_idx.length; + // fileposw+=sizeof(mail_idx_type); + }// else { + // od_printf("."); + //} + mliner+=mail_idx.length; + // fileposr+=sizeof(mail_idx_type); + // fseek(justfile,fileposr,SEEK_SET); + } + fclose(justfile); + fclose(njustfile); + fclose(rdonly1); + fclose(rdonly2); } - fclose(justfile); - fclose(njustfile); - fclose(rdonly1); - fclose(rdonly2); //od_printf("\n\r"); ny_line(21,0,1); // od_printf("### Mail file done...\n\r"); @@ -2426,23 +2515,25 @@ Maintanance(void) { fpUserFile=ShareFileOpen(USER_FILENAME,"rb"); ny_line(19,0,1); // od_printf("### Deleting messages for dead users...\n\r"); - while (ny_fread(&ibmail,sizeof(ibbs_mail_type),1,justfile)==1) { - fseek(fpUserFile,(INT32)0,SEEK_SET); - ibmail.deleted=TRUE; - while(ny_fread(&urec,sizeof(user_rec),1,fpUserFile)==1) { - if (strcmp(urec.bbsname,ibmail.recverI)==0) { - ibmail.deleted=FALSE; - break; + if(justfile != NULL && fpUserFile != NULL) { + while (ny_fread(&ibmail,sizeof(ibbs_mail_type),1,justfile)==1) { + fseek(fpUserFile,(INT32)0,SEEK_SET); + ibmail.deleted=TRUE; + while(ny_fread(&urec,sizeof(user_rec),1,fpUserFile)==1) { + if (strcmp(urec.bbsname,ibmail.recverI)==0) { + ibmail.deleted=FALSE; + break; + } } + if(ibmail.deleted==TRUE) { + fseek(justfile,(INT32)cnt*sizeof(ibbs_mail_type),SEEK_SET); + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + } + cnt++; } - if(ibmail.deleted==TRUE) { - fseek(justfile,(INT32)cnt*sizeof(ibbs_mail_type),SEEK_SET); - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - } - cnt++; + fclose(justfile); + fclose(fpUserFile); } - fclose(justfile); - fclose(fpUserFile); //ny_remove(DELUSER_FILENAME); //} ch_game_d(); @@ -2453,14 +2544,16 @@ Maintanance(void) { justfile=ShareFileOpen(IBBS_MAIL_INDEX,"wb"); ny_line(20,0,1); // od_printf("### Deleting read messages...\n\r"); - while (ny_fread(&ibmail,sizeof(ibbs_mail_type),1,rdonly1)==1) { - if (ibmail.deleted==FALSE) { + if(rdonly1 != NULL && justfile != NULL) { + while (ny_fread(&ibmail,sizeof(ibbs_mail_type),1,rdonly1)==1) { + if (ibmail.deleted==FALSE) { - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + } } + fclose(justfile); + fclose(rdonly1); } - fclose(justfile); - fclose(rdonly1); ny_line(21,0,1); // od_printf("### Mail file done...\n\r"); } @@ -2507,9 +2600,11 @@ ChangeOnlineRanks(void) { sscanf(numstr,"%d",&intval); ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,(INT32)intval*sizeof(user_rec),SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)intval*sizeof(user_rec),SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,justfile); + fclose(justfile); + } strcpy(numstr,*fname); numstr[9]='r'; numstr[10]='n'; @@ -2517,9 +2612,10 @@ ChangeOnlineRanks(void) { numstr[12]=0; ch_flag_d(); justfile=ShareFileOpen(numstr,"wb"); - ny_fwrite(&urec.rank,2,1,justfile); - fclose(justfile); - + if(justfile != NULL) { + ny_fwrite(&urec.rank,2,1,justfile); + fclose(justfile); + } } } } @@ -2571,47 +2667,51 @@ CrashRecovery(void) { ny_line(25,0,1); // od_printf("### Updating (no maintanance) user file and creating scorefile\n\r"); ch_flag_d(); - while(ny_fread(&urec, sizeof(user_rec), 1, bakfile) == 1 && user_num<=MAX_USERS) { - // ch_flag_d(); - sprintf(numstr, "u%07d.on",user_num); - if (fexist(numstr)) { - sprintf(numstr, "u%07d.sts",user_num); + if(scr_file != NULL && fpUserFile != NULL && bakfile != NULL) { + while(ny_fread(&urec, sizeof(user_rec), 1, bakfile) == 1 && user_num<=MAX_USERS) { + // ch_flag_d(); + sprintf(numstr, "u%07d.on",user_num); if (fexist(numstr)) { - justfile = ShareFileOpen(numstr, "rb"); - if(ny_fread(&urec, sizeof(user_rec), 1, justfile)!=1) { - fseek(bakfile, (INT32)user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec, sizeof(user_rec), 1, bakfile); + sprintf(numstr, "u%07d.sts",user_num); + if (fexist(numstr)) { + justfile = ShareFileOpen(numstr, "rb"); + if(justfile != NULL) { + if(ny_fread(&urec, sizeof(user_rec), 1, justfile)!=1) { + fseek(bakfile, (INT32)user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec, sizeof(user_rec), 1, bakfile); + } + fclose(justfile); + } } - fclose(justfile); } - } - sprintf(numstr, "u%07d.*",user_num); - if (fexist(numstr)) { - // ny_remove(numstr); sprintf(numstr, "u%07d.*",user_num); - ny_remove(numstr); + if (fexist(numstr)) { + // ny_remove(numstr); + sprintf(numstr, "u%07d.*",user_num); + ny_remove(numstr); + } + urec.rank=user_num; + // fseek(fpUserFile, (INT32)user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec, sizeof(user_rec), 1, fpUserFile); + + //offline records all + scr_user.online=FALSE; + strcpy(scr_user.name,urec.name); + scr_user.nation=urec.nation; + scr_user.level=urec.level; + scr_user.points=urec.points; + scr_user.alive=urec.alive; + scr_user.sex=urec.sex; + scr_user.user_num=user_num; + ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); + + /* Move user record number to next user record. */ + user_num++; } - urec.rank=user_num; - // fseek(fpUserFile, (INT32)user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec, sizeof(user_rec), 1, fpUserFile); - - //offline records all - scr_user.online=FALSE; - strcpy(scr_user.name,urec.name); - scr_user.nation=urec.nation; - scr_user.level=urec.level; - scr_user.points=urec.points; - scr_user.alive=urec.alive; - scr_user.sex=urec.sex; - scr_user.user_num=user_num; - ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); - - /* Move user record number to next user record. */ - user_num++; + fclose(fpUserFile); + fclose(scr_file); + fclose(bakfile); } - fclose(fpUserFile); - fclose(scr_file); - fclose(bakfile); ny_line(26,0,1); // od_printf("### User file done...\n\r"); ny_line(27,0,1); @@ -2645,73 +2745,188 @@ SortScrFile(INT16 usr,INT16 max) // pebble sorting of scorefile ch_game_d(); scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); - do { - cnt=1; - sorted=TRUE; + if(scr_file != NULL && fpUserFile != NULL) { + do { + cnt=1; + sorted=TRUE; - while (cnt<max) { - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[0], sizeof(scr_rec), 1, scr_file); + while (cnt<max) { + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[0], sizeof(scr_rec), 1, scr_file); - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - if (ny_fread(&rec[1], sizeof(scr_rec), 1, scr_file)!=1) { - /* This is terrible - ToDo */ -#ifndef ODPLAT_NIX - fcloseall(); -#endif + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + if (ny_fread(&rec[1], sizeof(scr_rec), 1, scr_file)!=1) { + /* This is terrible - ToDo */ + #ifndef ODPLAT_NIX + fcloseall(); + #endif - return; - } + return; + } - if (rec[0].points<rec[1].points) { // switch records + if (rec[0].points<rec[1].points) { // switch records - sorted=FALSE; // run another round - fseek(fpUserFile, (INT32)rec[0].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt; + sorted=FALSE; // run another round + fseek(fpUserFile, (INT32)rec[0].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt; - fseek(fpUserFile, (INT32)rec[0].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + fseek(fpUserFile, (INT32)rec[0].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - fseek(fpUserFile, (INT32)rec[1].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt-1; + fseek(fpUserFile, (INT32)rec[1].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt-1; - fseek(fpUserFile, (INT32)rec[1].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + fseek(fpUserFile, (INT32)rec[1].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - do - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); - while (ny_fwrite(&rec[1],sizeof(scr_rec),1,scr_file)!=1); + do + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + while (ny_fwrite(&rec[1],sizeof(scr_rec),1,scr_file)!=1); - do - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - while (ny_fwrite(&rec[0],sizeof(scr_rec),1,scr_file)!=1); + do + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + while (ny_fwrite(&rec[0],sizeof(scr_rec),1,scr_file)!=1); + } + cnt++; } - cnt++; - } - fseek(fpUserFile, (INT32)0, SEEK_SET); - fseek(scr_file, (INT32)0, SEEK_SET); - max--; - } while (sorted==FALSE); - fclose(scr_file); - fclose(fpUserFile); - + fseek(fpUserFile, (INT32)0, SEEK_SET); + fseek(scr_file, (INT32)0, SEEK_SET); + max--; + } while (sorted==FALSE); + fclose(scr_file); + fclose(fpUserFile); + } } else { // sort in a certain user either current or an offline user ch_game_d(); // if(no_kernel==TRUE) { scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); - /* } else { - no_kernel=TRUE; - scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); - fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); - no_kernel=FALSE; - }*/ + if(scr_file != NULL && fpUserFile != NULL) { + /* } else { + no_kernel=TRUE; + scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); + fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); + no_kernel=FALSE; + }*/ + + if (usr==nCurrentUserNumber) { + cnt=cur_user.rank; + } else { + fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); + ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); + cnt=urec.rank; + } + //od_printf("\n\r\n\r%d\n\r\n\r",cnt); + + crnt1=0; + crnt2=1; + + strcpy(rec[crnt1].name,cur_user.name); + rec[crnt1].nation=cur_user.nation; + rec[crnt1].level=cur_user.level; + rec[crnt1].points=cur_user.points; + rec[crnt1].alive=cur_user.alive; + rec[crnt1].sex=cur_user.sex; + rec[crnt1].user_num=nCurrentUserNumber; + rec[crnt1].online=TRUE; + + fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); + + if (cnt>0) { + ch_flag_d(); + do { + sorted=TRUE; + + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); + + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); + + if (rec[crnt1].points<rec[crnt2].points) { // switch records + + sorted=FALSE; // run another round + + sprintf(numstr,"u%07d.on",rec[crnt1].user_num); + if (single_node==FALSE && fexist(numstr)) { + sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + ny_fwrite(&cnt,2,1,njustfile); + fclose(njustfile); + } + } else { + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt; + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + } + + if (usr==nCurrentUserNumber) { + cur_user.rank=cnt-1; + } else { + sprintf(numstr,"u%07d.on",rec[crnt2].user_num); + if (single_node==FALSE && fexist(numstr)) { + sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + cnt--; + ny_fwrite(&cnt,2,1,njustfile); + cnt++; + fclose(njustfile); + } + } else { + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt-1; + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + } + } + + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); + + } + cnt--; + } while (sorted==FALSE && cnt>0); + } + + fclose(scr_file); + fclose(fpUserFile); + } + } +} + + + +void +SortScrFileB(INT16 usr) // pebble sorting of scorefile +{ + FILE *justfile; + FILE *scr_file; + FILE *fpUserFile; + FILE *njustfile; + INT16 crnt1,crnt2,cnt,sorted,cont; + scr_rec rec[2]; + user_rec urec; + char numstr[20]; + // ffblk ffblk; + // sort in a certain user either current or an offline user + ch_game_d(); + scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); + fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); + if(scr_file != NULL && fpUserFile != NULL) { if (usr==nCurrentUserNumber) { cnt=cur_user.rank; } else { @@ -2733,21 +2948,22 @@ SortScrFile(INT16 usr,INT16 max) // pebble sorting of scorefile rec[crnt1].user_num=nCurrentUserNumber; rec[crnt1].online=TRUE; + fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); + cont=filelength(fileno(scr_file))/sizeof(scr_rec); - if (cnt>0) { + if (cnt<(cont-1)) { ch_flag_d(); do { sorted=TRUE; - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); - - if (rec[crnt1].points<rec[crnt2].points) { // switch records + if (rec[crnt1].points>rec[crnt2].points) { // switch records sorted=FALSE; // run another round @@ -2755,8 +2971,10 @@ SortScrFile(INT16 usr,INT16 max) // pebble sorting of scorefile if (single_node==FALSE && fexist(numstr)) { sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); njustfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cnt,2,1,njustfile); - fclose(njustfile); + if(njustfile != NULL) { + ny_fwrite(&cnt,2,1,njustfile); + fclose(njustfile); + } } else { fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); ny_fread(&urec,sizeof(user_rec),1,fpUserFile); @@ -2766,35 +2984,36 @@ SortScrFile(INT16 usr,INT16 max) // pebble sorting of scorefile } if (usr==nCurrentUserNumber) { - cur_user.rank=cnt-1; + cur_user.rank=cnt+1; } else { sprintf(numstr,"u%07d.on",rec[crnt2].user_num); if (single_node==FALSE && fexist(numstr)) { sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); njustfile = ShareFileOpen(numstr, "wb"); - cnt--; - ny_fwrite(&cnt,2,1,njustfile); - cnt++; - fclose(njustfile); + if(njustfile != NULL) { + cnt++; + ny_fwrite(&cnt,2,1,njustfile); + cnt--; + fclose(njustfile); + } } else { fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt-1; + urec.rank=cnt+1; fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); } } - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); } - cnt--; - } while (sorted==FALSE && cnt>0); + cnt++; + } while (sorted==FALSE && cnt<(cont-1)); } - fclose(scr_file); fclose(fpUserFile); } @@ -2802,113 +3021,6 @@ SortScrFile(INT16 usr,INT16 max) // pebble sorting of scorefile -void -SortScrFileB(INT16 usr) // pebble sorting of scorefile -{ - FILE *justfile; - FILE *scr_file; - FILE *fpUserFile; - FILE *njustfile; - INT16 crnt1,crnt2,cnt,sorted,cont; - scr_rec rec[2]; - user_rec urec; - char numstr[20]; - // ffblk ffblk; - - // sort in a certain user either current or an offline user - ch_game_d(); - scr_file=ShareFileOpenAR(SCR_FILENAME,"r+b"); - fpUserFile=ShareFileOpenAR(USER_FILENAME,"r+b"); - if (usr==nCurrentUserNumber) { - cnt=cur_user.rank; - } else { - fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); - ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); - cnt=urec.rank; - } - //od_printf("\n\r\n\r%d\n\r\n\r",cnt); - - crnt1=0; - crnt2=1; - - strcpy(rec[crnt1].name,cur_user.name); - rec[crnt1].nation=cur_user.nation; - rec[crnt1].level=cur_user.level; - rec[crnt1].points=cur_user.points; - rec[crnt1].alive=cur_user.alive; - rec[crnt1].sex=cur_user.sex; - rec[crnt1].user_num=nCurrentUserNumber; - rec[crnt1].online=TRUE; - - - fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - cont=filelength(fileno(scr_file))/sizeof(scr_rec); - - if (cnt<(cont-1)) { - ch_flag_d(); - do { - sorted=TRUE; - - fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); - if (rec[crnt1].points>rec[crnt2].points) { // switch records - - sorted=FALSE; // run another round - - sprintf(numstr,"u%07d.on",rec[crnt1].user_num); - if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); - njustfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cnt,2,1,njustfile); - fclose(njustfile); - } else { - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt; - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - } - - if (usr==nCurrentUserNumber) { - cur_user.rank=cnt+1; - } else { - sprintf(numstr,"u%07d.on",rec[crnt2].user_num); - if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); - njustfile = ShareFileOpen(numstr, "wb"); - cnt++; - ny_fwrite(&cnt,2,1,njustfile); - cnt--; - fclose(njustfile); - } else { - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt+1; - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - } - } - - fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); - - } - cnt++; - } while (sorted==FALSE && cnt<(cont-1)); - } - fclose(scr_file); - fclose(fpUserFile); - -} - - - void change_info(void) { char key; @@ -3061,8 +3173,10 @@ char entry_menu(void) { ny_kernel(); ch_game_d(); justfile=ShareFileOpen(GAMEDAY_FILENAME,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } ny_line(34,0,0); // ny_disp_emu("`$T`6his game has been running for `0"); od_printf("%d",intval); @@ -3497,59 +3611,60 @@ MakeFiles(void) { ch_game_d(); ansi_file=ShareFileOpen(ansi_name,"w"); ascii_file=ShareFileOpen(ascii_name,"w"); - fprintf(ansi_file,"[0;1;32mP[0;32mlayer [1;32mL[0;32misting [1;32mF[0;32mor [1;31mN[0;31mew [1;31mY[0;31mork [1;31m2008\n\n"); - fprintf(ascii_file,"Player Listing For New York 2008\n\n"); - fprintf(ansi_file,"[0;32m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); - fprintf(ascii_file,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); - if ((scr_file=ShareFileOpen(SCR_FILENAME,"rb"))!=NULL) { - cnt=1; - fprintf(ansi_file,"[1;36mRank: Lvl: Name: Points: S: T:\n"); - fprintf(ascii_file,"Rank: Lvl: Name: Points: S: T:\n"); - while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { - fprintf(ansi_file,"[1;34m%-5d [1;32m%-2d [1;31m",cnt,user_scr.level); - fprintf(ascii_file,"%-5d %-2d ",cnt,user_scr.level); - ny_disp_emu_file(ansi_file,ascii_file,user_scr.name,25); - fprintf(ansi_file," [1;32m%-20s ",D_Num(user_scr.points)); - fprintf(ascii_file," %-20s ",D_Num(user_scr.points)); - if (user_scr.sex==MALE) { - fprintf(ansi_file,"[1;33mM "); - fprintf(ascii_file,"M "); - } else { - fprintf(ansi_file,"[1;33mF "); - fprintf(ascii_file,"F "); - } + if(ansi_file != NULL && ascii_file != NULL) { + fprintf(ansi_file,"[0;1;32mP[0;32mlayer [1;32mL[0;32misting [1;32mF[0;32mor [1;31mN[0;31mew [1;31mY[0;31mork [1;31m2008\n\n"); + fprintf(ascii_file,"Player Listing For New York 2008\n\n"); + fprintf(ansi_file,"[0;32m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); + fprintf(ascii_file,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"); + if ((scr_file=ShareFileOpen(SCR_FILENAME,"rb"))!=NULL) { + cnt=1; + fprintf(ansi_file,"[1;36mRank: Lvl: Name: Points: S: T:\n"); + fprintf(ascii_file,"Rank: Lvl: Name: Points: S: T:\n"); + while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { + fprintf(ansi_file,"[1;34m%-5d [1;32m%-2d [1;31m",cnt,user_scr.level); + fprintf(ascii_file,"%-5d %-2d ",cnt,user_scr.level); + ny_disp_emu_file(ansi_file,ascii_file,user_scr.name,25); + fprintf(ansi_file," [1;32m%-20s ",D_Num(user_scr.points)); + fprintf(ascii_file," %-20s ",D_Num(user_scr.points)); + if (user_scr.sex==MALE) { + fprintf(ansi_file,"[1;33mM "); + fprintf(ascii_file,"M "); + } else { + fprintf(ansi_file,"[1;33mF "); + fprintf(ascii_file,"F "); + } - switch(user_scr.nation) { - case HEADBANGER: - fprintf(ansi_file,"[1;34mHEADBANGER "); - fprintf(ascii_file,"HEADBANGER "); - break; - case HIPPIE: - fprintf(ansi_file,"[1;34mHIPPIE "); - fprintf(ascii_file,"HIPPIE "); - break; - case BIG_FAT_DUDE: - fprintf(ansi_file,"[1;34mBIG FAT DUDE "); - fprintf(ascii_file,"BIG FAT DUDE "); - break; - case CRACK_ADDICT: - fprintf(ansi_file,"[1;34mCRACK ADDICT "); - fprintf(ascii_file,"CRACK ADDICT "); - break; - case PUNK: - fprintf(ansi_file,"[1;34mPUNK "); - fprintf(ascii_file,"PUNK "); - break; - } + switch(user_scr.nation) { + case HEADBANGER: + fprintf(ansi_file,"[1;34mHEADBANGER "); + fprintf(ascii_file,"HEADBANGER "); + break; + case HIPPIE: + fprintf(ansi_file,"[1;34mHIPPIE "); + fprintf(ascii_file,"HIPPIE "); + break; + case BIG_FAT_DUDE: + fprintf(ansi_file,"[1;34mBIG FAT DUDE "); + fprintf(ascii_file,"BIG FAT DUDE "); + break; + case CRACK_ADDICT: + fprintf(ansi_file,"[1;34mCRACK ADDICT "); + fprintf(ascii_file,"CRACK ADDICT "); + break; + case PUNK: + fprintf(ansi_file,"[1;34mPUNK "); + fprintf(ascii_file,"PUNK "); + break; + } - fprintf(ansi_file,"\n"); - fprintf(ascii_file,"\n"); - cnt++; + fprintf(ansi_file,"\n"); + fprintf(ascii_file,"\n"); + cnt++; + } + fclose(scr_file); } - fclose(scr_file); fclose(ansi_file); fclose(ascii_file); - } } @@ -3618,12 +3733,12 @@ ListPlayers(void) { ch_game_d(); if ((scr_file=ShareFileOpen(SCR_FILENAME,"rb"))!=NULL) { //cnt=1; - while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { + while (scr_file != NULL && ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { PlInfo(&user_scr,cnt); cnt++; cnt2++; - if (nonstop==FALSE && cnt2%od_control.user_screen_length==0) { + if (scr_file != NULL && nonstop==FALSE && cnt2%od_control.user_screen_length==0) { filepos=ftell(scr_file); fclose(scr_file); @@ -3641,10 +3756,12 @@ ListPlayers(void) { //od_printf("\n\r"); scr_file=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(scr_file,filepos,SEEK_SET); + if(scr_file != NULL) + fseek(scr_file,filepos,SEEK_SET); } } - fclose(scr_file); + if(scr_file != NULL) + fclose(scr_file); if(rip) od_send_file("frame1.rip"); @@ -3679,12 +3796,12 @@ ListPlayersS(sex_type psex) { cnt=5; rnk=1; - while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { + while (scr_file != NULL && ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { if (user_scr.sex==psex) { PlInfo(&user_scr,cnt); cnt++; - if (nonstop==FALSE && cnt%od_control.user_screen_length==0) { + if (scr_file != NULL && nonstop==FALSE && cnt%od_control.user_screen_length==0) { filepos=ftell(scr_file); fclose(scr_file); @@ -3704,12 +3821,14 @@ ListPlayersS(sex_type psex) { //od_printf("\n\r"); scr_file=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(scr_file,filepos,SEEK_SET); + if(scr_file != NULL) + fseek(scr_file,filepos,SEEK_SET); } } rnk++; } - fclose(scr_file); + if(scr_file != NULL) + fclose(scr_file); if(rip) od_send_file("frame1.rip"); @@ -3745,14 +3864,14 @@ ListPlayersA() { if ((scr_file=ShareFileOpen(SCR_FILENAME,"rb"))!=NULL) { cnt=5; rnk=1; - while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { + while (scr_file != NULL && ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { if (user_scr.alive==ALIVE) { PlInfo(&user_scr,cnt); cnt++; - if (nonstop==FALSE && cnt%od_control.user_screen_length==0) { + if (scr_file != NULL && nonstop==FALSE && cnt%od_control.user_screen_length==0) { filepos=ftell(scr_file); fclose(scr_file); @@ -3771,12 +3890,14 @@ ListPlayersA() { //od_printf("\n\r\n\r"); scr_file=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(scr_file,filepos,SEEK_SET); + if(scr_file != NULL) + fseek(scr_file,filepos,SEEK_SET); } } rnk++; } - fclose(scr_file); + if(scr_file != NULL) + fclose(scr_file); if(rip) od_send_file("frame1.rip"); @@ -3820,7 +3941,7 @@ WhosOnline(void) { if ((scr_file=ShareFileOpen(SCR_FILENAME,"rb"))!=NULL) { cnt=5; rnk=1; - while (ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { + while (scr_file != NULL && ny_fread(&user_scr, sizeof(scr_rec), 1, scr_file) == 1) { if (user_scr.online==TRUE) { PlInfo(&user_scr,cnt); @@ -3844,12 +3965,14 @@ WhosOnline(void) { //od_printf("\n\r"); scr_file=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(scr_file,filepos,SEEK_SET); + if(scr_file != NULL) + fseek(scr_file,filepos,SEEK_SET); } } rnk++; } - fclose(scr_file); + if(scr_file != NULL) + fclose(scr_file); if(rip) od_send_file("frame1.rip"); @@ -4838,30 +4961,32 @@ DisplayBest(void) { ch_game_d(); if (fexist(BESTTEN_FILENAME)) { justfile=ShareFileOpen(BESTTEN_FILENAME,"rb"); - od_printf("\n\r\n\r"); - ny_clr_scr(); - if(rip) - od_send_file("frame.rip"); - if(rip) - od_send_file("frame1.rip"); - ny_send_menu(TEN_BEST,""); - cnt=1; - /* od_printf("\n\r`bright red`T`red`en `bright red`B`red`est ... `bright red`W`red`inners\n\r\n\r"); - od_printf("`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); - od_printf("`cyan`Rank: Name: Points:");*/ - while(ny_fread(&best_rec,sizeof(best_rec),1,justfile)==1) { - od_printf("`bright red`%-2d `bright green`",cnt); - ny_disp_emu(best_rec.name,25); - od_printf(" `bright red`%s\n\r",D_Num(best_rec.points)); - cnt++; - } - // od_printf("\n\r"); - ny_line(399,0,1); - //ny_send_menu(BLUE_LINE,""); - //od_printf("\n\r`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); - fclose(justfile); - ny_line(1,1,0); - // ny_disp_emu("\n\r`@Smack [ENTER] to go on."); + if(justfile != NULL) { + od_printf("\n\r\n\r"); + ny_clr_scr(); + if(rip) + od_send_file("frame.rip"); + if(rip) + od_send_file("frame1.rip"); + ny_send_menu(TEN_BEST,""); + cnt=1; + /* od_printf("\n\r`bright red`T`red`en `bright red`B`red`est ... `bright red`W`red`inners\n\r\n\r"); + od_printf("`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); + od_printf("`cyan`Rank: Name: Points:");*/ + while(ny_fread(&best_rec,sizeof(best_rec),1,justfile)==1) { + od_printf("`bright red`%-2d `bright green`",cnt); + ny_disp_emu(best_rec.name,25); + od_printf(" `bright red`%s\n\r",D_Num(best_rec.points)); + cnt++; + } + // od_printf("\n\r"); + ny_line(399,0,1); + //ny_send_menu(BLUE_LINE,""); + //od_printf("\n\r`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); + fclose(justfile); + } + ny_line(1,1,0); + // ny_disp_emu("\n\r`@Smack [ENTER] to go on."); od_get_answer("\n\r"); } } @@ -4876,33 +5001,35 @@ DisplayBestIB(void) { ch_game_d(); if (fexist(IBBS_BESTTEN_FILENAME)) { justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"rb"); - od_printf("\n\r\n\r"); - ny_clr_scr(); - if(rip) - od_send_file("frame.rip"); - if(rip) - od_send_file("frame1.rip"); - ny_send_menu(TEN_BEST_IBBS,""); - cnt=1; - /* od_printf("\n\r`bright red`T`red`en `bright red`B`red`est ... `bright red`W`red`inners\n\r\n\r"); - od_printf("`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); - od_printf("`cyan`Rank: Name: Points:");*/ - while(ny_fread(&best_rec,sizeof(best_rec),1,justfile)==1) { - //findmeagain - // od_printf("`bright red`%-2d `bright green`",cnt); - od_set_attrib(0x0a); - ny_disp_emu(best_rec.name,25); - od_printf(" `bright red`%-13s ",D_Num(best_rec.points)); - od_set_attrib(0x02); - ny_disp_emu(LocationOf(best_rec.location)); - od_disp_str("\n\r"); - cnt++; + if(justfile != NULL) { + od_printf("\n\r\n\r"); + ny_clr_scr(); + if(rip) + od_send_file("frame.rip"); + if(rip) + od_send_file("frame1.rip"); + ny_send_menu(TEN_BEST_IBBS,""); + cnt=1; + /* od_printf("\n\r`bright red`T`red`en `bright red`B`red`est ... `bright red`W`red`inners\n\r\n\r"); + od_printf("`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); + od_printf("`cyan`Rank: Name: Points:");*/ + while(ny_fread(&best_rec,sizeof(best_rec),1,justfile)==1) { + //findmeagain + // od_printf("`bright red`%-2d `bright green`",cnt); + od_set_attrib(0x0a); + ny_disp_emu(best_rec.name,25); + od_printf(" `bright red`%-13s ",D_Num(best_rec.points)); + od_set_attrib(0x02); + ny_disp_emu(LocationOf(best_rec.location)); + od_disp_str("\n\r"); + cnt++; + } + // od_printf("\n\r"); + ny_line(399,0,1); + //ny_send_menu(BLUE_LINE,""); + //od_printf("\n\r`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); + fclose(justfile); } - // od_printf("\n\r"); - ny_line(399,0,1); - //ny_send_menu(BLUE_LINE,""); - //od_printf("\n\r`bright blue`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\r"); - fclose(justfile); ny_line(1,1,0); // ny_disp_emu("\n\r`@Smack [ENTER] to go on."); od_get_answer("\n\r"); @@ -4926,11 +5053,13 @@ AddBestPlayer(void) { if (fexist(BESTTEN_FILENAME)) { justfile=ShareFileOpen(BESTTEN_FILENAME,"r+b"); - len_of_list=filelength(fileno(justfile))/sizeof(best_rec_type) +1; - if (len_of_list>10) - len_of_list=10; + if(justfile != NULL) { + len_of_list=filelength(fileno(justfile))/sizeof(best_rec_type) +1; + if (len_of_list>10) + len_of_list=10; + } - while (cnt<10 && ny_fread(&best_rec,sizeof(best_rec_type),1,justfile)==1) { + while (justfile != NULL && cnt<10 && ny_fread(&best_rec,sizeof(best_rec_type),1,justfile)==1) { if (cur_user.points>=best_rec.points) { //fseek(justfile,(INT32)cnt*sizeof(best_rec_type),SEEK_SET); //ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); @@ -4960,11 +5089,14 @@ AddBestPlayer(void) { } cnt++; } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); if (cnt<10) { justfile=ShareFileOpen(BESTTEN_FILENAME,"a+b"); - ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); + fclose(justfile); + } if(ibbs==FALSE) { ny_line(302,2,1); @@ -4988,8 +5120,10 @@ AddBestPlayer(void) { } } justfile=ShareFileOpen(BESTTEN_FILENAME,"wb"); - ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); + fclose(justfile); + } if(ibbs==FALSE) { ny_line(302,2,1); @@ -5020,12 +5154,14 @@ AddBestPlayerIB(void) { ch_game_d(); if (fexist(IBBS_BESTTEN_FILENAME)) { justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"r+b"); - len_of_list=filelength(fileno(justfile))/sizeof(ibbs_best_rec_type) +1; - if (len_of_list>10) - len_of_list=10; + if(justfile != NULL) { + len_of_list=filelength(fileno(justfile))/sizeof(ibbs_best_rec_type) +1; + if (len_of_list>10) + len_of_list=10; + } /*check if the same record exists*/ - while (cnt<10 && ny_fread(&best_rec,sizeof(ibbs_best_rec_type),1,justfile)==1) { + while (justfile != NULL && cnt<10 && ny_fread(&best_rec,sizeof(ibbs_best_rec_type),1,justfile)==1) { if (cur_user.points==best_rec.points && strcmp(best_rec.location,IBBSInfo.szThisNodeAddress)==0 && strcmp(best_rec.name,cur_user.name)==0) { @@ -5036,9 +5172,10 @@ AddBestPlayerIB(void) { } /*rewind the file to beginning*/ - fseek(justfile,0,SEEK_SET); + if(justfile != NULL) + fseek(justfile,0,SEEK_SET); - while (cnt<10 && ny_fread(&best_rec,sizeof(ibbs_best_rec_type),1,justfile)==1) { + while (justfile != NULL && cnt<10 && ny_fread(&best_rec,sizeof(ibbs_best_rec_type),1,justfile)==1) { if (cur_user.points>=best_rec.points) { //fseek(justfile,(INT32)cnt*sizeof(best_rec_type),SEEK_SET); //ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); @@ -5068,11 +5205,14 @@ AddBestPlayerIB(void) { } cnt++; } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); if (cnt<10) { justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"a+b"); - ny_fwrite(&best_rec2,sizeof(ibbs_best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(ibbs_best_rec_type),1,justfile); + fclose(justfile); + } ny_line(302,2,1); //od_printf("\n\r\n\r`bright red`Y`red`ou made the `bright`BEST`red` list.\n\r"); @@ -5092,8 +5232,10 @@ AddBestPlayerIB(void) { } } justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"wb"); - ny_fwrite(&best_rec2,sizeof(ibbs_best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(ibbs_best_rec_type),1,justfile); + fclose(justfile); + } ny_line(302,2,1); // od_printf("\n\r\n\r`bright red`Y`red`ou made the `bright`BEST`red` list.\n\r @@ -5122,13 +5264,13 @@ AddBestPlayerInIB(char *name,DWORD points) { ch_game_d(); if (fexist(IBBS_BESTTEN_FILENAME)) { justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"r+b"); - len_of_list=filelength(fileno(justfile))/sizeof(best_rec_type) +1; - if (len_of_list>10) - len_of_list=10; - - + if(justfile != NULL) { + len_of_list=filelength(fileno(justfile))/sizeof(best_rec_type) +1; + if (len_of_list>10) + len_of_list=10; + } - while (cnt<10 && ny_fread(&best_rec,sizeof(best_rec_type),1,justfile)==1) { + while (justfile != NULL && cnt<10 && ny_fread(&best_rec,sizeof(best_rec_type),1,justfile)==1) { if (points>=best_rec.points) { //fseek(justfile,(INT32)cnt*sizeof(best_rec_type),SEEK_SET); @@ -5161,11 +5303,14 @@ AddBestPlayerInIB(char *name,DWORD points) { } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); if (cnt<10) { justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"a+b"); - ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); + fclose(justfile); + } if(ibbs_maint_i==FALSE) { ny_line(302,2,1); @@ -5189,8 +5334,10 @@ AddBestPlayerInIB(char *name,DWORD points) { } } justfile=ShareFileOpen(IBBS_BESTTEN_FILENAME,"wb"); - ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2,sizeof(best_rec_type),1,justfile); + fclose(justfile); + } if(ibbs_maint_i==FALSE) { ny_line(302,2,1); @@ -5297,12 +5444,14 @@ mail_ops(void) { do { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); - do { - ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); - unum++; - } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.user_num==nCurrentUserNumber) && ret==1); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); + do { + ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); + unum++; + } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.user_num==nCurrentUserNumber) && ret==1); + fclose(justfile); + } } while (ret==1 && askifuser(urec.name)==FALSE); } if (ret!=1) { @@ -5350,9 +5499,11 @@ mail_ops(void) { } ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); - ny_fread(&u2rec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); + ny_fread(&u2rec,sizeof(user_rec),1,justfile); + fclose(justfile); + } ny_line(308,1,1); //od_printf("\n\r`bright red`O`red`k type yer message now (`bright red`/s`red`=save `bright red`/a`red`=abort):\n\r"); @@ -5360,13 +5511,15 @@ mail_ops(void) { ch_flag_d(); sprintf(numstr,"u%07d.tmg", nCurrentUserNumber); justfile=ShareFileOpen(numstr,"wb"); - cnt= -1; - do { - cnt++; - get_line(ovr,line,ovr,TRUE); - ny_fwrite(&line,80,1,justfile); - } while ((line[0]!='/' && (line[1]!='s' || line[1]!='S')) && (line[0]!='/' && (line[1]!='a' || line[1]!='A'))); - fclose(justfile); + if(justfile != NULL) { + cnt= -1; + do { + cnt++; + get_line(ovr,line,ovr,TRUE); + ny_fwrite(&line,80,1,justfile); + } while ((line[0]!='/' && (line[1]!='s' || line[1]!='S')) && (line[0]!='/' && (line[1]!='a' || line[1]!='A'))); + fclose(justfile); + } if ((line[1]=='s' || line[1]=='S') && (cnt>0 || mail_idx.flirt==1)) { ny_line(135,0,1); @@ -5385,32 +5538,38 @@ mail_ops(void) { justfile=ShareFileOpen(numstr,"rb"); ch_game_d(); msg_file=ShareFileOpen(MAIL_FILENAME,"a+b"); - fillen=filelength(fileno(msg_file)); - fillen/=80; - mail_idx.location=fillen; - while ((cnt--)>0) { - ny_fread(&line,80,1,justfile); - ny_fwrite(&line,80,1,msg_file); + if(justfile != NULL && msg_file != NULL) { + fillen=filelength(fileno(msg_file)); + fillen/=80; + mail_idx.location=fillen; + while ((cnt--)>0) { + ny_fread(&line,80,1,justfile); + ny_fwrite(&line,80,1,msg_file); + } + fclose(msg_file); + fclose(justfile); } - fclose(msg_file); - fclose(justfile); //sprintf(numstr,"del u%07d.tmg"); //system(numstr); ch_flag_d(); ny_remove(numstr); ch_game_d(); msg_file=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); - fclose(msg_file); + if(msg_file != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); + fclose(msg_file); + } if(single_node==FALSE && urec.online==TRUE) { ch_flag_d(); sprintf(numstr,"u%07d.omg",urec.user_num); omg[0]=27; omg[1]=0; justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } } } else { ny_line(136,0,1); @@ -5475,16 +5634,18 @@ mail_ops(void) { do { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); + if(justfile != NULL) { + fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); ask_online_again: - ; - do { - ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); - unum++; - } while (strzcmp(hand,ny_un_emu(urec.name,numstr)) && ret==1); - if (urec.online==FALSE && ret==1) - goto ask_online_again; - fclose(justfile); + ; + do { + ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); + unum++; + } while (strzcmp(hand,ny_un_emu(urec.name,numstr)) && ret==1); + if (urec.online==FALSE && ret==1) + goto ask_online_again; + fclose(justfile); + } } while (ret==1 && askifuser(urec.name)==FALSE); } unum--; @@ -5511,9 +5672,11 @@ ask_online_again: ch_flag_d(); sprintf(numstr,"u%07d.omg",urec.user_num); justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } ny_line(315,2,1); //Sent! if(!rip) @@ -5558,15 +5721,17 @@ read_mail(void) { do { ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"rb"); - fseek(justfile,filepos,SEEK_SET); - intval=ny_fread(&mail_idx,sizeof(mail_idx_type),1,justfile); - - ny_line(316,2,0); - //Searching ... - while (intval==1 && (strcmp(mail_idx.recverI,cur_user.bbsname)!=0 || mail_idx.deleted==TRUE)) + if(justfile != NULL) { + fseek(justfile,filepos,SEEK_SET); intval=ny_fread(&mail_idx,sizeof(mail_idx_type),1,justfile); - filepos=ftell(justfile); - fclose(justfile); + + ny_line(316,2,0); + //Searching ... + while (intval==1 && (strcmp(mail_idx.recverI,cur_user.bbsname)!=0 || mail_idx.deleted==TRUE)) + intval=ny_fread(&mail_idx,sizeof(mail_idx_type),1,justfile); + filepos=ftell(justfile); + fclose(justfile); + } if (intval==1) { nonstop=FALSE; @@ -5582,39 +5747,43 @@ read_mail(void) { if (mail_idx.flirt<=998) { ch_game_d(); justfile=ShareFileOpen(MAIL_FILENAME,"rb"); - fseek(justfile,(INT32)mail_idx.location * 80,SEEK_SET); - od_printf("`green`"); - while (cnt<mail_idx.length) { - ny_fread(&line,80,1,justfile); - if (cnt<mail_idx.afterquote) { - ny_disp_emu("`9>`2"); - ny_disp_emu(line); - od_printf("\n\r"); - } else { - od_set_attrib(0x0a); //bright green - ny_disp_emu(line); - od_printf("\n\r"); - } - cnt++; - cnt2++; - if (nonstop==FALSE && cnt2%od_control.user_screen_length==0) { - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,(INT32)mail_idx.location * 80,SEEK_SET); + od_printf("`green`"); + while (justfile != NULL && cnt<mail_idx.length) { + ny_fread(&line,80,1,justfile); + if (cnt<mail_idx.afterquote) { + ny_disp_emu("`9>`2"); + ny_disp_emu(line); + od_printf("\n\r"); + } else { + od_set_attrib(0x0a); //bright green + ny_disp_emu(line); + od_printf("\n\r"); + } + cnt++; + cnt2++; + if (nonstop==FALSE && cnt2%od_control.user_screen_length==0) { + fclose(justfile); - ny_disp_emu("`%More (Y/n/=)"); - key=ny_get_answer("YN=\n\r"); - ny_disp_emu("\r \r"); - cnt2=1; - if(key=='N') - return; - else if(key=='=') - nonstop=TRUE; + ny_disp_emu("`%More (Y/n/=)"); + key=ny_get_answer("YN=\n\r"); + ny_disp_emu("\r \r"); + cnt2=1; + if(key=='N') + return; + else if(key=='=') + nonstop=TRUE; - ch_game_d(); - justfile=ShareFileOpen(MAIL_FILENAME,"rb"); - fseek(justfile,(INT32)(mail_idx.location+cnt) * 80,SEEK_SET); + ch_game_d(); + justfile=ShareFileOpen(MAIL_FILENAME,"rb"); + if(justfile != NULL) + fseek(justfile,(INT32)(mail_idx.location+cnt) * 80,SEEK_SET); + } } + if(justfile != NULL) + fclose(justfile); } - fclose(justfile); if (mail_idx.flirt==1) { @@ -5650,10 +5819,12 @@ read_mail(void) { illness(mail_idx.ill,mail_idx.inf); ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } WaitForEnter(); key=-1; } else if (mail_idx.flirt==1000) { @@ -5666,10 +5837,12 @@ read_mail(void) { illness(mail_idx.ill,mail_idx.inf); ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } WaitForEnter(); key=-1; } else if (mail_idx.flirt==1001) { @@ -5681,19 +5854,22 @@ read_mail(void) { ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } WaitForEnter(); key=-1; } else if (mail_idx.flirt==1002) { ch_game_d(); justfile=ShareFileOpen(MAIL_FILENAME,"rb"); - fseek(justfile,(INT32)mail_idx.location * 80,SEEK_SET); - fread(&mon,sizeof(DWORD),1,justfile); - fclose(justfile); - + if(justfile != NULL) { + fseek(justfile,(INT32)mail_idx.location * 80,SEEK_SET); + fread(&mon,sizeof(DWORD),1,justfile); + fclose(justfile); + } med=ULONG_MAX-mon; if (med<=cur_user.money) @@ -5711,10 +5887,12 @@ read_mail(void) { wrt_sts(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } WaitForEnter(); key=-1; } @@ -5725,10 +5903,12 @@ read_mail(void) { //Deleting... ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } if(key=='D' && rip==TRUE) od_get_answer("\n\r"); } @@ -5745,10 +5925,12 @@ read_mail(void) { } else { ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); - mail_idx.deleted=TRUE; - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(mail_idx_type),SEEK_SET); + mail_idx.deleted=TRUE; + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } ny_line(327,2,0); //You just had sex with @@ -5779,33 +5961,40 @@ read_mail(void) { mail_idx.sender_sex=cur_user.sex; ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } if(single_node==FALSE) { unum=0; ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - while(ny_fread(&urec,sizeof(user_rec),1,justfile)==1) { - if(strcmp(urec.bbsname,mail_idx.recverI)==0) { - fclose(justfile); - ch_flag_d(); - sprintf(numstr,"u%07d.on",unum); - if(fexist(numstr)) { - sprintf(numstr,"u%07d.omg",unum); - omg[0]=27; - omg[1]=1; - justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); + if(justfile != NULL) { + while(justfile != NULL && ny_fread(&urec,sizeof(user_rec),1,justfile)==1) { + if(strcmp(urec.bbsname,mail_idx.recverI)==0) { fclose(justfile); + ch_flag_d(); + sprintf(numstr,"u%07d.on",unum); + if(fexist(numstr)) { + sprintf(numstr,"u%07d.omg",unum); + omg[0]=27; + omg[1]=1; + justfile=ShareFileOpen(numstr,"a+b"); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } + } + goto found_the_guy; } - goto found_the_guy; + unum++; } - unum++; + if(justfile != NULL) + fclose(justfile); } - fclose(justfile); found_the_guy: ; } @@ -5857,36 +6046,39 @@ found_the_guy: ch_flag_d(); sprintf(numstr,"u%07d.tmg",nCurrentUserNumber); njustfile=ShareFileOpen(numstr,"wb"); + if(njustfile != NULL) { + ny_line(308,1,1); + //Ok type yer message now (/s=save /a=abort): + if (key=='N') { + mail_idx.afterquote=0; + } else { + ch_game_d(); + justfile=ShareFileOpen(MAIL_FILENAME,"rb"); + if(justfile != NULL) { + cnt= mail_idx.afterquote; + fseek(justfile,(INT32)(mail_idx.location+cnt) * 80,SEEK_SET); + while (cnt<mail_idx.length) { + ny_fread(&line,80,1,justfile); + ny_fwrite(&line,80,1,njustfile); + ny_disp_emu("`9>`2"); + ny_disp_emu(line); + ny_disp_emu("\n\r"); + cnt++; + } + fclose(justfile); + } + mail_idx.afterquote=cnt-mail_idx.afterquote; + } - ny_line(308,1,1); - //Ok type yer message now (/s=save /a=abort): - if (key=='N') { - mail_idx.afterquote=0; - } else { - ch_game_d(); - justfile=ShareFileOpen(MAIL_FILENAME,"rb"); - cnt= mail_idx.afterquote; - fseek(justfile,(INT32)(mail_idx.location+cnt) * 80,SEEK_SET); - while (cnt<mail_idx.length) { - ny_fread(&line,80,1,justfile); - ny_fwrite(&line,80,1,njustfile); - ny_disp_emu("`9>`2"); - ny_disp_emu(line); - ny_disp_emu("\n\r"); + cnt=-1; + ovr[0]=0; + do { cnt++; - } - fclose(justfile); - mail_idx.afterquote=cnt-mail_idx.afterquote; + get_line(ovr,line,ovr,TRUE); + ny_fwrite(&line,80,1,njustfile); + } while ((line[0]!='/' && line[1]!='S') && (line[0]!='/' && line[1]!='A')); + fclose(njustfile); } - - cnt=-1; - ovr[0]=0; - do { - cnt++; - get_line(ovr,line,ovr,TRUE); - ny_fwrite(&line,80,1,njustfile); - } while ((line[0]!='/' && line[1]!='S') && (line[0]!='/' && line[1]!='A')); - fclose(njustfile); if (line[1]=='s' || line[1]=='S') { ny_line(135,0,1); // od_printf("\b\b`bright red`S`red`aving...\n\r"); @@ -5904,23 +6096,27 @@ found_the_guy: njustfile=ShareFileOpen(numstr,"rb"); ch_game_d(); justfile=ShareFileOpen(MAIL_FILENAME,"a+b"); - fillen=filelength(fileno(justfile)); - fillen/=80; - mail_idx.location=fillen; - while ((cnt--)>0) { - ny_fread(&line,80,1,njustfile); - ny_fwrite(&line,80,1,justfile); + if(njustfile != NULL && justfile != NULL) { + fillen=filelength(fileno(justfile)); + fillen/=80; + mail_idx.location=fillen; + while ((cnt--)>0) { + ny_fread(&line,80,1,njustfile); + ny_fwrite(&line,80,1,justfile); + } + fclose(justfile); + fclose(njustfile); } - fclose(justfile); - fclose(njustfile); //sprintf(numstr,"del u%07d.tmg"); //system(numstr); ch_flag_d(); ny_remove(numstr); ch_game_d(); justfile=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,justfile); + fclose(justfile); + } if(single_node==FALSE) { // scr_rec srec; @@ -5929,25 +6125,30 @@ found_the_guy: ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - while(ny_fread(&urec,sizeof(user_rec),1,justfile)==1) { - if(strcmp(urec.bbsname,mail_idx.recverI)==0) { - fclose(justfile); - ch_flag_d(); - sprintf(numstr,"u%07d.on",unum); - if(fexist(numstr)) { - sprintf(numstr,"u%07d.omg",unum); - omg[0]=27; - omg[1]=1; - justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); + if(justfile != NULL) { + while(justfile != NULL && ny_fread(&urec,sizeof(user_rec),1,justfile)==1) { + if(strcmp(urec.bbsname,mail_idx.recverI)==0) { fclose(justfile); + ch_flag_d(); + sprintf(numstr,"u%07d.on",unum); + if(fexist(numstr)) { + sprintf(numstr,"u%07d.omg",unum); + omg[0]=27; + omg[1]=1; + justfile=ShareFileOpen(numstr,"a+b"); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } + } + goto found_the_guy_2; } - goto found_the_guy_2; + unum++; } - unum++; + if(justfile != NULL) + fclose(justfile); } - fclose(justfile); found_the_guy_2: ; } @@ -6016,13 +6217,15 @@ read_ibmail(void) { do { ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"rb"); - fseek(justfile,filepos,SEEK_SET); - intval=ny_fread(&ibmail,sizeof(ibbs_mail_type),1,justfile); - ny_line(316,2,0); - while (intval==1 && (strcmp(ibmail.recverI,cur_user.bbsname)!=0 || ibmail.deleted==TRUE)) + if(justfile != NULL) { + fseek(justfile,filepos,SEEK_SET); intval=ny_fread(&ibmail,sizeof(ibbs_mail_type),1,justfile); - filepos=ftell(justfile); - fclose(justfile); + ny_line(316,2,0); + while (intval==1 && (strcmp(ibmail.recverI,cur_user.bbsname)!=0 || ibmail.deleted==TRUE)) + intval=ny_fread(&ibmail,sizeof(ibbs_mail_type),1,justfile); + filepos=ftell(justfile); + fclose(justfile); + } if (intval==1) { // nonstop=FALSE; ny_line(317,2,0); @@ -6086,10 +6289,12 @@ read_ibmail(void) { illness(ibmail.ill,ibmail.inf); ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } WaitForEnter(); } else if (ibmail.flirt==1003) { @@ -6108,10 +6313,12 @@ read_ibmail(void) { } ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } WaitForEnter(); } else if (ibmail.flirt==1005) { @@ -6133,10 +6340,12 @@ read_ibmail(void) { } ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } WaitForEnter(); } else if (ibmail.flirt==1004) { ny_disp_emu("\n\r`@"); @@ -6149,10 +6358,12 @@ read_ibmail(void) { ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } num=*(INT16 *)ibmail.lines[0]; any_attack_ops(&cur_user,"`@H`4ired `@H`4itman `@F`4ight",ibmail.lines[1], @@ -6180,10 +6391,12 @@ read_ibmail(void) { wrt_sts(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } WaitForEnter(); } @@ -6193,12 +6406,14 @@ read_ibmail(void) { ny_line(325,1,2); //od_printf("\n\r`bright red`D`red`eleting...\n\r\n\r"); ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - // od_printf("}>}%d{<{",(INT16)ibmail.deleted); - // filepos=0; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + // od_printf("}>}%d{<{",(INT16)ibmail.deleted); + // filepos=0; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } if(key=='D' && rip==TRUE) od_get_answer("\n\r"); @@ -6216,10 +6431,12 @@ read_ibmail(void) { } else { ch_game_d(); justfile=ShareFileOpen(IBBS_MAIL_INDEX,"r+b"); - fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); - ibmail.deleted=TRUE; - ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,filepos-sizeof(ibbs_mail_type),SEEK_SET); + ibmail.deleted=TRUE; + ny_fwrite(&ibmail,sizeof(ibbs_mail_type),1,justfile); + fclose(justfile); + } ny_line(327,2,0); //od_printf("\n\r\n\r`bright red`Y`red`ou just had sex with `bright red` diff --git a/src/doors/ny2008/src/nyedit.cpp b/src/doors/ny2008/src/nyedit.cpp index beb5bea02e0a8435761dde244d10038fe4da7915..7c36511cf838f851acdb2c517e4a08ba4b5b8e48 100644 --- a/src/doors/ny2008/src/nyedit.cpp +++ b/src/doors/ny2008/src/nyedit.cpp @@ -1264,92 +1264,97 @@ SortScrFile(INT16 usr) // pebble sorting of scorefile ch_game_d(); scr_file=ShareFileOpen(SCR_FILENAME,"r+b"); fpUserFile=ShareFileOpen(USER_FILENAME,"r+b"); - if (usr==user_num) { - cnt=cur_user.rank; - } else { - fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); - ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); - cnt=urec.rank; - } - - //od_printf("\n\r\n\r%d\n\r\n\r",cnt); + if(scr_file != NULL && fpUserFile != NULL) { + if (usr==user_num) { + cnt=cur_user.rank; + } else { + fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); + ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); + cnt=urec.rank; + } - crnt1=0; - crnt2=1; + //od_printf("\n\r\n\r%d\n\r\n\r",cnt); - strcpy(rec[crnt1].name,cur_user.name); - rec[crnt1].nation=cur_user.nation; - rec[crnt1].level=cur_user.level; - rec[crnt1].points=cur_user.points; - rec[crnt1].alive=cur_user.alive; - rec[crnt1].sex=cur_user.sex; - rec[crnt1].user_num=user_num; - rec[crnt1].online=TRUE; + crnt1=0; + crnt2=1; + strcpy(rec[crnt1].name,cur_user.name); + rec[crnt1].nation=cur_user.nation; + rec[crnt1].level=cur_user.level; + rec[crnt1].points=cur_user.points; + rec[crnt1].alive=cur_user.alive; + rec[crnt1].sex=cur_user.sex; + rec[crnt1].user_num=user_num; + rec[crnt1].online=TRUE; - fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - if (cnt>0) { - ch_flag_d(); - do { - sorted=TRUE; + fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); + if (cnt>0) { + ch_flag_d(); + do { + sorted=TRUE; - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); - if (rec[crnt1].points<rec[crnt2].points) { // switch records + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - sorted=FALSE; // run another round + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); + if (rec[crnt1].points<rec[crnt2].points) { // switch records - sprintf(numstr,"u%07d.on",rec[crnt1].user_num); - if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); - njustfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cnt,2,1,njustfile); - fclose(njustfile); - } else { - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt; - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - } + sorted=FALSE; // run another round - if (usr==user_num) { - cur_user.rank=cnt-1; - } else { - sprintf(numstr,"u%07d.on",rec[crnt2].user_num); + sprintf(numstr,"u%07d.on",rec[crnt1].user_num); if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); + sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); njustfile = ShareFileOpen(numstr, "wb"); - cnt--; - ny_fwrite(&cnt,2,1,njustfile); - cnt++; - fclose(njustfile); + if(njustfile != NULL) { + ny_fwrite(&cnt,2,1,njustfile); + fclose(njustfile); + } } else { - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt-1; - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + urec.rank=cnt; + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); } - } - fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); + if (usr==user_num) { + cur_user.rank=cnt-1; + } else { + sprintf(numstr,"u%07d.on",rec[crnt2].user_num); + if (single_node==FALSE && fexist(numstr)) { + sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + cnt--; + ny_fwrite(&cnt,2,1,njustfile); + cnt++; + fclose(njustfile); + } + } else { + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt-1; + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + } + } - } - cnt--; - } while (sorted==FALSE && cnt>0); - } - fclose(scr_file); - fclose(fpUserFile); + fseek(scr_file, (INT32)(cnt-1) * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); + } + cnt--; + } while (sorted==FALSE && cnt>0); + } + fclose(scr_file); + fclose(fpUserFile); + } } @@ -1370,92 +1375,97 @@ SortScrFileB(INT16 usr) // pebble sorting of scorefile ch_game_d(); scr_file=ShareFileOpen(SCR_FILENAME,"r+b"); fpUserFile=ShareFileOpen(USER_FILENAME,"r+b"); - if (usr==user_num) { - cnt=cur_user.rank; - } else { - fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); - ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); - cnt=urec.rank; - } - //od_printf("\n\r\n\r%d\n\r\n\r",cnt); + if(scr_file != NULL && fpUserFile != NULL) { + if (usr==user_num) { + cnt=cur_user.rank; + } else { + fseek(fpUserFile, (INT32)usr * sizeof(user_rec), SEEK_SET); + ny_fread(&urec, sizeof(user_rec), 1, fpUserFile); + cnt=urec.rank; + } + //od_printf("\n\r\n\r%d\n\r\n\r",cnt); - crnt1=0; - crnt2=1; + crnt1=0; + crnt2=1; - strcpy(rec[crnt1].name,cur_user.name); - rec[crnt1].nation=cur_user.nation; - rec[crnt1].level=cur_user.level; - rec[crnt1].points=cur_user.points; - rec[crnt1].alive=cur_user.alive; - rec[crnt1].sex=cur_user.sex; - rec[crnt1].user_num=user_num; - rec[crnt1].online=TRUE; + strcpy(rec[crnt1].name,cur_user.name); + rec[crnt1].nation=cur_user.nation; + rec[crnt1].level=cur_user.level; + rec[crnt1].points=cur_user.points; + rec[crnt1].alive=cur_user.alive; + rec[crnt1].sex=cur_user.sex; + rec[crnt1].user_num=user_num; + rec[crnt1].online=TRUE; - fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - cont=filelength(fileno(scr_file))/sizeof(scr_rec); + fseek(scr_file, (INT32)cur_user.rank * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1], sizeof(scr_rec), 1, scr_file); + cont=filelength(fileno(scr_file))/sizeof(scr_rec); - if (cnt<(cont-1)) { - ch_flag_d(); - do { - sorted=TRUE; + if (cnt<(cont-1)) { + ch_flag_d(); + do { + sorted=TRUE; - fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); - if (rec[crnt1].points>rec[crnt2].points) { // switch records + fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt1], sizeof(scr_rec), 1, scr_file); - sorted=FALSE; // run another round + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fread(&rec[crnt2], sizeof(scr_rec), 1, scr_file); + if (rec[crnt1].points>rec[crnt2].points) { // switch records - sprintf(numstr,"u%07d.on",rec[crnt1].user_num); - if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); - njustfile = ShareFileOpen(numstr, "wb"); - ny_fwrite(&cnt,2,1,njustfile); - fclose(njustfile); - } else { - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt; - fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); - ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); - } + sorted=FALSE; // run another round - if (usr==user_num) { - cur_user.rank=cnt+1; - } else { - sprintf(numstr,"u%07d.on",rec[crnt2].user_num); + sprintf(numstr,"u%07d.on",rec[crnt1].user_num); if (single_node==FALSE && fexist(numstr)) { - sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); + sprintf(numstr,"u%07d.rnk",rec[crnt1].user_num); njustfile = ShareFileOpen(numstr, "wb"); - cnt++; - ny_fwrite(&cnt,2,1,njustfile); - cnt--; - fclose(njustfile); + if(njustfile != NULL) { + ny_fwrite(&cnt,2,1,njustfile); + fclose(njustfile); + } } else { - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); ny_fread(&urec,sizeof(user_rec),1,fpUserFile); - urec.rank=cnt+1; - fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + urec.rank=cnt; + fseek(fpUserFile, (INT32)rec[crnt1].user_num * sizeof(user_rec), SEEK_SET); ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); } - } - fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); - fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); - ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); + if (usr==user_num) { + cur_user.rank=cnt+1; + } else { + sprintf(numstr,"u%07d.on",rec[crnt2].user_num); + if (single_node==FALSE && fexist(numstr)) { + sprintf(numstr,"u%07d.rnk",rec[crnt2].user_num); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + cnt++; + ny_fwrite(&cnt,2,1,njustfile); + cnt--; + fclose(njustfile); + } + } else { + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fread(&urec,sizeof(user_rec),1,fpUserFile); + urec.rank=cnt+1; + fseek(fpUserFile, (INT32)rec[crnt2].user_num * sizeof(user_rec), SEEK_SET); + ny_fwrite(&urec,sizeof(user_rec),1,fpUserFile); + } + } - } - cnt++; - } while (sorted==FALSE && cnt<(cont-1)); - } - fclose(scr_file); - fclose(fpUserFile); + fseek(scr_file, (INT32)(cnt+1) * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt2],sizeof(scr_rec),1,scr_file); + fseek(scr_file, (INT32)cnt * sizeof(scr_rec), SEEK_SET); + ny_fwrite(&rec[crnt1],sizeof(scr_rec),1,scr_file); + } + cnt++; + } while (sorted==FALSE && cnt<(cont-1)); + } + fclose(scr_file); + fclose(fpUserFile); + } } void @@ -1821,9 +1831,6 @@ FILE *ShareFileOpen(char *pszFileName, char *pszMode) { fpFile = fopen(pszFileName, pszMode); } - if(fpFile==NULL) - fpFile=fopen("cruft.tmp","w+"); - /* Return FILE pointer for opened file, if any. */ return(fpFile); } diff --git a/src/doors/ny2008/src/nyibbs.cpp b/src/doors/ny2008/src/nyibbs.cpp index 239dea4ae7a45819c9d0b61ac8c063d36e8526fe..f0d2fb123bca18190b52e0c51476c9de762932ba 100644 --- a/src/doors/ny2008/src/nyibbs.cpp +++ b/src/doors/ny2008/src/nyibbs.cpp @@ -56,59 +56,63 @@ void AddBestPlayerInIB(char *name, DWORD points, char location[]) { //ch_game_d(); if (fexist(IBBS_BESTTEN_FILENAME)) { justfile = ShareFileOpen(IBBS_BESTTEN_FILENAME, "r+b"); - len_of_list = filelength(fileno(justfile)) / sizeof(ibbs_best_rec_type) + 1; - if (len_of_list > 10) - len_of_list = 10; - - /* check if the same record exists */ - while (cnt < 10 && ny_fread(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile) == 1) { - //printf("[%ld=%ld],", best_rec.points, points); - //printf("[%s=%s],", best_rec.location, location); - //printf("[%s=%s]\n", best_rec.name, name); - if (points == best_rec.points && - strcmp(best_rec.location, location) == 0 && - strcmp(best_rec.name, name) == 0) { - /* if it already exists quit this function */ - fclose(justfile); - return; + if(justfile != NULL) { + len_of_list = filelength(fileno(justfile)) / sizeof(ibbs_best_rec_type) + 1; + if (len_of_list > 10) + len_of_list = 10; + + /* check if the same record exists */ + while (cnt < 10 && ny_fread(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile) == 1) { + //printf("[%ld=%ld],", best_rec.points, points); + //printf("[%s=%s],", best_rec.location, location); + //printf("[%s=%s]\n", best_rec.name, name); + if (points == best_rec.points && + strcmp(best_rec.location, location) == 0 && + strcmp(best_rec.name, name) == 0) { + /* if it already exists quit this function */ + fclose(justfile); + return; + } } - } - /* rewind the file to beginning */ - fseek(justfile, 0, SEEK_SET); - - while (cnt < 10 && ny_fread(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile) == 1) { - - if (points >= best_rec.points) { - //fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); - //ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); - strcpy(best_rec.name, best_rec2.name); - strcpy(best_rec.location, best_rec2.location); - best_rec.points = best_rec2.points; - //cnt++; - while (cnt < len_of_list) { - fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); - ny_fread(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); - fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); - ny_fwrite(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile); + /* rewind the file to beginning */ + fseek(justfile, 0, SEEK_SET); + + while (cnt < 10 && ny_fread(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile) == 1) { + + if (points >= best_rec.points) { + //fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); + //ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); strcpy(best_rec.name, best_rec2.name); strcpy(best_rec.location, best_rec2.location); best_rec.points = best_rec2.points; - cnt++; + //cnt++; + while (cnt < len_of_list) { + fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); + ny_fread(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); + fseek(justfile, (INT32)cnt * sizeof(ibbs_best_rec_type), SEEK_SET); + ny_fwrite(&best_rec, sizeof(ibbs_best_rec_type), 1, justfile); + strcpy(best_rec.name, best_rec2.name); + strcpy(best_rec.location, best_rec2.location); + best_rec.points = best_rec2.points; + cnt++; + } + fclose(justfile); + //od_control.od_ker_exec = NULL; + return; } - fclose(justfile); - //od_control.od_ker_exec = NULL; - return; + cnt++; + } - cnt++; + fclose(justfile); } - - fclose(justfile); if (cnt < 10) { justfile = ShareFileOpen(IBBS_BESTTEN_FILENAME, "a+b"); - ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); + fclose(justfile); + } //od_control.od_ker_exec = NULL; return; } else { @@ -117,8 +121,10 @@ void AddBestPlayerInIB(char *name, DWORD points, char location[]) { } } justfile = ShareFileOpen(IBBS_BESTTEN_FILENAME, "wb"); - ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&best_rec2, sizeof(ibbs_best_rec_type), 1, justfile); + fclose(justfile); + } //od_control.od_ker_exec = NULL; return; } @@ -591,10 +597,12 @@ void RefreshBest(void) { if (fexist(BESTTEN_FILENAME)) { /* open for reading */ justfile = ShareFileOpen(BESTTEN_FILENAME, "rb"); - while (ny_fread(&best_rec, sizeof(best_rec), 1, justfile) == 1) { - AddBestPlayerInIB(best_rec.name, best_rec.points, IBBSInfo.szThisNodeAddress); + if(justfile != NULL) { + while (ny_fread(&best_rec, sizeof(best_rec), 1, justfile) == 1) { + AddBestPlayerInIB(best_rec.name, best_rec.points, IBBSInfo.szThisNodeAddress); + } + fclose(justfile); } - fclose(justfile); } } @@ -771,27 +779,29 @@ INT16 main(INT16 argc, char *argv[]) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d MAIL", ibbsi_game_num); justfile = ShareFileOpen(IBBS_MAIL_INDEX, "a+b"); - //while (IBGet(&IBBSInfo, &ibmail, sizeof(ibbs_mail_type)) == eSuccess) { - - /* - for(x=0;x<(sizeof(ibbs_mail_type));x++) (((char - *)&ibmail)+x)=0; - */ - while (IBGetMail(&IBBSInfo, &ibmail) == eSuccess) { + if(justfile != NULL) { + //while (IBGet(&IBBSInfo, &ibmail, sizeof(ibbs_mail_type)) == eSuccess) { /* - printf(">>>(%s|",ibmail.sender); - printf("%s|",ibmail.senderI); - printf("%s|",ibmail.node_s); - printf("%s|",ibmail.node_r); - printf("%s|",ibmail.recver); - printf("%s)<<<\n\n",ibmail.recverI); + for(x=0;x<(sizeof(ibbs_mail_type));x++) (((char + *)&ibmail)+x)=0; */ + while (IBGetMail(&IBBSInfo, &ibmail) == eSuccess) { - if (strcmp(ibmail.node_r, IBBSInfo.szThisNodeAddress) == 0) - ny_fwrite(&ibmail, sizeof(ibbs_mail_type), 1, justfile); + /* + printf(">>>(%s|",ibmail.sender); + printf("%s|",ibmail.senderI); + printf("%s|",ibmail.node_s); + printf("%s|",ibmail.node_r); + printf("%s|",ibmail.recver); + printf("%s)<<<\n\n",ibmail.recverI); + */ + + if (strcmp(ibmail.node_r, IBBSInfo.szThisNodeAddress) == 0) + ny_fwrite(&ibmail, sizeof(ibbs_mail_type), 1, justfile); + } + fclose(justfile); } - fclose(justfile); } if (ibbs_send_nodelist && ibbsi_operator) { @@ -835,13 +845,15 @@ INT16 main(INT16 argc, char *argv[]) { memcpy((char *)IBBSInfo.paOtherSystem, InComing, sizeof(tOtherNode) * IBBSInfo.nTotalSystems); //free(InComing); justfile = ShareFileOpenAR(NODELIST_FILENAME, "wt"); - fprintf(justfile, ";Only the central system operator should change this node list!\n"); - for (x = 0; x < IBBSInfo.nTotalSystems; x++) { - fprintf(justfile, "LinkWith %s\n", ((tOtherNode *) InComing)[x].szAddress); - fprintf(justfile, "LinkName %s\n", ((tOtherNode *) InComing)[x].szSystemName); - fprintf(justfile, "LinkLocation %s\n\n", ((tOtherNode *) InComing)[x].szLocation); + if(justfile != NULL) { + fprintf(justfile, ";Only the central system operator should change this node list!\n"); + for (x = 0; x < IBBSInfo.nTotalSystems; x++) { + fprintf(justfile, "LinkWith %s\n", ((tOtherNode *) InComing)[x].szAddress); + fprintf(justfile, "LinkName %s\n", ((tOtherNode *) InComing)[x].szSystemName); + fprintf(justfile, "LinkLocation %s\n\n", ((tOtherNode *) InComing)[x].szLocation); + } + fclose(justfile); } - fclose(justfile); InComing--; } free(InComing); @@ -857,26 +869,28 @@ INT16 main(INT16 argc, char *argv[]) { if (strcmp(InComing, IBBSInfo.szThisNodeAddress) != 0) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d NAMELIST", ibbsi_game_num); justfile = ShareFileOpen(USER_FILENAME, "rb"); - cnt = filelength(fileno(justfile)) / sizeof(user_rec); - OutGoing = (char *)malloc(((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); - OutGoing += 2; - x = 0; - while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { - strcpy(OutGoing + 1 + ((25 + 36 + 1) * x), urec_i.name); - strcpy(OutGoing + 1 + ((25 + 36 + 1) * x) + 25, urec_i.bbsname); - *(OutGoing + (25 + 36 + 1) * (x + 1)) = (char)urec_i.sex; - x++; - } - strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); - if (x > 0) { - *OutGoing = cnt; - OutGoing -= 2; - *(INT16 *)OutGoing = ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 2; - IBSend(&IBBSInfo, InComing, OutGoing, ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); - } else { - OutGoing -= 2; + if(justfile != NULL) { + cnt = filelength(fileno(justfile)) / sizeof(user_rec); + OutGoing = (char *)malloc(((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); + OutGoing += 2; + x = 0; + while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { + strcpy(OutGoing + 1 + ((25 + 36 + 1) * x), urec_i.name); + strcpy(OutGoing + 1 + ((25 + 36 + 1) * x) + 25, urec_i.bbsname); + *(OutGoing + (25 + 36 + 1) * (x + 1)) = (char)urec_i.sex; + x++; + } + strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); + if (x > 0) { + *OutGoing = cnt; + OutGoing -= 2; + *(INT16 *)OutGoing = ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 2; + IBSend(&IBBSInfo, InComing, OutGoing, ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); + } else { + OutGoing -= 2; + } + fclose(justfile); } - fclose(justfile); free(OutGoing); sprintf(IBBSInfo.szProgName, "#@NYG#%05d LISTREQ", ibbsi_game_num); } @@ -894,8 +908,10 @@ INT16 main(INT16 argc, char *argv[]) { while (IBGet(&IBBSInfo, (char *)&newzfile, sizeof(newzfile)) == eSuccess) { //ch_game_d(); justfile = ShareFileOpen(TODNEWS_FILENAME, "a+b"); - ny_fwrite(&newzfile, sizeof(newzfile), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&newzfile, sizeof(newzfile), 1, justfile); + fclose(justfile); + } } sprintf(IBBSInfo.szProgName, "#@NYG#%05d BBSINFO", ibbsi_game_num); @@ -938,8 +954,10 @@ INT16 main(INT16 argc, char *argv[]) { bbs_spy_rec.players = 0; strcpy(bbs_spy_rec.node, bbs_rec.node); bbs_spy_rec.hi_points = bbs_rec.hi_points; - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + fclose(justfile); + } } } } @@ -959,72 +977,79 @@ INT16 main(INT16 argc, char *argv[]) { //printf("\nPlayers in the list: |%d|\n", cnt); //od_get_answer("1"); justfile = ShareFileOpen(IBBSSPY_FILENAME, "r+b"); - //fseek(justfile, 0, SEEK_SET); - //printf("3"); - xx = 0; - //printf("4"); + if(justfile != NULL) { + //fseek(justfile, 0, SEEK_SET); + //printf("3"); + xx = 0; + //printf("4"); - //printf("\n*|N#%s|\n", InComing + 1); - //+((25 + 36 + 1) * cnt)); - //printf("*|N#%s|\n", InComing + 26); - //+((25 + 36 + 1) * (cnt - 1))); - //od_get_answer("1"); + //printf("\n*|N#%s|\n", InComing + 1); + //+((25 + 36 + 1) * cnt)); + //printf("*|N#%s|\n", InComing + 26); + //+((25 + 36 + 1) * (cnt - 1))); + //od_get_answer("1"); - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - //printf("5"); - if (strcmp(InComing + 1 + ((25 + 36 + 1) * cnt), bbs_spy_rec.node) == 0) { - //printf("6"); - if (bbs_spy_rec.player_list != 0) { - //printf("7"); - sprintf(numstr, SBYDBT_PREFIX".%03d", bbs_spy_rec.player_list); - njustfile = ShareFileOpen(numstr, "wb"); - for (x = 0; x < cnt; x++) { - strcpy(ibscr_rec.name, InComing + 1 + ((25 + 36 + 1) * x)); - strcpy(ibscr_rec.nameI, InComing + 1 + ((25 + 36 + 1) * x) + 25); - ibscr_rec.sex = *(sex_type *) (InComing + (25 + 36 + 1) * (x + 1)); - //printf("\n+|%s|%s|%d|\n", ibscr_rec.name, ibscr_rec.nameI, (INT16)ibscr_rec.sex); - //od_get_answer("1"); - - ibscr_rec.level = -1; - ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, njustfile); - } - //printf("8"); - fclose(njustfile); - //printf("9"); - } else { - bbs_spy_rec.player_list = 0; - do { - bbs_spy_rec.player_list++; - sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); - } while (fexist(numstr)); - njustfile = ShareFileOpen(numstr, "wb"); - fclose(njustfile); - sprintf(numstr, SBYDBT_PREFIX".%03d", bbs_spy_rec.player_list); - njustfile = ShareFileOpen(numstr, "wb"); - for (x = 0; x < *InComing; x++) { - strcpy(ibscr_rec.name, InComing + 1 + ((25 + 36 + 1) * x)); - strcpy(ibscr_rec.nameI, InComing + 1 + ((25 + 36 + 1) * x) + 25); - ibscr_rec.level = -1; - ibscr_rec.sex = *(sex_type *) (InComing + (25 + 36 + 1) * (x + 1)); - //od_printf("++|%s|%s|%d|", ibscr_rec.name, ibscr_rec.nameI, (INT16)ibscr_rec.sex); - //od_get_answer("1"); - - ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, njustfile); + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + //printf("5"); + if (strcmp(InComing + 1 + ((25 + 36 + 1) * cnt), bbs_spy_rec.node) == 0) { + //printf("6"); + if (bbs_spy_rec.player_list != 0) { + //printf("7"); + sprintf(numstr, SBYDBT_PREFIX".%03d", bbs_spy_rec.player_list); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + for (x = 0; x < cnt; x++) { + strcpy(ibscr_rec.name, InComing + 1 + ((25 + 36 + 1) * x)); + strcpy(ibscr_rec.nameI, InComing + 1 + ((25 + 36 + 1) * x) + 25); + ibscr_rec.sex = *(sex_type *) (InComing + (25 + 36 + 1) * (x + 1)); + //printf("\n+|%s|%s|%d|\n", ibscr_rec.name, ibscr_rec.nameI, (INT16)ibscr_rec.sex); + //od_get_answer("1"); + + ibscr_rec.level = -1; + ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, njustfile); + } + //printf("8"); + fclose(njustfile); + //printf("9"); + } + } else { + bbs_spy_rec.player_list = 0; + do { + bbs_spy_rec.player_list++; + sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); + } while (fexist(numstr)); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) + fclose(njustfile); + sprintf(numstr, SBYDBT_PREFIX".%03d", bbs_spy_rec.player_list); + njustfile = ShareFileOpen(numstr, "wb"); + if(njustfile != NULL) { + for (x = 0; x < *InComing; x++) { + strcpy(ibscr_rec.name, InComing + 1 + ((25 + 36 + 1) * x)); + strcpy(ibscr_rec.nameI, InComing + 1 + ((25 + 36 + 1) * x) + 25); + ibscr_rec.level = -1; + ibscr_rec.sex = *(sex_type *) (InComing + (25 + 36 + 1) * (x + 1)); + //od_printf("++|%s|%s|%d|", ibscr_rec.name, ibscr_rec.nameI, (INT16)ibscr_rec.sex); + //od_get_answer("1"); + + ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, njustfile); + } + //printf("A"); + fclose(njustfile); + } + //printf("B"); + fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + //printf("C"); + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); } - //printf("A"); - fclose(njustfile); - //printf("B"); - fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); - //printf("C"); - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + break; } - break; + xx++; + fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + //printf("D"); } - xx++; - fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); - //printf("D"); + fclose(justfile); } - fclose(justfile); //printf("E"); free(InComing); //printf("\nKKK\n"); @@ -1050,68 +1075,74 @@ INT16 main(INT16 argc, char *argv[]) { //printf("J"); jfile = ShareFileOpen(*fname, "rb"); //printf("K"); + if(jfile != NULL) { - while (ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, jfile) == 1) { - //printf("L"); + while (ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, jfile) == 1) { + //printf("L"); - njustfile = ShareFileOpen(SBYDB_PREFIX""TEMP_EXTENSION, "r+b"); - justfile = ShareFileOpen(numstr, "a+b"); - found = FALSE; - //printf("M"); - x = 0; + njustfile = ShareFileOpen(SBYDB_PREFIX""TEMP_EXTENSION, "r+b"); + justfile = ShareFileOpen(numstr, "a+b"); + found = FALSE; + //printf("M"); + x = 0; - while (ny_fread(&ibscr_rec2, sizeof(ibbs_scr_rec), 1, njustfile) == 1) { + if(justfile!=NULL && njustfile != NULL) { + while (ny_fread(&ibscr_rec2, sizeof(ibbs_scr_rec), 1, njustfile) == 1) { - //printf("N"); - if (strcmp(ibscr_rec.nameI, ibscr_rec2.nameI) == 0) { - if (ibscr_rec2.level != -66) { - strcpy(ibscr_rec2.name, ibscr_rec.name); - ibscr_rec2.sex = ibscr_rec.sex; - ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile); + //printf("N"); + if (strcmp(ibscr_rec.nameI, ibscr_rec2.nameI) == 0) { + if (ibscr_rec2.level != -66) { + strcpy(ibscr_rec2.name, ibscr_rec.name); + ibscr_rec2.sex = ibscr_rec.sex; + ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile); + fseek(njustfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); + ibscr_rec2.level = -66; + ny_fwrite(&ibscr_rec2, sizeof(ibbs_scr_rec), 1, njustfile); + } + found = TRUE; + break; + } + //printf("O"); + x++; fseek(njustfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); - ibscr_rec2.level = -66; - ny_fwrite(&ibscr_rec2, sizeof(ibbs_scr_rec), 1, njustfile); } - found = TRUE; - break; + //printf("P"); + if (found == FALSE) + ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile); + fclose(njustfile); + fclose(justfile); } - //printf("O"); - x++; - fseek(njustfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); - } - //printf("P"); - if (found == FALSE) - ny_fwrite(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile); - fclose(njustfile); - fclose(justfile); - - //printf("Q"); + //printf("Q"); + } + //printf("R"); + fclose(jfile); } - //printf("R"); - fclose(jfile); - ny_remove(*fname); ny_remove(SBYDB_PREFIX""TEMP_EXTENSION); //printf("S"); justfile = ShareFileOpen(IBBSSPY_FILENAME, "r+b"); //fseek(justfile, 0, SEEK_SET); xx = 0; - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - if (bbs_spy_rec.player_list == cnt && cnt != 0) { - sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); - njustfile = ShareFileOpen(numstr, "rb"); - bbs_spy_rec.players = filelength(fileno(njustfile)) / sizeof(ibbs_scr_rec); - fclose(njustfile); + if(justfile != NULL) { + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + if (bbs_spy_rec.player_list == cnt && cnt != 0) { + sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); + njustfile = ShareFileOpen(numstr, "rb"); + if(njustfile != NULL) { + bbs_spy_rec.players = filelength(fileno(njustfile)) / sizeof(ibbs_scr_rec); + fclose(njustfile); + } + fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + break; + } + xx++; fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); - break; } - xx++; - fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + fclose(justfile); } - fclose(justfile); //printf("T"); } globfree(&ff); @@ -1156,7 +1187,7 @@ INT16 main(INT16 argc, char *argv[]) { if (act_rec.action == 0) { justfile = ShareFileOpen(IBBSSPY_FILENAME, "rb"); if (justfile != NULL) { - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + while (justfile != NULL && ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { if (strcmp(bbs_spy_rec.node, act_rec.node_s) == 0) { if (bbs_spy_rec.player_list == 0) { if (strcmp(act_rec.node_s, IBBSInfo.szThisNodeAddress) != 0) { @@ -1170,7 +1201,7 @@ INT16 main(INT16 argc, char *argv[]) { fclose(justfile); justfile = ShareFileOpen(numstr, "r+b"); x = 0; - while (ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile) == 1) { + while (justfile != NULL && ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile) == 1) { if (strcmp(ibscr_rec.nameI, act_rec.name_sI) == 0) { strcpy(ibscr_rec.name, act_rec.name_s); fseek(justfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); @@ -1181,11 +1212,11 @@ INT16 main(INT16 argc, char *argv[]) { fseek(justfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); } break; - } } } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } else { if (strcmp(act_rec.node_s, IBBSInfo.szThisNodeAddress) != 0) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d LISTREQ", ibbsi_game_num); @@ -1196,19 +1227,21 @@ INT16 main(INT16 argc, char *argv[]) { } else if (act_rec.action == 1) { justfile = ShareFileOpen(USER_FILENAME, "rb"); scr_spy_rec.nameI[0] = 0; - while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { - if (strcmp(urec_i.bbsname, act_rec.name_rI) == 0) { - strcpy(scr_spy_rec.name, urec_i.name); - strcpy(scr_spy_rec.nameI, urec_i.bbsname); - scr_spy_rec.nation = urec_i.nation; - scr_spy_rec.level = urec_i.level; - scr_spy_rec.points = urec_i.points; - scr_spy_rec.sex = urec_i.sex; - strcpy(scr_spy_rec.node, IBBSInfo.szThisNodeAddress); - break; + if(justfile != NULL) { + while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { + if (strcmp(urec_i.bbsname, act_rec.name_rI) == 0) { + strcpy(scr_spy_rec.name, urec_i.name); + strcpy(scr_spy_rec.nameI, urec_i.bbsname); + scr_spy_rec.nation = urec_i.nation; + scr_spy_rec.level = urec_i.level; + scr_spy_rec.points = urec_i.points; + scr_spy_rec.sex = urec_i.sex; + strcpy(scr_spy_rec.node, IBBSInfo.szThisNodeAddress); + break; + } } + fclose(justfile); } - fclose(justfile); if (scr_spy_rec.nameI[0] != 0) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d SPYINFO", ibbsi_game_num); IBSend(&IBBSInfo, act_rec.node_s, (char *)&scr_spy_rec, sizeof(ibbs_scr_spy_rec)); @@ -1227,13 +1260,13 @@ INT16 main(INT16 argc, char *argv[]) { justfile = ShareFileOpen(IBBSSPY_FILENAME, "rb"); if (justfile != NULL) { - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + while (justfile != NULL && ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { if (strcmp(bbs_spy_rec.node, scr_spy_rec.node) == 0 && bbs_spy_rec.player_list != 0) { sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); fclose(justfile); justfile = ShareFileOpen(numstr, "r+b"); x = 0; - while (ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile) == 1) { + while (justfile != NULL && ny_fread(&ibscr_rec, sizeof(ibbs_scr_rec), 1, justfile) == 1) { if (strcmp(ibscr_rec.nameI, scr_spy_rec.nameI) == 0) { strcpy(ibscr_rec.name, scr_spy_rec.name); ibscr_rec.nation = scr_spy_rec.nation; @@ -1245,12 +1278,14 @@ INT16 main(INT16 argc, char *argv[]) { break; } x++; - fseek(justfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); + if(justfile != NULL) + fseek(justfile, (INT32)x * sizeof(ibbs_scr_rec), SEEK_SET); } break; } } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } } //printf("~~~"); @@ -1266,13 +1301,15 @@ INT16 main(INT16 argc, char *argv[]) { strcpy(bbs_rec.node, IBBSInfo.szThisNodeAddress); justfile = ShareFileOpen(USER_FILENAME, "rb"); - bbs_rec.hi_points = 0; - cnt = 0; - while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { - if (urec_i.points > bbs_rec.hi_points) - bbs_rec.hi_points = urec_i.points; + if(justfile != NULL) { + bbs_rec.hi_points = 0; + cnt = 0; + while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { + if (urec_i.points > bbs_rec.hi_points) + bbs_rec.hi_points = urec_i.points; + } + fclose(justfile); } - fclose(justfile); if (IBSendAll(&IBBSInfo, (char *)&bbs_rec, sizeof(ibbs_bbs_rec)) != eSuccess) { printf("\n\nINTERBBS ERROR:Can't send the BBSINFO!!!\n\n"); @@ -1284,35 +1321,38 @@ INT16 main(INT16 argc, char *argv[]) { sprintf(IBBSInfo.szProgName, "#@NYG#%05d NAMELIST", ibbsi_game_num); justfile = ShareFileOpen(USER_FILENAME, "rb"); - cnt = filelength(fileno(justfile)) / sizeof(user_rec); - //printf("\n& Len of file: %ld len of user_rec : %ld", (INT32)filelength(fileno(justfile)), (INT32)sizeof(user_rec)); - OutGoing = (char *)malloc(((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); - OutGoing += 2; - x = 0; - //strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); - while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { - strcpy((OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); - //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); - strcpy(OutGoing + 1 + ((25 + 36 + 1) * x) + 25, urec_i.bbsname); - //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x) + 25), urec_i.bbsname); - *(OutGoing + (25 + 36 + 1) * (x + 1)) = (char)urec_i.sex; - //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); - x++; - } - strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); - if (x > 0) { - *OutGoing = cnt; - //printf("\nPlayers on the list: {%d}\n", cnt); - OutGoing -= 2; - *(INT16 *)OutGoing = ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 2; - IBSendAll(&IBBSInfo, OutGoing, ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); - } else { - OutGoing -= 2; + if(justfile != NULL) { + cnt = filelength(fileno(justfile)) / sizeof(user_rec); + //printf("\n& Len of file: %ld len of user_rec : %ld", (INT32)filelength(fileno(justfile)), (INT32)sizeof(user_rec)); + OutGoing = (char *)malloc(((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); + OutGoing += 2; + x = 0; + //strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); + while (ny_fread(&urec_i, sizeof(user_rec), 1, justfile) == 1) { + strcpy((OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); + //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); + strcpy(OutGoing + 1 + ((25 + 36 + 1) * x) + 25, urec_i.bbsname); + //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x) + 25), urec_i.bbsname); + *(OutGoing + (25 + 36 + 1) * (x + 1)) = (char)urec_i.sex; + //printf("\n[%d] - {%s} - |%s|", x, (OutGoing + 1 + ((25 + 36 + 1) * x)), urec_i.name); + x++; + } + strcpy(OutGoing + 1 + ((25 + 36 + 1) * cnt), IBBSInfo.szThisNodeAddress); + if (x > 0) { + *OutGoing = cnt; + //printf("\nPlayers on the list: {%d}\n", cnt); + OutGoing -= 2; + *(INT16 *)OutGoing = ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 2; + IBSendAll(&IBBSInfo, OutGoing, ((25 + 36 + 1) * cnt) + NODE_ADDRESS_CHARS + 4); + } else { + OutGoing -= 2; + } + fclose(justfile); + free(OutGoing); } - fclose(justfile); - free(OutGoing); justfile = ShareFileOpen(SENTLIST_FILENAME, "wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } if (!fexist(SENTBESTTEN_FILENAME)) { @@ -1339,7 +1379,8 @@ INT16 main(INT16 argc, char *argv[]) { } free(OutGoing); justfile = ShareFileOpen(SENTBESTTEN_FILENAME, "wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } } sprintf(IBBSInfo.szProgName, "#@NYG#%05d LISTREQ", ibbsi_game_num); @@ -1347,79 +1388,89 @@ INT16 main(INT16 argc, char *argv[]) { if (!fexist(IBBSSPY_FILENAME)) { IBSendAll(&IBBSInfo, IBBSInfo.szThisNodeAddress, NODE_ADDRESS_CHARS + 1); justfile = ShareFileOpen(IBBSSPY_FILENAME, "wb"); - for (x = 0; x < IBBSInfo.nTotalSystems; x++) { - if (strcmp(IBBSInfo.paOtherSystem[x].szAddress, IBBSInfo.szThisNodeAddress) != 0) { - strcpy(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress); - bbs_spy_rec.hi_points = 0; - bbs_spy_rec.players = 0; - bbs_spy_rec.player_list = 0; - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + if(justfile != NULL) { + for (x = 0; x < IBBSInfo.nTotalSystems; x++) { + if (strcmp(IBBSInfo.paOtherSystem[x].szAddress, IBBSInfo.szThisNodeAddress) != 0) { + strcpy(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress); + bbs_spy_rec.hi_points = 0; + bbs_spy_rec.players = 0; + bbs_spy_rec.player_list = 0; + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + } } + fclose(justfile); } - fclose(justfile); } else { justfile = ShareFileOpen(IBBSSPY_FILENAME, "r+b"); //fseek(justfile, 0, SEEK_SET); pack_spy = FALSE; xx = 0; - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - found = FALSE; - for (x = 0; x < IBBSInfo.nTotalSystems; x++) { - if (strcmp(IBBSInfo.paOtherSystem[x].szAddress, bbs_spy_rec.node) == 0) { - found = TRUE; - break; + if(justfile != NULL) { + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + found = FALSE; + for (x = 0; x < IBBSInfo.nTotalSystems; x++) { + if (strcmp(IBBSInfo.paOtherSystem[x].szAddress, bbs_spy_rec.node) == 0) { + found = TRUE; + break; + } } - } - if (found == FALSE) { - bbs_spy_rec.node[0] = 0; - fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + if (found == FALSE) { + bbs_spy_rec.node[0] = 0; + fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); - pack_spy = TRUE; + pack_spy = TRUE; + } + xx++; + fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); } - xx++; - fseek(justfile, (INT32)xx * sizeof(ibbs_bbs_spy_rec), SEEK_SET); + fclose(justfile); } - fclose(justfile); if (pack_spy == TRUE) { copyfile(IBBSSPY_FILENAME, IBBSSPY_TEMPFILENAME); justfile = ShareFileOpen(IBBSSPY_TEMPFILENAME, "rb"); njustfile = ShareFileOpen(IBBSSPY_FILENAME, "wb"); - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - if (bbs_spy_rec.node[0] != 0) { - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, njustfile); - } else if (bbs_spy_rec.player_list != 0) { - sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); - ny_remove(numstr); + if(justfile != NULL && njustfile != NULL) { + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + if (bbs_spy_rec.node[0] != 0) { + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, njustfile); + } else if (bbs_spy_rec.player_list != 0) { + sprintf(numstr, SBYDB_PREFIX".%03d", bbs_spy_rec.player_list); + ny_remove(numstr); + } } + fclose(justfile); + fclose(njustfile); } - fclose(justfile); - fclose(njustfile); ny_remove(IBBSSPY_TEMPFILENAME); } for (x = 0; x < IBBSInfo.nTotalSystems; x++) { found = FALSE; justfile = ShareFileOpen(IBBSSPY_FILENAME, "rb"); - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - if (strcmp(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress) == 0) { - found = TRUE; - if (bbs_spy_rec.player_list == 0 && strcmp(bbs_spy_rec.node, IBBSInfo.szThisNodeAddress) != 0) - IBSend(&IBBSInfo, bbs_spy_rec.node, IBBSInfo.szThisNodeAddress, NODE_ADDRESS_CHARS + 1); - break; + if(justfile != NULL) { + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + if (strcmp(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress) == 0) { + found = TRUE; + if (bbs_spy_rec.player_list == 0 && strcmp(bbs_spy_rec.node, IBBSInfo.szThisNodeAddress) != 0) + IBSend(&IBBSInfo, bbs_spy_rec.node, IBBSInfo.szThisNodeAddress, NODE_ADDRESS_CHARS + 1); + break; + } } + fclose(justfile); } - fclose(justfile); if (found == FALSE) { justfile = ShareFileOpen(IBBSSPY_FILENAME, "a+b"); strcpy(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress); bbs_spy_rec.hi_points = 0; bbs_spy_rec.players = 0; bbs_spy_rec.player_list = 0; - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile); + fclose(justfile); + } if (strcmp(bbs_spy_rec.node, IBBSInfo.szThisNodeAddress) != 0) IBSend(&IBBSInfo, bbs_spy_rec.node, IBBSInfo.szThisNodeAddress, NODE_ADDRESS_CHARS + 1); } @@ -1428,16 +1479,18 @@ INT16 main(INT16 argc, char *argv[]) { copyfile(IBBSSPY_FILENAME, IBBSSPY_TEMPFILENAME); justfile = ShareFileOpen(IBBSSPY_TEMPFILENAME, "rb"); njustfile = ShareFileOpen(IBBSSPY_FILENAME, "wb"); - while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { - for (x = 0; x < IBBSInfo.nTotalSystems; x++) { - if (strcmp(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress) == 0) { - ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, njustfile); - break; + if(justfile != NULL && njustfile != NULL) { + while (ny_fread(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, justfile) == 1) { + for (x = 0; x < IBBSInfo.nTotalSystems; x++) { + if (strcmp(bbs_spy_rec.node, IBBSInfo.paOtherSystem[x].szAddress) == 0) { + ny_fwrite(&bbs_spy_rec, sizeof(ibbs_bbs_spy_rec), 1, njustfile); + break; + } } } + fclose(njustfile); + fclose(justfile); } - fclose(njustfile); - fclose(justfile); ny_remove(IBBSSPY_TEMPFILENAME); } } @@ -1533,9 +1586,6 @@ FILE *ShareFileOpen(char *pszFileName, char *pszMode) { fpFile = fopen(pszFileName, pszMode); } - if(fpFile==NULL) - fpFile=fopen("cruft.tmp","w+"); - /* Return FILE pointer for opened file, if any. */ return (fpFile); } @@ -1582,9 +1632,6 @@ FILE *ShareFileOpenAR(char *pszFileName, char *pszMode) { } - if(fpFile==NULL) - fpFile=fopen("cruft.tmp","w+"); - /* Return FILE pointer for opened file, if any. */ return (fpFile); } diff --git a/src/doors/ny2008/src/second.cpp b/src/doors/ny2008/src/second.cpp index 485f9e2bfed6abbea777887bbc136c52f3bffc09..54ce9c708fa12d2c06faa8a7a9e369028579963f 100644 --- a/src/doors/ny2008/src/second.cpp +++ b/src/doors/ny2008/src/second.cpp @@ -217,9 +217,11 @@ newz_ops(void) { ch_game_d(); if (!fexist(YESNEWS_FILENAME) || !fexist(TODNEWS_FILENAME)) { justfile=ShareFileOpen(TODNEWS_FILENAME,"r+b"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); justfile=ShareFileOpen(YESNEWS_FILENAME,"r+b"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } if(rip==TRUE && oneframe==FALSE) { @@ -248,18 +250,22 @@ newz_ops(void) { else justfile=ShareFileOpen(YESNEWS_FILENAME,"rb"); - if(filelength(fileno(justfile))<sizeof(newzfile) && key=='T') { + if((justfile==NULL || filelength(fileno(justfile))<sizeof(newzfile)) && key=='T') { ny_line(413,1,1); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); justfile=ShareFileOpen(TODNEWS_FILENAME,"wb"); - fclose(justfile); - } else if(filelength(fileno(justfile))<sizeof(newzfile)) { + if(justfile != NULL) + fclose(justfile); + } else if(justfile == NULL || filelength(fileno(justfile))<sizeof(newzfile)) { ny_line(414,1,1); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); justfile=ShareFileOpen(YESNEWS_FILENAME,"wb"); - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } else { - while (ny_fread(&newzfile,sizeof(newzfile),1,justfile)==1) { + while (justfile != NULL && ny_fread(&newzfile,sizeof(newzfile),1,justfile)==1) { cnt+=2; if (newzfile.flag==0) { ny_disp_emu("\n\r`@"); @@ -339,11 +345,13 @@ newz_ops(void) { justfile=ShareFileOpen(TODNEWS_FILENAME,"rb"); else justfile=ShareFileOpen(YESNEWS_FILENAME,"rb"); - fseek(justfile,filepos,SEEK_SET); + if(justfile != NULL) + fseek(justfile,filepos,SEEK_SET); } } - fclose(justfile); + if(justfile != NULL) + fclose(justfile); } if(rip) od_send_file("frame2.rip"); @@ -371,11 +379,13 @@ news_post(char line[], char name1[], char name2[], INT16 flag) { ch_game_d(); justfile=ShareFileOpen(TODNEWS_FILENAME,"a+b"); - ny_fwrite(line,80,1,justfile); - ny_fwrite(name1,25,1,justfile); - ny_fwrite(name2,36,1,justfile); - ny_fwrite(&flag,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(line,80,1,justfile); + ny_fwrite(name1,25,1,justfile); + ny_fwrite(name2,36,1,justfile); + ny_fwrite(&flag,2,1,justfile); + fclose(justfile); + } if(c_dir==1) ch_flag_d(); @@ -1330,13 +1340,15 @@ get_laid_ops(void) { do { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); - do { - ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); - unum++; - //time_slice(); - } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.sex==cur_user.sex) && ret==1); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); + do { + ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); + unum++; + //time_slice(); + } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.sex==cur_user.sex) && ret==1); + fclose(justfile); + } } while (ret==1 && askifuser(urec.name)==FALSE); } if (ret!=1) { @@ -1354,9 +1366,11 @@ get_laid_ops(void) { ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); - ny_fread(&u2rec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); + ny_fread(&u2rec,sizeof(user_rec),1,justfile); + fclose(justfile); + } ny_line(134,1,1); // od_printf("\n\r`bright red`H`red`ow you gonna ask? (`bright red`/s`red`=save `bright red`/a`red`=abort):\n\r"); @@ -1364,14 +1378,16 @@ get_laid_ops(void) { ch_flag_d(); sprintf(numstr,"u%07d.tmg",nCurrentUserNumber); justfile=ShareFileOpen(numstr,"wb"); - cnt= -1; - ovr[0]=0; - do { - cnt++; - get_line(ovr,line,ovr,TRUE); - ny_fwrite(&line,80,1,justfile); - } while ((line[0]!='/' && (line[1]!='s' || line[1]!='S')) && (line[0]!='/' && (line[1]!='a' || line[1]!='A'))); - fclose(justfile); + if(justfile != NULL) { + cnt= -1; + ovr[0]=0; + do { + cnt++; + get_line(ovr,line,ovr,TRUE); + ny_fwrite(&line,80,1,justfile); + } while ((line[0]!='/' && (line[1]!='s' || line[1]!='S')) && (line[0]!='/' && (line[1]!='a' || line[1]!='A'))); + fclose(justfile); + } if (line[1]=='s' || line[1]=='S') { ny_line(135,0,1); // od_printf("`bright red`S`red`aving...\n\r"); @@ -1390,24 +1406,28 @@ get_laid_ops(void) { justfile=ShareFileOpen(numstr,"rb"); ch_game_d(); msg_file=ShareFileOpen(MAIL_FILENAME,"a+b"); - fillen=filelength(fileno(msg_file)); - fillen/=80; - mail_idx.location=fillen; - while ((cnt--)>0) { - ny_fread(&line,80,1,justfile); - ny_fwrite(&line,80,1,msg_file); - //time_slice(); + if(justfile != NULL && msg_file != NULL) { + fillen=filelength(fileno(msg_file)); + fillen/=80; + mail_idx.location=fillen; + while ((cnt--)>0) { + ny_fread(&line,80,1,justfile); + ny_fwrite(&line,80,1,msg_file); + //time_slice(); + } + fclose(msg_file); + fclose(justfile); } - fclose(msg_file); - fclose(justfile); ch_flag_d(); ny_remove(numstr); // sprintf(numstr,"del u%07d.tmg"); // system(numstr); ch_game_d(); msg_file=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); - fclose(msg_file); + if(msg_file != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); + fclose(msg_file); + } cur_user.sex_today--; if(single_node==FALSE && urec.online==TRUE) { ch_flag_d(); @@ -1416,9 +1436,11 @@ get_laid_ops(void) { omg[0]=27; omg[1]=0; justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } } if(rip) od_get_answer("\n\r"); @@ -1675,13 +1697,15 @@ money_ops(void) { do { ch_game_d(); justfile=ShareFileOpen(SCR_FILENAME,"rb"); - fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); - do { - ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); - unum++; - //time_slice(); - } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.user_num==nCurrentUserNumber) && ret==1); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(scr_rec) * (INT32)unum,SEEK_SET); + do { + ret=ny_fread(&urec,sizeof(scr_rec),1,justfile); + unum++; + //time_slice(); + } while ((strzcmp(hand,ny_un_emu(urec.name,numstr)) || urec.user_num==nCurrentUserNumber) && ret==1); + fclose(justfile); + } } while (ret==1 && askifuser(urec.name)==FALSE); } if (ret!=1) { @@ -1693,9 +1717,11 @@ money_ops(void) { } else if (hand[0]!=0) { ch_game_d(); justfile=ShareFileOpen(USER_FILENAME,"rb"); - fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); - ny_fread(&u2rec,sizeof(user_rec),1,justfile); - fclose(justfile); + if(justfile != NULL) { + fseek(justfile,sizeof(user_rec) * (INT32)urec.user_num,SEEK_SET); + ny_fread(&u2rec,sizeof(user_rec),1,justfile); + fclose(justfile); + } if(rip) { od_send_file("input.rip"); } @@ -1720,23 +1746,29 @@ money_ops(void) { mail_idx.inf=cur_user.std_percent; ch_game_d(); msg_file=ShareFileOpen(MAIL_FILENAME,"a+b"); - fillen=filelength(fileno(msg_file)); - fillen/=80; - mail_idx.location=fillen; - ny_fwrite(&intval,80,1,msg_file); - fclose(msg_file); + if(msg_file != NULL) { + fillen=filelength(fileno(msg_file)); + fillen/=80; + mail_idx.location=fillen; + ny_fwrite(&intval,80,1,msg_file); + fclose(msg_file); + } msg_file=ShareFileOpen(MAIL_INDEX,"a+b"); - ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); - fclose(msg_file); + if(msg_file != NULL) { + ny_fwrite(&mail_idx,sizeof(mail_idx_type),1,msg_file); + fclose(msg_file); + } if(single_node==FALSE && urec.online==TRUE) { ch_flag_d(); sprintf(numstr,"u%07d.omg",urec.user_num); omg[0]=27; omg[1]=0; justfile=ShareFileOpen(numstr,"a+b"); - ny_fwrite(&omg,51,1,justfile); - ny_fwrite(&cur_user.name,25,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fwrite(&omg,51,1,justfile); + ny_fwrite(&cur_user.name,25,1,justfile); + fclose(justfile); + } } if(!rip) WaitForEnter(); @@ -2826,15 +2858,17 @@ AskAgain: scr_file = ShareFileOpen(SCR_FILENAME, "a+b"); + if(fpUserFile != NULL && scr_file != NULL) { - /* Write the new record to the file. */ - if(ny_fwrite(&cur_user, sizeof(user_rec), 1, fpUserFile) == 1) { - /* If write succeeded, record that we now have a valid user record. */ - bGotUser = TRUE; + /* Write the new record to the file. */ + if(ny_fwrite(&cur_user, sizeof(user_rec), 1, fpUserFile) == 1) { + /* If write succeeded, record that we now have a valid user record. */ + bGotUser = TRUE; + } + ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); + fclose(scr_file); + fclose(fpUserFile); } - ny_fwrite(&scr_user, sizeof(scr_rec), 1, scr_file); - fclose(scr_file); - fclose(fpUserFile); ny_remove(SENTLIST_FILENAME); } @@ -2968,9 +3002,6 @@ FILE *ShareFileOpen(char *pszFileName, char *pszMode) { fpFile = fopen(pszFileName, pszMode); } - if(fpFile==NULL) - fpFile=fopen("cruft.tmp","w+"); - /* Return FILE pointer for opened file, if any. */ return fpFile; } @@ -3015,9 +3046,6 @@ FILE *ShareFileOpenAR(char *pszFileName, char *pszMode) { } - if(fpFile==NULL) - fpFile=fopen("cruft.tmp","w+"); - /* Return FILE pointer for opened file, if any. */ return fpFile; } @@ -3277,8 +3305,10 @@ nyr_disp_emu(char line[]) { } else if(line[cnt]=='d') { ch_game_d(); justfile=ShareFileOpen(GAMEDAY_FILENAME,"rb"); - ny_fread(&intval,2,1,justfile); - fclose(justfile); + if(justfile != NULL) { + ny_fread(&intval,2,1,justfile); + fclose(justfile); + } od_printf("%d",intval); } else if(line[cnt]=='h') od_printf("%s",D_Num(cur_user.hitpoints)); @@ -3843,8 +3873,10 @@ ibbs_bbs_scores(void) { if(strcmp(bbs_spy_rec.node,IBBSInfo.paOtherSystem[cnt].szAddress)==0) { if(strcmp(bbs_spy_rec.node,IBBSInfo.szThisNodeAddress)==0) { jfile=ShareFileOpen(SCR_FILENAME,"rb"); - ny_fread(&srec,sizeof(scr_rec),1,jfile); - fclose(jfile); + if(justfile != NULL) { + ny_fread(&srec,sizeof(scr_rec),1,jfile); + fclose(jfile); + } od_printf("`bright green`%-40s `dark green`%s\n\r",IBBSInfo.paOtherSystem[cnt].szSystemName,D_Num(srec.points)); } else { od_printf("`bright green`%-40s `dark green`%s\n\r",IBBSInfo.paOtherSystem[cnt].szSystemName,D_Num(bbs_spy_rec.hi_points)); @@ -3861,6 +3893,11 @@ ibbs_bbs_scores(void) { od_printf("\r \r"); cnt2=1; justfile=ShareFileOpen(IBBSSPY_FILENAME,"rb"); + if(justfile == NULL) { + ny_line(450,2,1); + WaitForEnter(); + return; + } fseek(justfile,filepos,SEEK_SET); if(key=='N') break; @@ -3925,6 +3962,11 @@ ibbs_bbs_name(INT16 bbs,INT16 sex,INT16 nochoice,char nameI[],INT16 *dbn,INT16 * fclose(justfile); justfile=ShareFileOpen(numstr,"rb"); + if(justfile==NULL) { + ny_line(450,0,1); + WaitForEnter(); + return; + } cnt2=4; if(nochoice) { @@ -3984,6 +4026,11 @@ ibbs_bbs_name(INT16 bbs,INT16 sex,INT16 nochoice,char nameI[],INT16 *dbn,INT16 * od_printf("\r \r"); cnt2=2; justfile=ShareFileOpen(numstr,"rb"); + if(justfile==NULL) { + ny_line(450,0,1); + WaitForEnter(); + return; + } fseek(justfile,filepos,SEEK_SET); if(key=='N') break; @@ -4007,6 +4054,11 @@ ibbs_bbs_name(INT16 bbs,INT16 sex,INT16 nochoice,char nameI[],INT16 *dbn,INT16 * od_disp_str("\n\r"); if(sex>0 && cnt<bbs_spy_rec.players) { justfile=ShareFileOpen(numstr,"rb"); + if(justfile==NULL) { + ny_line(450,0,1); + WaitForEnter(); + return; + } fseek(justfile,cnt*sizeof(ibbs_scr_rec),SEEK_SET); ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); strcpy(nameI,ibscr_rec.nameI); @@ -4018,6 +4070,11 @@ ibbs_bbs_name(INT16 bbs,INT16 sex,INT16 nochoice,char nameI[],INT16 *dbn,INT16 * } } while(cnt>=bbs_spy_rec.players); justfile=ShareFileOpen(numstr,"rb"); + if(justfile==NULL) { + ny_line(450,0,1); + WaitForEnter(); + return; + } fseek(justfile,cnt*sizeof(ibbs_scr_rec),SEEK_SET); ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); strcpy(nameI,ibscr_rec.nameI); @@ -4080,9 +4137,11 @@ ibbs_ops(void) { cur_user.InterBBSMoves--; sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } strcpy(act_rec.name_rI,ibscr_rec.nameI); strcpy(act_rec.name_sI,cur_user.bbsname); @@ -4110,9 +4169,11 @@ ibbs_ops(void) { if(hand[0]!=0) { sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=0; if (ibscr_rec.sex!=cur_user.sex && cur_user.sex_today>0) { @@ -4223,9 +4284,11 @@ ibbs_ops(void) { if(hand[0]!=0) { sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=0; if (ibscr_rec.sex!=cur_user.sex && cur_user.sex_today>0) { @@ -4303,9 +4366,11 @@ ibbs_ops(void) { cur_user.InterBBSMoves--; sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=1002; ibmail.quote_length=0; @@ -4411,9 +4476,11 @@ ibbs_ops(void) { money_minus(money); sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=1005; ibmail.quote_length=0; @@ -4504,9 +4571,11 @@ ibbs_ops(void) { money_minus(money); sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=1004; ibmail.quote_length=0; @@ -4570,9 +4639,11 @@ ibbs_ops(void) { money_minus(money); sprintf(numstr,SBYDB_PREFIX".%03d",dbn); justfile=ShareFileOpen(numstr,"rb"); - fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); - ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); - fclose(justfile); + if(justfile!=NULL) { + fseek(justfile,pn*sizeof(ibbs_scr_rec),SEEK_SET); + ny_fread(&ibscr_rec,sizeof(ibbs_scr_rec),1,justfile); + fclose(justfile); + } ibmail.flirt=1003; ibmail.quote_length=0;