diff options
-rw-r--r-- | include/extern.h | 6 | ||||
-rw-r--r-- | include/services.h | 20 | ||||
-rw-r--r-- | include/users.h | 10 | ||||
-rw-r--r-- | src/send.c | 13 | ||||
-rw-r--r-- | src/users.c | 36 |
5 files changed, 58 insertions, 27 deletions
diff --git a/include/extern.h b/include/extern.h index 4708457f7..b4a0e4347 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1019,9 +1019,9 @@ E void notice_server(char *source, Server * s, char *fmt, ...) E void notice_user(char *source, User *u, const char *fmt, ...) FORMAT(printf,3,4); -E void notice_list(const char *source, const char *dest, char **text); -E void notice_lang(const char *source, User *dest, int message, ...); -E void notice_help(const char *source, User *dest, int message, ...); +E void notice_list(const char *source, const char *dest, char **text) MARK_DEPRECATED; +E void notice_lang(const char *source, User *dest, int message, ...) MARK_DEPRECATED; +E void notice_help(const char *source, User *dest, int message, ...) MARK_DEPRECATED; /**** servers.c ****/ diff --git a/include/services.h b/include/services.h index 2931fa078..db8025193 100644 --- a/include/services.h +++ b/include/services.h @@ -55,12 +55,8 @@ #include <stdlib.h> #include <string.h> -/* Windows does not have: - * unistd.h, grp.h, - * netdb.h, netinet/in.h, - * sys/socket.h, sys/time.h - * Windows requires: - * winsock.h +/* Windows does not have: unistd.h, grp.h, netdb.h, netinet/in.h, sys/socket.h, sys/time.h + * Windows requires: winsock.h * -- codemastr */ @@ -164,13 +160,6 @@ * prototypes. */ extern int strcasecmp(const char *, const char *); extern int strncasecmp(const char *, const char *, size_t); -# if 0 /* These break on some AIX boxes (4.3.1 reported). */ -extern int gettimeofday(struct timeval *, struct timezone *); -extern int socket(int, int, int); -extern int bind(int, struct sockaddr *, int); -extern int connect(int, struct sockaddr *, int); -extern int shutdown(int, int); -# endif # undef FD_ZERO # define FD_ZERO(p) memset((p), 0, sizeof(*(p))) #endif /* _AIX */ @@ -206,6 +195,11 @@ extern int shutdown(int, int); # undef int32 #endif +#ifndef _WIN32 + #define MARK_DEPRECATED __attribute((deprecated)) +#else + #define MARK_DEPRECATED +#endif /* Miscellaneous definitions. */ #include "defs.h" diff --git a/include/users.h b/include/users.h index fcf01e004..a1136e321 100644 --- a/include/users.h +++ b/include/users.h @@ -90,5 +90,15 @@ class User /** Updates the realname of the user record. */ void SetRealname(const std::string &realname); + + /** + * Send a message (notice or privmsg, depending on settings) to a user + * @param source Sender nick + * @param fmt Format of the Message + * @param ... any number of parameters + * @return void + */ + void SendMessage(const char *source, const char *fmt, ...); + void SendMessage(const char *source, const std::string &msg); }; diff --git a/src/send.c b/src/send.c index bd03cc4a6..accf6a680 100644 --- a/src/send.c +++ b/src/send.c @@ -100,17 +100,8 @@ void notice_user(char *source, User * u, const char *fmt, ...) va_start(args, fmt); vsnprintf(buf, BUFSIZE - 1, fmt, args); - /* Send privmsg instead of notice if: - * - UsePrivmsg is enabled - * - The user is not registered and NSDefMsg is enabled - * - The user is registered and has set /ns set msg on - */ - if (UsePrivmsg && ((!u->na && (NSDefFlags & NI_MSG)) - || (u->na && (u->na->nc->flags & NI_MSG)))) { - anope_cmd_privmsg2(source, u->nick, buf); - } else { - anope_cmd_notice2(source, u->nick, buf); - } + u->SendMessage(source, buf); + va_end(args); } } diff --git a/src/users.c b/src/users.c index ba9fb3e48..f69e5ef37 100644 --- a/src/users.c +++ b/src/users.c @@ -260,6 +260,42 @@ User::~User() alog("debug: User::~User() done"); } +void User::SendMessage(const char *source, const char *fmt, ...) +{ + va_list args; + char buf[BUFSIZE]; + *buf = '\0'; + + if (fmt) + { + va_start(args, fmt); + vsnprintf(buf, BUFSIZE - 1, fmt, args); + + this->SendMessage(source, std::string(buf)); + + va_end(args); + } +} + +void User::SendMessage(const char *source, const std::string &msg) +{ + /* Send privmsg instead of notice if: + * - UsePrivmsg is enabled + * - The user is not registered and NSDefMsg is enabled + * - The user is registered and has set /ns set msg on + */ + if (UsePrivmsg && + ((!this->na && NSDefFlags & NI_MSG) || (this->na && this->na->nc->flags & NI_MSG))) + { + anope_cmd_privmsg2(source, this->nick, msg.c_str()); + } + else + { + anope_cmd_notice2(source, this->nick, msg.c_str()); + } +} + + /*************************************************************************/ /*************************************************************************/ |