kike: implement NOTICE
This commit is contained in:
		
							parent
							
								
									17fdf0d4bf
								
							
						
					
					
						commit
						c386592d70
					
				
							
								
								
									
										27
									
								
								src/kike.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/kike.c
									
									
									
									
									
								
							| @ -1287,7 +1287,8 @@ irc_handle_mode (const struct irc_message *msg, struct client *c) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
| irc_handle_privmsg (const struct irc_message *msg, struct client *c) | irc_handle_user_message (const struct irc_message *msg, struct client *c, | ||||||
|  | 	const char *command, bool allow_away_reply) | ||||||
| { | { | ||||||
| 	if (msg->params.len < 1) | 	if (msg->params.len < 1) | ||||||
| 		RETURN_WITH_REPLY (c, IRC_ERR_NORECIPIENT, msg->command); | 		RETURN_WITH_REPLY (c, IRC_ERR_NORECIPIENT, msg->command); | ||||||
| @ -1299,9 +1300,9 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c) | |||||||
| 	struct client *client = str_map_find (&c->ctx->users, target); | 	struct client *client = str_map_find (&c->ctx->users, target); | ||||||
| 	if (client) | 	if (client) | ||||||
| 	{ | 	{ | ||||||
| 		irc_send (client, ":%s!%s@%s PRIVMSG %s :%s", | 		irc_send (client, ":%s!%s@%s %s %s :%s", | ||||||
| 			c->nickname, c->username, c->hostname, target, text); | 			c->nickname, c->username, c->hostname, command, target, text); | ||||||
| 		if (client->away_message) | 		if (allow_away_reply && client->away_message) | ||||||
| 			irc_send_reply (c, IRC_RPL_AWAY, target, client->away_message); | 			irc_send_reply (c, IRC_RPL_AWAY, target, client->away_message); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| @ -1319,8 +1320,8 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c) | |||||||
| 		 && !client_in_mask_list (c, &chan->exception_list)) | 		 && !client_in_mask_list (c, &chan->exception_list)) | ||||||
| 			RETURN_WITH_REPLY (c, IRC_ERR_CANNOTSENDTOCHAN, target); | 			RETURN_WITH_REPLY (c, IRC_ERR_CANNOTSENDTOCHAN, target); | ||||||
| 
 | 
 | ||||||
| 		char *message = xstrdup_printf (":%s!%s@%s PRIVMSG %s :%s", | 		char *message = xstrdup_printf (":%s!%s@%s %s %s :%s", | ||||||
| 			c->nickname, c->username, c->hostname, target, text); | 			c->nickname, c->username, c->hostname, command, target, text); | ||||||
| 		irc_channel_multicast (chan, message); | 		irc_channel_multicast (chan, message); | ||||||
| 		free (message); | 		free (message); | ||||||
| 		return; | 		return; | ||||||
| @ -1329,6 +1330,18 @@ irc_handle_privmsg (const struct irc_message *msg, struct client *c) | |||||||
| 	irc_send_reply (c, IRC_ERR_NOSUCHNICK, target); | 	irc_send_reply (c, IRC_ERR_NOSUCHNICK, target); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static void | ||||||
|  | irc_handle_privmsg (const struct irc_message *msg, struct client *c) | ||||||
|  | { | ||||||
|  | 	irc_handle_user_message (msg, c, "PRIVMSG", true); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static void | ||||||
|  | irc_handle_notice (const struct irc_message *msg, struct client *c) | ||||||
|  | { | ||||||
|  | 	irc_handle_user_message (msg, c, "NOTICE", false); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void | static void | ||||||
| irc_send_rpl_list (struct client *c, const struct channel *chan) | irc_send_rpl_list (struct client *c, const struct channel *chan) | ||||||
| { | { | ||||||
| @ -1768,7 +1781,6 @@ irc_register_handlers (struct server_context *ctx) | |||||||
| { | { | ||||||
| 	// TODO: add an index for IRC_ERR_NOSUCHSERVER validation?
 | 	// TODO: add an index for IRC_ERR_NOSUCHSERVER validation?
 | ||||||
| 	// TODO: add a minimal parameter count?
 | 	// TODO: add a minimal parameter count?
 | ||||||
| 	// TODO: more commands, see RFC 2812 :!
 |  | ||||||
| 	static const struct irc_command message_handlers[] = | 	static const struct irc_command message_handlers[] = | ||||||
| 	{ | 	{ | ||||||
| 		{ "PASS",     false, irc_handle_pass     }, | 		{ "PASS",     false, irc_handle_pass     }, | ||||||
| @ -1789,6 +1801,7 @@ irc_register_handlers (struct server_context *ctx) | |||||||
| 
 | 
 | ||||||
| 		{ "MODE",     true,  irc_handle_mode     }, | 		{ "MODE",     true,  irc_handle_mode     }, | ||||||
| 		{ "PRIVMSG",  true,  irc_handle_privmsg  }, | 		{ "PRIVMSG",  true,  irc_handle_privmsg  }, | ||||||
|  | 		{ "NOTICE",   true,  irc_handle_notice   }, | ||||||
| 		{ "JOIN",     true,  irc_handle_join     }, | 		{ "JOIN",     true,  irc_handle_join     }, | ||||||
| 		{ "PART",     true,  irc_handle_part     }, | 		{ "PART",     true,  irc_handle_part     }, | ||||||
| 		{ "TOPIC",    true,  irc_handle_topic    }, | 		{ "TOPIC",    true,  irc_handle_topic    }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user