summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2023-08-09 23:40:58 -0400
committerTest_User <hax@andrewyu.org>2023-08-09 23:40:58 -0400
commitffc06e4614772a681114d4059a072f599ee378f8 (patch)
treeb19699cf499e66c056104e7192fe00f01d583931
parentbe4a88382717cb297d7aefadedb32d5f9c41ffb1 (diff)
downloadcoupserv-ffc06e4614772a681114d4059a072f599ee378f8.tar.gz
coupserv-ffc06e4614772a681114d4059a072f599ee378f8.zip
STRING_EQ
-rw-r--r--general_network.c8
-rw-r--r--server_network.c10
-rw-r--r--types.h3
3 files changed, 12 insertions, 9 deletions
diff --git a/general_network.c b/general_network.c
index 01384ca..14c3eb8 100644
--- a/general_network.c
+++ b/general_network.c
@@ -83,7 +83,7 @@ char channel_mode_types[UCHAR_MAX] = {
};
int privmsg(struct string source, struct string target, struct string message) {
- if (!(target.len == 9 && memcmp(target.data, "1HC000001", 9) == 0)) { // if not sending to our one local user
+ if (!STRING_EQ(target, STRING("1HC000001"))) { // if not sending to our one local user
if (source.len != 0) {
SEND(STRING(":"));
SEND(source);
@@ -113,13 +113,13 @@ int privmsg(struct string source, struct string target, struct string message) {
if (source.len != 0) {
SENDCLIENT(STRING(":"));
// TODO: Proper lookups of users and such
- if (source.len == 9 && memcmp(source.data, "1HC000000", 9) == 0) {
+ if (STRING_EQ(source, STRING("1HC000000"))) {
SENDCLIENT(nick);
SENDCLIENT(STRING("!"));
SENDCLIENT(nick);
SENDCLIENT(STRING("@"));
SENDCLIENT(hostmask);
- } else if (source.len == 3 && memcmp(source.data, "1HC", 3) == 0) {
+ } else if (STRING_EQ(source, STRING("1HC"))) {
SENDCLIENT(server_name);
} else {
SENDCLIENT(source);
@@ -131,7 +131,7 @@ int privmsg(struct string source, struct string target, struct string message) {
SENDCLIENT(STRING(" PRIVMSG "));
}
- if (target.len == 9 && memcmp(target.data, "1HC000001", 9) == 0)
+ if (STRING_EQ(target, STRING("1HC000001")))
SENDCLIENT(client_nick);
else
SENDCLIENT(target);
diff --git a/server_network.c b/server_network.c
index 6f32425..3d69341 100644
--- a/server_network.c
+++ b/server_network.c
@@ -374,7 +374,7 @@ int kill_handler(struct string sender, uint64_t argc, struct string *argv) {
if (!user)
return 0; // TODO: Currently not all local users are considered; fix that, then make this give an error
- if (user->server.len == 3 && memcmp(user->server.data, "1HC", 3) == 0) {
+ if (STRING_EQ(user->server, STRING("1HC"))) {
char user_time[21];
snprintf(user_time, 21, "%ld", user->user_ts);
char nick_time[21];
@@ -592,7 +592,7 @@ int squit_handler(struct string sender, uint64_t argc, struct string *argv) {
for (uint64_t i = 0; i < user_list.len;) {
struct user_info *info = user_list.array[i].ptr;
- if (argv[0].len == info->server.len && memcmp(argv[0].data, info->server.data, argv[0].len) == 0) {
+ if (STRING_EQ(info->server, argv[0])) {
remove_user(user_list.array[i].name, STRING("*.net *.split"));
} else {
i++; // removal of the user from the table shifts the next user into place for us
@@ -636,7 +636,7 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) {
SENDCLIENT(argv[1]);
SENDCLIENT(STRING("\r\n"));
}
- } else if (argv[0].len == 9 && memcmp(argv[0].data, "1HC000001", 9) == 0) {
+ } else if (STRING_EQ(argv[0], STRING("1HC000001"))) {
SENDCLIENT(STRING(":"));
SENDCLIENT(user->nick);
SENDCLIENT(STRING("!"));
@@ -663,7 +663,7 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) {
SENDCLIENT(argv[1]);
SENDCLIENT(STRING("\r\n"));
}
- } else if (argv[0].len == 9 && memcmp(argv[0].data, "1HC000001", 9) == 0) {
+ } else if (STRING_EQ(argv[0], STRING("1HC000001"))) {
SENDCLIENT(STRING(":"));
SENDCLIENT(server->address);
SENDCLIENT(STRING(" PRIVMSG "));
@@ -681,7 +681,7 @@ int privmsg_handler(struct string sender, uint64_t argc, struct string *argv) {
return 0;
offset = command_prefix.len;
- } else if (argv[0].len == 9 && memcmp(argv[0].data, "1HC000000", 9) == 0) {
+ } else if (STRING_EQ(argv[0], STRING("1HC000000"))) {
offset = 0;
} else {
return 0;
diff --git a/types.h b/types.h
index 2251bcc..b403ec9 100644
--- a/types.h
+++ b/types.h
@@ -38,4 +38,7 @@ struct string {
#define STRING(x) (struct string){x, sizeof(x)-1}
#define NULSTR(x) (struct string){x, strlen(x)}
+
+#define STRING_EQ(x, y) (x.len == y.len && memcmp(x.data, y.data, x.len) == 0)
+
#define WRITES(x, y) write(x, y.data, y.len)