Division(i) = Location(i);
Parent(i) = Location(i);
}
- /* make sure their division is set correctly. */
- if(SDIV(i).object != -1 && SDIV(i).object == i) {
- do_rawlog(LT_ERR, T("ERROR: Bad Master-Division."));
- SDIV(i).object = -1;
- }
+
/* make sure their division is a valid object */
- if((!GoodObject(Division(i)) && Division(i) != NOTHING) || IsGarbage(Division(i))) {
- Division(i) = -1;
- do_rawlog(LT_ERR, T("ERROR: Bad Division(#%d) set on object #%d"), Division(i), i);
+ if((!GoodObject(Division(i)) && Division(i) != NOTHING)
+ || IsGarbage(Division(i))) {
+ Division(i) = NOTHING;
+ do_rawlog(LT_ERR, T("ERROR: Bad Division(#%d) set on object #%d"),
+ Division(i), i);
}
+
+ /* check for division loops */
+ if(GoodObject(Division(i))) {
+ dbref tmp;
+ unsigned j;
+
+ for(tmp = Division(i), j = 0; GoodObject(tmp) && j < MAX_DIVISION_DEPTH;
+ tmp = Division(tmp), j++) {
+ if(tmp == i) {
+ do_rawlog(LT_ERR, T("ERROR: Division loop detected at #%d"), i);
+ Division(i) = NOTHING;
+ Parent(i) = NOTHING;
+ }
+ }
+ }
+
/* now check parent tree */
if(Division(i) != -1)
Parent(i) = Division(i);
ATTR *divrcd;
char *p_buf[BUFFER_LEN / 2];
char buf[BUFFER_LEN], *bp;
- dbref cur_obj, divi;
+ dbref cur_obj, divi, tmp;
struct power_group_list *pg_l;
int cnt;
return;
}
- if (divi == target) {
- notify(exec, T("Can't division something to itself."));
- return;
+ for (tmp = divi; GoodObject(tmp); tmp = Division(tmp)) {
+ if (tmp == target) {
+ notify(exec, T("Can't create loops in division tree."));
+ return;
+ }
}
/* Make sure the receiving division has the quota to receive all of this crapp...
{
/* check if scopee is in the divscope of scoper */
dbref div1, div2;
+ unsigned i;
if (!GoodObject(scopee))
return 0;
if (div2 == NOTHING) /* they're automatically at the bottom of the divtree */
return 1;
- for (; div1 != div2; div2 = SDIV(div2).object)
+ for (i = 0; i < MAX_DIVISION_DEPTH && div1 != div2;
+ div2 = SDIV(div2).object, i++)
if (div2 == NOTHING) /* went off the tree */
return 0;
- else if (div2 == SDIV(div2).object) { /* detect & fix bad division tree */
- do_log(LT_ERR, scoper, scopee,
- T("Bad Master Division(#%d). Corrected."), div2);
- SDIV(div2).object = NOTHING;
- }
+
+ if (div1 != div2) { /* maximum depth reached without finding it */
+ do_rawlog(LT_ERR, T("Caught probable division loop circa #%d"), div1);
+ return 0;
+ }
+
return 1;
}