struct Node * hash_get_node(uint64_t hash) { struct Node *curNode = nodes + HASH_LOOKUP(hash); while (curNode->hash != HASH_CHECK(hash) && curNode->visits) { curNode++; if (curNode >= nodes + MAX_NODES) curNode = nodes; } // else if (create) // out(fileGTP, "Existing hash at %p/%p/%d (%x) wtih %x %d\n" // , pos, target, nodeType // , hash, curNode, curNode->visits); return curNode; }
void hash_set_node_special(uint64_t hash, double winrate) { struct Node *curNode = nodes + HASH_LOOKUP(hash); while (curNode->hash != HASH_CHECK(hash) && curNode->visits) { curNode++; if (curNode >= nodes + MAX_NODES) curNode = nodes; } if (!curNode->visits) { curNode->hash = HASH_CHECK(hash); hash_node_count++; } curNode->visits = 100000; curNode->wins = winrate * curNode->visits; }
void hash_set_node(uint64_t hash, int win) { struct Node *curNode = nodes + HASH_LOOKUP(hash); while (curNode->hash != HASH_CHECK(hash) && curNode->visits) { curNode++; if (curNode >= nodes + MAX_NODES) curNode = nodes; } if (!curNode->visits) { curNode->hash = HASH_CHECK(hash); hash_node_count++; } curNode->visits++; curNode->wins += win; }
int ClientHandlerNotice(PCLIENT pClient, char* strCommand, char* strParams) { if(CompareIRCAddressNick(strParams,c_strBouncerName)) { char *strAction,*str; pClient->cMessageMode = CMM_NOTICE; strAction = strParams+strlen(c_strBouncerName)+1; if(*strAction == ':') strAction++; str = strAction; do { if(*str == ' ') { *(str++) = '\0'; break; } else if(*str == '\r' || *str == '\n') { *str = '\0'; break; } *str = toupper(*str); ++str; } while(*str); { struct tagCLIENTHANDLER* pHandler; HASH_LOOKUP(CLIENTHANDLER_HASH,g_hashClientHandlers,strAction,pHandler); if(pHandler && ( !(pHandler->nFlags & CHF_BOUNCER) || (!(pHandler->nFlags & CHF_ADMIN) && (!pClient->pUser->strAllowedCommands || !ConfigFindVar(pClient->pUser->strAllowedCommands,pHandler->strAction))) || (pHandler->nFlags & CHF_ADMIN && !pClient->bAdmin) ) ) pHandler = 0; if(pHandler) { sprintf(strCommand,"notice %s %s",c_strBouncerName,pHandler->strAction); pHandler->pProc(pClient,strCommand,str); } else ClientMessage(pClient,"Unknown command \"%s\"\r\n",strAction); } pClient->cMessageMode = CMM_DEFAULT; return 1; } { char* strArg[2]; if(SplitIRCParams(strParams,strArg,sizeof(strArg)/sizeof(*strArg),1) == sizeof(strArg)/sizeof(*strArg)) { if(*strArg[1] == '\001' && strncmp(&strArg[1][1],"ACTION ",7) ) /* ctcp answer */ { if(!strncmp(&strArg[1][1],"VERSION",7) ) /* hook version answer */ { if(pClient->pProfile && pClient->pProfile->pServer && pClient->pProfile->pServer->bRegistered) { char* strCtcpArg = &strArg[1][8]; char* str; if(*strCtcpArg == ' ') strCtcpArg++; str = strCtcpArg+strlen(strCtcpArg)-1; if(*str == '\001') *str = '\0'; ConnectionSendFormat(pClient->pProfile->pServer->pConnection,"NOTICE %s :\001VERSION %s - %s\001\r\n",strArg[0],g_strVersion,strCtcpArg); } return 1; } return 0; /* don't log ctcp answers */ } if(pClient->pProfile) { PPROFILE pProfile = pClient->pProfile; PPROFILECHANNEL pProfileChannel; HASHLIST_LOOKUP(PROFILE_PROFILECHANNEL_HASHLIST,pProfile->hashlistProfileChannels,strArg[0],pProfileChannel); if(pProfileChannel) { PCLIENT pCurClient; ProfileLogMsgCreate(0,pProfileChannel,++pProfile->nLogID,g_strCurrentCommand,g_nCurrentCommandLength,PLMF_TIMESTAMP|PLMF_ADJUSTNICKLEN); for(pCurClient = pProfile->listClients.pFirst; pCurClient; pCurClient = pCurClient->llProfile.pNext) if(pCurClient != pClient) ConnectionSendFormat(pCurClient->pConnection,":%s!~%s@%s NOTICE %s :%s\r\n",pClient->strNick,pClient->pUser->strName,iptoa(pClient->pConnection->nIP),strArg[0],strArg[1]); } } } } return 0; }
int ClientHandlerPrivmsg(PCLIENT pClient, char* strCommand, char* strParams) { if(CompareIRCAddressNick(strParams,c_strBouncerName)) { char *strAction,*str; pClient->cMessageMode = CMM_PRIVMSG; strAction = strParams+strlen(c_strBouncerName)+1; if(*strAction == ':') strAction++; str = strAction; do { if(*str == ' ') { *(str++) = '\0'; break; } else if(*str == '\r' || *str == '\n') { *str = '\0'; break; } *str = toupper(*str); ++str; } while(*str); { struct tagCLIENTHANDLER* pHandler; HASH_LOOKUP(CLIENTHANDLER_HASH,g_hashClientHandlers,strAction,pHandler); if(pHandler && ( !(pHandler->nFlags & CHF_BOUNCER) || (!(pHandler->nFlags & CHF_ADMIN) && (!pClient->pUser->strAllowedCommands || !ConfigFindVar(pClient->pUser->strAllowedCommands,pHandler->strAction))) || (pHandler->nFlags & CHF_ADMIN && !pClient->bAdmin) ) ) pHandler = 0; if(pHandler) { sprintf(strCommand,"msg %s %s",c_strBouncerName,pHandler->strAction); pHandler->pProc(pClient,strCommand,str); } else ClientMessage(pClient,"Unknown command \"%s\"\r\n",strAction); } pClient->cMessageMode = CMM_DEFAULT; return 1; } { char* strArg[2]; if(SplitIRCParams(strParams,strArg,sizeof(strArg)/sizeof(*strArg),1) == sizeof(strArg)/sizeof(*strArg)) { if(pClient->pProfile) { PPROFILE pProfile = pClient->pProfile; PPROFILECHANNEL pProfileChannel; HASHLIST_LOOKUP(PROFILE_PROFILECHANNEL_HASHLIST,pProfile->hashlistProfileChannels,strArg[0],pProfileChannel); if(pProfileChannel) { PCLIENT pCurClient; unsigned short sLength; sLength = strformat(g_strOutBuffer,sizeof(g_strOutBuffer),":%s!~%s@%s PRIVMSG %s :%s\r\n",pClient->strNick,pClient->pUser->strName,iptoa(pClient->pConnection->nIP),strArg[0],strArg[1]); for(pCurClient = pProfile->listClients.pFirst; pCurClient; pCurClient = pCurClient->llProfile.pNext) if(pCurClient != pClient) ConnectionSend(pCurClient->pConnection,g_strOutBuffer,sLength); ProfileLogMsgCreate(0,pProfileChannel,++pProfile->nLogID,g_strOutBuffer,sLength,PLMF_TIMESTAMP|PLMF_ADJUSTNICKLEN); } } } } return 0; }