/* * Our hashtable iterator */ static void findfcn ( const void *key, void *value, void *closure ) { NSSCKMDObject *mdObject = (NSSCKMDObject *)value; nssCKMDSessionObject *mdso = (nssCKMDSessionObject *)mdObject->etc; nssCKMDFindSessionObjects *mdfso = (nssCKMDFindSessionObjects *)closure; CK_ULONG i, j; struct nodeStr *node; if( CKR_OK != mdfso->error ) { return; } for( i = 0; i < mdfso->ulCount; i++ ) { CK_ATTRIBUTE_PTR p = &mdfso->pTemplate[i]; for( j = 0; j < mdso->n; j++ ) { if( mdso->types[j] == p->type ) { if( !items_match(&mdso->attributes[j], p->pValue, p->ulValueLen) ) { return; } else { break; } } } if( j == mdso->n ) { /* Attribute not found */ return; } } /* Matches */ node = nss_ZNEW(mdfso->arena, struct nodeStr); if( (struct nodeStr *)NULL == node ) { mdfso->error = CKR_HOST_MEMORY; return; } node->mdObject = mdObject; node->next = mdfso->list; mdfso->list = node; return; }
void cTrade::sellaction(int s) { int i, amt, value=0, totgold=0; P_ITEM pRestock = NULL; P_ITEM pNoRestock = NULL; P_ITEM pSellCont = NULL; if (buffer[s][8]!=0) { P_CHAR pc_n = FindCharBySerial(calcserial(buffer[s][3], buffer[s][4], buffer[s][5], buffer[s][6])); if (pc_n == NULL) return; P_ITEM pi; unsigned int ci; vector<SERIAL> vecContainer = contsp.getData(pc_n->serial); for ( ci = 0; ci < vecContainer.size(); ci++) { pi = FindItemBySerial(vecContainer[ci]); if (pi->layer==0x1A) pRestock = pi; // Buy Restock container else if (pi->layer==0x1B) pNoRestock = pi; // Buy no restock container else if (pi->layer==0x1C) pSellCont = pi; // Sell container } // Pre Calculate Total Amount of selling items to STOPS if the items if greater than SELLMAXITEM - Magius(CHE) int maxsell=0; i=buffer[s][8]; if (i>256) return; for (i=0;i<buffer[s][8];i++) { amt=ShortFromCharPtr(buffer[s]+9+(6*i)+4); maxsell+=amt; } if (maxsell>SrvParams->sellmaxitem()) { char tmpmsg[256]; sprintf(tmpmsg,"Sorry %s but i can buy only %i items at time!",currchar[s]->name.c_str(),SrvParams->sellmaxitem()); npctalkall(pc_n, tmpmsg,0); return; } for (i=0;i<buffer[s][8];i++) { P_ITEM pSell=FindItemBySerPtr(buffer[s]+9+(6*i)); // the item to sell if (!pSell) continue; amt=ShortFromCharPtr(buffer[s]+9+(6*i)+4); // player may have taken items out of his bp while the sell menu was up ;-) if (pSell->amount<amt) { npctalkall(pc_n, "Cheating scum! Leave now, before I call the guards!",0); return; } // Search the buy restock Container P_ITEM join = NULL; ci=0; P_ITEM pi; vector<SERIAL> vecContainer = contsp.getData(pRestock->serial); for ( ci = 0; ci < vecContainer.size(); ci++) { pi = FindItemBySerial(vecContainer[ci]); if (items_match(pi,pSell)) join = pi; } // Search the sell Container to determine the price ci=0; vecContainer.clear(); vecContainer = contsp.getData(pSellCont->serial); for ( ci = 0; ci < vecContainer.size(); ci++) { pi = FindItemBySerial(vecContainer[ci]); if (items_match(pi,pSell)) { value=pi->value; value=calcValue(pSell, value); if (SrvParams->trade_system()==1) value=calcGoodValue(currchar[s], pSell, value, 1); // Fixed for adv trade --- by Magius(CHE) § break; // let's take the first match } } totgold+=(amt*value); // add to the bill if (join != NULL) // The item goes to the container with restockable items { join->amount+=amt; join->restock-=amt; pSell->ReduceAmount(amt); } else { pSell->SetContSerial(pNoRestock->serial); SndRemoveitem(pSell->serial); if (pSell->amount!=amt) Commands->DupeItem(s, pSell, pSell->amount-amt); } } addgold(s, totgold); goldsfx(s, totgold); // Dupois, SFX for gold movement // Added Oct 08, 1998 } char clearmsg[9]; clearmsg[0]=0x3B; clearmsg[1]=0x00; clearmsg[2]=0x08; clearmsg[3]=buffer[s][3]; clearmsg[4]=buffer[s][4]; clearmsg[5]=buffer[s][5]; clearmsg[6]=buffer[s][6]; clearmsg[7]=0x00; Xsend(s, clearmsg, 8); }