Exemplo n.º 1
0
/*
// Name: nick
// In: c, the client that sent the command.
// 	   tag, the tag sent from the client.
//	   newname, the name that the client wants to have.
//	   is_quoted, if the name contains quotes.
//	   clients, all connected clients.
// Out: 0
// Purpose: Handles the command NICK
*/
int nick(clientconn_t *c, char *tag, char *newname, 
						int is_quoted, hash *clients) {
	if(newname==NULL || strlen(newname)==0) {
		char msg[MAXTOKENSIZE];
		client_write(c, "* NICK ", 7);
		if(strstr(c->name, " ")) {
			client_write(c, enquote(c->name), strlen(enquote(c->name)));
		} else {
			client_write(c, c->name, strlen(c->name));
		}
		client_write(c, "\r\n", 2);
	} else {
		if(is_quoted) {
			remove_quote(newname, strlen(newname));
		} else if (strstr(newname, " ")!=NULL){
			return badly_formed(c, tag);
		}
		if(nickoccupied(newname, clients)) {
			client_write(c, tag, strlen(tag));
			client_write(c, " NO Name ", 9);
			client_write(c, newname, strlen(newname));
			client_write(c," is already in use.\r\n", 22);
			return 0;
		}
		char prev_name[MAXTOKENSIZE];
		strcpy(prev_name, c->name);
		memset(c->name, '\0', MAXTOKENSIZE);
		remove_quote(newname, strlen(newname));
		strncpy(c->name, newname, strlen(newname));
		if(strlen(prev_name)!=0 && c->joined) {
			char msg[MAXTOKENSIZE];
			strcpy(msg, "* RENAME ");
			if(strstr(prev_name, " ")) {
				strcat(msg, enquote(prev_name));
			} else {
				strcat(msg,prev_name);
			}
			strcat(msg, " ");
			if(is_quoted) {
				strcat(msg, enquote(newname));
			} else {
				strcat(msg, newname);
			}
			broadcast(msg, strlen(msg), c, clients, MSG_RENAME);
		} else {
			char msg[MAXTOKENSIZE];
			strcpy(msg, "* NICK ");
			if(is_quoted) {
				strcat(msg, enquote(newname));
			} else { 
				strcat(msg, newname);
			}
			strcat(msg, "\r\n");
			client_write(c, msg, strlen(msg));
		}
	}
	client_write(c, tag, strlen(tag));
	client_write(c, " OK NICK\r\n", 10);
	return 0;
}
Exemplo n.º 2
0
void			GUI_Prefs_Write(const char * app_name)
{
	string pref_dir;
	if (!GUI_GetPrefsDir(pref_dir)) { DoUserAlert("Warning: preferences file could not be written - preferences directory not found."); return; }
	pref_dir += DIR_STR;
    #if LIN
    pref_dir += ".";
    pref_dir +=  app_name;
    #else
	pref_dir += app_name;
    #endif
	pref_dir += ".prefs";

	FILE * fi = fopen(pref_dir.c_str(), "w");
	if (fi == NULL) { DoUserAlert("Warning: preferences file could not be written - could not write file."); return; }
	for(GUI_Prefs_t::iterator s = sPrefs.begin(); s != sPrefs.end(); ++s)
	{
		fprintf(fi,"[%s]" CRLF, s->first.c_str());
		for(GUI_PrefSection_t::iterator p = s->second.begin(); p != s->second.end(); ++p)
		{
			string k(p->first), v(p->second);
			enquote(k);
			enquote(v);
			fprintf(fi,"%s=%s" CRLF, k.c_str(), v.c_str());
		}
	}
	fclose(fi);
}
Exemplo n.º 3
0
void ArrayVariableProperty::write_cache(const wxArrayString& val) const {
	const wxString name = GetLabel();
	const wxString dir = boost::filesystem::current_path().string();
	const wxString pathname = dir + '/' + name + ".csv";;
	std::fstream fs(pathname.c_str(), std::fstream::out);
	for (wxArrayString::const_iterator it = val.begin(); it != val.end(); it++)
		fs << enquote(*it) << std::endl;
	fs.close();
}
Exemplo n.º 4
0
/*
// Name: talk
// In: c, the client that sent the command.
// 	   tag, the tag sent from the client.
//	   message, the message that the client wants to send.
//	   clients, all clients connected.
// Out: 0
// Purpose: Handles the comman TALK.
*/
int talk(clientconn_t *c, char *tag, char *message, hash *clients) {
	char msg[MAXTOKENSIZE];
	memset(msg,'\0', MAXTOKENSIZE);
	strcpy(msg, "* TALK ");
	if(strstr(c->name, " ")) {
		enquote(c->name);
	}
	strcat(msg, c->name);
	strcat(msg, " ");
	strcat(msg, message);
	broadcast(msg, strlen(msg), c, clients, MSG_TALK);
	client_write(c, tag, strlen(tag));
	client_write(c, " OK TALK completed.\r\n", 21);
	return 0;
}
Exemplo n.º 5
0
int open_outfile()         /* return 1 if fail */
{
#ifdef DOS_NT_OS2
    if (stat(filename, &statbuf) == 0 && !(statbuf.st_mode & S_IWRITE))
        chmod(filename, S_IREAD | S_IWRITE);
#endif
#ifdef UNIX
    if (stat(filename, &statbuf) == 0 && unlink(filename) < 0) {
        FPRINTF(stderr, LoadFarString(CannotDeleteOldFile), filename);
        return 1;
    }
#endif
#ifdef TOPS20
    char *tfilnam;

    if ((tfilnam = (char *)malloc(2*strlen(filename)+1)) == (char *)NULL)
        return 1;
    strcpy(tfilnam, filename);
    upper(tfilnam);
    enquote(tfilnam);
    if ((outfile = fopen(tfilnam, FOPW)) == (FILE *)NULL) {
        FPRINTF(stderr, LoadFarString(CannotCreateFile), tfilnam);
        free(tfilnam);
        return 1;
    }
    free(tfilnam);
#else
#ifdef MTS
    if (aflag)
        outfile = fopen(filename, FOPWT);
    else
        outfile = fopen(filename, FOPW);
    if (outfile == (FILE *)NULL) {
        FPRINTF(stderr, LoadFarString(CannotCreateFile), filename);
        return 1;
    }
#else
    if ((outfile = fopen(filename, FOPW)) == (FILE *)NULL) {
        FPRINTF(stderr, LoadFarString(CannotCreateFile), filename);
        return 1;
    }
#endif
#endif

#if 0      /* this SUCKS!  on Ultrix, it must be writing a byte at a time... */
    setbuf(outfile, (char *)NULL);   /* make output unbuffered */
#endif

#ifdef USE_FWRITE
#ifdef DOS_NT_OS2
    /* 16-bit MSC: buffer size must be strictly LESS than 32K (WSIZE):  bogus */
    setbuf(outfile, (char *)NULL);   /* make output unbuffered */
#else /* !DOS_NT_OS2 */
#ifdef _IOFBF  /* make output fully buffered (works just about like write()) */
    setvbuf(outfile, (char *)slide, _IOFBF, WSIZE);
#else
    setbuf(outfile, (char *)slide);
#endif
#endif /* ?DOS_NT_OS2 */
#endif /* USE_FWRITE */
    return 0;

} /* end function open_outfile() */