- ttt_socket_write (_socket, message, strlen (message));
-
- maxread = 100;
- numread = read (_socket, buffer, maxread);
- if (numread > 0) {
- buffer[numread] = '\0';
- xasprintf (&message, "%s", buffer);
- wprint (dispwin, message);
+ sockin=fdopen(_socket,"r");
+ sockout=fdopen(_socket,"w");
+
+
+ xasprintf(&confpath,"%s/.ttt/",getenv("HOME"));
+ xasprintf(&conffile,"%s/.ttt/client.conf",getenv("HOME"));
+ username="user";
+ if (access (conffile, F_OK) != 0 ) {
+ envuser=getenv("USER");
+ if (envuser != NULL) username=strdup(envuser);
+ if (access (confpath, F_OK) != 0 ) {
+ xasprintf(&command_string,"mkdir %s",confpath);
+ system (command_string);
+ }
+ if ((conf_file = fopen(conffile,"w")) != NULL) {
+ fprintf(conf_file,"username=%s",username);
+ fclose(conf_file);
+ }
+ }
+ if ((conf_file = fopen(conffile,"r")) != NULL) {
+ while (fgets(buffer,BUFSIZ,conf_file)) {
+ if (strncmp(buffer,"username=",9) == 0) {
+ xasprintf (&username, "%s", &buffer[9]);
+ break;
+ }
+ }
+ fclose(conf_file);
+ }
+
+ fprintf(sockout, "HELO %s\r\n",username);
+ fflush(sockout);
+
+ if (fgets(buffer,BUFSIZ,sockin)) {
+ if ((strncmp(buffer,"NOTICE MESSAGE ",15) == 0) && (strlen(buffer) > 15)) {
+ wprint (dispwin, buffer);
+ }
+ else {
+ if (strncmp(buffer,"MESSAGE",7) != 0) wprint (statwin, buffer);
+ }