/* * call-seq: memory.put_string(offset, str) * @param [Numeric] offset * @param [String] str * @return [self] * @raise {SecurityError} when writing unsafe string to memory * @raise {IndexError} if +offset+ is too great * @raise {NullPointerError} if memory not initialized * Put a string in memory. */ static VALUE memory_put_string(VALUE self, VALUE offset, VALUE str) { AbstractMemory* ptr = MEMORY(self); long off, len; Check_Type(str, T_STRING); off = NUM2LONG(offset); len = RSTRING_LEN(str); checkWrite(ptr); checkBounds(ptr, off, len + 1); memcpy(ptr->address + off, RSTRING_PTR(str), len); *((char *) ptr->address + off + len) = '\0'; return self; }
static VALUE memory_get_string(int argc, VALUE* argv, VALUE self) { VALUE length = Qnil, offset = Qnil; AbstractMemory* ptr = MEMORY(self); long off, len; char* end; int nargs = rb_scan_args(argc, argv, "11", &offset, &length); off = NUM2LONG(offset); len = nargs > 1 && length != Qnil ? NUM2LONG(length) : (ptr->size - off); checkRead(ptr); checkBounds(ptr, off, len); end = memchr(ptr->address + off, 0, len); return rb_tainted_str_new((char *) ptr->address + off, (end != NULL ? end - ptr->address - off : len)); }
/* * call-seq: put(pointer, proc) * @param [AbstractMemory] pointer pointer to a {Struct} * @param [Function, Proc] proc * @return [Function] * Set a {Function} to memory pointed by +pointer+ as a function. * * If a Proc is submitted as +proc+, it is automatically transformed to a {Function}. */ static VALUE function_field_put(VALUE self, VALUE pointer, VALUE proc) { StructField* f; VALUE value = Qnil; Data_Get_Struct(self, StructField, f); if (NIL_P(proc) || rb_obj_is_kind_of(proc, rbffi_FunctionClass)) { value = proc; } else if (rb_obj_is_kind_of(proc, rb_cProc) || rb_respond_to(proc, rb_intern("call"))) { value = rbffi_Function_ForProc(f->rbType, proc); } else { rb_raise(rb_eTypeError, "wrong type (expected Proc or Function)"); } (*rbffi_AbstractMemoryOps.pointer->put)(MEMORY(pointer), f->offset, value); return self; }
UTracker::UTracker(std::string method) { MEMORY("UTracker created"); if(method == "mil") { WARNING("UTracker: using MIL tracking methid"); _method.reset(new MILTrackingMethod()); } if(method == "median-flow") { WARNING("UTracker: using MediaFlow tracking methid"); _method.reset(new MedianFlowTrackingMethod()); } if(method == "boosting") { WARNING("UTracker: using Boosting tracking methid"); _method.reset(new BoostingTrackingMethod()); } if(method == "tld") { WARNING("UTracker: using TLD tracking methid"); _method.reset(new TLDTrackingMethod()); } }
void* OvMemoryPool::alloc_memory_debug(char* _pBlock,int _iLine) { if ( ! m_pFreeMemoryList) { add_pool(); } OvMemHeader* k_alloc = NULL; k_alloc = m_pFreeMemoryList; void* k_return_mem = MEMORY(k_alloc); m_pFreeMemoryList = m_pFreeMemoryList->mNext; k_alloc->mMemPool = this; k_alloc->m_pBlock = _pBlock; k_alloc->m_iLine = _iLine; return k_return_mem; }
static VALUE struct_initialize_copy(VALUE self, VALUE other) { Struct* src; Struct* dst; VALUE memargs[3]; Data_Get_Struct(self, Struct, dst); Data_Get_Struct(other, Struct, src); if (dst == src) { return self; } dst->rbLayout = src->rbLayout; dst->layout = src->layout; // // A new MemoryPointer instance is allocated here instead of just calling // #dup on rbPointer, since the Pointer may not know its length, or may // be longer than just this struct. // if (src->pointer->address != NULL) { memargs[0] = INT2FIX(1); memargs[1] = INT2FIX(src->layout->size); memargs[2] = Qfalse; dst->rbPointer = rb_class_new_instance(2, memargs, rbffi_MemoryPointerClass); dst->pointer = MEMORY(dst->rbPointer); memcpy(dst->pointer->address, src->pointer->address, src->layout->size); } else { dst->rbPointer = src->rbPointer; dst->pointer = src->pointer; } if (src->layout->referenceFieldCount > 0) { dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount); memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE)); } return self; }
static VALUE memory_put_string(VALUE self, VALUE offset, VALUE str) { AbstractMemory* ptr = MEMORY(self); long off, len; Check_Type(str, T_STRING); off = NUM2LONG(offset); len = RSTRING_LEN(str); checkWrite(ptr); checkBounds(ptr, off, len + 1); if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) { rb_raise(rb_eSecurityError, "Writing unsafe string to memory"); return Qnil; } memcpy(ptr->address + off, RSTRING_PTR(str), len); *((char *) ptr->address + off + len) = '\0'; return self; }
/* * call-seq: initialize_copy(other) * @return [nil] * DO NOT CALL THIS METHOD */ static VALUE struct_initialize_copy(VALUE self, VALUE other) { Struct* src; Struct* dst; Data_Get_Struct(self, Struct, dst); Data_Get_Struct(other, Struct, src); if (dst == src) { return self; } dst->rbLayout = src->rbLayout; dst->layout = src->layout; /* * A new MemoryPointer instance is allocated here instead of just calling * #dup on rbPointer, since the Pointer may not know its length, or may * be longer than just this struct. */ if (src->pointer->address != NULL) { dst->rbPointer = rbffi_MemoryPointer_NewInstance(1, src->layout->size, false); dst->pointer = MEMORY(dst->rbPointer); memcpy(dst->pointer->address, src->pointer->address, src->layout->size); } else { dst->rbPointer = src->rbPointer; dst->pointer = src->pointer; } if (src->layout->referenceFieldCount > 0) { dst->rbReferences = ALLOC_N(VALUE, dst->layout->referenceFieldCount); memcpy(dst->rbReferences, src->rbReferences, dst->layout->referenceFieldCount * sizeof(VALUE)); } return self; }
/* Extract a ch completely from the world, and leave his stuff behind */ void extract_char_final(struct char_data *ch) { struct char_data *k, *temp; struct descriptor_data *d; struct obj_data *obj; int i; if (IN_ROOM(ch) == NOWHERE) { log("SYSERR: NOWHERE extracting char %s. (%s, extract_char_final)", GET_NAME(ch), __FILE__); exit(1); } /* We're booting the character of someone who has switched so first we need * to stuff them back into their own body. This will set ch->desc we're * checking below this loop to the proper value. */ if (!IS_NPC(ch) && !ch->desc) { for (d = descriptor_list; d; d = d->next) if (d->original == ch) { do_return(d->character, NULL, 0, 0); break; } } if (ch->desc) { /* This time we're extracting the body someone has switched into (not the * body of someone switching as above) so we need to put the switcher back * to their own body. If this body is not possessed, the owner won't have a * body after the removal so dump them to the main menu. */ if (ch->desc->original) do_return(ch, NULL, 0, 0); else { /* Now we boot anybody trying to log in with the same character, to help * guard against duping. CON_DISCONNECT is used to close a descriptor * without extracting the d->character associated with it, for being * link-dead, so we want CON_CLOSE to clean everything up. If we're * here, we know it's a player so no IS_NPC check required. */ for (d = descriptor_list; d; d = d->next) { if (d == ch->desc) continue; if (d->character && GET_IDNUM(ch) == GET_IDNUM(d->character)) STATE(d) = CON_CLOSE; } STATE(ch->desc) = CON_MENU; write_to_output(ch->desc, "%s", CONFIG_MENU); } } /* On with the character's assets... */ if (ch->followers || ch->master) die_follower(ch); /* Check to see if we are grouped! */ if (GROUP(ch)) leave_group(ch); /* transfer objects to room, if any */ while (ch->carrying) { obj = ch->carrying; obj_from_char(obj); obj_to_room(obj, IN_ROOM(ch)); } /* transfer equipment to room, if any */ for (i = 0; i < NUM_WEARS; i++) if (GET_EQ(ch, i)) obj_to_room(unequip_char(ch, i), IN_ROOM(ch)); if (FIGHTING(ch)) stop_fighting(ch); for (k = combat_list; k; k = temp) { temp = k->next_fighting; if (FIGHTING(k) == ch) stop_fighting(k); } /* Whipe character from the memory of hunters and other intelligent NPCs... */ for (temp = character_list; temp; temp = temp->next) { /* PCs can't use MEMORY, and don't use HUNTING() */ if (!IS_NPC(temp)) continue; /* If "temp" is hunting our extracted char, stop the hunt. */ if (HUNTING(temp) == ch) HUNTING(temp) = NULL; /* If "temp" has allocated memory data and our ch is a PC, forget the * extracted character (if he/she is remembered) */ if (!IS_NPC(ch) && GET_POS(ch) == POS_DEAD && MEMORY(temp)) forget(temp, ch); /* forget() is safe to use without a check. */ } char_from_room(ch); if (IS_NPC(ch)) { if (GET_MOB_RNUM(ch) != NOTHING) /* prototyped */ mob_index[GET_MOB_RNUM(ch)].number--; clearMemory(ch); if (SCRIPT(ch)) extract_script(ch, MOB_TRIGGER); if (SCRIPT_MEM(ch)) extract_script_mem(SCRIPT_MEM(ch)); } else { save_char(ch); Crash_delete_crashfile(ch); } /* If there's a descriptor, they're in the menu now. */ if (IS_NPC(ch) || !ch->desc) free_char(ch); }
Blob::~Blob(){ MEMORY("Blob " + _name + " deleted"); }
KnnMDMethod::~KnnMDMethod() { MEMORY("KnnMDMethod destroyed"); }
KnnMDMethod::KnnMDMethod() { MEMORY("KnnMDMethod created"); }
void KMemoryWidget::update() { int mib[2]; size_t len; #ifdef UVM #if __NetBSD_Version__ > 499000100 /* 4.99.2+ */ struct uvmexp_sysctl uvmexp; #else struct uvmexp uvmexp; #endif #else /* !UVM */ struct swapent *swaplist; int64_t nswap, rnswap, totalswap, freeswap, usedswap; #endif #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */ quad_t memory; #else int memory; #endif /* memory */ #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */ mib[0] = CTL_HW; mib[1] = HW_PHYSMEM64; #else mib[0] = CTL_HW; mib[1] = HW_PHYSMEM; #endif len = sizeof(memory); if(sysctl(mib, 2, &memory, &len, NULL, 0) < 0) Memory_Info[TOTAL_MEM] = NO_MEMORY_INFO; else Memory_Info[TOTAL_MEM] = memory; #ifdef UVM mib[0] = CTL_VM; #if __NetBSD_Version__ > 499000100 /* 4.99.2+ */ mib[1] = VM_UVMEXP2; #else mib[1] = VM_UVMEXP; #endif len = sizeof(uvmexp); if(sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0) { Memory_Info[FREE_MEM] = NO_MEMORY_INFO; Memory_Info[ACTIVE_MEM] = NO_MEMORY_INFO; Memory_Info[INACTIVE_MEM] = NO_MEMORY_INFO; Memory_Info[SWAP_MEM] = NO_MEMORY_INFO; Memory_Info[FREESWAP_MEM] = NO_MEMORY_INFO; Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; } else { t_memsize pgsz = MEMORY(uvmexp.pagesize); Memory_Info[FREE_MEM] = pgsz * uvmexp.free; Memory_Info[ACTIVE_MEM] = pgsz * uvmexp.active; Memory_Info[INACTIVE_MEM] = pgsz * uvmexp.inactive; Memory_Info[SWAP_MEM] = pgsz * uvmexp.swpages; Memory_Info[FREESWAP_MEM] = pgsz * (uvmexp.swpages - uvmexp.swpginuse); #if __NetBSD_Version__ > 106000000 Memory_Info[CACHED_MEM] = pgsz * (uvmexp.filepages + uvmexp.execpages); #else Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; #endif } #else Memory_Info[FREE_MEM] = NO_MEMORY_INFO; Memory_Info[ACTIVE_MEM] = NO_MEMORY_INFO; Memory_Info[INACTIVE_MEM] = NO_MEMORY_INFO; /* swap */ totalswap = freeswap = usedswap = 0; nswap = swapctl(SWAP_NSWAP, 0, 0); if(nswap > 0) { if((swaplist = (struct swapent *)malloc(nswap * sizeof(*swaplist)))) { rnswap = swapctl(SWAP_STATS, swaplist, nswap); if(rnswap < 0 || rnswap > nswap) totalswap = freeswap = -1; /* Error */ else { while(rnswap-- > 0) { totalswap += swaplist[rnswap].se_nblks; usedswap += swaplist[rnswap].se_inuse; } freeswap = totalswap - usedswap; } } else totalswap = freeswap = -1; /* Error */ if(totalswap == -1) { Memory_Info[SWAP_MEM] = NO_MEMORY_INFO; Memory_Info[FREESWAP_MEM] = NO_MEMORY_INFO; } else { Memory_Info[SWAP_MEM] = MEMORY(totalswap); Memory_Info[FREESWAP_MEM] = MEMORY(freeswap); } } #endif }
void KCMMemory::fetchValues() { vm_statistics_data_t vm_info; mach_msg_type_number_t info_count; DIR *dirp; struct dirent *dp; t_memsize total; info_count = HOST_VM_INFO_COUNT; if (host_statistics(mach_host_self (), HOST_VM_INFO, (host_info_t)&vm_info, &info_count)) { kDebug() << "could not get memory statistics"; return; } memoryInfos[TOTAL_MEM] = MEMORY(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) * vm_page_size; memoryInfos[FREE_MEM] = MEMORY(vm_info.free_count) * vm_page_size; memoryInfos[SHARED_MEM] = NO_MEMORY_INFO; memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO; memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; dirp = opendir("/private/var/vm"); if (!dirp) { kDebug() << "unable to open /private/var/vm"; return; } total = 0; while ((dp = readdir (dirp)) != NULL) { struct stat sb; char fname [MAXNAMLEN]; if (strncmp (dp->d_name, "swapfile", 8)) continue; strcpy (fname, "/private/var/vm/"); strcat (fname, dp->d_name); if (stat (fname, &sb) < 0) continue; total += sb.st_size; } closedir (dirp); info_count = HOST_VM_INFO_COUNT; if (host_statistics (mach_host_self (), HOST_VM_INFO, (host_info_t) &vm_info, &info_count)) { kDebug() << "unable to get VM info"; } memoryInfos[SWAP_MEM] = total; // off_t used = (vm_info.pageouts - vm_info.pageins) * vm_page_size; memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO; /* free = MEMORY(vm_info.free_count) * vm_page_size; used = MEMORY(vm_info.active_count) * vm_page_size; total = MEMORY(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) * vm_page_size; */ }
UTracker::~UTracker() { MEMORY("UTracker destroyed"); }
void mobile_activity(void) { struct char_data *ch, *next_ch, *vict; struct obj_data *obj, *best_obj; int door, found, max; memory_rec *names; for (ch = character_list; ch; ch = next_ch) { next_ch = ch->next; if (!IS_MOB(ch)) continue; /* Examine call for special procedure */ if (MOB_FLAGGED(ch, MOB_SPEC) && !no_specials) { if (mob_index[GET_MOB_RNUM(ch)].func == NULL) { log("SYSERR: %s (#%d): Attempting to call non-existing mob function.", GET_NAME(ch), GET_MOB_VNUM(ch)); REMOVE_BIT_AR(MOB_FLAGS(ch), MOB_SPEC); } else { char actbuf[MAX_INPUT_LENGTH] = ""; if ((mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, actbuf)) continue; /* go to next char */ } } /* If the mob has no specproc, do the default actions */ if (FIGHTING(ch) || !AWAKE(ch)) continue; /* hunt a victim, if applicable */ hunt_victim(ch); /* Scavenger (picking up objects) */ if (MOB_FLAGGED(ch, MOB_SCAVENGER)) if (world[IN_ROOM(ch)].contents && !rand_number(0, 10)) { max = 1; best_obj = NULL; for (obj = world[IN_ROOM(ch)].contents; obj; obj = obj->next_content) if (CAN_GET_OBJ(ch, obj) && GET_OBJ_COST(obj) > max) { best_obj = obj; max = GET_OBJ_COST(obj); } if (best_obj != NULL) { obj_from_room(best_obj); obj_to_char(best_obj, ch); act("$n gets $p.", FALSE, ch, best_obj, 0, TO_ROOM); } } /* Mob Movement */ if (!MOB_FLAGGED(ch, MOB_SENTINEL) && (GET_POS(ch) == POS_STANDING) && ((door = rand_number(0, 18)) < DIR_COUNT) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_DEATH) && (!MOB_FLAGGED(ch, MOB_STAY_ZONE) || (world[EXIT(ch, door)->to_room].zone == world[IN_ROOM(ch)].zone))) { /* If the mob is charmed, do not move the mob. */ if (ch->master == NULL) perform_move(ch, door, 1); } /* Aggressive Mobs */ if (!MOB_FLAGGED(ch, MOB_HELPER) && (!AFF_FLAGGED(ch, AFF_BLIND) || !AFF_FLAGGED(ch, AFF_CHARM))) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (IS_NPC(vict) || !CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; if (MOB_FLAGGED(ch, MOB_WIMPY) && AWAKE(vict)) continue; if (MOB_FLAGGED(ch, MOB_AGGRESSIVE ) || (MOB_FLAGGED(ch, MOB_AGGR_EVIL ) && IS_EVIL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_NEUTRAL) && IS_NEUTRAL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_GOOD ) && IS_GOOD(vict))) { /* Can a master successfully control the charmed monster? */ if (aggressive_mob_on_a_leash(ch, ch->master, vict)) continue; hit(ch, vict, TYPE_UNDEFINED); found = TRUE; } } } /* Mob Memory */ if (MOB_FLAGGED(ch, MOB_MEMORY) && MEMORY(ch)) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (IS_NPC(vict) || !CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; for (names = MEMORY(ch); names && !found; names = names->next) { if (names->id != GET_IDNUM(vict)) continue; /* Can a master successfully control the charmed monster? */ if (aggressive_mob_on_a_leash(ch, ch->master, vict)) continue; found = TRUE; act("'Hey! You're the fiend that attacked me!!!', exclaims $n.", FALSE, ch, 0, 0, TO_ROOM); hit(ch, vict, TYPE_UNDEFINED); } } } /* Charmed Mob Rebellion: In order to rebel, there need to be more charmed * monsters than the person can feasibly control at a time. Then the * mobiles have a chance based on the charisma of their leader. * 1-4 = 0, 5-7 = 1, 8-10 = 2, 11-13 = 3, 14-16 = 4, 17-19 = 5, etc. */ if (AFF_FLAGGED(ch, AFF_CHARM) && ch->master && num_followers_charmed(ch->master) > (GET_CHA(ch->master) - 2) / 3) { if (!aggressive_mob_on_a_leash(ch, ch->master, ch->master)) { if (CAN_SEE(ch, ch->master) && !PRF_FLAGGED(ch->master, PRF_NOHASSLE)) hit(ch, ch->master, TYPE_UNDEFINED); stop_follower(ch); } } /* Helper Mobs */ if (MOB_FLAGGED(ch, MOB_HELPER) && (!AFF_FLAGGED(ch, AFF_BLIND) || !AFF_FLAGGED(ch, AFF_CHARM))) { found = FALSE; for (vict = world[IN_ROOM(ch)].people; vict && !found; vict = vict->next_in_room) { if (ch == vict || !IS_NPC(vict) || !FIGHTING(vict)) continue; if (IS_NPC(FIGHTING(vict)) || ch == FIGHTING(vict)) continue; act("$n jumps to the aid of $N!", FALSE, ch, 0, vict, TO_ROOM); hit(ch, FIGHTING(vict), TYPE_UNDEFINED); found = TRUE; } } /* Add new mobile actions here */ } /* end for() */ }
TLDTrackingMethod::TLDTrackingMethod() { MEMORY("TLDTrackingMethod created"); step = 0; }
void mobile_activity(void) { register struct char_data *ch, *next_ch, *vict; struct char_data *min_vict = NULL; struct obj_data *obj, *next_obj, *best_obj, *cont; int door, found, max, where; int casual, max_abil=0, curr_abil, gold; memory_rec *names; room_rnum target_room; extern int no_specials; ACMD(do_get); for (ch = character_list; ch; ch = next_ch) { next_ch = ch->next; if (!IS_MOB(ch)) continue; //lance ripristina il master! if (IS_NPC(ch) && MOB_FLAGGED(ch, MOB_SAVE)) chkmaster(ch); // Examine call for special procedure if (MOB_FLAGGED(ch, MOB_SPEC) && !no_specials) { if (mob_index[GET_MOB_RNUM(ch)].func == NULL) { sprintf(buf, "SYSERR: %s (#%d): Attempting to call non-existing mob func", GET_NAME(ch), GET_MOB_VNUM(ch)); log(buf); REMOVE_BIT(MOB_FLAGS(ch), MOB_SPEC); } else { //(mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, ""); if ((mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, "")) continue; /* go to next char*/ } } // If the mob has no specproc, do the default actions if (FIGHTING(ch) || !AWAKE(ch)) continue; // Nuovo Scavenger (picking up objects) by Rusty if (MOB_FLAGGED(ch, MOB_SCAVENGER)) if (world[ch->in_room].contents && (number(0, 10) > 5)) { max = -1000; best_obj = NULL; for (obj = world[ch->in_room].contents; obj; obj = obj->next_content) if (CAN_GET_OBJ(ch, obj) && objlevel(obj) > max) { best_obj = obj; max = objlevel(obj); } if (best_obj != NULL) { obj_from_room(best_obj); obj_to_char(best_obj, ch); act("$n prende $p.", FALSE, ch, best_obj, 0, TO_ROOM); // Orione, tolta la procedura che fa indossare l'eq raccolto ai mob scavenger // Scavenger Plus:Mob wear the best object /* where=find_eq_pos(ch, best_obj, 0); if (CAN_WEAR(best_obj, ITEM_WEAR_WIELD)) where=WEAR_WIELD; if ( (where>0) && GET_EQ(ch,where)) { // se ce l'ha gia! if ((objlevel((ch)->equipment[where]))< objlevel(best_obj)) { obj_to_char((obj=unequip_char(ch, where)), ch); act("$n smette di usare $p.", FALSE, ch, obj, 0, TO_ROOM); } else { where = NUM_WEARS; // cioe' oggetto non indossabile } if (GET_LEVEL(ch)>=objlevel(best_obj)) { if (where>=0 && where <NUM_WEARS) { obj_from_char(best_obj); equip_char(ch,best_obj,where); wear_message(ch,best_obj,where); } } } */ } } //End ifif // Mob BodyGuard !? if (MOB_FLAGGED(ch, MOB_BGUARD) && (ch->master)) { if ( (FIGHTING(ch->master) && (npc_rescue(ch, ch->master) == FALSE)) || (ch->master && WHOKILLED(ch->master)) ) { act("$N Si schiera Prontamente al tuo fianco!", FALSE,ch->master, 0, ch, TO_CHAR); act("$n Si schiera prontamente al fianco di $N", FALSE, ch, 0, ch->master, TO_ROOM); if (WHOKILLED(ch->master)) hit(ch, WHOKILLED(ch->master), TYPE_UNDEFINED);/*in ogni caso assiste*/ else hit(ch, FIGHTING(ch->master), TYPE_UNDEFINED);/*in ogni caso assiste*/ } if (FIGHTING(ch)) { npc_rescue(ch, ch->master); if (WHOKILLED(ch->master)) hit(ch, WHOKILLED(ch->master), TYPE_UNDEFINED); /*in ogni caso assiste*/ continue; } } //MOB_THIEF if ( MOB_FLAGGED(ch, MOB_CRIMINAL) && (GET_POS(ch) == POS_RESTING) && IS_AFFECTED(ch, AFF_HIDE) && GET_HIT(ch) >= 2*GET_MAX_HIT(ch)/3) { appear(ch); GET_POS(ch)=POS_STANDING; } if ( MOB_FLAGGED(ch, MOB_CRIMINAL) && ( GET_POS(ch) == POS_STANDING) && ( (casual = number(0, 11)) < 6 ) ) { // 50% Rubare // cerca le vittime 1) Devono aver almeno 1 coin // 2) Deve aver una buona prob di farcela for (found=FALSE, min_vict = NULL, vict = world[ch->in_room].people; vict; vict = vict->next_in_room) { if (CAN_SEE(ch, vict) && (vict != ch)) { if ((min_vict == NULL) || (max_abil < 100)) { //se ha il 100% tanto vale fermarsi //Calcolo dell abilita:presa esattamente da D n'D curr_abil = MIN(90, (10*(GET_LEVEL(ch)) - 5*GET_LEVEL(vict))); curr_abil -= dex_app[GET_DEX(vict)].reaction; if (GET_POS(vict) < POS_STANDING) curr_abil += 200; // Se la vittima e' addormentata-stunned - incap o morta ovviamente // deruberai questa sicuramente if ( (curr_abil >= 40) && (GET_GOLD(vict) != 0) && (curr_abil > max_abil) ) { min_vict = vict; max_abil = curr_abil; found=TRUE; } } } } // Se ha trovato la vittima if (found == TRUE) { if ((casual = number(1, 100)) > max_abil) { if (!IS_NPC(min_vict)) act(" $n cerca di prendere dei soldi dal tuo Borsello", FALSE, ch, 0, min_vict, TO_CHAR); else { act("Oops...", FALSE, ch, 0, min_vict, TO_ROOM); act("$n cerca di rubare soldi a $N..Ma viene Scoperto! ", FALSE, ch, 0, min_vict, TO_ROOM); } //Beccato ... fa 2 tentativi di fuga if (((door = number(1, 7)) < NUM_OF_DIRS) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); if ((door -= 1) < NUM_OF_DIRS && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); if ((door += 2) < NUM_OF_DIRS && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); if (IS_NPC(min_vict)) { act("$n Urla: $N e' uno sporco LADRO!!!!", FALSE, min_vict, 0, ch, TO_ROOM); hit(min_vict, ch, TYPE_UNDEFINED); } } // Il Bastardo ce la fa! else { if (GET_POS(min_vict) < 5) { GET_GOLD(ch) += GET_GOLD(min_vict); GET_GOLD(min_vict) = 0; //la ripulisce completamente } else { gold = number((GET_GOLD(min_vict) / 10), (GET_GOLD(min_vict) / 2)); //gold = MIN(5000, gold); if (gold > 0) { GET_GOLD(ch) += gold; GET_GOLD(min_vict) -= gold; if (GET_GOLD(min_vict) < 0) GET_GOLD(min_vict) = 0; } } // Dopo il furto si allontana if (((door = number(1, 6)) < NUM_OF_DIRS) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); if ((door -=1) < NUM_OF_DIRS && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); if ((door +=2) < NUM_OF_DIRS && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch,door,1,CAN_SHOW_ROOM); } } else { // Nessuna vittima appetibile:se ne va! if (((door = number(0, 6)) < NUM_OF_DIRS) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) ) perform_move(ch, door, 1, CAN_SHOW_ROOM); } } // Mob Sciacalli indossano EQ if (MOB_FLAGGED(ch, MOB_NECRO) && !FIGHTING(ch) && AWAKE(ch)) if (world[ch->in_room].contents) { max = -1000; best_obj=NULL; for (cont = world[ch->in_room].contents;cont;cont = cont->next_content) if (GET_OBJ_TYPE(cont) == ITEM_CONTAINER) { for (obj = cont->contains; obj; obj = next_obj) { next_obj = obj->next_content; if (obj != NULL) { if (CAN_SEE_OBJ(ch, obj) && ( (max = objlevel(obj)) <= GET_LEVEL(ch)) ) { perform_get_from_container(ch, obj, cont, FIND_OBJ_INV); if (obj != NULL) { where = find_eq_pos(ch, obj, 0); if (CAN_WEAR(obj, ITEM_WEAR_HOLD)) where = WEAR_HOLD; if (GET_OBJ_TYPE(obj)==ITEM_LIGHT) where = WEAR_LIGHT; if (CAN_WEAR(obj, ITEM_WEAR_WIELD)) where = WEAR_WIELD; if (where < 0) { sprintf(buf,"SYSERR:pos < 0 ,in cont %s obj %d %s In room %d", cont->name, GET_OBJ_RNUM(obj), obj->name, IN_ROOM(ch)); log(buf); where = NUM_WEARS; } if (GET_EQ(ch, where) && where < NUM_WEARS) { if ((objlevel((ch)->equipment[where])) < objlevel(obj)) { obj_to_char((best_obj = unequip_char(ch, where)), ch); act("$n smette di usare $p.",FALSE, ch, best_obj, 0, TO_ROOM); } else where = NUM_WEARS; } if (where >= 0 && where < NUM_WEARS) { wear_message(ch, obj, where); obj_from_char(obj); equip_char(ch, obj, where); } } } } } } //End forif } //End ifif // Mob Movement if (HUNTING(ch)) hunt_victim(ch); else { if (MOB_FLAGGED(ch , MOB_SEARCHER)) {} else { if (ch->in_room != NOWHERE) { if (!IS_IN_WILD(ch)) { if ( !MOB_FLAGGED(ch, MOB_SENTINEL) && (GET_POS(ch) == POS_STANDING) && ( (door = number(0, 8)) < NUM_OF_DIRS) && CAN_GO(ch, door) && !ROOM_FLAGGED(EXIT(ch, door)->to_room, ROOM_NOMOB | ROOM_DEATH) && ( !MOB_FLAGGED(ch, MOB_STAY_ZONE) || (world[EXIT(ch, door)->to_room].zone == world[ch->in_room].zone))) { perform_move(ch, door, 1, CAN_SHOW_ROOM); } } else { // E' in wilderness if (MOB_FLAGGED(ch, MOB_WILDHUNT)) door = wild_mobhunter(ch); else door = number(0, 8); if (door >= 0 && door < NUM_OF_DIRS) target_room = wild_target_room(ch, door); else target_room = -1; if ( !MOB_FLAGGED(ch, MOB_SENTINEL) && (GET_POS(ch) == POS_STANDING) && (target_room != -1) && ( !MOB_FLAGGED(ch, MOB_STAY_ZONE) || (world[target_room].wild_rnum == world[ch->in_room].wild_rnum))) { perform_move(ch, door, 1, CAN_SHOW_ROOM); } } } } } // Aggressive Mobs if (MOB_FLAGGED(ch, MOB_AGGRESSIVE | MOB_AGGR_TO_ALIGN)) { found = FALSE; for (vict = world[ch->in_room].people; vict && !found; vict = vict->next_in_room) { if (IS_NPC(vict) || !CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; if (number(0, 3) < 2) continue; // Simple simulate Random a Joke from Phantom ;P if (GET_ABIL (vict, ABIL_TRATTATIVA) >= EXPERT_LIV) continue; // I pg con trattativa ad esperto fanno pace con gli aggressivi (by Spini) if (controllo_volo(ch, vict)) continue; if (affected_by_spell (vict, SPELLSKILL, DISEASE_PESTE)) continue; if (MOB_FLAGGED(ch, MOB_AGGR_NO_PROP) && (MASTER_ID(ch)==GET_IDNUM(vict))) continue; if (MOB_FLAGGED(ch, MOB_AGGR_NO_CLAN) && (CLAN_ID(ch)==GET_CLAN(vict))) continue; if (MOB_FLAGGED(ch, MOB_AGGR_NO_AL_CLAN) && (GET_CLAN_DIPLO(GET_CLAN(ch),GET_CLAN(vict)) == ALLIANCE)) continue; if (MOB_FLAGGED(ch, MOB_AGGR_NO_EN_CLAN) && (GET_CLAN_DIPLO(GET_CLAN(ch),GET_CLAN(vict)) == WAR)) continue; if (MOB_FLAGGED(ch, MOB_AGGR_NO_PC_CLAN) && (GET_CLAN_DIPLO(GET_CLAN(ch),GET_CLAN(vict)) == PEACE)) continue; if (MOB_FLAGGED(ch, MOB_AGGR_VAS_CLAN) && (GET_CLAN_DIPLO(GET_CLAN(ch),GET_CLAN(vict)) == VASSALLO)) continue; if ( !MOB_FLAGGED(ch, MOB_AGGR_TO_ALIGN) || (MOB_FLAGGED(ch, MOB_AGGR_EVIL) && IS_EVIL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_NEUTRAL) && IS_NEUTRAL(vict)) || (MOB_FLAGGED(ch, MOB_AGGR_GOOD) && IS_GOOD(vict)) ) { if (GET_MOB_SPEC(ch)== thief) npc_backstab(ch,vict); else hit(ch, vict, TYPE_UNDEFINED); found = TRUE; } } } // Mob Memory if (MOB_FLAGGED(ch, MOB_MEMORY) && MEMORY(ch)) { found = FALSE; for (vict = world[ch->in_room].people; vict && !found; vict = vict->next_in_room) { if (!CAN_SEE(ch, vict) || PRF_FLAGGED(vict, PRF_NOHASSLE)) continue; for (names = MEMORY(ch); names && !found; names = names->next) if (names->id == GET_IDNUM(vict)) { found = TRUE; act("$n esclama, 'Hey!! Tu sei il tipo che mi ha attaccato!!!'", FALSE, ch, 0, 0, TO_ROOM); hit(ch, vict, TYPE_UNDEFINED); } //End forif } } // Helper Mobs Paladino del bene if ( MOB_FLAGGED(ch, MOB_HELPER) && !MOB_FLAGGED(ch, MOB_CRIMINALHELPER) ) { found = FALSE; for (vict = world[ch->in_room].people; vict && !found; vict = vict->next_in_room) if ( ch != vict && IS_NPC(vict) && FIGHTING(vict) && !IS_NPC(FIGHTING(vict)) && ch != FIGHTING(vict) ) { if ( MOB_FLAGGED(vict, MOB_CRIMINAL) || ( (ch->master) && (FIGHTING(vict) == ch->master) ) ) { hit(ch, vict, TYPE_UNDEFINED); found = TRUE; } else { act("$n arriva in aiuto di $N!", FALSE, ch, 0, vict, TO_ROOM); hit(ch, FIGHTING(vict), TYPE_UNDEFINED); found = TRUE; } } //End forif } // Helper Mobs Servo del male if ( MOB_FLAGGED(ch, MOB_CRIMINALHELPER) && !MOB_FLAGGED(ch, MOB_HELPER) ) { found = FALSE; for (vict = world[ch->in_room].people; vict && !found; vict = vict->next_in_room) if ( ch != vict && IS_NPC(vict) && FIGHTING(vict) && !IS_NPC(FIGHTING(vict)) && ch != FIGHTING(vict) ) { if ( MOB_FLAGGED(vict, MOB_CRIMINAL) || ( (ch->master) && (vict == ch->master) ) ) { act("$n arriva in aiuto di $N!", FALSE, ch, 0, vict, TO_ROOM); hit(ch, FIGHTING(vict), TYPE_UNDEFINED); found = TRUE; } } //End forif } // Add new mobile actions here } // end for() }
TLDTrackingMethod::~TLDTrackingMethod() { MEMORY("TLDTrackingMethod destroyed"); }
/* * call-seq: get(pointer) * @param [AbstractMemory] pointer pointer on a {Struct} * @return [Function] * Get a {Function} from memory pointed by +pointer+. */ static VALUE function_field_get(VALUE self, VALUE pointer) { StructField* f; Data_Get_Struct(self, StructField, f); return rbffi_Function_NewInstance(f->rbType, (*rbffi_AbstractMemoryOps.pointer->get)(MEMORY(pointer), f->offset)); }
/* 0 -- continue * 1 -- stop */ int msg(int code) { switch (code) { case 0: return 0; break; case SIGNATURE_ERROR: printf("Signature error. Possibly you file damaged, check it with \n" " hare -t filename\n" "Find next file... (NOT REALIZED)\n"); WARNING(L"Signature error, find next (NOT REALIZED)"); return 2; break; case IO_EOF: INFO("End of file\n"); return 0; break; case MEMORY_ALLOCATE_ERROR: printf("Can not allocate memory. Close one or more programm to release memory.\n"); MEMORY("Can'not allocate"); return 1; break; case HASH_HEADER_CHECK_ERROR: printf("Check summ file in archive does not match, search next file... (NOT REALIZED)\n"); WARNING("Hash header check error"); return 2; break; case MKDIR_ERROR: printf("Error when create folder `%s`\n", __forErrorFileName); __forErrorFileName = NULL; return 0; break; case FSEEK_ERROR: printf("Fseek error in archive `%s`\n", __forErrorFileName); ERROR("Fseek error"); __forErrorFileName = NULL; return 1; break; case FILE_OPEN_ERROR: printf("Can not open file `%s` to write. Please, check file permission.\n", __forErrorFileName); __forErrorFileName = NULL; return 0; break; case ARCHIVE_ERROR: printf("Error while read archive\n"); return 0; break; case IO_WRITE_ERROR: printf("Error while write data to `%s`\n", __forErrorFileName); __forErrorFileName = NULL; return 1; break; case OPEN_ARCHIVE_FILE_ERROR: printf("Error open archive file `%s`, please, check filename and permissions\n",__forErrorFileName); __forErrorFileName = NULL; return 1; break; case INCORRECT_FILE_NAME: printf("`%s` not found in archive\n", __forErrorFileName); __forErrorFileName = NULL; return 0; break; default: printf("Unknown error `%d`\n",code); return 1; break; } }
/* * call-seq: put(pointer, value) * @param [AbstractMemory] pointer pointer on a {Struct} * @param [String, Array] value +value+ may be a String only if array's type is a kind of +int8+ * @return [value] * Set an array in a {Struct}. */ static VALUE array_field_put(VALUE self, VALUE pointer, VALUE value) { StructField* f; ArrayType* array; Data_Get_Struct(self, StructField, f); Data_Get_Struct(f->rbType, ArrayType, array); if (isCharArray(array) && rb_obj_is_instance_of(value, rb_cString)) { VALUE argv[2]; argv[0] = INT2FIX(f->offset); argv[1] = value; rb_funcall2(pointer, rb_intern("put_string"), 2, argv); } else { #ifdef notyet MemoryOp* op; int count = RARRAY_LEN(value); int i; AbstractMemory* memory = MEMORY(pointer); if (count > array->length) { rb_raise(rb_eIndexError, "array too large"); } /* clear the contents in case of a short write */ checkWrite(memory); checkBounds(memory, f->offset, f->type->ffiType->size); if (count < array->length) { memset(memory->address + f->offset + (count * array->componentType->ffiType->size), 0, (array->length - count) * array->componentType->ffiType->size); } /* now copy each element in */ if ((op = get_memory_op(array->componentType)) != NULL) { for (i = 0; i < count; ++i) { (*op->put)(memory, f->offset + (i * array->componentType->ffiType->size), rb_ary_entry(value, i)); } } else if (array->componentType->nativeType == NATIVE_STRUCT) { for (i = 0; i < count; ++i) { VALUE entry = rb_ary_entry(value, i); Struct* s; if (!rb_obj_is_kind_of(entry, rbffi_StructClass)) { rb_raise(rb_eTypeError, "array element not an instance of FFI::Struct"); break; } Data_Get_Struct(entry, Struct, s); checkRead(s->pointer); checkBounds(s->pointer, 0, array->componentType->ffiType->size); memcpy(memory->address + f->offset + (i * array->componentType->ffiType->size), s->pointer->address, array->componentType->ffiType->size); } } else { rb_raise(rb_eNotImpError, "put not supported for arrays of type %s", rb_obj_classname(array->rbComponentType)); } #else rb_raise(rb_eNotImpError, "cannot set array field"); #endif } return value; }
int printFilesOfFolder(FILE *arch, char *nameFolder) { char *currentNameFile; ArchFileInfo **foldersArch = NULL, **filesArch = NULL; ArchFileInfo *info = (ArchFileInfo *)malloc(sizeof(ArchFileInfo)); info->fileInfo = (FileInfo *)malloc(sizeof(FileInfo)); int64_t howFolders = 0, howFiles = 0; int64_t blocksFolder = 0, blocksFile = 0; int64_t i; fpos_t archPos; int err = 0; int64_t max_len = 0; if (!nameFolder) { nameFolder = "./."; } char *nameFolderCan = pathToCanon(nameFolder); printf("`%s`:\n", nameFolderCan); LOGGING_FUNC_START; fgetpos(arch, &archPos); while ((err = readHeader(arch, info)) != IO_EOF){ if (SIGNATURE_ERROR == err){ findSignature(arch); continue; } else if (err != 0){ break; } currentNameFile = info->fileInfo->name; if (isFolder(currentNameFile) && (levels(nameFolderCan) == levels(currentNameFile) - 1) && (pathInDest(nameFolderCan, currentNameFile))) { howFolders++; if (howFolders > blocksFolder * SIZE_BLOCK){ blocksFolder++; if ((foldersArch = (ArchFileInfo **)realloc(foldersArch, blocksFolder * SIZE_BLOCK * sizeof(ArchFileInfo *))) == NULL){ MEMORY(L"Memory allocate error!"); LOGGING_FUNC_STOP; return MEMORY_ALLOCATE_ERROR; } } foldersArch[howFolders - 1] = info; if ((int64_t)strlen(currentNameFile) > max_len) { max_len = strlen(currentNameFile); } } else if (!isFolder(currentNameFile) && (levels(nameFolderCan) == levels(currentNameFile)) && (pathInDest(nameFolderCan, currentNameFile))) { howFiles++; //printf("DEBUG: %s | %s \n", currentNameFile, ) if (howFiles > blocksFile * SIZE_BLOCK){ blocksFile++; if ((filesArch = (ArchFileInfo **)realloc(filesArch, blocksFile * SIZE_BLOCK * sizeof(ArchFileInfo *))) == NULL){ MEMORY(L"Memory allocate error!"); LOGGING_FUNC_STOP; return MEMORY_ALLOCATE_ERROR; } } filesArch[howFiles - 1] = info; if ((int64_t)strlen(currentNameFile) > max_len){ max_len = strlen(currentNameFile); } } fgetpos(arch, &archPos); // Goto next file // free(info->fileInfo); // free(info); info = malloc(sizeof(ArchFileInfo)); info->fileInfo = malloc(sizeof(FileInfo)); } double size_can; char char_size; for (i = 0;i < howFolders;i++) { if (strchr(foldersArch[i]->fileInfo->name + 2, '/') - foldersArch[i]->fileInfo->name + 1 != strlen(foldersArch[i]->fileInfo->name) - 1){ continue; } printf("%-*s|\n", (int)max_len, getFileByPath(nameFolderCan, foldersArch[i]->fileInfo->name) + 2); } for (i = 0; i < howFolders; i++){ printf("%s", foldersArch[i]->fileInfo->name); } for (i = 0;i < howFiles ;i++) { if ( strchr(filesArch[i]->fileInfo->name + 2,'/' ) != NULL){ continue; } size_can = (double)filesArch[i]->fileInfo->size; char_size = 'b'; if (size_can > 1024){ size_can /= 1024; char_size = 'K'; if (size_can > 1024){ size_can /= 1024; char_size = 'M'; } } printf("%-*s|%7.2f%c | %3d%%\n", (int)max_len, getFileByPath(nameFolderCan, filesArch[i]->fileInfo->name) + 2, size_can, char_size, (int)(filesArch[i]->dataSize * 100 / filesArch[i]->fileInfo->size)); } for(i = 0;i < howFiles;i++){ free(filesArch[i]->fileInfo); free(filesArch[i]); } for (i = 0;i < howFolders;i++){ free(foldersArch[i]->fileInfo); free(foldersArch[i]); } LOGGING_FUNC_STOP; return 0; }