示例#1
0
static int tolua_faction_get(lua_State * L)
{
    int no = tolua_toid(L, 1, 0);
    faction *f = findfaction(no);
    tolua_pushusertype(L, f, TOLUA_CAST "faction");
    return 1;
}
示例#2
0
文件: gmcmd.c 项目: UweKopf/server
static void
gm_messagefaction(const void *tnext, struct unit *gm, struct order *ord)
{
  int n = getid();
  faction *f = findfaction(n);
  const char *msg = getstrtoken();
  plane *p = rplane(gm->region);
  attrib *permissions = a_find(gm->faction->attribs, &at_permissions);
  if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) {
    mistake(gm, ord, "permission denied.");
    return;
  }
  if (f != NULL) {
    region *r;
    for (r = regions; r; r = r->next)
      if (rplane(r) == p) {
        unit *u;
        for (u = r->units; u; u = u->next)
          if (u->faction == f) {
            add_message(&f->msgs, msg_message("msg_event", "string", msg));
            return;
          }
      }
  }
  mistake(gm, ord, "cannot send messages to this faction.");
}
示例#3
0
static int tolua_bindings_atlantis_factions_get00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_isnumber(tolua_S,1,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  int id = ((int)  tolua_tonumber(tolua_S,1,0));
  {
   faction* tolua_ret = (faction*)  findfaction(id);
    tolua_pushusertype(tolua_S,(void*)tolua_ret,"faction");
  }
 }
 return 1;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'get'.",&tolua_err);
 return 0;
#endif
}
示例#4
0
文件: group.c 项目: TomBraun/server
void read_groups(struct storage *store, faction * f)
{
  for (;;) {
    ally **pa;
    group *g;
    int gid;
    char buf[1024];

    READ_INT(store, &gid);
    if (gid == 0)
      break;
    READ_STR(store, buf, sizeof(buf));
    g = new_group(f, buf, gid);
    pa = &g->allies;
    for (;;) {
      ally *a;
      variant fid;
      READ_INT(store, &fid.i);
      if (fid.i <= 0)
        break;
      if (global.data_version < STORAGE_VERSION && fid.i == 0)
        break;
      a = malloc(sizeof(ally));
      *pa = a;
      pa = &a->next;
      READ_INT(store, &a->status);

      a->faction = findfaction(fid.i);
      if (!a->faction)
        ur_add(fid, &a->faction, resolve_faction);
    }
    *pa = 0;
    a_read(store, &g->attribs, g);
  }
}
示例#5
0
static int createunit_read(trigger * t, gamedata *data)
{
    createunit_data *td = (createunit_data *)t->data.v;
    variant var;
    int result = AT_READ_OK;
    var = read_faction_reference(data);
    if (var.i > 0) {
        td->f = findfaction(var.i);
        if (!td->f) {
            ur_add(var, &td->f, resolve_faction);
        }
    }
    else {
        result = AT_READ_FAIL;
    }
    // read_reference(&td->f, store, read_faction_reference, resolve_faction);

    read_reference(&td->r, data, read_region_reference,
        RESOLVE_REGION(data->version));
    td->race = (const struct race *)read_race_reference(data->store).v;
    if (!td->race) {
        result = AT_READ_FAIL;
    }
    READ_INT(data->store, &td->number);
    return result;
}
示例#6
0
static void test_addfaction(CuTest *tc) {
    faction *f = 0;
    const struct race *rc;
    const struct locale *lang;

    test_cleanup();
    rc = rc_get_or_create("human");
    lang = test_create_locale();
    f = addfaction("*****@*****.**", "hurrdurr", rc, lang, 1234);
    CuAssertPtrNotNull(tc, f);
    CuAssertPtrNotNull(tc, f->name);
    CuAssertPtrEquals(tc, NULL, (void *)f->units);
    CuAssertPtrEquals(tc, NULL, (void *)f->next);
    CuAssertPtrEquals(tc, NULL, (void *)f->banner);
    CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
    CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
    CuAssertPtrEquals(tc, (void *)factions, (void *)f);
    CuAssertStrEquals(tc, "*****@*****.**", f->email);
    CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
    CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
    CuAssertIntEquals(tc, 1234, f->subscription);
    CuAssertIntEquals(tc, FFL_ISNEW, f->flags);
    CuAssertIntEquals(tc, 0, f->age);
    CuAssertTrue(tc, faction_alive(f));
    CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
    CuAssertIntEquals(tc, turn, f->lastorders);
    CuAssertPtrEquals(tc, f, findfaction(f->no));
    test_cleanup();
}
示例#7
0
文件: gmcmd.c 项目: UweKopf/server
/**
 ** GM: KILL FACTION <id> <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_killfaction(const void *tnext, struct unit *u, struct order *ord)
{
  int n = getid();
  faction *f = findfaction(n);
  const char *msg = getstrtoken();
  plane *p = rplane(u->region);
  attrib *permissions = a_find(u->faction->attribs, &at_permissions);
  if (!permissions || !has_permission(permissions, atoi36("gmkill"))) {
    mistake(u, ord, "permission denied.");
    return;
  }
  if (f != NULL) {
    region *r;
    for (r = regions; r; r = r->next)
      if (rplane(r) == p) {
        unit *target;
        for (target = r->units; target; target = target->next) {
          if (target->faction == f) {
            scale_number(target, 0);
            ADDMSG(&target->faction->msgs, msg_message("killedbygm",
                "region unit string", r, target, msg));
            return;
          }
        }
      }
  }
  mistake(u, ord, "cannot remove a unit from this faction.");
}
示例#8
0
文件: group.c 项目: Xolgrim/server
void read_groups(struct storage *store, faction * f)
{
    for (;;) {
        ally **pa;
        group *g;
        int gid;
        char buf[1024];

        READ_INT(store, &gid);
        if (gid == 0)
            break;
        READ_STR(store, buf, sizeof(buf));
        g = new_group(f, buf, gid);
        pa = &g->allies;
        for (;;) {
            ally *a;
            variant fid;

            READ_INT(store, &fid.i);
            if (fid.i <= 0)
                break;
            a = ally_add(pa, findfaction(fid.i));
            READ_INT(store, &a->status);
            if (!a->faction)
                ur_add(fid, &a->faction, resolve_faction);
        }
        a_read(store, &g->attribs, g);
    }
}
示例#9
0
文件: gmcmd.c 项目: UweKopf/server
faction *gm_addfaction(const char *email, plane * p, region * r)
{
  attrib *a;
  unit *u;
  faction *f = calloc(1, sizeof(faction));

  assert(p != NULL);

  /* GM faction */
  a_add(&f->attribs, make_key(atoi36("quest")));
  f->banner = _strdup("quest faction");
  f->name = _strdup("quest faction");
  f->passw = _strdup(itoa36(rng_int()));
  if (set_email(&f->email, email) != 0) {
    log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
  }
  f->race = new_race[RC_TEMPLATE];
  f->age = 0;
  f->lastorders = turn;
  f->alive = true;
  f->locale = default_locale;
  f->options =
    want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN);
  {
    faction *xist;
    int id = atoi36("gm00") - 1;
    do {
      xist = findfaction(++id);
    } while (xist);

    f->no = id;
    addlist(&factions, f);
    fhash(f);
  }

  /* generic permissions */
  a = a_add(&f->attribs, a_new(&at_permissions));
  if (a) {
    attrib *ap = (attrib *) a->data.v;
    const char *keys[] =
      { "gmterf", "gmtele", "gmgive", "gmskil", "gmtake", "gmmsgr", "gmmsgu",
        "gmgate", 0 };
    const char **key_p = keys;
    while (*key_p) {
      add_key(&ap, atoi36(*key_p));
      ++key_p;
    }
    a_add(&ap, make_atgmcreate(resource2item(r_silver)));

    a->data.v = ap;
  }

  /* one initial unit */
  u = create_unit(r, f, 1, new_race[RC_TEMPLATE], 1, "quest master", NULL);
  u->irace = new_race[RC_GNOME];

  return f;
}
示例#10
0
文件: faction.c 项目: eressea/server
faction *get_or_create_monsters(void)
{
    faction *f = findfaction(MONSTER_ID);
    if (!f) {
        const race *rc = rc_get_or_create("dragon");
        const char *email = config_get("monster.email");
        f = addfaction(email, NULL, rc, default_locale);
        renumber_faction(f, MONSTER_ID);
        faction_setname(f, "Monster");
        fset(f, FFL_NPC | FFL_NOIDLEOUT);
    }
    return f;
}
示例#11
0
static int tolua_faction_set_id(lua_State * L)
{
    faction *self = (faction *)tolua_tousertype(L, 1, 0);
    int id = (int)tolua_tonumber(L, 2, 0);
    if (findfaction(id) == NULL) {
        renumber_faction(self, id);
        lua_pushboolean(L, 1);
    }
    else {
        lua_pushboolean(L, 0);
    }
    return 1;
}
示例#12
0
文件: monster.c 项目: Xolgrim/server
faction *get_or_create_monsters(void)
{
    faction *f = findfaction(MONSTER_ID);
    if (!f) {
        const race *rc = rc_get_or_create("dragon");
        const char *email = get_param(global.parameters, "monster.email");
        f = addfaction(email ? email : "*****@*****.**", NULL, rc, default_locale, 0);
        renumber_faction(f, MONSTER_ID);
        faction_setname(f, "Monster");
        fset(f, FFL_NPC | FFL_NOIDLEOUT);
    }
    return f;
}
示例#13
0
static void test_remove_dead_factions(CuTest *tc) {
    faction *f, *fm;
    region *r;
    int fno;

    test_cleanup();
    r = test_create_region(0, 0, 0);
    fm = get_or_create_monsters();
    f = test_create_faction(0);
    assert(fm && r && f);
    test_create_unit(f, r);
    test_create_unit(fm, r);
    remove_empty_factions();
    CuAssertPtrEquals(tc, f, findfaction(f->no));
    CuAssertPtrNotNull(tc, get_monsters());
    fm->units = 0;
    f->_alive = false;
    fno = f->no;
    remove_empty_factions();
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    CuAssertPtrEquals(tc, fm, get_monsters());
    test_cleanup();
}
示例#14
0
文件: faction.c 项目: eressea/server
int read_faction_reference(gamedata * data, faction **fp)
{
    int id;
    READ_INT(data->store, &id);
    if (id > 0) {
        *fp = findfaction(id);
        if (*fp == NULL) {
            *fp = faction_create(id);
        }
    }
    else {
        *fp = NULL;
    }
    return id;
}
示例#15
0
static void test_remove_empty_factions(CuTest *tc) {
    faction *f, *fm;
    int fno;

    test_cleanup();
    fm = get_or_create_monsters();
    assert(fm);
    f = test_create_faction(0);
    fno = f->no;
    remove_empty_factions();
    CuAssertIntEquals(tc, false, f->_alive);
    CuAssertPtrEquals(tc, fm, factions);
    CuAssertPtrEquals(tc, NULL, fm->next);
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    CuAssertPtrEquals(tc, fm, get_monsters());
    test_cleanup();
}
示例#16
0
文件: arena.c 项目: UweKopf/server
static void guardian_faction(plane * pl, int id)
{
  region *r;
  faction *f = findfaction(id);

  if (!f) {
    f = calloc(1, sizeof(faction));
    f->banner = _strdup("Sie dienen dem großen Wyrm");
    f->passw = _strdup(itoa36(rng_int()));
    set_email(&f->email, "*****@*****.**");
    f->name = _strdup("Igjarjuks Kundschafter");
    f->race = new_race[RC_ILLUSION];
    f->age = turn;
    f->locale = find_locale("de");
    f->options =
      want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN) |
      want(O_DEBUG);

    f->no = id;
    addlist(&factions, f);
    fhash(f);
  }
  if (f->race != new_race[RC_ILLUSION]) {
    assert(!"guardian id vergeben");
    exit(0);
  }
  f->lastorders = turn;
  f->alive = true;
  for (r = regions; r; r = r->next)
    if (getplane(r) == pl && rterrain(r) != T_FIREWALL) {
      unit *u;
      freset(r, RF_ENCOUNTER);
      for (u = r->units; u; u = u->next) {
        if (u->faction == f)
          break;
      }
      if (u)
        continue;
      u = createunit(r, f, 1, new_race[RC_GOBLIN]);
      set_string(&u->name, "Igjarjuks Auge");
      set_item(u, I_RING_OF_INVISIBILITY, 1);
      set_order(&u->thisorder, NULL);
      fset(u, UFL_ANON_FACTION);
      set_money(u, 1000);
    }
}
示例#17
0
static void test_group_readwrite_dead_faction(CuTest *tc) {
    gamedata data;
    storage store;
    faction *f, *f2;
    unit * u;
    group *g;
    ally *al;
    int fno;

    test_cleanup();
    f = test_create_faction(0);
    fno = f->no;
    CuAssertPtrEquals(tc, f, factions);
    CuAssertPtrEquals(tc, 0, f->next);
    f2 = test_create_faction(0);
    CuAssertPtrEquals(tc, f2, factions->next);
    u = test_create_unit(f2, test_create_region(0, 0, 0));
    CuAssertPtrNotNull(tc, u);
    g = join_group(u, "group");
    CuAssertPtrNotNull(tc, g);
    al = ally_add(&g->allies, f);
    CuAssertPtrNotNull(tc, al);

    CuAssertPtrEquals(tc, f, factions);
    destroyfaction(&factions);
    CuAssertTrue(tc, !f->_alive);
    CuAssertPtrEquals(tc, f2, factions);
    mstream_init(&data.strm);
    gamedata_init(&data, &store, RELEASE_VERSION);
    write_game(&data);
    free_gamedata();
    f = f2 = NULL;
    data.strm.api->rewind(data.strm.handle);
    read_game(&data);
    mstream_done(&data.strm);
    gamedata_done(&data);
    CuAssertPtrEquals(tc, 0, findfaction(fno));
    f2 = factions;
    CuAssertPtrNotNull(tc, f2);
    u = f2->units;
    CuAssertPtrNotNull(tc, u);
    g = get_group(u);
    CuAssertPtrNotNull(tc, g);
    CuAssertPtrEquals(tc, 0, g->allies);
    test_cleanup();
}
示例#18
0
void read_allies(gamedata * data, allies **p_al)
{
    for (;;) {
        faction *f;
        int aid, status;
        READ_INT(data->store, &aid);
        /* TODO: deal with unresolved factions, somehow */
        if (aid <= 0) {
            break;
        }
        f = findfaction(aid);
        if (!f) f = faction_create(aid);
        READ_INT(data->store, &status);
        /* NB: some data files have allies with status=0 */
        if (status > 0) {
            ally_set(p_al, f, status);
        }
    }
}
示例#19
0
文件: faction.c 项目: eressea/server
faction *getfaction(void)
{
    return findfaction(getid());
}
示例#20
0
文件: faction.c 项目: eressea/server
bool faction_id_is_unused(int id)
{
    return findfaction(id) == NULL;
}