33#define log_attribute log_debug
52#define SPECHASH_TAG attribute
53#define SPECHASH_IKEY_TYPE struct attr_key *
54#define SPECHASH_IDATA_TYPE void *
55#define SPECHASH_IKEY_VAL attr_key_val
56#define SPECHASH_IKEY_COMP attr_key_comp
57#define SPECHASH_IKEY_COPY attr_key_dup
58#define SPECHASH_IKEY_FREE attr_key_destroy
59#define SPECHASH_IDATA_FREE free
61#define attribute_hash_values_iterate(hash, pvalue) \
62 TYPED_HASH_DATA_ITERATE(void *, hash, pvalue)
63#define attribute_hash_values_iterate_end HASH_DATA_ITERATE_END
64#define attribute_hash_iterate(hash, pkey, pvalue) \
65 TYPED_HASH_ITERATE(const struct attr_key *, void *, hash, pkey, pvalue)
66#define attribute_hash_iterate_end HASH_ITERATE_END
85 return pkey1->
key == pkey2->
key
86 && pkey1->
id == pkey2->
id
87 && pkey1->
x == pkey2->
x
88 && pkey1->
y == pkey2->
y;
135 void **pdata,
int *pdata_length)
153 int total_length, value_lengths[
entries];
163 total_length = 4 + 1 + 4 + 4;
165 total_length +=
entries * (4 + 4 + 4 + 2 + 2);
173 total_length += value_lengths[i];
209 "serialize_hash() total_length = %lu, actual = %lu",
210 (
long unsigned)total_length,
217 *pdata_length = total_length;
219 "serialized %lu entries in %lu bytes",
220 (
long unsigned)
entries, (
long unsigned) total_length);
237 attribute_hash_clear(
hash);
243 log_verbose(
"attribute.c unserialize_hash() preamble, uint32 %lu != 0",
244 (
long unsigned) dummy);
249 log_verbose(
"attribute.c unserialize_hash() preamble, "
250 "uint8 %lu != 2 version", (
long unsigned) dummy);
255 if (dummy != data_length) {
256 log_verbose(
"attribute.c unserialize_hash() preamble, "
257 "uint32 %lu != %lu data_length",
258 (
long unsigned) dummy, (
long unsigned) data_length);
263 "uint32 %lu entries, %lu data_length",
264 (
long unsigned)
entries, (
long unsigned) data_length);
266 for (i = 0; i <
entries; i++) {
274 "uint32 value_length dio_input_too_short");
278 "uint32 %lu value_length", (
long unsigned) value_length);
286 "uint32 key dio_input_too_short");
295 "memory dio_input_too_short");
299 if (!attribute_hash_insert(
hash, &key, pvalue)) {
306 attribute_hash_clear(
hash);
316 "ignored %lu trailing octets",
369 "Your citizen governor settings may be broken."));
372 log_normal(
_(
"Old attributes detected and removed."));
384 const void *
const data)
388 log_attribute(
"attribute_set(key = %d, id = %d, x = %d, y = %d, "
389 "data_length = %lu, data = %p)",
key,
id,
x,
y,
390 (
long unsigned) data_length, data);
394 if (0 != data_length) {
395 void *pvalue =
fc_malloc(data_length + 4);
423 log_attribute(
"attribute_get(key = %d, id = %d, x = %d, y = %d, "
424 "max_data_length = %lu, data = %p)", key,
id, x, y,
425 (
long unsigned) max_data_length, data);
437 if (length <= max_data_length) {
449 const void *
const data)
460 return attribute_get(what, unit_id, -1, -2, max_data_length, data);
483 const void *
const data)
494 return attribute_get(what, city_id, -1, -1, max_data_length, data);
517 const void *
const data)
526 size_t max_data_length,
void *data)
528 return attribute_get(what, player_id, -1, -1, max_data_length, data);
535 const void *
const data)
struct @124::my_agent entries[MAX_AGENTS]
void attribute_set(int key, int id, int x, int y, size_t data_length, const void *const data)
static struct attribute_hash * attribute_hash
size_t attr_city_get_int(enum attr_city what, int city_id, int *data)
static void attr_key_destroy(struct attr_key *pkey)
void attribute_init(void)
void attribute_free(void)
size_t attr_tile_get(enum attr_tile what, int x, int y, size_t max_data_length, void *data)
void attr_player_set(enum attr_player what, int player_id, size_t data_length, const void *const data)
size_t attr_unit_get_int(enum attr_unit what, int unit_id, int *data)
void attr_tile_set(enum attr_tile what, int x, int y, size_t data_length, const void *const data)
static enum attribute_serial unserialize_hash(struct attribute_hash *hash, const void *data, size_t data_length)
void attribute_flush(void)
#define attribute_hash_iterate_end
size_t attribute_get(int key, int id, int x, int y, size_t max_data_length, void *data)
size_t attr_city_get(enum attr_city what, int city_id, size_t max_data_length, void *data)
static struct attr_key * attr_key_dup(const struct attr_key *pkey)
#define attribute_hash_values_iterate_end
static genhash_val_t attr_key_val(const struct attr_key *pkey)
void attribute_restore(void)
void attr_unit_set(enum attr_unit what, int unit_id, size_t data_length, const void *const data)
size_t attr_unit_get(enum attr_unit what, int unit_id, size_t max_data_length, void *data)
size_t attr_player_get(enum attr_player what, int player_id, size_t max_data_length, void *data)
static enum attribute_serial serialize_hash(const struct attribute_hash *hash, void **pdata, int *pdata_length)
#define attribute_hash_iterate(hash, pkey, pvalue)
void attr_unit_set_int(enum attr_unit what, int unit_id, int data)
static bool attr_key_comp(const struct attr_key *pkey1, const struct attr_key *pkey2)
void attr_city_set_int(enum attr_city what, int city_id, int data)
void attr_city_set(enum attr_city what, int city_id, size_t data_length, const void *const data)
#define attribute_hash_values_iterate(hash, pvalue)
bool client_is_observer(void)
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
size_t dio_input_remaining(struct data_in *din)
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
void dio_put_sint16_raw(struct raw_data_out *dout, int value)
bool dio_get_uint32_raw(struct data_in *din, int *dest)
bool dio_get_sint16_raw(struct data_in *din, int *dest)
void dio_put_uint32_raw(struct raw_data_out *dout, int value)
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
void dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
bool dio_get_uint8_raw(struct data_in *din, int *dest)
size_t dio_output_used(struct raw_data_out *dout)
void dio_input_init(struct data_in *din, const void *src, size_t src_size)
unsigned int genhash_val_t
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_normal(message,...)
#define log_error(message,...)
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
#define ADD_TO_POINTER(p, n)
struct attribute_block_s attribute_block