int main () { char *key = "aaabbbccccdddd"; hashpjw (key); return 0; }
void make_inst_hash_tables( unsigned int count, sword *Words ) /*******************************************************************/ { char *name; unsigned i; unsigned *p; unsigned pos; unsigned size = sizeof( AsmOpTable ) / sizeof( AsmOpTable[0] ); index_table = calloc( count, sizeof( *index_table ) ); pos_table = calloc( count, sizeof( *pos_table ) ); for( pos = 0, i = 0; i < count; i++ ) { // create indexes for hash item lists name = Words[i].word; for( p = &inst_table[hashpjw( name )]; *p; p = &index_table[*p - 1] ) { if( stricmp( name, Words[*p - 1].word ) == 0 ) { break; } } if( *p == 0 ) { index_table[i] = 0; *p = i + 1; } // create index for position in AsmOpTable while ( AsmOpTable[pos] < i && pos < size ) pos++; if( AsmOpTable[pos] != i || pos >= size ) { printf( "Wrong data in asminsd.h. position=%d, index=%d\n", pos, i ); exit( 1 ); } pos_table[i] = pos; } }
void flushMail( int fd, char *id, char *charname ) { int i,c=0; unsigned int h ; char id_charname[1000]; #define MAX_FLUSH_MAIL 1024 int flush_index[MAX_FLUSH_MAIL]; int flush_i=0; snprintf( id_charname, sizeof( id_charname ) , "%s_%s", id, charname ); h = hashpjw( id_charname ); // Nuke +1 log("邮件缓冲大小:%d (%s)\n",mailbufsize,chartime()); // Nuke *1 for(i=0;(i<mailbufsize)&&(i<MAX_FLUSH_MAIL);i++){ if( mailbuf[i].id_charname_hash == h && mailbuf[i].use && strcmp( mailbuf[i].id_to , id ) == 0 && strcmp( mailbuf[i].charname_to, charname ) == 0 ){ log( "消息ID:%u\n", mailbuf[i].message_id ); flush_index[flush_i++] = i; c++; } } for(i=0; i< flush_i ; i++ ){ int j; for(j=0; j < flush_i-1 ; j++ ){ if( mailbuf[flush_index[j]].message_id > mailbuf[flush_index[j+1]].message_id ){ int sw = flush_index[j]; flush_index[j] = flush_index[j+1]; flush_index[j+1] = sw; log( "inverted %d and %d in %d \n", flush_index[j], flush_index[j+1], j ); } } } /* 端卞霜耨允月 */ for(i=0;i< flush_i; i++ ){ /* flush 及桦宁反}flush毛霜耨仄化五凶必□丞扔□田□卞 覆仄化分仃霜耨允木壬中中 */ saacproto_Message_send( fd, mailbuf[flush_index[i]].id_from, mailbuf[flush_index[i]].charname_from, mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to, mailbuf[flush_index[i]].text, mailbuf[flush_index[i]].option, mailbuf[flush_index[i]].message_id ); mailbuf[flush_index[i]].state = MS_WAIT_ACK; log( "分类邮件ID:%u\n", mailbuf[flush_index[i]].message_id ); } // Nuke *1 log( "邮件: 发送 %d 封邮件到 %s(%s)(%s)\n", c, id, charname ,chartime()); }
// Rebuild hash code void TypeInfo::_setup_hash() const { int h = hashpjw(name()); if (h == 0) h = 1; ((TypeInfo *)this)->_hash = h; }
void CHAR_initChatMagic(void) { int i; for(i = 0; i < arraysizeof(CHAR_cmtbl); i++) CHAR_cmtbl[i].hash = hashpjw(CHAR_cmtbl[i].magicname); for(i = 0; i < DEBUGCDKEYNUM; i++) { DebugCDKey[i].use = FALSE; DebugCDKey[i].cdkey[0] = '\0'; } }
int CHAR_getChatMagicFuncLevel(char *name, int isDebug) { int i; int hash = hashpjw(name); for(i = 0; i < arraysizeof(CHAR_cmtbl); i++) if(CHAR_cmtbl[i].hash == hash && CHAR_cmtbl[i].isdebug == isDebug && strcmp(CHAR_cmtbl[i].magicname, name) == 0) return CHAR_cmtbl[i].level; return -1; }
static CHATMAGICFUNC CHAR_getChatMagicFuncPointer(char *name, int isDebug) { int i; int hash = hashpjw(name); for(i = 0; i < arraysizeof(CHAR_cmtbl); i++) if(CHAR_cmtbl[i].hash == hash && CHAR_cmtbl[i].isdebug == isDebug && strcmp(CHAR_cmtbl[i].magicname, name) == 0) return CHAR_cmtbl[i].func; return NULL; }
void expireMail() { int i,c=0; unsigned int h ; char id_charname[1000]; time_t now=time(NULL); /* 1荚及flush 匹霜耨允月 醒 */ #define MAX_FLUSH_MAIL 1024 int flush_index[MAX_FLUSH_MAIL]; int flush_i=0; // Nuke +1 log("邮件缓冲大小:%d (%s)\n",mailbufsize,chartime()); // Nuke *1 for(i=0;(i<mailbufsize)&&(i<MAX_FLUSH_MAIL);i++){ if(mailbuf[i].use && (now - mailbuf[i].recv_time >= MAIL_EXPIRE_TIME)) { log( "消息ID:%u 已过期\n", mailbuf[i].message_id ); flush_index[flush_i++] = i; c++; } } /* 端卞霜耨允月 */ for(i=0;i< flush_i; i++ ){ snprintf( id_charname, sizeof( id_charname), "%s_%s", mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to ); h = hashpjw( id_charname ) & 0xff ; { char savefile[1024]; char childname[1000]; snprintf( childname,sizeof(childname),"%u", mailbuf[flush_index[i]].message_id ); makeDirFilename( savefile, sizeof(savefile),maildir, h, childname ); if( unlink( savefile ) != 0 ){ log( "failed to unlink %s: %s\n", savefile, strerror(errno )); } else { log( "过期邮件: 删除游戏 " "%u 从 %s(%s) 到 %s(%s)\n", mailbuf[flush_index[i]].message_id, mailbuf[flush_index[i]].id_from, mailbuf[flush_index[i]].charname_from, mailbuf[flush_index[i]].id_to, mailbuf[flush_index[i]].charname_to ); } memset( &mailbuf[flush_index[i]], 0 , sizeof( mailbuf[0] )); } } // Nuke *1 log( "过期邮件: 过期 %d 消息 (%s)\n", c ,chartime()); }
// Return list of defs for FUNC_NAME; 0 if not found VSLDefList* VSLLib::deflist(const string& func_name) const { unsigned hashcode = hashpjw(func_name.chars()) % hashSize; VSLDefList *d; for (d = defs[hashcode]; d != 0 && d->func_name() != func_name; d = d->next()) ; return d; }
/*------------------------------------------------------------ * Ù¯ ±å¸²É±ÔÊÔ template ¼° index ë߯ÔÊ£Û * ¦ÐÑ * templatename char* ¼þÃóÒÁ¡õÐþ¼° ó¡ * ߯Ի°À * -1 ¼°Áݾ޷¡õ ------------------------------------------------------------*/ int NPC_templateGetTemplateIndex( char* templatename ) { int i; int hash=hashpjw( templatename ); for( i = 0 ; i < NPC_templatenum ; i ++ ) if( hash == NPC_template[i].hash && strcasecmp( templatename , NPC_template[i].chardata[NPC_TEMPLATENAME].string) == 0 ) return i; return -1; }
void receiveMailAck( char *id, char *charname, int a , int mesgid ) { int i; unsigned int h; char id_charname[1024]; snprintf( id_charname, sizeof( id_charname), "%s_%s", id, charname ); h = hashpjw( id_charname ) & 0xff ; for(i=0;i<mailbufsize;i++){ if( mailbuf[i].message_id == mesgid ){ if( mailbuf[i].use && mailbuf[i].id_charname_hash == h && strcmp( mailbuf[i].id_to, id ) == 0 && strcmp( mailbuf[i].charname_to, charname ) == 0 && mailbuf[i].state == MS_WAIT_ACK ){ char savefile[1024]; char childname[1000]; snprintf( childname,sizeof(childname),"%u", mailbuf[i].message_id ); makeDirFilename( savefile, sizeof(savefile),maildir, h, childname ); if( unlink( savefile ) != 0 ){ log( "failed to unlink %s: %s\n", savefile, strerror(errno )); } else { log( "回复邮件: 删除邮件 " "%u 从 %s(%s) to %s(%s)\n", mailbuf[i].message_id, mailbuf[i].id_from, mailbuf[i].charname_from, mailbuf[i].id_to, mailbuf[i].charname_to ); } memset( &mailbuf[i], 0 , sizeof( mailbuf[0] )); return; } else { log( "回复邮件: 无用信息或ID或名称或声明严重错误" ); log( "use[%d] h[%d][%d] id[%s][%s] nm[%s][%s] st[%d]\n", mailbuf[i].use, mailbuf[i].id_charname_hash, h, mailbuf[i].id_to, id, mailbuf[i].charname_to, charname, mailbuf[i].state); } } } log( "回复邮件: 邮件 %u 不能从 %s(%s) 找到\n", mesgid, id,charname ); }
// Add definition to library VSLDef *VSLLib::add(const string& func_name, VSLNode *pattern, VSLNode *expr, bool global, const string& filename, int lineno) { BACKGROUND(); // Find DefList for function name VSLDefList *d = deflist(func_name); if (d == 0) { // Not found? Create a new DefList... unsigned hashcode = hashpjw(func_name.chars()) % hashSize; d = defs[hashcode]; defs[hashcode] = new VSLDefList(this, hashcode, func_name, global); defs[hashcode]->next() = d; // ...and return it d = defs[hashcode]; } // Append new def to DefList bool newFlag; VSLDef* newdef = d->add(newFlag, pattern, expr, filename, lineno); if (newFlag) { // Insert def into global list if (_last == 0) _first = newdef; else { _last->libnext() = newdef; newdef->libprev() = _last; } _last = newdef; } // Setup scope: Scope is global if any def is global. d->global() = d->global() || global; return newdef; }
void* getFunctionPointerFromName( char* funcname ) { int i; int hashcode; if( funcname == NULL || funcname[0] == '\0' ){ return NULL; } hashcode = hashpjw( funcname ); for( i=0 ; i<arraysizeof(correspondStringAndFunctionTable) ; i++ ) if( correspondStringAndFunctionTable[i].hashcode == hashcode ) if( strcmp( correspondStringAndFunctionTable[i].functionName.string,funcname ) == 0 ){ return correspondStringAndFunctionTable[i].functionPointer; } #ifdef DEBUG print("No such Function: %s\n" ,funcname ); #endif return NULL; }
/* * pp_generic_case_hash() - Assumes that p points to a GENERIC-compatible * struct, and hashes on the lowercased name field of that struct. * return : hash value * p(in): A pointer to a generic structure to be hashed. */ unsigned int pp_generic_case_hash (void *p) { char *s, *d, nam[256]; int i; GENERIC *gp; gp = (GENERIC *) p; s = gp->name; d = nam; if (s) { for (i = 0; *s && i < 256; s++, d++, i++) { *d = char_tolower (*s); } } *d = '\0'; return hashpjw (nam); }
BOOL initFunctionTable( void ) { int i; { char* strings[arraysizeof(correspondStringAndFunctionTable)]; int stringnum=0; for( i=0 ; i<arraysizeof(correspondStringAndFunctionTable) ; i++ ) strings[stringnum++] = correspondStringAndFunctionTable[i].functionName.string; if( ! checkStringsUnique( strings, stringnum , 1 ) ){ fprint("Function Name Table is overlapped.\n" ); fprint("It is not allowed\n"); return FALSE; } } for(i = 0; i < arraysizeof(correspondStringAndFunctionTable) ; i ++ ){ correspondStringAndFunctionTable[i].hashcode = hashpjw( correspondStringAndFunctionTable[i]. functionName.string); } return TRUE; }
static int64_t hash_string(char *s) { return hashpjw(s, strlen(s)); }
static int fldap_getattr(const char* path, struct stat* stbuf) { static char* attrs[] = {"stmode", "stnlink", "stuid", "stgid", "strdev", "stblksize", "stsize", "stblocks", "statime", "createtimest\ amp", "modifytimestamp", NULL}; int res = 0; struct tm tm = {0}; char* dn; LDAPMessage* msg = NULL; LDAPMessage* entry = NULL; BerElement* ber = NULL; char** vals; char* attr; memset(stbuf, 0, sizeof(struct stat)); dn = path_to_dn(path, "ou="); ldap_search_s(ld, dn, LDAP_SCOPE_BASE, "(ObjectClass=*)", attrs, 0, &msg); entry = ldap_first_entry(ld, msg); if (!entry) { ldap_msgfree(msg); free(dn); dn = path_to_dn(path, "cn="); ldap_search_s(ld, dn, LDAP_SCOPE_BASE, "(ObjectClass=*)", attrs, 0, &msg); if (!(entry = ldap_first_entry(ld, msg))) { ldap_msgfree(msg); free(dn); return -ENOENT; } } entry = ldap_first_entry(ld, msg); if (strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 2; } else if (entry == NULL) { res = -ENOENT; } else { for (attr = ldap_first_attribute(ld, entry, &ber); attr != NULL; attr = ldap_next_attribute(ld, entry, ber)) { if ((vals = ldap_get_values(ld, entry, attr)) != NULL) { switch (hashpjw(attr)) { case MODE_HASH: stbuf->st_mode = atoi(vals[0]); break; case NLINK_HASH: stbuf->st_nlink = atoi(vals[0]); break; case UID_HASH: stbuf->st_uid = atoi(vals[0]); break; case GID_HASH: stbuf->st_gid = atoi(vals[0]); break; case RDEV_HASH: stbuf->st_rdev = atoi(vals[0]); break; case SIZE_HASH: stbuf->st_size = atoi(vals[0]); break; case BLKZ_HASH: stbuf->st_blksize = atoi(vals[0]); break; case BLOCK_HASH: stbuf->st_blocks = atoi(vals[0]); break; case ATIME_HASH: stbuf->st_atime = atoi(vals[0]); break; case CTIME_HASH: strptime(vals[0], "%Y%m%d%H%M%SZ", &tm); stbuf->st_ctime = mktime(&tm); break; case MTIME_HASH: strptime(vals[0], "%Y%m%d%H%M%SZ", &tm); stbuf->st_mtime = mktime(&tm); break; } ldap_value_free(vals); } ldap_memfree(attr); } ber_free(ber, 0); } ldap_msgfree(msg); free(dn); return res; }
/*------------------------------------------------------------ * NPCTemplate °×ÑëÄÌ»ïë·òÎç¹´ ¸ê£Û * ¦ÐÑ * filename char* ɬÀð×ÑëÄÌ»ïë ÐÄ炙§ÔÂÐþÓÀÃó·¸Å«ÒÁÛÍÐþØø * ߯Ի°À * ÔÀ TRUE(1) * ·Ö»§(³ðľ¶¯Ïþ°×ÑëÄÌ»ïë ÊÏÆ¥·´ÖÐØêئÖÐ) * Áà FALSE(0) ------------------------------------------------------------*/ BOOL NPC_readTemplateFile( char* filename ) { FILE* f; char line[512]; int linenum=0; int start=OFF; NPC_Template temp; int itmreadindex=0; char* ret; int randomdata[NPC_TEMPLATEINTNUM]; int i; if( NPC_template_readindex >= NPC_templatenum ){ print("Template Exceed configured buffer\n" ); print("configured template number is %d\n", NPC_templatenum); return FALSE; } for( i=0; i<NPC_TEMPLATEINTNUM ; i++ ) randomdata[i] = 0; NPC_setDefaultNPCTemplate( &temp ); f= fopen( filename ,"r"); if( f == NULL )return FALSE; ret = fgets( line, sizeof( line ), f ); if( ret == NULL )goto FCLOSERETURNFALSE; if( strcmp( NPC_TEMPLATEFILEMAGIC, line ) != 0 ){ print( "This file is not a template file.\n" ); goto FCLOSERETURNFALSE ; } linenum = 1; while( fgets( line , sizeof( line ) , f ) ){ linenum++; if( line[0] == '#' )continue; /* comment */ if( line[0] == '\n' )continue; /* none */ chomp( line ); switch( line[0] ){ case '{': if( start == ON ){ fprint( "Find {. But already START state. %s:%d\n", filename, linenum); goto FCLOSERETURNFALSE; }else start = ON; break; case '}': if( start == ON ){ int err=FALSE; if( strcmp(temp.chardata[NPC_TEMPLATENAME].string ,"") == 0 ){ fprint( "There is no name %s:%d\n", filename, linenum ); err = TRUE; }else if( temp.intdata[NPC_TEMPLATETYPE] == -1 ){ temp.intdata[NPC_TEMPLATETYPE] = SPR_pet001; } if( err ){ if( temp.intdata[NPC_TEMPLATEITEMNUM] != 0 ) freeMemory( temp.haveitem ); }else{ temp.hash = hashpjw(temp.chardata[NPC_TEMPLATENAME].string); temp.intdata[NPC_TEMPLATEITEMNUM] = itmreadindex; for( i=0 ; i<NPC_TEMPLATEINTNUM ; i++ ){ temp.randomdata[i] = randomdata[i]; randomdata[i]=0; } memcpy( &NPC_template[NPC_template_readindex], &temp, sizeof( NPC_Template ) ); NPC_template_readindex++; if( NPC_template_readindex >= NPC_templatenum ){ print("Template Exceed configured buffer\n" ); print("configured template number is %d\n", NPC_templatenum); goto FCLOSERETURNFALSE; } } NPC_setDefaultNPCTemplate( &temp ); itmreadindex=0; start=OFF; }else{ fprint( "Unresolved '}' at %s:%d\n",filename,linenum); goto FCLOSERETURNFALSE; } break; default: { typedef struct tagNPC_Readtemplate { char* keyword; NPC_TYPECATEGORYATREADFILE type; int index; void* func; }NPC_Readtemplate; static NPC_Readtemplate NPC_readtemplate[NPC_TEMPLATECHARNUM+NPC_TEMPLATEINTNUM]= { {"templatename" , NPC_CHARENTRY, NPC_TEMPLATENAME,NULL}, {"name" , NPC_CHARENTRY, NPC_TEMPLATECHARNAME, NULL}, {"makeatnobody", NPC_INTENTRY, NPC_TEMPLATEMAKEATNOBODY, NULL}, {"makeatnosee" , NPC_INTENTRY, NPC_TEMPLATEMAKEATNOSEE, NULL}, {"graphicname", NPC_INTFUNC, NPC_TEMPLATEIMAGENUMBER, NPC_seekGraphicNumberFromString}, {"type", NPC_INTFUNC, NPC_TEMPLATETYPE, NPC_seekGraphicNumberFromString}, {"hp", NPC_INTFUNC, NPC_TEMPLATEMINHP, NPC_getRandomValue}, {"mp", NPC_INTFUNC, NPC_TEMPLATEMINMP, NPC_getRandomValue}, {"str", NPC_INTFUNC, NPC_TEMPLATEMINSTR, NPC_getRandomValue}, {"tough", NPC_INTFUNC, NPC_TEMPLATEMINTOUGH, NPC_getRandomValue}, {"fly", NPC_INTENTRY,NPC_TEMPLATEISFLYING,NULL}, {"itemnum", NPC_INTENTRY, NPC_TEMPLATEITEMNUM, NULL,}, {"functionset",NPC_INTFUNC, NPC_TEMPLATEFUNCTIONINDEX, NPC_searchFunctionSet,}, {"initfunc", NPC_CHARENTRY, NPC_TEMPLATEINITFUNC,NULL,}, {"walkprefunc", NPC_CHARENTRY, NPC_TEMPLATEWALKPREFUNC, NULL,}, {"walkpostfunc",NPC_CHARENTRY, NPC_TEMPLATEWALKPOSTFUNC, NULL,}, {"preoverfunc", NPC_CHARENTRY, NPC_TEMPLATEPREOVERFUNC, NULL,}, {"postoverfunc",NPC_CHARENTRY, NPC_TEMPLATEPOSTOVERFUNC, NULL,}, {"watchfunc", NPC_CHARENTRY, NPC_TEMPLATEWATCHFUNC, NULL,}, {"loopfunc", NPC_CHARENTRY, NPC_TEMPLATELOOPFUNC, NULL,}, {"talkedfunc",NPC_CHARENTRY,NPC_TEMPLATETALKEDFUNC,NULL,}, {"dyingfunc",NPC_CHARENTRY,NPC_TEMPLATEDYINGFUNC,NULL,}, {"preattackedfunc",NPC_CHARENTRY, NPC_TEMPLATEPREATTACKEDFUNC,NULL,}, {"postattackedfunc",NPC_CHARENTRY, NPC_TEMPLATEPOSTATTACKEDFUNC,NULL,}, {"offfunc",NPC_CHARENTRY,NPC_TEMPLATEOFFFUNC,NULL,}, {"lookedfunc",NPC_CHARENTRY,NPC_TEMPLATELOOKEDFUNC,NULL,}, {"itemputfunc",NPC_CHARENTRY,NPC_TEMPLATEITEMPUTFUNC, NULL,}, {"specialtalkedfunc",NPC_CHARENTRY, NPC_TEMPLATESPECIALTALKEDFUNC, NULL,}, {"windowtalkedfunc",NPC_CHARENTRY, NPC_TEMPLATEWINDOWTALKEDFUNC, NULL,}, {"loopfunctime",NPC_INTENTRY,NPC_TEMPLATELOOPFUNCTIME, NULL,}, }; char firstToken[256]; int ret,i; ret = getStringFromIndexWithDelim( line, "=", 1, firstToken, sizeof( firstToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); break; } if( strcasecmp(firstToken,"itm") == 0 ){ char one[128]; char two[128]; char three[128]; int itemnumber=0,rate=0,amount=1; char secondToken[256]={""}; if( itmreadindex < temp.intdata[NPC_TEMPLATEITEMNUM] && temp.haveitem != NULL ) ; else continue; ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, sizeof(secondToken ) ); if( ret == FALSE ){ print( "Find error at %s in line %d. Ignore\n", filename , linenum); secondToken[0] = '\0'; } ret = getStringFromIndexWithDelim( secondToken, "|", 1, one,sizeof( one ) ); if( ret != FALSE )itemnumber=atoi(one); ret = getStringFromIndexWithDelim( secondToken, "|", 2, two,sizeof(two)); if( ret != FALSE )rate=atoi(two); ret = getStringFromIndexWithDelim( secondToken, "|", 3, three,sizeof(three)); if( ret != FALSE )amount=atoi(three); if( rate > 0 && amount > 0 ){ if( itemnumber == -1 ){ temp.haveitem[itmreadindex].itemnumber = -1; temp.haveitem[itmreadindex].haverate = rate; temp.haveitem[itmreadindex].havenum = amount; itmreadindex++; }else if( ITEM_CHECKITEMTABLE( itemnumber ) == TRUE ){ temp.haveitem[itmreadindex].itemnumber=itemnumber; temp.haveitem[itmreadindex].haverate = rate; temp.haveitem[itmreadindex].havenum = amount; itmreadindex++; }else print("this item is not item %s:%d\n", filename , linenum); }else print("rate or amount is odd setting. rate=%d " "amount=%d %s:%d\n", rate,amount, filename, linenum); goto NEXT; }else{ for( i = 0 ; i < arraysizeof(NPC_readtemplate) ; i ++ ){ if( strcasecmp( NPC_readtemplate[i].keyword, firstToken ) == 0 ){ char secondToken[256]={""}; ret = getStringFromIndexWithDelim( line, "=", 2, secondToken, sizeof(secondToken) ); if( ret == FALSE ) print( "Find error at %s in line %d. Ignore\n" ,filename , linenum); switch( NPC_readtemplate[i].type ){ case NPC_INTENTRY: temp.intdata[NPC_readtemplate[i].index]=atoi(secondToken); if( NPC_readtemplate[i].index == NPC_TEMPLATEITEMNUM ) NPC_templateallocitemdata( &temp ); break; case NPC_CHARENTRY: strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, sizeof(temp.chardata[NPC_readtemplate[i].index].string), secondToken); break; case NPC_INTFUNC: { int (*intfunction)(char*,int* ); intfunction = NPC_readtemplate[i].func; temp.intdata[NPC_readtemplate[i].index] = intfunction( secondToken, &randomdata[NPC_readtemplate[i].index]); break; } case NPC_CHARFUNC: { char* (*charfunction)(char* ); charfunction = NPC_readtemplate[i].func; strcpysafe( temp.chardata[NPC_readtemplate[i].index].string, sizeof(temp.chardata[NPC_readtemplate[i].index].string), charfunction(secondToken)); break; } default: break; } goto NEXT; } } } fprint("%s:%d There is no such entry: %s\n" , filename, linenum, firstToken ); NEXT: break; } break; } } fclose(f); return TRUE; FCLOSERETURNFALSE: fclose(f); return FALSE; }
// Return hash code inline unsigned hash(const char *name) { return hashpjw(name) % MAX_FONTS; }
unsigned int pp_generic_hash (void *p) { GENERIC *gp = (GENERIC *) p; return hashpjw (gp->name); }
void receiveMail( char *id_from, char *charname_from, char *id_to, char *charname_to, char *message, int option, int use_msgid, unsigned int msgid ) { char id_charname[1024]; int h, mbindex; snprintf( id_charname, sizeof( id_charname), "%s_%s", id_to, charname_to ); h = hashpjw( id_charname ) & 0xff ; if( (mbindex = allocMail(use_msgid, msgid )) < 0 ){ log( "回复邮件: 获取新的邮件缓冲失败.\n" ); return; } mailbuf[mbindex].id_charname_hash = h; snprintf( mailbuf[mbindex].text, sizeof( mailbuf[mbindex].text ), "%s", message ); snprintf( mailbuf[mbindex].id_to, sizeof( mailbuf[mbindex].id_to ), "%s", id_to ); snprintf( mailbuf[mbindex].charname_to, sizeof( mailbuf[mbindex].charname_to ), "%s", charname_to ); snprintf( mailbuf[mbindex].id_from, sizeof( mailbuf[mbindex].id_from ),"%s", id_from ); snprintf( mailbuf[mbindex].charname_from, sizeof( mailbuf[mbindex].charname_from ),"%s", charname_from ); mailbuf[mbindex].option = option; { char childname[1000]; char savefile[1000]; char charname2[CHARNAME_MAX*2+1]; char text2[TEXT_MAX*2+1]; FILE *fp; snprintf( childname, sizeof( childname ),"%u" , mailbuf[mbindex].message_id ); makeDirFilename( savefile , sizeof(savefile), maildir, h, childname ); fp = fopen( savefile, "w" ); if( fp == NULL ){ log( "回复邮件 : 不能保存邮件文件: %s %s\n", savefile, strerror( errno )); return; } #define TO_ID_HEAD "ToID: " #define TO_CHAR_HEAD "ToChar: " #define FROM_ID_HEAD "FromID: " #define FROM_CHAR_HEAD "FromChar: " #define OPTION_HEAD "Option: " #define TEXT_HEAD "Text: " fprintf( fp, TO_ID_HEAD "%s\n", id_to ); snprintf( charname2, sizeof( charname2), "%s", charname_to ); fprintf( fp, TO_CHAR_HEAD "%s\n", makeEscapeString( charname_to, charname2,sizeof(charname2)) ); fprintf( fp, FROM_ID_HEAD "%s\n", id_from ); snprintf( charname2, sizeof( charname2), "%s", charname_from ); fprintf( fp, FROM_CHAR_HEAD "%s\n", makeEscapeString( charname_from, charname2,sizeof(charname2)) ); fprintf( fp, OPTION_HEAD "%d\n", option ); snprintf( text2, sizeof( text2 ) , "%s", message ); fprintf( fp, TEXT_HEAD "%s\n", makeEscapeString( message, text2, sizeof(text2)) ); fclose(fp); { static int mailnum=0; if( mailnum%10 == 0) log("."); mailnum = (++mailnum%1000); if( mailnum == 0 ) log("\n"); } } { extern gmsv gs[MAXCONNECTION]; int i; for(i=0;i<MAXCONNECTION;i++){ if( gs[i].use && gs[i].name[0] ){ saacproto_Message_send( i, id_from, charname_from, id_to, charname_to, message, option, mailbuf[mbindex].message_id ); mailbuf[mbindex].state = MS_WAIT_ACK; } } } }
// 將 profession.txt 載入 BOOL PROFESSION_initSkill( char *filename) { FILE* f; char line[256]; int linenum=-1; int skill_readlen=0; int i, j; int max_skillid = 0; f = fopen(filename,"r"); if( f == NULL ){ print( "file open error\n"); return FALSE; } profession_skill_num=0; while( fgets( line, sizeof( line ), f ) ){ char token[256]; linenum ++; if( line[0] == '#' )continue; if( line[0] == '\n' )continue; chomp( line ); profession_skill_num++; #ifdef _PROSKILL_OPTIMUM // Robin 取出最大職技ID if( getStringFromIndexWithDelim( line, ",", PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1, token, sizeof(token)) == FALSE ) continue; max_skillid = max( atoi( token), max_skillid); #endif } if( fseek( f, 0, SEEK_SET ) == -1 ){ fprint( "Seek Error\n" ); fclose(f); return FALSE; } #ifdef _PROSKILL_OPTIMUM // 職技Table數為 最大技能ID +1 profession_skill_num = max_skillid +1; print("\n 最大職技ID = %d\n", max_skillid); #endif PROFESSION_skill = allocateMemory( sizeof(struct tagProfessionkill) * profession_skill_num + 1 ); if( PROFESSION_skill == NULL ){ fprint( "Can't allocate Memory %d\n", sizeof(struct tagProfessionkill)*profession_skill_num); fclose( f ); return FALSE; } // init skill for( i = 0; i < profession_skill_num; i ++ ) { for( j = 0; j < PROFESSION_SKILL_DATAINTNUM; j ++ ) PROFESSION_SKILL_setInt( i,j,-1); for( j = 0; j < PROFESSION_SKILL_DATACHARNUM; j ++ ) PROFESSION_SKILL_setChar( i,j,""); } linenum = -1; while( fgets( line, sizeof( line ), f ) ){ linenum ++; if( line[0] == '#' )continue; if( line[0] == '\n' )continue; chomp( line ); replaceString( line, '\t' , ' ' ); { char buf[256]; for( i = 0; i < strlen( line); i ++) { if( line[i] != ' ' ) { break; } strcpy( buf, &line[i]); } if( i != 0 ) { strcpy( line, buf); } } { char token[256]; int ret; #ifdef _PROSKILL_OPTIMUM // 讀取本行職技的ID, 直接以職技ID當Table index ret = getStringFromIndexWithDelim( line, ",", PROFESSION_SKILL_DATACHARNUM+PROFESSION_SKILL_ID+1, token, sizeof(token)); if( ret==FALSE ){ fprint("Syntax Error file:%s line:%d\n",filename,linenum); break; } skill_readlen = atoi( token); #endif for( i = 0; i < PROFESSION_SKILL_DATACHARNUM; i ++ ) { ret = getStringFromIndexWithDelim( line,",", i + 1, token,sizeof(token)); if( ret==FALSE ){ fprint("Syntax Error file:%s line:%d\n",filename,linenum); break; } PROFESSION_SKILL_setChar( skill_readlen, i, token); } for( i = 0; i < PROFESSION_SKILL_DATAINTNUM; i ++ ) { ret = getStringFromIndexWithDelim( line, ",", i+PROFESSION_SKILL_DATACHARNUM+1, token, sizeof(token)); if( ret==FALSE ){ fprint("Syntax Error file:%s line:%d\n",filename,linenum); break; } if( strlen( token) != 0 ) { PROFESSION_SKILL_setInt( skill_readlen, i , atoi( token )); } } skill_readlen ++; } } fclose(f); profession_skill_num = skill_readlen; for( i = 0; i < arraysizeof( PROFESSION_SKILL_functbl); i ++ ){ PROFESSION_SKILL_functbl[i].hash = hashpjw( PROFESSION_SKILL_functbl[i].functionname ); } return TRUE; }