Project

General

Profile

Feature #2479 ยป 0066-notify.c-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 11/14/2026 07:53 AM

View differences:

server/notify.c
char buf[MAX_LEN_MSG];
char *str;
fc_assert_ret(NULL != packet);
fc_assert_ret(packet != nullptr);
packet->tile = (NULL != ptile ? tile_index(ptile) : -1);
packet->tile = (ptile != nullptr ? tile_index(ptile) : -1);
packet->event = event;
packet->conn_id = pconn ? pconn->id : -1;
packet->turn = game.info.turn;
......
const struct ft_color color,
const char *format, va_list vargs)
{
package_event_full(packet, NULL, E_CHAT_MSG, sender, color, format, vargs);
package_event_full(packet, nullptr, E_CHAT_MSG, sender, color, format, vargs);
}
/**********************************************************************//**
......
const struct ft_color color,
const char *format, va_list vargs)
{
package_event_full(packet, ptile, event, NULL, color, format, vargs);
package_event_full(packet, ptile, event, nullptr, color, format, vargs);
}
/**********************************************************************//**
......
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,
pconn->playing == nullptr && pconn->observer). If coords are not required,
caller should specify (x,y) = (-1,-1); otherwise make sure that the
coordinates have been normalized.
**************************************************************************/
......
}
if (S_S_RUNNING <= server_state()
&& ptile /* special case, see above */
&& ((NULL == pconn->playing && pconn->observer)
|| (NULL != pconn->playing
&& ptile /* Special case, see above */
&& ((pconn->playing == nullptr && pconn->observer)
|| (pconn->playing != nullptr
&& map_is_known(ptile, pconn->playing)))) {
/* tile info is OK; see above. */
/* FIXME: in the case this is a city event, we should check if the
/* Tile info is OK; see above. */
/* FIXME: In the case this is a city event, we should check if the
* city is really known. */
real_packet.tile = tile;
} else {
......
}
if (early) {
send_packet_early_chat_msg(pconn, (struct packet_early_chat_msg *)(&real_packet));
send_packet_early_chat_msg(pconn,
(struct packet_early_chat_msg *)(&real_packet));
} else {
send_packet_chat_msg(pconn, &real_packet);
}
......
/**********************************************************************//**
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)
If player != nullptr, sends to all connections for that player.
If player == nullptr, sends to all game connections, to support
old code, but this feature may go away - should use notify_conn(nullptr)
instead.
**************************************************************************/
void notify_player(const struct player *pplayer,
......
const struct ft_color color,
const char *format, ...)
{
struct conn_list *dest = pplayer ? pplayer->connections : NULL;
struct conn_list *dest = pplayer ? pplayer->connections : nullptr;
struct packet_chat_msg genmsg;
va_list args;
......
const char *format, ...)
{
struct packet_chat_msg genmsg;
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
va_list args;
va_start(args, format);
......
}
/**********************************************************************//**
Sends a message to all players on pplayer's team. If 'pplayer' is NULL,
Sends a message to all players on pplayer's team. If 'pplayer' is nullptr,
sends to all players.
**************************************************************************/
void notify_team(const struct player *pplayer,
......
{
struct conn_list *dest = game.est_connections;
struct packet_chat_msg genmsg;
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
va_list args;
va_start(args, format);
......
const char *format, ...)
{
struct packet_chat_msg genmsg;
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
va_list args;
va_start(args, format);
vpackage_event(&genmsg, NULL, event, color, format, args);
vpackage_event(&genmsg, nullptr, event, color, format, args);
va_end(args);
research_players_iterate(presearch, aplayer) {
......
const char *format, ...)
{
struct packet_chat_msg genmsg;
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
va_list args;
va_start(args, format);
vpackage_event(&genmsg, NULL, event, color, format, args);
vpackage_event(&genmsg, nullptr, event, color, format, args);
va_end(args);
players_iterate(aplayer) {
......
};
/* The full list of the events. */
static struct event_cache_data_list *event_cache = NULL;
static struct event_cache_data_list *event_cache = nullptr;
/* Event cache status: ON(TRUE) / OFF(FALSE); used for saving the
* event cache */
......
struct event_cache_data *pdata;
int max_events;
if (NULL == event_cache) {
if (event_cache == nullptr) {
/* Don't do log for this, because this could make an infinite
* recursion. */
return NULL;
return nullptr;
}
fc_assert_ret_val(NULL != packet, NULL);
fc_assert_ret_val(packet != nullptr, nullptr);
if (packet->event == E_MESSAGE_WALL) {
/* No popups at save game load. */
return NULL;
return nullptr;
}
if (!game.server.event_cache.chat && packet->event == E_CHAT_MSG) {
/* chat messages should _not_ be saved */
return NULL;
/* Chat messages should _not_ be saved */
return nullptr;
}
/* check if cache is active */
/* Check if cache is active */
if (!event_cache_status) {
return NULL;
return nullptr;
}
pdata = fc_malloc(sizeof(*pdata));
......
**************************************************************************/
void event_cache_init(void)
{
if (event_cache != NULL) {
if (event_cache != nullptr) {
event_cache_free();
}
event_cache = event_cache_data_list_new_full(event_cache_data_free);
......
**************************************************************************/
void event_cache_free(void)
{
if (event_cache != NULL) {
if (event_cache != nullptr) {
event_cache_data_list_destroy(event_cache);
event_cache = NULL;
event_cache = nullptr;
}
event_cache_status = FALSE;
}
......
/* This assumes that entries are in order, the ones to be removed first. */
current = event_cache_data_list_get(event_cache, 0);
while (current != NULL
while (current != nullptr
&& current->packet.turn + game.server.event_cache.turns <= game.info.turn) {
event_cache_data_list_pop_front(event_cache);
current = event_cache_data_list_get(event_cache, 0);
......
void event_cache_add_for_all(const struct packet_chat_msg *packet)
{
if (0 < game.server.event_cache.turns) {
(void) event_cache_data_new(packet, time(NULL),
server_state(), ECT_ALL, NULL);
(void) event_cache_data_new(packet, time(nullptr),
server_state(), ECT_ALL, nullptr);
}
}
......
void event_cache_add_for_global_observers(const struct packet_chat_msg *packet)
{
if (0 < game.server.event_cache.turns) {
(void) event_cache_data_new(packet, time(NULL),
server_state(), ECT_GLOBAL_OBSERVERS, NULL);
(void) event_cache_data_new(packet, time(nullptr),
server_state(), ECT_GLOBAL_OBSERVERS, nullptr);
}
}
/**********************************************************************//**
Add an event to the cache for one player.
N.B.: event_cache_add_for_player(&packet, NULL) will have the same effect
N.B.: event_cache_add_for_player(&packet, nullptr) 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.
**************************************************************************/
void event_cache_add_for_player(const struct packet_chat_msg *packet,
const struct player *pplayer)
{
if (NULL == pplayer) {
if (pplayer == nullptr) {
event_cache_add_for_all(packet);
return;
}
......
&& (server_state() > S_S_INITIAL || !game.info.is_new_game)) {
struct event_cache_data *pdata;
pdata = event_cache_data_new(packet, time(NULL),
server_state(), ECT_PLAYERS, NULL);
fc_assert_ret(NULL != pdata);
pdata = event_cache_data_new(packet, time(nullptr),
server_state(), ECT_PLAYERS, nullptr);
fc_assert_ret(pdata != nullptr);
BV_SET(pdata->target, player_index(pplayer));
}
}
......
struct event_cache_players *players)
{
if (0 < game.server.event_cache.turns
&& NULL != players
&& players != nullptr
&& BV_ISSET_ANY(players->vector)
&& (server_state() > S_S_INITIAL || !game.info.is_new_game)) {
(void) event_cache_data_new(packet, time(NULL),
(void) event_cache_data_new(packet, time(nullptr),
server_state(), ECT_PLAYERS, players);
}
if (NULL != players) {
if (players != nullptr) {
free(players);
}
}
/**********************************************************************//**
Select players for event_cache_add_for_players(). Pass NULL as players
Select players for event_cache_add_for_players(). Pass nullptr as players
argument to create a new selection. Usually the usage of this function
would look to:
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
players_iterate(pplayer) {
if (some_condition) {
......
event_cache_player_add(struct event_cache_players *players,
const struct player *pplayer)
{
if (NULL == players) {
if (players == nullptr) {
players = fc_malloc(sizeof(*players));
BV_CLR_ALL(players->vector);
}
if (NULL != pplayer) {
if (pplayer != nullptr) {
BV_SET(players->vector, player_index(pplayer));
}
......
case ECT_ALL:
return include_public;
case ECT_PLAYERS:
return (NULL != pplayer
return (pplayer != nullptr
&& BV_ISSET(pdata->target, player_index(pplayer)));
case ECT_GLOBAL_OBSERVERS:
return is_global_observer;
......
struct packet_chat_msg packet;
enum event_cache_target target_type;
enum server_states server_status;
struct event_cache_players *players = NULL;
struct event_cache_players *players = nullptr;
int i, x, y, event_count;
time_t timestamp, now;
const char *p, *q;
......
return;
}
now = time(NULL);
now = time(nullptr);
for (i = 0; i < event_count; i++) {
int turn;
int phase;
/* restore packet */
/* Restore packet */
x = secfile_lookup_int_default(file, -1, "%s.events%d.x", section, i);
y = secfile_lookup_int_default(file, -1, "%s.events%d.y", section, i);
packet.tile = (is_normal_map_pos(x, y)
......
packet.conn_id = -1;
p = secfile_lookup_str(file, "%s.events%d.event", section, i);
if (NULL == p) {
if (p == nullptr) {
log_verbose("[Event cache %4d] Missing event type.", i);
continue;
}
......
}
p = secfile_lookup_str(file, "%s.events%d.message", section, i);
if (NULL == p) {
if (p == nullptr) {
log_verbose("[Event cache %4d] Missing message.", i);
continue;
}
sz_strlcpy(packet.message, p);
/* restore event cache data */
/* Restore event cache data */
turn = secfile_lookup_int_default(file, 0, "%s.events%d.turn",
section, i);
packet.turn = turn;
......
section, i);
p = secfile_lookup_str(file, "%s.events%d.server_state", section, i);
if (NULL == p) {
if (p == nullptr) {
log_verbose("[Event cache %4d] Missing server state info.", i);
continue;
}
......
}
p = secfile_lookup_str(file, "%s.events%d.target", section, i);
if (NULL == p) {
if (p == nullptr) {
log_verbose("[Event cache %4d] Missing target info.", i);
continue;
} else if (0 == fc_strcasecmp(p, "All")) {
......
q++;
} players_iterate_end;
if (!valid && NULL == players) {
if (!valid && players == nullptr) {
log_verbose("[Event cache %4d] invalid target bitmap: %s", i, p);
if (NULL != players) {
if (players != nullptr) {
FC_FREE(players);
}
}
}
/* insert event into the cache */
/* Insert event into the cache */
(void) event_cache_data_new(&packet, timestamp, server_status,
target_type, players);
if (NULL != players) {
/* free the event cache player selection */
if (players != nullptr) {
/* Free the event cache player selection */
FC_FREE(players);
}
......
char *p;
int tile_x = -1, tile_y = -1;
if (ptile != NULL) {
if (ptile != nullptr) {
index_to_map_pos(&tile_x, &tile_y, tile_index(ptile));
}
    (1-1/1)