--- deliantra/server/common/utils.C 2008/08/30 05:19:03 1.79 +++ deliantra/server/common/utils.C 2008/12/30 07:24:16 1.84 @@ -53,7 +53,7 @@ state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; for (int i = 11; --i; ) - operator ()(); + next (); } uint32_t @@ -67,19 +67,24 @@ return state [0] ^ state [1] ^ state [2] ^ state [3]; } +template uint32_t -tausworthe_random_generator::get_range (uint32_t num) +random_number_generator::get_range (uint32_t num) { - return (next () * (uint64_t)num) >> 32U; + return (this->next () * (uint64_t)num) >> 32U; } // return a number within (min .. max) +template int -tausworthe_random_generator::get_range (int r_min, int r_max) +random_number_generator::get_range (int r_min, int r_max) { return r_min + get_range (max (r_max - r_min + 1, 0)); } +template struct random_number_generator; +template struct random_number_generator; + /* * The random functions here take luck into account when rolling random * dice or numbers. This function has less of an impact the larger the @@ -202,9 +207,9 @@ /* convert materialname to materialtype_t */ materialtype_t * -name_to_material (const shstr &name) +name_to_material (const shstr_cmp name) { - for (materialtype_t *mt = materialt; mt && mt->next; mt = mt->next) + for (materialtype_t *mt = materialt; mt; mt = mt->next) if (name == mt->name) return mt; @@ -220,10 +225,10 @@ materialtype_t *mt; int j; - if (op->materialname == NULL) + if (!op->materialname) return; - if (change->materialname != NULL && strcmp (op->materialname, change->materialname)) + if (change->materialname && strcmp (op->materialname, change->materialname)) return; if (!op->is_armor ()) @@ -253,14 +258,16 @@ { materialtype_t *mt, *lmt; - if (op->materialname != NULL) + if (!op->materialname) return; - if (nmt == NULL) + if (nmt) + lmt = nmt; + else { - lmt = NULL; + lmt = 0; - for (mt = materialt; mt && mt->next; mt = mt->next) + for (mt = materialt; mt; mt = mt->next) if (op->materials & mt->material && rndm (1, 100) <= mt->chance && difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) { @@ -269,10 +276,8 @@ break; } } - else - lmt = nmt; - if (lmt != NULL) + if (lmt) { if (op->stats.dam && op->is_weapon ()) { @@ -451,7 +456,14 @@ { if (!fork ()) { - signal (SIGABRT, SIG_DFL); + signal (SIGINT , SIG_IGN); + signal (SIGTERM, SIG_IGN); + signal (SIGABRT, SIG_IGN); + + signal (SIGSEGV, SIG_DFL); + signal (SIGBUS , SIG_DFL); + signal (SIGILL , SIG_DFL); + signal (SIGTRAP, SIG_DFL); // try to put corefiles into a subdirectory, if existing, to allow // an administrator to reduce the I/O load. @@ -469,6 +481,14 @@ close (i); } + { + sigset_t empty; + sigemptyset (&empty); + sigprocmask (SIG_SETMASK, &empty, 0); + } + + // try to coredump with SIGTRAP + kill (getpid (), SIGTRAP); abort (); }