Example #1
0
void init_world(void)
{
	int x, y;
	cform * f;

	world.zones = malloc(sizeof(zone *));

	load_iforms();
	load_cforms();

	*world.zones = zone_new(500, 300);

	f = cform_new('@' | A_BOLD);
	f->weight = TILE_MAX_WEIGHT / 2;
	f->max_health = 10;

	crtr_init(&world.plyr, f);
	world.plyr.nofree = 1;
	world.plyr.inv = inv_new(500);
	world.plyr.attack = 5;

	do {
		x = random() % get_dispw();
		y = random() % get_disph();
	} while (!crtr_tele(&world.plyr, x, y, *world.zones));

	zone_update(world.plyr.z, x, y);
}
Example #2
0
/* Create fake root zone. */
void create_root_zone(server_t *server, mm_ctx_t *mm)
{
	/* Insert root zone. */
	conf_zone_t *conf = malloc(sizeof(conf_zone_t));
	conf_init_zone(conf);
	conf->name = strdup(".");

	zone_t *root = zone_new(conf);
	root->contents = knot_zone_contents_new(root->name);

	knot_rrset_t *soa_rrset = knot_rrset_new(root->name,
	                                         KNOT_RRTYPE_SOA, KNOT_CLASS_IN,
	                                         NULL);
	knot_rrset_add_rdata(soa_rrset, SOA_RDATA, SOA_RDLEN, 7200, NULL);
	node_add_rrset(root->contents->apex, soa_rrset, NULL);

	/* Bake the zone. */
	zone_node_t *first_nsec3 = NULL, *last_nsec3 = NULL;
	knot_zone_contents_adjust_full(root->contents, &first_nsec3, &last_nsec3);

	/* Switch zone db. */
	knot_zonedb_free(&server->zone_db);
	server->zone_db = knot_zonedb_new(1);
	knot_zonedb_insert(server->zone_db, root);
	knot_zonedb_build_index(server->zone_db);
}
Example #3
0
File: world.c Project: cmr/iiag
//
// Performs the first initialization of the world
// Will call assure_world if it has yet to be called
//
void init_world(void) {
	zone * z;

	assure_world();

	z = zone_new(150, 50);
	vector_append(&world.zones, z);

	world.plyr.on_death.c_func    = (trigger_cfunc)plyr_ev_death;
	world.plyr.on_lvlup.c_func    = (trigger_cfunc)plyr_ev_lvlup;
	world.plyr.on_act_comp.c_func = (trigger_cfunc)plyr_ev_act_comp;
	world.plyr.on_act_fail.c_func = (trigger_cfunc)plyr_ev_act_fail;
	world.plyr.refs = NOFREE;

	crtr_spawn(&world.plyr, z);
	zone_update(z, world.plyr.x, world.plyr.y);
}
Example #4
0
File: player.c Project: cmr/iiag
void plyr_act_enter(int argc, char ** argv) {
	int ox, oy;
	zone * oz;
	tile * t = tileof(&PLYR);

	if (t->linked) {
		// TODO generalize

		if (t->link_z == NULL) {
			ox = PLYR.x;
			oy = PLYR.y;
			oz = PLYR.z;

			// generate new zone
			vector_append(&world.zones, zone_new(150, 50)); // TODO why 150,50?
			t->link_z = world.zones.arr[world.zones.cnt - 1];

			// place player randomly
			crtr_spawn(&PLYR, t->link_z);
			t->link_x = PLYR.x;
			t->link_y = PLYR.y;

			// link back
			t = tileof(&PLYR);
			t->linked = 1;
			t->link_x = ox;
			t->link_y = oy;
			t->link_z = oz;
			t->ch = '@';
			t->show_ch = '@';
		} else {
			if (!crtr_tele(&PLYR, t->link_x, t->link_y, t->link_z)) {
				memo("Your way appears to be blocked?");
			}
		}

		update_vis();
		zone_draw(PLYR.z);
	} else {
		memo("I see no visible method of doing that.");
	}
}
Example #5
0
File: rrl.c Project: dnstap/knot
int main(int argc, char *argv[])
{
	plan(10);

	/* Prepare query. */
	knot_pkt_t *query = knot_pkt_new(NULL, 512, NULL);
	if (query == NULL) {
		return KNOT_ERROR; /* Fatal */
	}

	knot_dname_t *qname = knot_dname_from_str("beef.");
	int ret = knot_pkt_put_question(query, qname, KNOT_CLASS_IN, KNOT_RRTYPE_A);
	knot_dname_free(&qname, NULL);
	if (ret != KNOT_EOK) {
		knot_pkt_free(&query);
		return KNOT_ERROR; /* Fatal */
	}

	/* Prepare response */
	uint8_t rbuf[65535];
	size_t rlen = sizeof(rbuf);
	memcpy(rbuf, query->wire, query->size);
	knot_wire_flags_set_qr(rbuf);

	rrl_req_t rq;
	rq.w = rbuf;
	rq.len = rlen;
	rq.query = query;
	rq.flags = 0;

	/* 1. create rrl table */
	rrl_table_t *rrl = rrl_create(RRL_SIZE);
	ok(rrl != NULL, "rrl: create");

	/* 2. set rate limit */
	uint32_t rate = 10;
	rrl_setrate(rrl, rate);
	is_int(rate, rrl_rate(rrl), "rrl: setrate");

	/* 3. setlocks */
	ret = rrl_setlocks(rrl, RRL_LOCKS);
	is_int(KNOT_EOK, ret, "rrl: setlocks");

	/* 4. N unlimited requests. */
	conf_zone_t *zone_conf = malloc(sizeof(conf_zone_t));
	conf_init_zone(zone_conf);
	zone_conf->name = strdup("rrl.");
	zone_t *zone = zone_new(zone_conf);

	struct sockaddr_storage addr;
	struct sockaddr_storage addr6;
	sockaddr_set(&addr, AF_INET, "1.2.3.4", 0);
	sockaddr_set(&addr6, AF_INET6, "1122:3344:5566:7788::aabb", 0);
	ret = 0;
	for (unsigned i = 0; i < rate; ++i) {
		if (rrl_query(rrl, &addr, &rq, zone) != KNOT_EOK ||
		    rrl_query(rrl, &addr6, &rq, zone) != KNOT_EOK) {
			ret = KNOT_ELIMIT;
			break;
		}
	}
	is_int(0, ret, "rrl: unlimited IPv4/v6 requests");

#ifdef ENABLE_TIMED_TESTS
	/* 5. limited request */
	ret = rrl_query(rrl, &addr, &rq, zone);
	is_int(0, ret, "rrl: throttled IPv4 request");

	/* 6. limited IPv6 request */
	ret = rrl_query(rrl, &addr6, &rq, zone);
	is_int(0, ret, "rrl: throttled IPv6 request");
#else
	skip_block(2, "Timed tests not enabled");
#endif

	/* 7. invalid values. */
	ret = 0;
	rrl_create(0);            // NULL
	ret += rrl_setrate(0, 0); // 0
	ret += rrl_rate(0);       // 0
	ret += rrl_setlocks(0,0); // -1
	ret += rrl_query(0, 0, 0, 0); // -1
	ret += rrl_query(rrl, 0, 0, 0); // -1
	ret += rrl_query(rrl, (void*)0x1, 0, 0); // -1
	ret += rrl_destroy(0); // -1
	is_int(-488, ret, "rrl: not crashed while executing functions on NULL context");

#ifdef ENABLE_TIMED_TESTS
	/* 8. hopscotch test */
	struct runnable_data rd = {
		1, rrl, &addr, &rq, zone
	};
	rrl_hopscotch(&rd);
	ok(rd.passed, "rrl: hashtable is ~ consistent");

	/* 9. reseed */
	is_int(0, rrl_reseed(rrl), "rrl: reseed");

	/* 10. hopscotch after reseed. */
	rrl_hopscotch(&rd);
	ok(rd.passed, "rrl: hashtable is ~ consistent");
#else
	skip_block(3, "Timed tests not enabled");
#endif

	zone_free(&zone);
	knot_pkt_free(&query);
	rrl_destroy(rrl);
	return 0;
}