Replace set_server_flag() with update_server_umode() and remove get_possible_umodes()

The idea here is not to expose the internal server implementation for storing umodes,
but instead have callers just work in terms of umode characters.

The 'possible umodes' have always been the same for all servers anyway.  We just assume
that [a-zA-Z] is the bounding set.
This commit is contained in:
Kevin Easton
2017-12-06 23:30:24 +11:00
parent 305cfe2afb
commit 1769c03951
6 changed files with 35 additions and 42 deletions

View File

@@ -10,7 +10,7 @@
* if we change the table below, we change this module number to the * if we change the table below, we change this module number to the
* current date (YYYYMMDDxx where xx is a serial number). * current date (YYYYMMDDxx where xx is a serial number).
*/ */
#define MODULE_VERSION 2017112301UL #define MODULE_VERSION 2017120601UL
#include "struct.h" #include "struct.h"
@@ -267,7 +267,7 @@ enum FUNCTION_VALUE
RESET_NICKNAME, RESET_NICKNAME,
/* various set server struct functions */ /* various set server struct functions */
SET_SERVER_COOKIE, SET_SERVER_COOKIE,
SET_SERVER_FLAG, UPDATE_SERVER_UMODE,
SET_SERVER_MOTD, SET_SERVER_MOTD,
SET_SERVER_OPERATOR, SET_SERVER_OPERATOR,
SET_SERVER_ITSNAME, SET_SERVER_ITSNAME,
@@ -286,7 +286,6 @@ enum FUNCTION_VALUE
GET_SERVER_OPERATOR, GET_SERVER_OPERATOR,
GET_SERVER_VERSION, GET_SERVER_VERSION,
GET_SERVER_FLAG, GET_SERVER_FLAG,
GET_POSSIBLE_UMODES,
GET_SERVER_PORT, GET_SERVER_PORT,
GET_SERVER_LAG, GET_SERVER_LAG,
GET_SERVER2_8, GET_SERVER2_8,

View File

@@ -514,7 +514,7 @@ extern Function_ptr *global;
#define reset_nickname (*(void (*)(int ))global[RESET_NICKNAME]) #define reset_nickname (*(void (*)(int ))global[RESET_NICKNAME])
#define set_server_cookie (*(void (*)(int , char *))global[SET_SERVER_COOKIE]) #define set_server_cookie (*(void (*)(int , char *))global[SET_SERVER_COOKIE])
#define set_server_flag (*(void (*)(int , int , int ))global[SET_SERVER_FLAG]) #define update_server_umode (*(void (*)(int , char , int ))global[UPDATE_SERVER_UMODE])
#define set_server_motd (*(void (*)(int , int ))global[SET_SERVER_MOTD]) #define set_server_motd (*(void (*)(int , int ))global[SET_SERVER_MOTD])
#define set_server_operator (*(void (*)(int , int ))global[SET_SERVER_OPERATOR]) #define set_server_operator (*(void (*)(int , int ))global[SET_SERVER_OPERATOR])
#define set_server_itsname (*(void (*)(int , char *))global[SET_SERVER_ITSNAME]) #define set_server_itsname (*(void (*)(int , char *))global[SET_SERVER_ITSNAME])
@@ -533,7 +533,6 @@ extern Function_ptr *global;
#define get_server_operator (*(int (*)(int ))global[GET_SERVER_OPERATOR]) #define get_server_operator (*(int (*)(int ))global[GET_SERVER_OPERATOR])
#define get_server_version (*(int (*)(int ))global[GET_SERVER_VERSION]) #define get_server_version (*(int (*)(int ))global[GET_SERVER_VERSION])
#define get_server_flag (*(int (*)(int , int ))global[GET_SERVER_FLAG]) #define get_server_flag (*(int (*)(int , int ))global[GET_SERVER_FLAG])
#define get_possible_umodes (*(char *(*)(int ))global[GET_POSSIBLE_UMODES])
#define get_server_port (*(int (*)(int ))global[GET_SERVER_PORT]) #define get_server_port (*(int (*)(int ))global[GET_SERVER_PORT])
#define get_server_lag (*(int (*)(int ))global[GET_SERVER_LAG]) #define get_server_lag (*(int (*)(int ))global[GET_SERVER_LAG])
#define get_server2_8 (*(int (*)(int ))global[GET_SERVER2_8]) #define get_server2_8 (*(int (*)(int ))global[GET_SERVER2_8])

View File

@@ -230,7 +230,6 @@ extern SGroup *server_group_list;
void set_server_bits (fd_set *rd, fd_set *wr, struct timeval *wake_time); void set_server_bits (fd_set *rd, fd_set *wr, struct timeval *wake_time);
void BX_set_server_itsname (int, char *); void BX_set_server_itsname (int, char *);
void BX_set_server_version (int, int); void BX_set_server_version (int, int);
char *BX_get_possible_umodes(int);
int BX_is_server_open (int); int BX_is_server_open (int);
int BX_get_server_port (int); int BX_get_server_port (int);
@@ -270,7 +269,7 @@ extern SGroup *server_group_list;
void send_from_server_queue (void); void send_from_server_queue (void);
void clear_sent_to_server (int); void clear_sent_to_server (int);
int sent_to_server (int); int sent_to_server (int);
void BX_set_server_flag (int, int, int); void BX_update_server_umode (int, char, int);
int BX_get_server_flag (int, int); int BX_get_server_flag (int, int);
char * get_server_userhost (int); char * get_server_userhost (int);
void got_my_userhost (UserhostItem *item, char *nick, char *stuff); void got_my_userhost (UserhostItem *item, char *nick, char *stuff);

View File

@@ -262,7 +262,7 @@ static int already_done = 0;
global_table[RESET_NICKNAME] = (Function_ptr) BX_reset_nickname; global_table[RESET_NICKNAME] = (Function_ptr) BX_reset_nickname;
/* various set server struct functions */ /* various set server struct functions */
global_table[SET_SERVER_COOKIE] = (Function_ptr) BX_set_server_cookie; global_table[SET_SERVER_COOKIE] = (Function_ptr) BX_set_server_cookie;
global_table[SET_SERVER_FLAG] = (Function_ptr) BX_set_server_flag; global_table[UPDATE_SERVER_UMODE] = (Function_ptr) BX_update_server_umode;
global_table[SET_SERVER_MOTD] = (Function_ptr) BX_set_server_motd; global_table[SET_SERVER_MOTD] = (Function_ptr) BX_set_server_motd;
global_table[SET_SERVER_OPERATOR] = (Function_ptr) BX_set_server_operator; global_table[SET_SERVER_OPERATOR] = (Function_ptr) BX_set_server_operator;
global_table[SET_SERVER_ITSNAME] = (Function_ptr) BX_set_server_itsname; global_table[SET_SERVER_ITSNAME] = (Function_ptr) BX_set_server_itsname;
@@ -282,7 +282,6 @@ static int already_done = 0;
global_table[GET_SERVER_OPERATOR] = (Function_ptr) BX_get_server_operator; global_table[GET_SERVER_OPERATOR] = (Function_ptr) BX_get_server_operator;
global_table[GET_SERVER_VERSION] = (Function_ptr) BX_get_server_version; global_table[GET_SERVER_VERSION] = (Function_ptr) BX_get_server_version;
global_table[GET_SERVER_FLAG] = (Function_ptr) BX_get_server_flag; global_table[GET_SERVER_FLAG] = (Function_ptr) BX_get_server_flag;
global_table[GET_POSSIBLE_UMODES] = (Function_ptr) BX_get_possible_umodes;
global_table[GET_SERVER_PORT] = (Function_ptr) BX_get_server_port; global_table[GET_SERVER_PORT] = (Function_ptr) BX_get_server_port;
global_table[GET_SERVER_LAG] = (Function_ptr) BX_get_server_lag; global_table[GET_SERVER_LAG] = (Function_ptr) BX_get_server_lag;
global_table[GET_SERVER2_8] = (Function_ptr) BX_get_server2_8; global_table[GET_SERVER2_8] = (Function_ptr) BX_get_server2_8;

View File

@@ -1462,11 +1462,9 @@ static void check_bitch_mode(char *from, char *uh, char *channel, char *line, Ch
reset_display_target(); reset_display_target();
} }
static void update_user_mode(int server, const char *modes) static void update_user_modes(int server, const char *modes)
{ {
int onoff = 1; int onoff = 1;
const char *p_umodes = get_possible_umodes(server);
const char *p;
for (; *modes; modes++) for (; *modes; modes++)
{ {
@@ -1485,11 +1483,7 @@ static void update_user_mode(int server, const char *modes)
set_server_operator(server, onoff); set_server_operator(server, onoff);
/* fallthrough */ /* fallthrough */
default: default:
p = strchr(p_umodes, c); update_server_umode(server, c, onoff);
if (p)
set_server_flag(server, p - p_umodes, onoff);
else
yell("Ignoring invalid user mode '%c' from server", c);
} }
} }
} }
@@ -1568,7 +1562,7 @@ static void p_mode(char *from, char **ArgList)
put_it("%s", convert_output_format(fget_string_var(fset), "%s %s %s %s %s", update_clock(GET_TIME), from, display_uh, target, line)); put_it("%s", convert_output_format(fget_string_var(fset), "%s %s %s %s %s", update_clock(GET_TIME), from, display_uh, target, line));
} }
if (!my_stricmp(target, get_server_nickname(from_server))) if (!my_stricmp(target, get_server_nickname(from_server)))
update_user_mode(from_server, line); update_user_modes(from_server, line);
logmsg(LOG_MODE_USER, from, 0, "%s %s", target, line); logmsg(LOG_MODE_USER, from, 0, "%s %s", target, line);
} }
update_all_status(current_window, NULL, 0); update_all_status(current_window, NULL, 0);

View File

@@ -1887,16 +1887,6 @@ static char *set_umode (int du_index)
return server_list[du_index].umode; return server_list[du_index].umode;
} }
char *BX_get_possible_umodes (int gu_index)
{
if (gu_index == -1)
gu_index = primary_server;
else if (gu_index >= number_of_servers)
return empty_string;
return server_list[gu_index].umodes;
}
char *BX_get_umode (int gu_index) char *BX_get_umode (int gu_index)
{ {
if (gu_index == -1) if (gu_index == -1)
@@ -2017,28 +2007,41 @@ time_t get_server_awaytime(int server)
return server_list[server].awaytime; return server_list[server].awaytime;
} }
void BX_set_server_flag (int ssf_index, int flag, int value) /* update_server_umode()
*
* Updates the client's idea of the status of a single umode flag.
*/
void BX_update_server_umode(int server, char mode, int value)
{ {
if (ssf_index == -1) const char *p = strchr(umodes, mode);
ssf_index = primary_server;
else if (ssf_index >= number_of_servers) if (server <= -1 || server > number_of_servers)
return; return;
if (flag > 31) if (p)
{ {
if (value) const int flag = p - umodes;
server_list[ssf_index].flags2 |= 0x1L << (flag - 32);
if (flag > 31)
{
if (value)
server_list[server].flags2 |= 0x1L << (flag - 32);
else
server_list[server].flags2 &= ~(0x1L << (flag - 32));
}
else else
server_list[ssf_index].flags2 &= ~(0x1L << (flag - 32)); {
if (value)
server_list[server].flags |= 0x1L << flag;
else
server_list[server].flags &= ~(0x1L << flag);
}
set_umode(server);
} }
else else
{ {
if (value) yell("Ignoring invalid user mode '%c' from server", mode);
server_list[ssf_index].flags |= 0x1L << flag;
else
server_list[ssf_index].flags &= ~(0x1L << flag);
} }
set_umode(ssf_index);
} }
int BX_get_server_flag (int gsf_index, int flag) int BX_get_server_flag (int gsf_index, int flag)