Greetings should work. Cool !
Greetings should work. Cool !

file:a/.vstmDB -> file:b/.vstmDB
--- a/.vstmDB
+++ b/.vstmDB
@@ -4,6 +4,5 @@
 handle registering
 @H variables MAX_NICK_LEN and NICK_SPACE_NEEDED
 @L implement locking for users file
-@H greeting message
 @H Do the PKG and co.
 

file:a/Makefile -> file:b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CC ?= clang
-CFLAGS ?= -O2
+CFLAGS ?= -O2 -D_GNU_SOURCE
 LDFLAGS +=
 CFDEBUG = -g3 -Wall -Wextra -Wunused -Wunused-parameter
 

--- a/bin/tnc.conf
+++ b/bin/tnc.conf
@@ -3,4 +3,6 @@
 users-file=./passwd
 allow-registering=YES
 default-color=YES
+greetings=Hello, You stranger\nWelcome here\n
+#greetings=/etc/issue
 

--- a/src/config.c
+++ b/src/config.c
@@ -27,6 +27,7 @@
 
 
 	srv->allow_colors_dft = ALLOW_COLORS_DFT_CLIENTS;
+	srv->greetings_message = DFT_GREETINGS_MESSAGE;
 
 	srv->config_file = NULL;
 	srv->users_file  = NULL;
@@ -133,7 +134,8 @@
 	line = 1;
 	while(fgets(line_buffer, sizeof(line_buffer) - 2, file) != NULL) {
 
-		if(*line_buffer == '\0' || *line_buffer == '\n')
+		if(*line_buffer == '\0' || *line_buffer == '\n' ||
+		   *line_buffer == '#')
 			continue;
 
 		arg = line_buffer;
@@ -145,6 +147,8 @@
 		}
 
 		opt = my_trim(line_buffer);
+		if(*opt == '#')
+			continue;
 		arg = my_trim(arg);
 		config_switch(srv, opt, arg, line);
 		line++;
@@ -164,7 +168,10 @@
 	}
 	else if(!strcmp(opt, "default-color")) {
 		if(*arg == 'Y' || *arg == 'y' || *arg == '1' || *arg == 't') {
-			puts("COLORS ENABLED");
+			printf("COLORS %sE%sN%sA%sB%sL%sE%sD%s\n",
+			     COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_OTHER,
+			     COLOR_YELLOW, COLOR_BLUE, COLOR_GREEN,
+			     COLOR_NORMAL);
 			srv->allow_colors_dft = 1;
 		}
 		else {
@@ -175,6 +182,10 @@
 	else if(!strcmp(opt, "users-file")) {
 		srv->users_file = strdup(arg);
 	}
+	else if(!strcmp(opt, "greetings")) {
+		arg = str_replace_min("\\n", '\n', arg); /* no need to free */
+		srv->greetings_message = strdup(arg);
+	}
 	else {
 		fprintf(stderr, "Unknown option: %s (arg: %s, line: %d)\n",
 		        opt, arg, line);

--- a/src/connections.c
+++ b/src/connections.c
@@ -34,6 +34,7 @@
 #include <poll.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include "server.h"
 #include "users.h"
@@ -62,6 +63,7 @@
 	int new_client_fd;
 	int new_client;
 	char *buffer = NULL;
+	char *greetings;
 
 	new_client_fd = accept(srv->fds[0].fd, NULL, NULL);
 
@@ -75,6 +77,11 @@
 
 	asprintf(&buffer, "User %d", new_client);
 	srv->client_list[new_client].nick = buffer;
+
+	/* and send the greetings message */
+	greetings = get_greetings_message(srv);
+	send_msg_to_client(srv, greetings, new_client);
+	free(greetings);
 
 	return new_client;
 } /* }}} */
@@ -156,3 +163,13 @@
 	close(srv->sock_fd);
 } /* }}} */
 
+char *
+get_greetings_message(struct srv_conf *srv)
+{ /* {{{ */
+	/* the greetings message is a file */
+	if(!access(srv->greetings_message, F_OK))
+		return read_file(srv->greetings_message);
+	else /* if it's a string */
+		return strdup(srv->greetings_message);
+} /* }}} */
+

--- a/src/connections.h
+++ b/src/connections.h
@@ -6,7 +6,6 @@
 
 void
 init_client_list(struct srv_conf *srv);
-
 
 int
 new_client(struct srv_conf *srv);
@@ -20,5 +19,8 @@
 void
 close_all_connections(struct srv_conf *srv);
 
+char *
+get_greetings_message(struct srv_conf *srv);
+
 #endif
 

file:a/src/main.c -> file:b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,7 @@
 {
 	puts("Exiting !");
 	close_all_connections(srv_conf_global);
+
 	exit(EXIT_SUCCESS);
 }
 

--- a/src/server.h
+++ b/src/server.h
@@ -9,6 +9,8 @@
 
 #define VERSION "0.95"
 #define NAME "telnetChat"
+
+#define DFT_GREETINGS_MESSAGE "Hi there !\n"
 
 
 #define COLOR_RED    "\033[;31m"
@@ -85,6 +87,7 @@
 	/* serv. general config */
 	char *config_file;
 	char *users_file;
+	char *greetings_message;
 };
 
 #endif

--- a/src/utils.c
+++ b/src/utils.c
@@ -122,3 +122,61 @@
 	return 1;
 }
 
+char *
+read_file(char *file)
+{
+	FILE *f;
+	char *content;
+	char buffer[2048];
+	int buf_len;
+	int content_size;
+
+	if((f = fopen(file, "r")) == NULL) {
+		fprintf(stderr, "Could not open %s for reading\n", file);
+		return NULL;
+	}
+
+	content = NULL;
+	content_size = 0;
+	while(fgets(buffer, sizeof(buffer) - 2, f) != NULL) {
+		buf_len = strlen(buffer);
+		if(!content) {
+			content = calloc(buf_len + 1, sizeof(*content));
+		}
+		else {
+			content = realloc(content, (buf_len + content_size+1) *
+			                           sizeof(*content));
+		}
+
+		strcat(content, buffer);
+		content_size += buf_len + 1;
+	}
+
+	fclose(f);
+
+	return content; /* Hey! don't forget to free me ! */
+}
+
+char *
+str_replace_min(char* search, char replace, char *haystack)
+{
+	int hay_len, search_len, i;
+	char *found;
+
+	hay_len = strlen(haystack);
+	search_len = strlen(search);
+
+	i = 0;
+	while((found = strstr(haystack, search))) {
+		*found = replace;
+		found++;
+		while(*(found+1) != '\0') {
+			*found = *(found+1);
+			found++;
+		}
+		*found = '\0';
+	}
+
+	return haystack;
+}
+

--- a/src/utils.h
+++ b/src/utils.h
@@ -14,5 +14,11 @@
 char *
 my_trim(char *str);
 
+char *
+read_file(char *file);
+
+char *
+str_replace_min(char* search, char replace, char *haystack);
+
 #endif