char *NPC_Util_GetArgStr(int index, char *argstr, int len) { char filename[128]; char *cret = NULL; if (NPC_Util_CheckAssignArgFile(index, filename) != NULL) { if (NPC_Util_MargeStrFromArgFile(filename, argstr, len) != NULL) { cret = argstr; } } else { if (CHAR_getChar(index, CHAR_NPCARGUMENT) != NULL) { strcpy(argstr, CHAR_getChar(index, CHAR_NPCARGUMENT)); cret = argstr; } else { cret = NULL; } } if (cret == NULL) print("File:%s\n", NPC_Util_CheckAssignArgFile(index, filename)); return (cret); }
/*#ifdef _JZ_NPCBUF CHAR_NPCBUFPOINT = CHAR_WORKEQUITFIRE, //NPC arg文件緩存指針 CHAR_NPCTIMERH32 = CHAR_WORKEQUITTHUNDER, //NPC 計時器(高32位) CHAR_NPCTIMERL32 = CHAR_WORKEQUITICE, //NPC 計時器(低32位) CHAR_NPCFILECTIMEH32 = CHAR_WORKEQUITWEAKEN, //讀NPC arg文件的時間(高32位) CHAR_NPCFILECTIMEL32 = CHAR_WORKEQUITBARRIER, //讀NPC arg文件的時間(低32位) //CHAR_NPCFILECTIME_HOUR = CHAR_WORKEQUITNOCAST, //讀NPC arg文件時的時鐘 //CHAR_NPCFILECTIME_MIN = CHAR_WORKEQUITFALLRIDE, //讀NPC arg文件時的分鐘 #endif*/ char *NPC_Util_GetArgStr( int index, char *argstr, int len) { char filename[128]; Char *ch; char *cret = NULL; struct stat buff; int fd; char opfile[128]; if( (ch = CHAR_getCharPointer( index)) == NULL ) { print("GetArgStr Not get CharPointer\n"); return NULL; //獲得NPC結構指針 } if( NPC_Util_CheckAssignArgFile( index, filename) != NULL ) { sprintf( opfile, "%s/%s", getNpcdir(),filename); if(stat(opfile,&buff)!=0) { print("NPC緩存機制 stat error:%s\n",strerror( errno )); buff.st_size = NPC_UTIL_GETARGSTR_BUFSIZE; }else{ buff.st_size++; } //if(buff.st_size > len)buff.st_size = len; cret = (char *)ch->workint[CHAR_NPCBUFPOINT]; //獲得NPC緩存指針 if( cret == NULL ) { //首先判斷NPC緩存是否已經加載數據 //未加載緩存,申請內存,並將文件內容讀到緩存中 loadarg: cret = allocateMemory((unsigned int)buff.st_size); //申請內存 memset( cret, 0,buff.st_size); if( cret == NULL ) { //判斷申請內存是否成功,如果不成功則採用舊的模式 //舊的文件即時讀取模式 //print("NPC BUF OLD LOAD FILE %d\n",buff.st_size); if( NPC_Util_MargeStrFromArgFile( opfile, argstr, len) != NULL ) { cret = argstr; } }else{ //新的NPC緩存模式 //print("NPC BUF NEW LOAD FILE %d\n",buff.st_size); if( NPC_Util_MargeStrFromArgFile( opfile, cret, buff.st_size) != NULL ) { //memcpy(cret,argstr,buff.st_size); ch->workint[CHAR_NPCBUFPOINT] = (int)cret; ch->workint[CHAR_NPCFILECTIMEH32] = (unsigned long)buff.st_mtime; }else{ freeMemory(cret); cret = NULL; } } }else { //print("NPC BUF NEW %d\n",buff.st_size); //已加載緩存,判斷是否數據被更改,如果沒被更改直接返回緩存指針,如果更改的話則GOTO到未加載緩存的代碼 //2個計時器暫時不用 //if(buff.st_size > NPC_UTIL_GETARGSTR_BUFSIZE)buff.st_size = NPC_UTIL_GETARGSTR_BUFSIZE; if((unsigned long)ch->workint[CHAR_NPCFILECTIMEH32] != (unsigned long)buff.st_mtime) { print("npc updata:%s\n",opfile); freeMemory(cret); cret = NULL; goto loadarg; } //memcpy(argstr,cret,buff.st_size); //cret = argstr; } }else { if( CHAR_getChar( index, CHAR_NPCARGUMENT) != NULL ){ strcpy( argstr, CHAR_getChar( index, CHAR_NPCARGUMENT)); cret = argstr; }else{ cret = NULL; } } if( cret == NULL ) print("File:%s\n", NPC_Util_CheckAssignArgFile( index, opfile)); return( cret); /* if( NPC_Util_CheckAssignArgFile( index, filename) != NULL ) { if( NPC_Util_MargeStrFromArgFile( filename, argstr, len) != NULL ) { cret = argstr; } }else { if( CHAR_getChar( index, CHAR_NPCARGUMENT) != NULL ){ strcpy( argstr, CHAR_getChar( index, CHAR_NPCARGUMENT)); cret = argstr; }else{ cret = NULL; } } if( cret == NULL ) print("File:%s\n", NPC_Util_CheckAssignArgFile( index, filename)); return( cret);*/ }