From 2be48a13f730992a20af790dd8723c2557241437 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Thu, 14 Feb 2013 00:11:27 +0100 Subject: [PATCH] Made sure we now have an 'Operations' user logged in. This is still pretty much work in progress. --- src/core/hub.c | 18 +++++++++++++++++- src/core/user.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/core/hub.c b/src/core/hub.c index db99561..2e1ce90 100644 --- a/src/core/hub.c +++ b/src/core/hub.c @@ -808,14 +808,30 @@ static void unload_ssl_certificates(struct hub_info* hub) // #ifdef BOT_SUPPORT +/// This receives private messages and transmits them to the connected operators. static void hub_bot_op_notify_handle(struct hub_user* bot, struct adc_message* msg) { - LOG_INFO("Invoked hub_bot_op_notify_handle()"); + char* chat; + LOG_TRACE("Invoked hub_bot_op_notify_handle()"); + switch (msg->cmd) + { + case ADC_CMD_EMSG: + case ADC_CMD_DMSG: + chat = adc_msg_get_argument(msg, 0); + LOG_DEBUG("Hub chat: \"%s\"", chat); + hub_notify(bot->hub, notify_info, chat); + hub_free(chat); + break; + default: + /* ignore these messages! */ + break; + } } static void hub_bot_op_notify_create(struct hub_info* hub) { struct hub_user* opcom = user_create_bot(hub, "Operations", "Hub operators", hub_bot_op_notify_handle); + uman_add(hub->users, opcom); } // #endif diff --git a/src/core/user.c b/src/core/user.c index 702478e..2d9e886 100644 --- a/src/core/user.c +++ b/src/core/user.c @@ -65,6 +65,21 @@ struct hub_user* user_create(struct hub_info* hub, struct net_connection* con, s return user; } +/// generate a semi-stable CID: base32_encode(tiger({hub name} + {nick})) +static const char* generate_bot_cid(struct hub_info* hub, const char* nick) +{ + static char result[MAX_CID_LEN+1]; + char buf[(MAX_NICK_LEN*2)+1]; + uint64_t tiger_res[3]; + + memset(buf, 0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s%s", hub->config->hub_name, nick); + tiger((uint64_t*) buf, sizeof(buf), (uint64_t*) tiger_res); + base32_encode((unsigned char*) tiger_res, TIGERSIZE, result); + result[MAX_CID_LEN] = 0; + return result; +} + struct hub_user* user_create_bot(struct hub_info* hub, const char* nick, const char* description, bot_recv_msg msg_handler) { struct hub_user* user = NULL; @@ -92,6 +107,7 @@ struct hub_user* user_create_bot(struct hub_info* hub, const char* nick, const c adc_msg_add_named_argument_string(user->info, ADC_INF_FLAG_USER_AGENT, PRODUCT_STRING); adc_msg_add_named_argument_string(user->info, ADC_INF_FLAG_NICK, nick); adc_msg_add_named_argument_string(user->info, ADC_INF_FLAG_DESCRIPTION, description); + adc_msg_add_named_argument(user->info, ADC_INF_FLAG_CLIENT_ID, generate_bot_cid(hub, nick)); } user->hub = hub;