Freeciv21
Develop your civilization from humble roots to a global empire
handchat.cpp File Reference
#include <cstdarg>
#include <cstring>
#include "fcintl.h"
#include "log.h"
#include "shared.h"
#include "support.h"
#include "chat.h"
#include "game.h"
#include "packets.h"
#include "player.h"
#include "console.h"
#include "notify.h"
#include "stdinhand.h"
#include "handchat.h"
+ Include dependency graph for handchat.cpp:

Go to the source code of this file.

Macros

#define MAX_LEN_CHAT_NAME    (2 * MAX_LEN_NAME + 10)
 

Functions

static void send_chat_msg (struct connection *pconn, const struct connection *sender, const struct ft_color color, const char *format,...)
 Send a chat message packet. More...
 
static void static bool conn_is_ignored (const struct connection *sender, const struct connection *dest)
 Returns whether 'dest' is ignoring the 'sender' connection. More...
 
static void form_chat_name (struct connection *pconn, char *buffer, size_t len)
 Formulate a name for this connection, prefering the player name when available and unambiguous (since this is the "standard" case), else use the username. More...
 
static void complain_ambiguous (struct connection *pconn, const char *name, int player_conn)
 Complain to sender that name was ambiguous. More...
 
static void chat_msg_to_conn (struct connection *sender, struct connection *dest, char *msg)
 Send private message to single connection. More...
 
static void chat_msg_to_player (struct connection *sender, struct player *pdest, char *msg)
 Send private message to multi-connected player. More...
 
static void chat_msg_to_allies (struct connection *sender, char *msg)
 Send private message to player allies. More...
 
static void chat_msg_to_global_observers (struct connection *sender, char *msg)
 Send private message to all global observers. More...
 
static void chat_msg_to_all (struct connection *sender, char *msg)
 Send private message to all connections. More...
 
void handle_chat_msg_req (struct connection *pconn, const char *message)
 Handle a chat message packet from client: More...
 

Macro Definition Documentation

◆ MAX_LEN_CHAT_NAME

#define MAX_LEN_CHAT_NAME    (2 * MAX_LEN_NAME + 10)

Definition at line 36 of file handchat.cpp.

Function Documentation

◆ chat_msg_to_all()

static void chat_msg_to_all ( struct connection sender,
char *  msg 
)
static

Send private message to all connections.

Definition at line 286 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ chat_msg_to_allies()

static void chat_msg_to_allies ( struct connection sender,
char *  msg 
)
static

Send private message to player allies.

Definition at line 222 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ chat_msg_to_conn()

static void chat_msg_to_conn ( struct connection sender,
struct connection dest,
char *  msg 
)
static

Send private message to single connection.

Definition at line 122 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ chat_msg_to_global_observers()

static void chat_msg_to_global_observers ( struct connection sender,
char *  msg 
)
static

Send private message to all global observers.

Definition at line 258 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ chat_msg_to_player()

static void chat_msg_to_player ( struct connection sender,
struct player pdest,
char *  msg 
)
static

Send private message to multi-connected player.

Definition at line 151 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ complain_ambiguous()

static void complain_ambiguous ( struct connection pconn,
const char *  name,
int  player_conn 
)
static

Complain to sender that name was ambiguous.

'player_conn' is 0 for player names, 1 for connection names, 2 for attempt to send to an anonymous player.

Definition at line 98 of file handchat.cpp.

Referenced by handle_chat_msg_req().

◆ conn_is_ignored()

static void static bool conn_is_ignored ( const struct connection sender,
const struct connection dest 
)
inlinestatic

Returns whether 'dest' is ignoring the 'sender' connection.

Definition at line 47 of file handchat.cpp.

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

◆ form_chat_name()

static void form_chat_name ( struct connection pconn,
char *  buffer,
size_t  len 
)
static

Formulate a name for this connection, prefering the player name when available and unambiguous (since this is the "standard" case), else use the username.

Definition at line 62 of file handchat.cpp.

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

◆ handle_chat_msg_req()

void handle_chat_msg_req ( struct connection pconn,
const char *  message 
)

Handle a chat message packet from client:

  1. Work out whether it is a server command and if so run it;
  2. Otherwise work out whether it is directed to a single player, or to a single connection, and send there. (For a player, send to all clients connected as that player, in multi-connect case);
  3. Or it may be intended for all allied players.
  4. Else send to all connections (game.est_connections).

In case 2, there can sometimes be ambiguity between player and connection names. By default this tries to match player name first, and only if that fails tries to match connection name. User can override this and specify connection only by using two colons ("::") after the destination name/prefix, instead of one.

The message sent will name the sender, and via format differences also indicates whether the recipient is either all connections, a single connection, or multiple connections to a single player.

Message is also echoed back to sender (with different format), avoiding sending both original and echo if sender is in destination set.

Definition at line 326 of file handchat.cpp.

◆ send_chat_msg()

static void send_chat_msg ( struct connection pconn,
const struct connection sender,
const struct ft_color  color,
const char *  format,
  ... 
)
static

Send a chat message packet.

Definition at line 78 of file handchat.cpp.

Referenced by chat_msg_to_conn(), and chat_msg_to_player().