📄 char.c
字号:
c ++ ; // 戚及 侬尺 out[c] = str[c]; continue; } out[c] = str[c]; if( str[c] == '\0' )break; if( str[c] == SPACE ){ out[c] = '\0'; break; } }}static void getCharOptionFromString( char *str , char *out ){ int c; int outc = 0; out[outc] = '\0'; for(c=0;;c++){ if( str[c]=='\0')break; if( IS_2BYTEWORD( str[c] ) ){ c++; if( str[c] == '\0' )break; // 公及 侬互允匹卞NULL卅日蔽 continue; } if( str[c]== SPACE ){ c++; for(;;c++){ if( str[c] == '\0' ){ // 蔽 分匀凶日 NULL 木化蔽歹月 out[outc] = '\0'; break; } // 仇仇手ㄡ田奶玄 侬及ㄠ田奶玄 卅日手丹域田奶玄戊疋□允月 //---- For 2Byte Code ---- if( IS_2BYTEWORD( str[c] ) ){ out[outc++] = str[c++]; // ㄠ田奶玄 戊疋□ out[outc++] = str[c]; // ㄡ田奶玄 戊疋□ if( str[c] == '\0' )break; // 公及 侬互允匹卞NULL卅日蔽 continue; } // 骚橘 侬反ㄠ田奶玄戊疋□ out[outc] = str[c]; // 引内戊疋□ if( str[c] == '\0' )break; // 蔽 分匀凶日蔽歹月 if( str[c] == SPACE ){ out[outc] = '\0'; break; } outc++; } return; } }}void getCharInfoFromString( char *str , char *out ){ int c=0,outc=0; int space_counter=0; out[outc] = '\0'; for(c=0;;c++){ if( str[c]=='\0')break; if( IS_2BYTEWORD( str[c] ) ){ c++; continue; }else if( str[c]== SPACE ){ space_counter++; } if( space_counter==2 && str[c]== SPACE ){ c++; for(;;c++){ if( IS_2BYTEWORD( str[c] ) ){ out[outc++] = str[c++]; out[outc++] = str[c]; if( str[c] == '\0' ){ out[outc] = '\0'; break; } continue; } out[outc] = str[c]; if( str[c] == '\0' )break; if( str[c] == SPACE ){ out[outc] = '\0'; break; } outc++; } return; } }}static void makeCharFileName( char *id,char *output, int outlen, int num){ char body[1024]; if ( strlen( id) < 1)return; snprintf(body , sizeof(body ) , "%s.%d.char" , id , num ); makeDirFilename(output , outlen, chardir , getHash(id) ,body);}#ifdef _SLEEP_CHAR // 取得非活跃人物档名static void makeSleepCharFileName( char *id,char *output, int outlen, int num){ char body[1024]; if ( strlen( id) < 1)return; snprintf(body , sizeof(body ) , "%s.%d.char" , id , num ); makeDirFilename(output , outlen, sleepchardir , getHash(id) ,body);}#endifint loadCharNameAndOption( char *id , char *output , int outlen){ char chbuf[MAXCHAR_PER_USER][CHARDATASIZE]; char namework[CHARDATASIZE]; char optionwork[CHARDATASIZE]; char nm_work[CHARDATASIZE]; int i,count=0; int so_far_bytes = 0; output[0] = 0; for(i=0;i<MAXCHAR_PER_USER;i++){ int l; char delim[2]; chbuf[i][0] = 0; loadCharOne( id , i , chbuf[i] , sizeof( chbuf[i] )); getCharNameFromString( chbuf[i] , namework ); getCharOptionFromString( chbuf[i] , optionwork ); if( chbuf[i][0] == 0 )continue; if( strlen( output ) > 0 ){ delim[0] = SPACE; delim[1] = 0; } else { delim[0] = 0; } snprintf( nm_work , sizeof( nm_work ), "%s%s|%s" , delim,namework , optionwork ); l = strlen( nm_work ); if( ( so_far_bytes + l ) < outlen ){ strcat( output , nm_work ); so_far_bytes += l; count++; } } return count;}int loadCharOne( char *id , int num, char *output , int outlen ){ char fn[1024]; FILE *fp; char c_temp,*c_ptr; c_ptr=output; makeCharFileName( id , fn , sizeof(fn),num ); fp = fopen( fn , "r" ); if( fp == NULL ){ return -1; } do{ c_temp = fgetc(fp); *c_ptr=c_temp; c_ptr++; }while(c_temp != EOF); *c_ptr='\0'; if( output[0]=='|' && output[1]=='|' ){ return -1; } fclose(fp); return 0;}int saveCharOne( char *id , int num , char *input ){ char fn[1024]; FILE *fp; char *strp; char *strp1; // Won 修正 hp 为负的人 makeCharFileName( id , fn , sizeof(fn),num ); fp= fopen( fn , "w" ); if( fp == NULL ) { log( "save error 01: %d",errno );//Change add errno return -1; } // Won 修正 hp 为负的人 if ((strp=strstr(input,"\\nhp=-"))!=NULL) { strp1=strstr(input,"\\nmp="); *(strp+5)='1'; strcpy((strp+6), strp1); } // Arminius if ((strp=strstr(input,"\\nhp=0\\n"))!=NULL) *(strp+5)='1'; fprintf( fp , "%s" , input ); fclose(fp); log( "写入 %s 档案文件:%s\n",id , fn ); chmod(fn,0777); return 0; }static int makeSaveCharString( char *out , int outlen , char *nm , char *opt , char *info ){ char nmwork[CHARDATASIZE]; char optwork[CHARDATASIZE]; char infowork[CHARDATASIZE]; char outwork[CHARDATASIZE]; char *nmwork_p , *optwork_p , *infowork_p; int l; /* 戊疋□仄化 */ strncpy( nmwork , nm , sizeof( nmwork )); nmwork[strlen( nm)]=0; strncpy( optwork , opt , sizeof( optwork )); optwork[strlen(opt)]=0; strncpy( infowork , info , sizeof( infowork )); infowork[strlen(info)]=0; /* 巨旦弗□皿仄 */ /* if ( esc ) { nmwork_p = makeEscapeString1( nm , nmwork ,sizeof( nmwork )); optwork_p = makeEscapeString1( opt , optwork , sizeof( optwork )); infowork_p = makeEscapeString1( info , infowork , sizeof( infowork ));} else {*/ nmwork_p = makeEscapeString( nm , nmwork ,sizeof( nmwork )); optwork_p = makeEscapeString( opt , optwork , sizeof( optwork )); infowork_p = makeEscapeString( info , infowork , sizeof( infowork )); // } /* 勾卅仆月[赞中互巨仿□腹请及凶户卞域荚伐□弁卞中木月[ */ snprintf( outwork ,sizeof( outwork ) , "%s" SPACESTRING "%s" SPACESTRING "%s" , nmwork_p , optwork_p , infowork_p ); l = strlen( outwork ); if( l >= (outlen-1)){ return -1; } /* NULL 侬互 卞丐月井日0毛中木氏午中井氏及分[ */ memcpy( out , outwork , l + 1); return 0;}int getCharIndexByName( char *id , char *charname ){ int i; for(i=0;i<MAXCHAR_PER_USER;i++){ char output[CHARDATASIZE]; if( loadCharOne( id , i , output , sizeof( output )) < 0 ){ /* 丐中化中月″ */ continue; } else { /* 平乓仿互绣箕仄凶 */ char cn[CHARDATASIZE]; getCharNameFromString( output , cn ); /* Escape毛荸仁 */ if( strcmp( charname , makeStringFromEscaped(cn) ) == 0 ){ return i; }else{ } } } return -1;}/* 平乓仿及丐中化中月旦夫永玄毛腹绸允月 卅日丐中化中卅中[0动晓卅日丐五旦夫永玄及index. 签卞夫□玉匹五卅井匀凶日公木毛井尹允分仃[ 手匀午切扎氏午匹五月支欠仃升手[ */static int findBlankCharIndex( char *id ){ int i; char output[CHARDATASIZE]; for(i=0;i<MAXCHAR_PER_USER;i++){ if( loadCharOne( id , i , output , sizeof( output ) ) < 0 ){ return i; } } return -1;}static int unlinkCharFile( char *id , int num ){ char fname[1024];#ifdef _SLEEP_CHAR //删除人物时旧档也删 makeSleepCharFileName( id, fname, sizeof(fname),num ); unlink( fname );#endif makeCharFileName( id, fname, sizeof(fname),num ); return unlink( fname );}int lockUser( char *gmsvname , char *id , char *passwd , int lock , char *result, int resultlen, char *retdata , int retdatalen , char *process , char *deadline){ char fname[1024]; int ret = -1; if(!id[0]){ snprintf(result , resultlen , FAILED); snprintf(retdata , retdatalen , "bad id"); return -1; } retdata[0] = 0; if( lock ){ if (isLocked(id)) { snprintf( result , resultlen, FAILED ); snprintf( retdata , retdatalen, "already locked" ); log( "写入内存信息: 用户:%x/%s 已经同意锁定 !!\n", getHash(id), id); return -1; } else { if( InsertMemLock( getHash(id) & 0xff, id, passwd, gmsvname, atoi(process), deadline ) ) return 0; else return -1; } } else { if( !isLocked( id) ) { log( "删除内存信息: 用户:%x/%s 没有锁定!!\n", getHash(id), id); } if( DeleteMemLock( getHash(id) & 0xff, id, &ret) ) { snprintf( result , resultlen, SUCCESSFUL ); snprintf( retdata , retdatalen, "removed" ); return ret; } else { snprintf( result , resultlen, FAILED ); snprintf( retdata , retdatalen, "不能移除锁定" ); log( "不能解锁 %x:%s !\n", getHash(id), id); return ret; } }}int isLocked( char *id ){ if (!id[0]) return 1; // invalid id: lock it return isMemLocked(getHash(id) & 0xff, id);}int checkValidCharName( char *a){ int i; for(i=0;;i++){ if( a[i] == 0 )break; if( a[i] == SPACE )return -1; } return 0;}int filecopy( char *oldfilename, char *newfilename){ FILE *oldfile; FILE *newfile; char c_temp; if( (oldfile = fopen( oldfilename, "r") ) == NULL ) { return -1; } if( (newfile = fopen( newfilename, "w") ) == NULL ) { return -1; } while(1) { c_temp = fgetc( oldfile); if( c_temp == EOF) break; fputc( c_temp, newfile); }; fclose( oldfile); fclose( newfile); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -