void init_crypto(void) { if (mpz_init_set_str(&groupgenerator, MODP_GENERATOR, 10) != 0 || mpz_init_set_str(&generator_dh22, MODP_GENERATOR_DH22, 16) != 0 || mpz_init_set_str(&generator_dh23, MODP_GENERATOR_DH23, 16) != 0 || mpz_init_set_str(&generator_dh24, MODP_GENERATOR_DH24, 16) != 0 /* modp768_modulus no longer supported */ || mpz_init_set_str(&modp1024_modulus, MODP1024_MODULUS, 16) != 0 || mpz_init_set_str(&modp1536_modulus, MODP1536_MODULUS, 16) != 0 || mpz_init_set_str(&modp2048_modulus, MODP2048_MODULUS, 16) != 0 || mpz_init_set_str(&modp3072_modulus, MODP3072_MODULUS, 16) != 0 || mpz_init_set_str(&modp4096_modulus, MODP4096_MODULUS, 16) != 0 || mpz_init_set_str(&modp6144_modulus, MODP6144_MODULUS, 16) != 0 || mpz_init_set_str(&modp8192_modulus, MODP8192_MODULUS, 16) != 0 || mpz_init_set_str(&dh22_modulus, MODP1024_MODULUS_DH22, 16) != 0 || mpz_init_set_str(&dh23_modulus, MODP2048_MODULUS_DH23, 16) != 0 || mpz_init_set_str(&dh24_modulus, MODP2048_MODULUS_DH24, 16) != 0 ) exit_log("mpz_init_set_str() failed in init_crypto()"); #ifdef USE_TWOFISH ike_alg_twofish_init(); #endif #ifdef USE_SERPENT ike_alg_serpent_init(); #endif #ifdef USE_AES ike_alg_aes_init(); #endif #ifdef USE_3DES ike_alg_add((struct ike_alg *) &crypto_encrypter_3des); #endif #ifdef USE_SHA2 ike_alg_sha2_init(); #endif #ifdef USE_SHA1 ike_alg_add((struct ike_alg *) &crypto_hasher_sha1); ike_alg_add((struct ike_alg *) &crypto_integ_sha1); #endif #ifdef USE_MD5 ike_alg_add((struct ike_alg *) &crypto_hasher_md5); ike_alg_add((struct ike_alg *) &crypto_integ_md5); #endif }
void init_crypto(void) { if (mpz_init_set_str(&groupgenerator, MODP_GENERATOR, 10) != 0 || mpz_init_set_str(&modp768_modulus, MODP768_MODULUS, 16) != 0 || mpz_init_set_str(&modp1024_modulus, MODP1024_MODULUS, 16) != 0 || mpz_init_set_str(&modp1536_modulus, MODP1536_MODULUS, 16) != 0 || mpz_init_set_str(&modp2048_modulus, MODP2048_MODULUS, 16) != 0 || mpz_init_set_str(&modp3072_modulus, MODP3072_MODULUS, 16) != 0 || mpz_init_set_str(&modp4096_modulus, MODP4096_MODULUS, 16) != 0 || mpz_init_set_str(&modp6144_modulus, MODP6144_MODULUS, 16) != 0 || mpz_init_set_str(&modp8192_modulus, MODP8192_MODULUS, 16) != 0) exit_log("mpz_init_set_str() failed in init_crypto()"); ike_alg_add((struct ike_alg *) &crypto_encryptor_des); ike_alg_add((struct ike_alg *) &crypto_encryptor_3des); ike_alg_add((struct ike_alg *) &crypto_hasher_sha1); ike_alg_add((struct ike_alg *) &crypto_hasher_md5); ike_alg_init(); }
int mameql_exec(char *target) { char filename[FILENAME_MAX+1]; struct stat binname_sb; FILE *fpin; FILE *fpout; int i,c; if ( help ) return -1; if ( binname == NULL ) { return -1; } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".ql"); } else { strcpy(filename,outfile); } if ( description == NULL ) { description = binname; } if ((origin == -1) && ((crtfile == NULL) || ((origin = get_org_addr(crtfile)) == -1))) { origin = 0; } if ( exec == -1 ) { exec = origin; } if ( stat(binname, &binname_sb) < 0 || ( (fpin=fopen_bin(binname, NULL) ) == NULL )) { exit_log(1,"Can't open input file %s\n",binname); } if ( ( fpout = fopen(binname, "rb")) == NULL ) { exit_log(1,"Can't open input file %s\n", binname); } if ( ( fpout = fopen(filename, "wb")) == NULL ) { exit_log(1,"Can't open output file %s\n", filename); } /* Header */ writebyte(0xfd, fpout); writebyte(0x00, fpout); writebyte(0x80, fpout); writebyte(0x00, fpout); writebyte(0x00, fpout); writebyte(0xf9, fpout); writebyte(0x01, fpout); // Varies, what is it? /* Write the program name */ for ( i = 0; i < strlen(description); i++ ) { writebyte(description[i], fpout); } // Description terminator writebyte(0x1a, fpout); // Exec address writeword(exec, fpout); // Start address writeword(origin, fpout); // End address writeword(origin + binname_sb.st_size - 1, fpout); for ( i = 0; i < binname_sb.st_size; i++) { c = getc(fpin); writebyte(c,fpout); } fclose(fpin); fclose(fpout); return 0; }
int main(int argc,char *args[]) { int n,c; unsigned long long prof,start,end; end_of_data_ptr=sbrk(0); time_now=time(NULL); printf("\n"); printf(" ********************************************\n"); printf(" * Astonia 3 - The Conflict Server *\n"); printf(" * Version %d.%02d.%02d *\n",VERSION>>16,(VERSION>>8)&255,VERSION&255); printf(" ********************************************\n"); printf(" * Copyright (C) 2001-2008 Intent Software *\n"); printf(" * Copyright (C) 1997-2001 Daniel Brockhaus *\n"); printf(" ********************************************\n"); printf("\n"); if (argc>1) { while (1) { c=getopt(argc,args,"a:m:i:dhc"); if (c==-1) break; switch (c) { case 'a': if (optarg) areaID=atoi(optarg); break; case 'm': if (optarg) areaM=atoi(optarg); break; case 'd': demon=1; break; case 'h': fprintf(stderr,"Usage: %s [-a <areaID>] [-m <mirror>] [-n <use this class A net>] [-d] [-c]\n\n-d Demonize\n-c Disable concurrent database access\n\n",args[0]); exit(0); case 'c': multi=0; break; //case 'n': if (optarg) server_net=atoi(optarg); break; case 'i': if (optarg) serverID=atoi(optarg); break; } } } if (!areaID) { printf("No areaID given, assuming areaID=1\n"); areaID=1; } if (!areaM) { printf("No mirror given, assuming areaM=1\n"); areaM=1; } if (!serverID) { printf("No serverID given, assuming serverID=1\n"); serverID=1; } #ifdef STAFF while (!check_staff_start()) sleep(1); #endif // set character number limit depending on area switch(areaID) { case 1: maxchars=512; break; case 2: maxchars=896; break; case 3: maxchars=384; break; case 4: maxchars=2048; break; case 5: maxchars=768; break; case 6: maxchars=384; break; case 7: maxchars=1280; break; case 8: maxchars=384; break; case 9: maxchars=1280; break; case 10: maxchars=512; break; case 11: maxchars=384; break; case 12: maxitem=1024*48; maxchars=384; break; case 13: maxchars=9*50+200; break; case 14: maxchars=16*50+200; break; case 15: maxchars=384; break; case 16: maxchars=384; break; case 17: maxchars=512; break; case 18: maxchars=768; break; case 19: maxchars=384; break; case 20: maxchars=768; break; case 21: maxchars=768; break; case 22: maxchars=512; break; case 23: maxchars=512; break; case 24: maxchars=384; break; case 25: maxchars=384+8*25*2; break; case 26: maxchars=256; break; case 27: maxchars=2048; break; case 28: maxchars=384; break; case 29: maxchars=512; break; case 30: maxchars=384; break; case 31: maxitem=1024*40; maxchars=512; break; case 32: maxchars=1280; break; case 33: maxchars=1600; break; case 34: maxchars=1280; break; case 35: maxchars=768; break; case 36: maxchars=768; break; case 37: maxchars=1024; break; default: maxchars=768; break; } // set item and effect limit if (!maxitem) maxitem=max(maxchars*12+10240,20480); if (!maxeffect) maxeffect=max(maxchars*2,1024); printf("serverID=%d, areaID=%d, areaM=%d, maxchars=%d, maxitem=%d, maxeffect=%d\n\n", serverID,areaID,areaM,maxchars,maxitem,maxeffect); if (demon) { printf("Demonizing...\n\n"); if (fork()) exit(0); for (n=0; n<256; n++) close(n); setsid(); #ifndef STAFF nologin=1; #endif } // ignore the silly pipe errors: signal(SIGPIPE,SIG_IGN); // ignore sighup - just to be safe signal(SIGHUP,SIG_IGN); /*signal(SIGSEGV,sig_crash); signal(SIGFPE,sig_crash); signal(SIGBUS,sig_crash); signal(SIGSTKFLT,sig_crash);*/ // shutdown gracefully if possible: signal(SIGQUIT,sig_leave); signal(SIGINT,sig_leave); signal(SIGTERM,sig_leave); // show profile info on CTRL-Z signal(SIGTSTP,sig_showprof); // init random number generator srand(time_now); if (!init_smalloc()) exit(1); if (!init_mem()) exit(1); if (!init_prof()) exit(1); if (!init_log()) exit(1); if (!init_database()) exit(1); if (!init_lookup()) exit(1); if (!init_sector()) exit(1); if (!init_los()) exit(1); if (!init_timer()) exit(1); if (!init_notify()) exit(1); if (!init_create()) exit(1); if (!init_lib()) exit(1); if (!init_io()) exit(1); if (!init_path()) exit(1); if (!init_effect()) exit(1); if (!init_container()) exit(1); if (!init_store()) exit(1); if (!init_chat()) exit(1); init_sound_sector(); xlog("AreaID=%d, AreaM=%d, entering game loop...",areaID,areaM); dlog(0,0,"Server started"); prof_reset(); while (!quit) { sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (busy)",areaID,areaM,serverID,online,(10000-server_idle)/100); start=rdtsc(); lock_server(); time_now=time(NULL); prof=prof_start(26); tick_date(); prof_stop(26,prof); prof=prof_start(22); tick_timer(); prof_stop(22,prof); prof=prof_start(4); tick_char(); prof_stop(4,prof); prof=prof_start(24); tick_effect(); prof_stop(24,prof); prof=prof_start(36); tick_clan(); prof_stop(36,prof); prof=prof_start(39); tick_club(); prof_stop(39,prof); prof=prof_start(5); tick_player(); prof_stop(5,prof); prof=prof_start(34); tick_login(); prof_stop(34,prof); prof=prof_start(6); pflush(); prof_stop(6,prof); prof=prof_start(7); io_loop(); prof_stop(7,prof); prof=prof_start(3); tick_chat(); prof_stop(3,prof); if (showprof) { show_prof(); showprof=0; } prof=prof_start(8); prof_update(); prof_stop(8,prof); end=rdtsc(); cycles=end-start; if ((ticker&2047)==0) { prof=prof_start(27); area_alive(0); prof_stop(27,prof); prof=prof_start(28); backup_players(); prof_stop(28,prof); call_stat_update(); read_motd(); reinit_log(); } if ((ticker&255)==0) { call_check_task(); call_area_load(); shutdown_warn(); #ifdef STAFF check_staff_stop(); #endif } if ((ticker&255)==168) { prof=prof_start(38); consistency_check_items(); consistency_check_map(); consistency_check_chars(); consistency_check_containers(); prof_stop(38,prof); } unlock_server(); sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (idle)",areaID,areaM,serverID,online,(10000-server_idle)/100); prof=prof_start(1); tick_sleep(0); prof_stop(1,prof); ticker++; } xlog("Left game loop"); respawn_check(); for (n=1; n<MAXCHARS; n++) { if (ch[n].flags&CF_PLAYER) { exit_char(n); } } area_alive(1); show_prof(); dlog(0,0,"Server stopped"); xlog("map check"); check_map(); exit_lib(); exit_database(); xlog("Clean shutdown"); showmem(); exit_log(); exit_io(); return 0; }
int main(int argc, char *argv[]) { if (argc < 2) { printf("arguments too few!\n"); printf("Usage:\t%s filename.\n",argv[0]); exit(1); } init_log(Log.logfile, "debug"); FILE *f; char *filepath = argv[1]; struct stat buf; //get the file status in order to check whether it is a regular file if(lstat(argv[1],&buf) < 0){ debuglog("Get %s status failed!\n",argv[1]); printf("Get %s status failed!\n",argv[1]); exit(1); } if(!S_ISREG(buf.st_mode)){ debuglog("%s is not a regular file!\n",argv[1]); printf("%s is not a regular file!\n",argv[1]); exit(1); } if (!(f = fopen(filepath, "rb"))) { debuglog("Failure to open stream \"%s\"!\n",argv[1]); printf("Failure to open stream \"%s\"!\n",argv[1]); exit(1); } if (!check_file(f)) { debuglog("Could not find start of Header - check stream!\n"); printf("Could not find start of Header - check stream!\n"); exit(1); } init_pidlist(&pidlist); //static char buf[BUF_SIZE];如何使用缓冲呢? //setbuf(f,buf); int packet = 0; int total = get_total_packet(f); printf("totalpackets:%d\n", total); printf("processing...\n"); while (!feof(f) && !error) { handle_packet(packet++, f); //printf("\b\b\b%.2d%%",(int)(100 *(float)packet/total)); } printf("\ndone!\n"); fclose(f); exit_log(); int i = 0; for(i=0;i<128;i++){ if(globle_epg[i].service_provider_name[0] == '\0') continue; printf("globle_epg[%d].service_provider_name:%s\t",i,globle_epg[i].service_provider_name); printf("globle_epg[%d].service_name:%s\t",i,globle_epg[i].service_name); printf("globle_epg[%d].event_name:%s\t",i,globle_epg[i].event_name); printf("globle_epg[%d].start_date:%d\t",i,globle_epg[i].start_date); printf("globle_epg[%d].start_time:%u\t",i,globle_epg[i].start_time); printf("globle_epg[%d].duration:%u\n",i,globle_epg[i].duration); } return 0; }