⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 char.c

📁 石器时代8.0服务端完整源代码。可以直接编译
💻 C
📖 第 1 页 / 共 3 页
字号:
					}				}				else {					fclose( fp_new);				}			}						// 移仓库档			makeCharPoolItemFileName( id, fn_new, sizeof(fn_new));			fp_new = fopen( fn_new, "r");			if( fp_new == NULL ) {				makeSleepCharPoolItemFileName( id, fn_old, sizeof(fn_old));				fp_old = fopen( fn_old, "r");				if( fp_old != NULL ) {					fclose( fp_old);					rename( fn_old, fn_new); // 搬移					//filecopy( fn_old, fn_new); // 复制					log(" 移档_%s ", fn_new);				}			}			else {				fclose( fp_new);			}					}#endif		#ifdef _DEATH_FAMILY_LOGIN_CHECK//无法读取人物资料		if( loadCharNameAndOption( id , listbuf,sizeof(listbuf)) == 0 ){			saacproto_ACCharList_send( ti , FAILED , "locked" , mesgid );			return;		}#endif		#ifdef _DEATH_CONTEND //无法读取人物资料		if( loadCharNameAndOption( id , listbuf,sizeof(listbuf)) == 0 ){			saacproto_ACCharList_send( ti , FAILED , "locked" , mesgid );			return;		}#else    loadCharNameAndOption( id , listbuf,sizeof(listbuf));#endif    // Arminius    saacproto_ACCharList_send( ti ,  SUCCESSFUL , listbuf , mesgid);    total_ok_charlist++;#endif}void charDeleteCallback( int ti , int auth ,												char *c0 , char *c1 , char *c2 , char *c3 ,												char *c4 , int i0 , int i1 ){	int charindex;	char *id = c0;	char *charname = c2;	int mesgid = i0;	struct tm *now;	time_t timenow;	char logfile[128];		if( auth != 0 ){		char data[100];		snprintf( data, sizeof( data ) , "%d" , auth );		saacproto_ACCharDelete_send( ti , FAILED , data, mesgid );		return;	}        			charindex = getCharIndexByName( id , charname );	if( charindex < 0 ){		saacproto_ACCharDelete_send( ti , FAILED , "nochar",  mesgid );		return;	}   	if( unlinkCharFile( id , charindex ) < 0 ){		saacproto_ACCharDelete_send( ti , FAILED , "fileI/O" , mesgid);		return;	}#ifdef	__FAMILY	// CoolFish: Family 2001/6/12	{		int index = 0, fmindex = 0, fmcharindex = 0;		char fmname[32];		index = ACgetFMInfoFromChar(fmname, &fmindex, charname, id, &fmcharindex);		if (index != -1)		{			if (fmcharindex == 0)			{#ifdef _FMVER21				if (ChangeFMLeader(index, fmname, fmindex) >= 0)				{					if (ACDelFM(index, fmname, fmindex) >= 0)						log("ACDelFM index:%d fmname:%s fmindex:%d charname:%s, charid:%s, charindex:%d\n",						index, fmname, fmindex, charname, id, fmcharindex);				}				log("ChangeFMLeader_3 index:%d fmname:%s fmindex:%d\n", index, fmname, fmindex);#else				if (ACDelFM(index, fmname, fmindex) >= 0)					log("ACDelFM index:%d fmname:%s fmindex:%d charname:%s, charid:%s, charindex:%d\n",					index, fmname, fmindex, charname, id, fmcharindex);#endif			}			else 			{#ifdef _FMVER21				if (ACMemberLeaveFM(index, fmname, fmindex, charname, 0, 0, fmcharindex) >= 0)					log("ACMemberLeaveFM index:%d fmname:%s fmindex:%d charname:%s, charid:%s, charindex:%d\n",					index, fmname, fmindex, charname, id, fmcharindex);#else				if (ACMemberLeaveFM(index, fmname, fmindex, charname, 0, fmcharindex) >= 0)					log("ACMemberLeaveFM index:%d fmname:%s fmindex:%d charname:%s, charid:%s, charindex:%d\n",					index, fmname, fmindex, charname, id, fmcharindex);#endif			}		}	}#endif    	// Spock 2000/12/6	time( &timenow );	now = localtime( &timenow );	sprintf( logfile , "log/chardel/%04d%02d%02d.log" ,		now->tm_year + 1900 , now->tm_mon + 1 , now->tm_mday );	LOGBASE( logfile , "%04d/%02d/%02d %02d:%02d:%02d id:[%s] char:[%s] index:[%d]\n" ,		now->tm_year + 1900 , now->tm_mon + 1 , now->tm_mday ,		now->tm_hour , now->tm_min , now->tm_sec ,		id , charname , charindex );	// Spock end	USERLOG( id , "chardelete: successful\n" );	saacproto_ACCharDelete_send( ti ,  SUCCESSFUL , "ok" , mesgid);}void dummyCallback( int ti , int auth ,									 char *c0 , char *c1 , char *c2 , char *c3 ,									 char *c4 , int i0 , int i1 ){	return;}static void getCharNameFromString(char*str ,char *out ){	int c;		out[0]='\0';	for(c=0;;c++){		if( IS_2BYTEWORD( str[c] ) ){			out[c] = str[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;}#ifdef _CHECK_BADFILESint backupBadcharfile( char *filename, char *cdkey, int num){	char file1[256],file2[256];	char userpath[256];	FILE *fp;		log("backupBadcharfile( %s) -%s.%d-%s\n", filename, cdkey, num, userpath);	sprintf( userpath , "%s.%d.char" , cdkey , num );	sprintf( file1, "char/0x%x/%s", getHash(cdkey) & 0xff, userpath);	sprintf( file2, "badchar/%s", userpath);	{		char buf[1024];		int f;		bzero(buf,sizeof(buf));		f=open( file1, O_RDONLY);		if ( f <= 0 ){			log( "Can't open %s..\n", file1);			return 1;		}		lseek( f, -4, SEEK_END);		read(f,buf,4);		close(f);		if ((buf[2]=='\\')&&(buf[3]=='n')&&			(buf[0]=='\\')&&(buf[1]=='z')){			return 1;		}	}	if (mkdir("badchar", 0755) == 0)		log("create %s\n", "badchar");	sprintf( file2, "./badchar/%s", filename);	fp = fopen( file2, "a+");	if( fp == NULL ){				log("create file:%s error !!\n", file1);		return -1;	}	fprintf( fp, "%s %s\n", cdkey, file1);	fclose( fp);		log("backup badcharfile:%s..\n", userpath);	return -1;}#endifint 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);#ifdef _CHECK_BADFILES	if( backupBadcharfile( "badfilelist.txt", id, num) < 0 ){		return -1;	}#endif	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);	#if 0 //_SLEEP_CHAR // 旧档也存	{		char fn1[1024], fn2[1024];		makeSleepCharFileName( id , fn1 , sizeof(fn1),num );		fp = fopen( fn1 , "w" );		if( fp != NULL ) {			fprintf( fp , "%s" , input );			fclose(fp);		}				// 复制新仓库档到旧档		makeCharPoolItemFileName( id, fn1, sizeof(fn));		makeSleepCharPoolItemFileName( id, fn2, sizeof(fn));		filecopy( fn1, fn2);	}#endif#ifdef _SQL_BACKGROUND	sasql_update(id,fn);	sasql_online(id,NULL);#endif	log( "写入 %s 档案文件:%s\n",id , fn );	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 ));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -