degesch: fix /invite
This commit is contained in:
		
							parent
							
								
									bdad7bd7c2
								
							
						
					
					
						commit
						8eb31ad2e1
					
				
							
								
								
									
										11
									
								
								common.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								common.c
									
									
									
									
									
								
							| @ -70,6 +70,17 @@ str_vector_find (const struct str_vector *v, const char *s) | |||||||
| 	return -1; | 	return -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static char * | ||||||
|  | str_vector_steal (struct str_vector *self, size_t i) | ||||||
|  | { | ||||||
|  | 	// TODO: str_vector_remove() is then just free(str_vector_steal())
 | ||||||
|  | 	hard_assert (i < self->len); | ||||||
|  | 	char *tmp = self->vector[i]; | ||||||
|  | 	memmove (self->vector + i, self->vector + i + 1, | ||||||
|  | 		(self->len-- - i) * sizeof *self->vector); | ||||||
|  | 	return tmp; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int | static int | ||||||
| strncasecmp_ascii (const char *a, const char *b, size_t n) | strncasecmp_ascii (const char *a, const char *b, size_t n) | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										29
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								degesch.c
									
									
									
									
									
								
							| @ -6502,18 +6502,33 @@ handle_command_invite (struct app_context *ctx, char *arguments) | |||||||
| 	if (!server_command_check (ctx, "invite", true)) | 	if (!server_command_check (ctx, "invite", true)) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 
 | ||||||
| 	// XXX: the order of arguments should probably be reverse
 |  | ||||||
| 	struct server *s = ctx->current_buffer->server; | 	struct server *s = ctx->current_buffer->server; | ||||||
| 	char *channel_name = try_get_channel (ctx, &arguments); | 
 | ||||||
|  | 	struct str_vector v; | ||||||
|  | 	str_vector_init (&v); | ||||||
|  | 	split_str_ignore_empty (arguments, ' ', &v); | ||||||
|  | 
 | ||||||
|  | 	char *channel_name = NULL; | ||||||
|  | 	size_t last = v.len - 1; | ||||||
|  | 	if (v.len && irc_is_channel (s, v.vector[last])) | ||||||
|  | 		channel_name = str_vector_steal (&v, last); | ||||||
|  | 	else if (ctx->current_buffer->type == BUFFER_CHANNEL) | ||||||
|  | 		channel_name = xstrdup (ctx->current_buffer->channel->name); | ||||||
|  | 
 | ||||||
|  | 	bool result = true; | ||||||
| 	if (!channel_name) | 	if (!channel_name) | ||||||
| 		buffer_send_error (ctx, ctx->current_buffer, | 		buffer_send_error (ctx, ctx->current_buffer, | ||||||
| 			"%s: %s", "Can't invite", | 			"%s: %s", "Can't invite", | ||||||
| 			"no channel name given and this buffer is not a channel"); | 			"no channel name given and this buffer is not a channel"); | ||||||
| 	else if (*arguments) | 	else if (v.len) | ||||||
| 		irc_send (s, "INVITE %s %s", arguments, channel_name); | 		for (size_t i = 0; i < v.len; i++) | ||||||
|  | 			irc_send (s, "INVITE %s %s", v.vector[i], channel_name); | ||||||
| 	else | 	else | ||||||
| 		return false; | 		result = false; | ||||||
| 	return true; | 
 | ||||||
|  | 	str_vector_free (&v); | ||||||
|  | 	free (channel_name); | ||||||
|  | 	return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static bool | static bool | ||||||
| @ -6807,7 +6822,7 @@ g_command_handlers[] = | |||||||
| 	  "[<channel>] <mask>...", | 	  "[<channel>] <mask>...", | ||||||
| 	  handle_command_unban }, | 	  handle_command_unban }, | ||||||
| 	{ "invite",     "Invite user to channel", | 	{ "invite",     "Invite user to channel", | ||||||
| 	  "[<channel>] <user>", | 	  "<user>... [<channel>]", | ||||||
| 	  handle_command_invite }, | 	  handle_command_invite }, | ||||||
| 
 | 
 | ||||||
| 	{ "connect",    "Connect to the server", | 	{ "connect",    "Connect to the server", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user