Freeciv-3.2
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
notify.c File Reference
#include <stdarg.h>
#include "bitvector.h"
#include "log.h"
#include "registry.h"
#include "connection.h"
#include "events.h"
#include "featured_text.h"
#include "game.h"
#include "research.h"
#include "packets.h"
#include "player.h"
#include "tile.h"
#include "maphand.h"
#include "srv_main.h"
#include "notify.h"
#include "speclist.h"

Go to the source code of this file.

Data Structures

struct  event_cache_data
 
struct  event_cache_players
 

Macros

#define SPECLIST_TAG   event_cache_data
 
#define SPECLIST_TYPE   struct event_cache_data
 
#define event_cache_iterate(pdata)    TYPED_LIST_ITERATE(struct event_cache_data, event_cache, pdata)
 
#define event_cache_iterate_end   LIST_ITERATE_END
 

Enumerations

enum  event_cache_target { ECT_ALL , ECT_PLAYERS , ECT_GLOBAL_OBSERVERS }
 

Functions

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)
 
void vpackage_chat_msg (struct packet_chat_msg *packet, const struct connection *sender, const struct ft_color color, const char *format, va_list vargs)
 
void package_chat_msg (struct packet_chat_msg *packet, const struct connection *sender, const struct ft_color color, const char *format,...)
 
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)
 
void package_event (struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
static void notify_conn_packet (struct conn_list *dest, const struct packet_chat_msg *packet, bool early)
 
void notify_conn (struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_conn_early (struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_player (const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_embassies (const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_team (const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_research (const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
 
void notify_research_embassies (const struct research *presearch, const struct player *exclude, enum event_type event, const struct ft_color color, const char *format,...)
 
static void event_cache_data_free (struct event_cache_data *data)
 
static struct event_cache_dataevent_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)
 
void event_cache_init (void)
 
void event_cache_free (void)
 
void event_cache_clear (void)
 
void event_cache_remove_old (void)
 
void event_cache_add_for_all (const struct packet_chat_msg *packet)
 
void event_cache_add_for_global_observers (const struct packet_chat_msg *packet)
 
void event_cache_add_for_player (const struct packet_chat_msg *packet, const struct player *pplayer)
 
void event_cache_add_for_players (const struct packet_chat_msg *packet, struct event_cache_players *players)
 
struct event_cache_playersevent_cache_player_add (struct event_cache_players *players, const struct player *pplayer)
 
static bool event_cache_match (const struct event_cache_data *pdata, const struct player *pplayer, bool is_global_observer, bool include_public)
 
void send_pending_events (struct connection *pconn, bool include_public)
 
void event_cache_load (struct section_file *file, const char *section)
 
void event_cache_save (struct section_file *file, const char *section)
 
void event_cache_phases_invalidate (void)
 

Variables

static struct event_cache_data_listevent_cache = NULL
 
static bool event_cache_status = FALSE
 

Macro Definition Documentation

◆ event_cache_iterate

#define event_cache_iterate (   pdata)     TYPED_LIST_ITERATE(struct event_cache_data, event_cache, pdata)

Definition at line 487 of file notify.c.

◆ event_cache_iterate_end

#define event_cache_iterate_end   LIST_ITERATE_END

Definition at line 489 of file notify.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   event_cache_data

Definition at line 484 of file notify.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct event_cache_data

Definition at line 485 of file notify.c.

Enumeration Type Documentation

◆ event_cache_target

Enumerator
ECT_ALL 
ECT_PLAYERS 
ECT_GLOBAL_OBSERVERS 

Definition at line 469 of file notify.c.

Function Documentation

◆ event_cache_add_for_all()

void event_cache_add_for_all ( const struct packet_chat_msg packet)

Add an event to the cache for all connections.

Definition at line 619 of file notify.c.

Referenced by chat_msg_to_all(), cmd_reply_line(), establish_new_connection(), event_cache_add_for_player(), notify_conn(), notify_conn_early(), and notify_team().

◆ event_cache_add_for_global_observers()

void event_cache_add_for_global_observers ( const struct packet_chat_msg packet)

Add an event to the cache for all global observers.

Definition at line 630 of file notify.c.

Referenced by chat_msg_to_global_observers().

◆ event_cache_add_for_player()

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.

N.B.: event_cache_add_for_player(&packet, NULL) will have the same effect as event_cache_add_for_all(&packet). N.B.: in pregame, this will never success, because players are not fixed.

Definition at line 645 of file notify.c.

Referenced by city_turn_notify(), dai_diplo_notify(), and notify_player().

◆ event_cache_add_for_players()

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. See event_cache_player_add() to see how to select players. This also free the players pointer argument.

N.B.: in pregame, this will never success, because players are not fixed.

Definition at line 671 of file notify.c.

Referenced by chat_msg_to_allies(), chat_msg_to_player(), notify_embassies(), notify_research(), notify_research_embassies(), and notify_team().

◆ event_cache_clear()

void event_cache_clear ( void  )

Remove all events from the cache.

Definition at line 594 of file notify.c.

Referenced by srv_main().

◆ event_cache_data_free()

static void event_cache_data_free ( struct event_cache_data data)
static

Callback for freeing event cache data

Definition at line 505 of file notify.c.

Referenced by event_cache_init().

◆ event_cache_data_new()

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 
)
static

Creates a new event_cache_data, appened to the list. It may remove an old entry if needed.

Definition at line 515 of file notify.c.

Referenced by event_cache_add_for_all(), event_cache_add_for_global_observers(), event_cache_add_for_player(), event_cache_add_for_players(), and event_cache_load().

◆ event_cache_free()

void event_cache_free ( void  )

Frees the event cache.

Definition at line 582 of file notify.c.

Referenced by event_cache_init(), and server_game_free().

◆ event_cache_init()

void event_cache_init ( void  )

Initializes the event cache.

Definition at line 570 of file notify.c.

Referenced by server_game_init().

◆ event_cache_load()

void event_cache_load ( struct section_file file,
const char section 
)

Load the event cache from a savefile.

Definition at line 783 of file notify.c.

Referenced by sg_load_event_cache(), and sg_load_event_cache().

◆ event_cache_match()

static bool event_cache_match ( const struct event_cache_data pdata,
const struct player pplayer,
bool  is_global_observer,
bool  include_public 
)
static

Returns whether the event may be displayed for the connection.

Definition at line 721 of file notify.c.

Referenced by send_pending_events().

◆ event_cache_phases_invalidate()

void event_cache_phases_invalidate ( void  )

Mark all existing phase values in event cache invalid.

Definition at line 977 of file notify.c.

Referenced by begin_turn().

◆ event_cache_player_add()

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(). Pass NULL as players argument to create a new selection. Usually the usage of this function would look to:

struct event_cache_players *players = NULL;

players_iterate(pplayer) { if (some_condition) { players = event_cache_player_add(players, pplayer); } } players_iterate_end; Now add to the cache. event_cache_add_for_players(&packet, players); // Free players.

Definition at line 703 of file notify.c.

Referenced by chat_msg_to_allies(), chat_msg_to_player(), event_cache_load(), notify_embassies(), notify_research(), notify_research_embassies(), and notify_team().

◆ event_cache_remove_old()

void event_cache_remove_old ( void  )

Remove the old events from the cache.

Definition at line 602 of file notify.c.

Referenced by begin_turn().

◆ event_cache_save()

void event_cache_save ( struct section_file file,
const char section 
)

Save the event cache into the savegame.

Definition at line 903 of file notify.c.

Referenced by sg_save_event_cache().

◆ notify_conn()

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.

Definition at line 238 of file notify.c.

Referenced by aifill(), aifill_action(), announce_player(), auth_handle_reply(), cancelvote_command(), check_for_game_over(), city_global_turn_notify(), cmd_reply_line(), complain_ambiguous(), con_handle_log(), connection_detach(), debug_command(), delegate_command(), depr_warn_callback(), do_nuclear_explosion(), end_command(), establish_new_connection(), handle_chat_msg_req(), handle_edit_city(), handle_edit_city_create(), handle_edit_city_remove(), handle_edit_mode(), handle_edit_player(), handle_edit_player_create(), handle_edit_player_remove(), handle_edit_player_vision(), handle_edit_startpos(), handle_edit_startpos_full(), handle_edit_tile(), handle_edit_tile_extra(), handle_edit_tile_terrain(), handle_edit_toggle_fogofwar(), handle_edit_unit(), handle_edit_unit_create(), handle_edit_unit_remove(), handle_edit_unit_remove_by_id(), handle_nation_select_req(), handle_player_ready(), handle_report_req(), handle_save_scenario(), handle_stdin_input_real(), lost_connection_to_client(), nationset_action(), notify_if_first_access_level_is_available(), notify_ruleset_fallback(), real_bodyguard_log(), real_city_log(), real_diplo_log(), real_tech_log(), real_unit_log(), save_game(), save_thread_run(), send_delegation_info(), send_year_to_clients(), server_packet_input(), server_remove_player(), server_remove_unit_full(), set_running_game_access_level(), srv_ready(), start_cmd_reply(), start_command(), start_game(), surrender_command(), take_command(), timing_results_real(), update_timeout(), and wall().

◆ notify_conn_early()

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. Use for early connecting protocol messages.

Definition at line 263 of file notify.c.

Referenced by auth_user().

◆ notify_conn_packet()

static void notify_conn_packet ( struct conn_list dest,
const struct packet_chat_msg packet,
bool  early 
)
static

This is the basis for following notify_* functions. It uses the struct packet_chat_msg as defined by vpackage_event().

Notify specified connections of an event of specified type (from events.h) and specified (x,y) coords associated with the event. Coords will only apply if game has started and the conn's player knows that tile (or NULL == pconn->playing && pconn->observer). If coords are not required, caller should specify (x,y) = (-1,-1); otherwise make sure that the coordinates have been normalized.

Definition at line 192 of file notify.c.

Referenced by notify_conn(), notify_conn_early(), notify_embassies(), notify_player(), notify_team(), and send_pending_events().

◆ notify_embassies()

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 player.

Definition at line 315 of file notify.c.

Referenced by api_notify_embassies_msg().

◆ notify_player()

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". If player != NULL, sends to all connections for that player. If player == NULL, sends to all game connections, to support old code, but this feature may go away - should use notify_conn(NULL) instead.

Definition at line 291 of file notify.c.

Referenced by announce_trade_route_removal(), api_edit_give_technology(), api_notify_event_msg(), apply_disaster(), auto_arrange_workers(), begin_turn(), bounce_unit(), build_free_small_wonders(), can_unit_move_to_tile_with_notify(), change_build_target(), check_city_migrations_player(), check_for_game_over(), check_player_max_rates(), check_pollution(), check_units_single_tile(), city_add_unit(), city_build(), city_build_building(), city_build_unit(), city_distribute_surplus_shields(), city_empty_food_stock(), city_illness_strike(), city_increase_size(), city_landlocked_sell_coastal_improvements(), city_map_update_radius_sq(), city_populate(), city_refresh_after_city_size_increase(), civil_war(), collect_ransom(), create_barbarian_player(), create_city(), dai_city_sell_noncritical(), diplomat_bribe(), diplomat_embassy(), diplomat_escape_full(), diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_may_lose_gold(), diplomat_sabotage(), disband_city(), do_airline(), do_attack(), do_capture_units(), do_city_migration(), do_expel_unit(), do_heal_unit(), do_nuke_tile(), do_paradrop(), do_spaceship_place(), do_tech_parasite_effects(), do_unit_change_homecity(), do_unit_establish_trade(), do_unit_strike_city_building(), do_unit_strike_city_production(), do_unit_upgrade(), do_upgrade_effects(), do_wipe_units(), end_phase(), end_turn(), execute_orders(), explain_why_no_action_enabled(), forget_tech_transferred(), found_new_tech(), global_warming(), government_change(), handle_city_change(), handle_city_rename(), handle_diplomacy_accept_treaty_req(), handle_diplomacy_cancel_pact(), handle_diplomacy_init_meeting_req(), handle_nation_select_req(), handle_player_change_government(), handle_player_place_infra(), handle_player_rates(), handle_spaceship_launch(), handle_unit_get_actions(), handle_unit_type_upgrade(), hut_get_limited(), illegal_action(), illegal_action_msg(), illegal_action_pay_price(), kill_player(), kill_unit(), make_contact(), notify_actor_caught(), notify_actor_success(), notify_global_caught(), notify_global_success(), notify_illegal_armistice_units(), notify_new_government_options(), notify_unit_experience(), notify_victim_caught(), notify_victim_success(), nuclear_winter(), player_loot_player(), player_restore_units(), really_diplomacy_cancel_meeting(), really_handle_city_buy(), really_handle_city_sell(), remove_city(), remove_illegal_armistice_units(), remove_obsolete_buildings_city(), research_tech_lost(), revolution_length(), sell_random_building(), sell_random_unit(), server_remove_unit_full(), spaceship_arrived(), spaceship_lost(), spy_nuke_city(), spy_poison(), spy_sabotage_unit(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), srv_scores(), steal_a_tech(), tech_transfer(), teleport_unit_to_city(), terrain_change_bounce_single_unit(), transfer_city(), transfer_city_units(), transfer_unit(), try_summon_barbarians(), try_to_save_unit(), unit_activities_cancel(), unit_attack_civilian_casualties(), unit_bombard(), unit_can_do_action_now(), unit_conquer_city(), unit_convert(), unit_do_destroy_city(), unit_do_help_build(), unit_lost_with_transport(), unit_nuke(), update_city_activity(), update_diplomatics(), update_national_activities(), update_revolution(), upgrade_all_city_extras(), upgrade_building_prod(), upgrade_unit_prod(), wakeup_neighbor_sentries(), worklist_change_build_target(), and worklist_item_postpone_req_vec().

◆ notify_research()

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.

Unlike other notify functions this one does not take a tile argument. We assume no research message will have a tile associated.

Definition at line 393 of file notify.c.

Referenced by api_edit_give_technology(), api_notify_research_msg(), choose_tech_goal(), city_build_building(), do_tech_parasite_effects(), forget_tech_transferred(), found_new_tech(), handle_diplomacy_accept_treaty_req(), steal_a_tech(), tech_transfer(), and update_bulbs().

◆ notify_research_embassies()

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.

Unlike other notify functions this one does not take a tile argument. We assume no research message will have a tile associated.

Exclude parameter excludes everyone who has embassy (only) with that player.

FIXME: Should not send multiple messages if one has embassy with multiple members of the research group, should really exclude ones having embassy with the exclude -one as the use-case for exclusion is that different message is being sent to those excluded here.

Definition at line 433 of file notify.c.

Referenced by api_edit_give_technology(), api_notify_research_embassies_msg(), city_build_building(), do_tech_parasite_effects(), found_new_tech(), handle_diplomacy_accept_treaty_req(), research_tech_lost(), steal_a_tech(), and tech_researched().

◆ notify_team()

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. If 'pplayer' is NULL, sends to all players.

Definition at line 345 of file notify.c.

Referenced by cancelvote_command(), check_vote(), and handle_stdin_input_real().

◆ package_chat_msg()

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.

Parameters
packetA pointer to the packet.
senderThe sender of the message.
colorThe requested color or ftc_any if not requested. Some colors are predefined in common/featured_text.h. You can pass a custom one using ft_color().
formatThe format of the message.
...The extra arguments to build the message.

Definition at line 123 of file notify.c.

Referenced by chat_msg_to_all(), chat_msg_to_allies(), chat_msg_to_global_observers(), and chat_msg_to_player().

◆ package_event()

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.

Parameters
packetA pointer to the packet.
ptileA pointer to a tile the event is occurring.
eventThe event type.
colorThe requested color or ftc_any if not requested. Some colors are predefined in common/featured_text.h. You can pass a custom one using ft_color().
formatThe format of the message.
...The extra arguments to build the message.

Definition at line 168 of file notify.c.

Referenced by city_turn_notify(), cmd_reply_line(), establish_new_connection(), and set_command().

◆ package_event_full()

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 
)
static

Fill a packet_chat_msg structure.

Parameters
packetA pointer to the packet.
ptileA pointer to a tile the event is occurring.
eventThe event type.
pconnThe sender of the event (e.g. when event is E_CHAT_MSG).
colorThe requested color or ftc_any if not requested. Some colors are predefined in common/featured_text.h. You can pass a custom one using ft_color().
formatThe format of the message.
vargsThe extra arguments to build the message.

Definition at line 55 of file notify.c.

Referenced by vpackage_chat_msg(), and vpackage_event().

◆ send_pending_events()

void send_pending_events ( struct connection pconn,
bool  include_public 
)

Send all available events. If include_public is TRUE, also fully global message will be sent.

Definition at line 753 of file notify.c.

Referenced by connection_attach_real(), establish_new_connection(), and srv_running().

◆ vpackage_chat_msg()

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.

Parameters
packetA pointer to the packet.
senderThe sender of the message.
colorThe requested color or ftc_any if not requested. Some colors are predefined in common/featured_text.h. You can pass a custom one using ft_color().
formatThe format of the message.
vargsThe extra arguments to build the message.

Definition at line 104 of file notify.c.

Referenced by package_chat_msg(), and send_chat_msg().

◆ vpackage_event()

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.

Parameters
packetA pointer to the packet.
ptileA pointer to a tile the event is occurring.
eventThe event type.
colorThe requested color or ftc_any if not requested. Some colors are predefined in common/featured_text.h. You can pass a custom one using ft_color().
formatThe format of the message.
vargsThe extra arguments to build the message.

Definition at line 147 of file notify.c.

Referenced by dai_diplo_notify(), notify_conn(), notify_conn_early(), notify_embassies(), notify_player(), notify_research(), notify_research_embassies(), notify_team(), and package_event().

Variable Documentation

◆ event_cache

struct event_cache_data_list* event_cache = NULL
static

◆ event_cache_status

bool event_cache_status = FALSE
static