53 const struct tile *ptile,
54 enum event_type
event,
57 const char *format, va_list vargs)
64 packet->tile = (
nullptr != ptile ?
tile_index(ptile) : -1);
65 packet->event =
event;
66 packet->conn_id = pconn ? pconn->
id : -1;
104 const struct ft_color color,
const char *format,
124 const struct ft_color color,
const char *format, ...)
128 va_start(args, format);
147 const char *format, va_list vargs)
166 const char *format, ...)
170 va_start(args, format);
187 const struct packet_chat_msg *packet,
190 struct packet_chat_msg real_packet = *packet;
191 int tile = packet->tile;
203 if ((packet->event == E_LOG_ERROR || packet->event == E_LOG_FATAL)
204 && pconn->access_level != ALLOW_HACK) {
209 && ((
nullptr == pconn->playing && pconn->observer)
210 || (
nullptr != pconn->playing
215 real_packet.tile =
tile;
218 real_packet.tile = -1;
222 send_packet_early_chat_msg(
224 reinterpret_cast<struct packet_early_chat_msg *
>(&real_packet));
226 send_packet_chat_msg(pconn, &real_packet);
237 const char *format, ...)
239 struct packet_chat_msg genmsg;
242 va_start(args, format);
260 const char *format, ...)
262 struct packet_chat_msg genmsg;
265 va_start(args, format);
286 const char *format, ...)
288 struct conn_list *dest = pplayer ? pplayer->
connections :
nullptr;
289 struct packet_chat_msg genmsg;
292 va_start(args, format);
308 const char *format, ...)
310 struct packet_chat_msg genmsg;
314 va_start(args, format);
321 && pplayer != other_player) {
338 const char *format, ...)
341 struct packet_chat_msg genmsg;
345 va_start(args, format);
350 dest = conn_list_new();
358 conn_list_append(dest, pconn);
376 conn_list_destroy(dest);
387 const struct player *exclude,
enum event_type
event,
388 const struct ft_color color,
const char *format, ...)
390 struct packet_chat_msg genmsg;
394 va_start(args, format);
400 if (exclude != aplayer) {
401 lsend_packet_chat_msg(aplayer->connections, &genmsg);
427 const struct player *exclude,
428 enum event_type
event,
430 const char *format, ...)
432 struct packet_chat_msg genmsg;
436 va_start(args, format);
442 if (exclude == aplayer ||
research_get(aplayer) == presearch) {
449 lsend_packet_chat_msg(aplayer->connections, &genmsg);
469 struct packet_chat_msg
packet;
476 #define SPECLIST_TAG event_cache_data
477 #define SPECLIST_TYPE struct event_cache_data
479 #define event_cache_iterate(pdata) \
480 TYPED_LIST_ITERATE(struct event_cache_data, event_cache, pdata)
481 #define event_cache_iterate_end LIST_ITERATE_END
508 enum server_states server_status,
522 if (
packet->event == E_MESSAGE_WALL) {
552 while (event_cache_data_list_size(
event_cache) > max_events) {
596 current = event_cache_data_list_get(
event_cache, 0);
598 while (current !=
nullptr
602 current = event_cache_data_list_get(
event_cache, 0);
621 const struct packet_chat_msg *
packet)
637 const struct player *pplayer)
639 if (
nullptr == pplayer) {
665 if (0 <
game.
server.event_cache.turns &&
nullptr != players
672 if (
nullptr != players) {
694 const struct player *pplayer)
696 if (
nullptr == players) {
701 if (
nullptr != pplayer) {
712 const struct player *pplayer,
713 bool is_global_observer,
bool include_public)
727 return include_public;
729 return (
nullptr != pplayer
732 return is_global_observer;
747 struct packet_chat_msg pcm;
755 strftime(timestr,
sizeof(timestr),
"%H:%M:%S",
756 localtime(&pdata->timestamp));
758 fc_snprintf(pcm.message,
sizeof(pcm.message),
"(T%d - %s) %s",
759 pdata->packet.turn, timestr, pdata->packet.message);
774 struct packet_chat_msg packet;
776 enum server_states server_status;
778 int i, x, y, event_count;
779 time_t timestamp, now;
783 qDebug(
"Saved events: %d.", event_count);
785 if (0 >= event_count) {
790 for (i = 0; i < event_count; i++) {
803 qDebug(
"[Event cache %4d] Missing event type.", i);
807 if (!event_type_is_valid(packet.event)) {
808 qDebug(
"[Event cache %4d] Not supported event type: %s", i, p);
814 qDebug(
"[Event cache %4d] Missing message.", i);
825 "%s.events%d.phase",
section, i);
826 packet.phase = phase;
829 file, now,
"%s.events%d.timestamp",
section, i);
833 qDebug(
"[Event cache %4d] Missing server state info.", i);
837 if (!server_states_is_valid(server_status)) {
838 qDebug(
"[Event cache %4d] Server state no supported: %s", i, p);
844 qDebug(
"[Event cache %4d] Missing target info.", i);
859 }
else if (
'0' != *q) {
869 if (!valid &&
nullptr == players) {
870 qDebug(
"[Event cache %4d] invalid target bitmap: %s", i, p);
878 target_type, players);
881 qDebug(
"Event %4d loaded.", i);
901 int tile_x = -1, tile_y = -1;
903 if (ptile !=
nullptr) {
924 "%s.events%d.server_state",
section, event_count);
926 "%s.events%d.event",
section, event_count);
927 switch (pdata->target_type) {
941 fc_snprintf(target,
sizeof(target),
"Global Observers");
949 qDebug(
"Event %4d saved.", event_count);
958 qDebug(
"Events saved: %d.", event_count);
970 if (pdata->packet.phase >= 0) {
bool BV_ISSET(const BV &bv, int bit)
#define BV_ISSET_ANY(vec)
struct player * conn_get_player(const struct connection *pconn)
Returns the player that this connection is attached to, or nullptr.
bool conn_is_global_observer(const struct connection *pconn)
Returns TRUE if the given connection is a global observer.
#define conn_list_iterate(connlist, pconn)
#define conn_list_iterate_end
#define PHASE_INVALIDATED
#define MAX_NUM_PLAYER_SLOTS
char * capitalized_string(const char *str)
This function tries to capitalize first letter of the string.
bool is_capitalization_enabled()
Automatic capitalization features requested.
size_t featured_text_apply_tag(const char *text_source, char *featured_text, size_t featured_text_len, enum text_tag_type tag_type, ft_offset_t start_offset, ft_offset_t stop_offset,...)
Apply a tag to a text.
static bool ft_color_requested(const struct ft_color color)
#define GAME_MAX_EVENT_CACHE_MAX_SIZE
#define fc_assert_ret(condition)
#define fc_assert_ret_val(condition, val)
bool is_normal_map_pos(int x, int y)
Returns TRUE iff the map position is normal.
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Return the tile for the given index position.
static int map_pos_to_index(struct civ_map *nmap, int map_x, int map_y)
#define index_to_map_pos(pmap_x, pmap_y, mindex)
bool map_is_known(const struct tile *ptile, const struct player *pplayer)
Return whether the player knows the tile.
void event_cache_clear()
Remove all events from the cache.
void event_cache_init()
Initializes the event cache.
struct event_cache_players * event_cache_player_add(struct event_cache_players *players, const struct player *pplayer)
Select players for event_cache_add_for_players().
void notify_research(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that share research.
#define event_cache_iterate(pdata)
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Similar to notify_conn_packet (see also), but takes player as "destination".
void send_pending_events(struct connection *pconn, bool include_public)
Send all available events.
void package_chat_msg(struct packet_chat_msg *packet, const struct connection *sender, const struct ft_color color, const char *format,...)
Fill a packet_chat_msg structure for a chat message.
void event_cache_add_for_players(const struct packet_chat_msg *packet, struct event_cache_players *players)
Add an event to the cache for selected players.
void event_cache_load(struct section_file *file, const char *section)
Load the event cache from a savefile.
void notify_research_embassies(const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players that have embassies with someone who shares research.
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
void event_cache_remove_old()
Remove the old events from the cache.
void vpackage_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format, va_list vargs)
Fill a packet_chat_msg structure for common server event.
event_cache_target
Event cache datas.
void event_cache_free()
Frees the event cache.
void notify_team(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Sends a message to all players on pplayer's team.
static struct event_cache_data * event_cache_data_new(const struct packet_chat_msg *packet, time_t timestamp, enum server_states server_status, enum event_cache_target target_type, struct event_cache_players *players)
Creates a new event_cache_data, appened to the list.
void event_cache_phases_invalidate()
Mark all existing phase values in event cache invalid.
void notify_embassies(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Send message to all players who have an embassy with pplayer, but excluding pplayer and specified pla...
static void notify_conn_packet(struct conn_list *dest, const struct packet_chat_msg *packet, bool early)
This is the basis for following notify_* functions.
void package_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Fill a packet_chat_msg structure for common server event.
void notify_conn_early(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
void event_cache_add_for_global_observers(const struct packet_chat_msg *packet)
Add an event to the cache for all global observers.
static void package_event_full(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct connection *pconn, const struct ft_color color, const char *format, va_list vargs)
Fill a packet_chat_msg structure.
static bool event_cache_match(const struct event_cache_data *pdata, const struct player *pplayer, bool is_global_observer, bool include_public)
Returns whether the event may be displayed for the connection.
static void event_cache_data_free(struct event_cache_data *data)
Callback for freeing event cache data.
void event_cache_add_for_player(const struct packet_chat_msg *packet, const struct player *pplayer)
Add an event to the cache for one player.
void vpackage_chat_msg(struct packet_chat_msg *packet, const struct connection *sender, const struct ft_color color, const char *format, va_list vargs)
Fill a packet_chat_msg structure for a chat message.
#define event_cache_iterate_end
static bool event_cache_status
void event_cache_add_for_all(const struct packet_chat_msg *packet)
Add an event to the cache for all connections.
void event_cache_save(struct section_file *file, const char *section)
Save the event cache into the savegame.
static struct event_cache_data_list * event_cache
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
int player_index(const struct player *pplayer)
Return the player index.
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
#define players_iterate_end
#define players_iterate(_pplayer)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
Lookup a string value in the secfile.
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
Lookup a integer value in the secfile.
#define secfile_insert_int(secfile, value, path,...)
#define secfile_insert_str(secfile, string, path,...)
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
#define research_players_iterate(_presearch, _pplayer)
#define research_players_iterate_end
enum server_states server_state()
Return current server state.
struct civ_game::@28::@32 server
struct conn_list * est_connections
struct packet_game_info info
enum server_states server_state
struct packet_chat_msg packet
enum event_cache_target target_type
struct conn_list * connections
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
#define sz_strlcpy(dest, src)