Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions
handchat.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#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"

Go to the source code of this file.

Macros

#define MAX_LEN_CHAT_NAME   (2*MAX_LEN_NAME+10) /* for form_chat_name() names */
 

Functions

static void send_chat_msg (struct connection *pconn, const struct connection *sender, const struct ft_color color, const char *format,...) fc__attribute((__format__(__printf__
 
static void static bool conn_is_ignored (const struct connection *sender, const struct connection *dest)
 
static void form_chat_name (struct connection *pconn, char *buffer, size_t len)
 
static void complain_ambiguous (struct connection *pconn, const char *name, int player_conn)
 
static void chat_msg_to_conn (struct connection *sender, struct connection *dest, char *msg)
 
static void chat_msg_to_player (struct connection *sender, struct player *pdest, char *msg)
 
static void chat_msg_to_allies (struct connection *sender, char *msg)
 
static void chat_msg_to_global_observers (struct connection *sender, char *msg)
 
static void chat_msg_to_all (struct connection *sender, char *msg)
 
void handle_chat_msg_req (struct connection *pconn, const char *message)
 

Macro Definition Documentation

◆ MAX_LEN_CHAT_NAME

#define MAX_LEN_CHAT_NAME   (2*MAX_LEN_NAME+10) /* for form_chat_name() names */

Definition at line 41 of file handchat.c.

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 280 of file handchat.c.

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

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 127 of file handchat.c.

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 254 of file handchat.c.

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 156 of file handchat.c.

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 103 of file handchat.c.

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 52 of file handchat.c.

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, preferring the player name when available and unambiguous (since this is the "standard" case), else use the username.

Definition at line 67 of file handchat.c.

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 320 of file handchat.c.

Referenced by server_handle_packet().

◆ 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 83 of file handchat.c.

Referenced by chat_msg_to_conn(), and chat_msg_to_player().