Exemplo n.º 1
0
void identd_read(int s)
{
char buffer[100];
char *bufptr;
unsigned int lport = 0, rport = 0;
	*buffer = 0;
	bufptr = buffer;
	if (recv(s, buffer, sizeof(buffer)-1, 0) <=0)
	{
		bitchsay("ERROR in identd request");
		close_socketread(s);
		return;
	}
	if (sscanf(bufptr, "%d , %d", &lport, &rport) == 2)
	{
		if (lport < 1 || rport < 1 || lport > 32767 || rport > 32767)
		{
			close_socketread(s);
			bitchsay("ERROR port for identd bad [%d:%d]", lport, rport);
			return;
		}
		sprintf(buffer, "%hu , %hu : USERID : UNIX : %s", lport, rport, get_dllstring_var("identd_user"));
		dcc_printf(s, "%s\r\n", buffer);
		bitchsay("Sent IDENTD request %s", buffer);
		set_socketflags(identd, now);
	}
	close_socketread(s);
}
Exemplo n.º 2
0
Arquivo: send.c Projeto: jnbek/TekNap
void nap_firewall_start(int snum)
{
GetFile *gf;
unsigned char buffer[BIG_BUFFER_SIZE+1];
SocketList *s;
	s = get_socket(snum);
	if (!s || !(gf = (GetFile *)get_socketinfo(snum)))
	{
		close_socketread(snum);
		return;
	}
	if (write(snum, "SEND", 4) == -1)
	{
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}
	snprintf(buffer, BIG_BUFFER_SIZE, "%s \"%s\" %lu", get_server_nickname(from_server), gf->filename, gf->filesize);
	convertnap_dos(buffer);
	if (write(snum, buffer, strlen(buffer)) == -1)
	{
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}
	s->func_read = nap_firewall_start1;
}
Exemplo n.º 3
0
Arquivo: send.c Projeto: jnbek/TekNap
void nap_firewall_start1(int snum)
{
GetFile *gf;
unsigned char buffer[BIG_BUFFER_SIZE+1];
SocketList *s;
int rc;
unsigned long resume = 0;
	s = get_socket(snum);
	if (!s || !(gf = (GetFile *)get_socketinfo(snum)))
	{
		close_socketread(snum);
		return;
	}
	if ((rc = read(snum, buffer, BIG_BUFFER_SIZE)) < 1)
	{
		break_from_list((List **)&transfer_struct, (List *)gf);
		if (gf->write != -1)
		{
			close(gf->write);
			gf->write = -1;
		}
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}	
	buffer[rc+1] = 0;
	resume = my_atol(buffer);
	put_it("Maybe this is where firewall resume is? %s", buffer);
	if (lseek(gf->write, resume, SEEK_SET) != -1)
		gf->resume = resume;
	
	gf->starttime = now;
	s->is_write = s->is_read;
	s->func_write = s->func_read = napfile_sendfile;
	napfile_sendfile(snum);
}
Exemplo n.º 4
0
Arquivo: send.c Projeto: jnbek/TekNap
void nap_chat_start(int snum)
{
GetFile *gf;
SocketList *s;

	if (!(s = get_socket(snum)) || !(gf = (GetFile *)s->info))
	{
		put_it("error get_socket(%d)", snum);
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}
	if (gf->deleted)
	{
		if (gf->write != -1)
			close(gf->write);
		gf->write = -1;
		if (gf->deleted++ > 5)
			close_socketread(snum);
		return;
	}
	if ((gf->flags & NAP_CHAT) == NAP_CHAT)
	{
		/* we need to accept the connection here. */
		struct  sockaddr_in     remaddr;
		int sra = sizeof(struct sockaddr_in);
		int sock = -1;
		if ((sock = my_accept(snum, (struct sockaddr *) &remaddr, &sra)) > -1)
		{
			set_keepalive(sock);
			gf->port = ntohs(remaddr.sin_port);
			add_socketread(sock, gf->port, 0, inet_ntoa(remaddr.sin_addr), nap_chat, NULL);
			set_socketinfo(sock, gf);
			s->info = NULL;
			gf->flags = NAP_CHAT_CONNECTED;
			gf->socket = sock;
			malloc_strcpy(&gf->ip, inet_ntoa(remaddr.sin_addr));
			say("DCC CHAT to %s [%s:%d] established", gf->nick, gf->ip, gf->port);
			gf->starttime = now;
		}
		close_socketread(snum);
		return;
	}
}
Exemplo n.º 5
0
int Identd_Cleanup(IrcCommandDll **intp, Function_ptr *global_table)
{
	if (identd != -1)
	{
		close_socketread(identd);
		identd = -1;
	}
	remove_module_proc(VAR_PROC, MODULENAME, NULL, NULL);
	return 0;
}
Exemplo n.º 6
0
Arquivo: send.c Projeto: jnbek/TekNap
void nap_chat(int snum)
{
GetFile *gf;
unsigned char buffer[3*BIG_BUFFER_SIZE+1];
SocketList *s;
long bytesread;
char *tmp, *p;

	if (!(s = get_socket(snum)) || !(gf = (GetFile *)s->info))
	{
		put_it("error get_socket(%d)", snum);
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}
	if (gf->deleted)
	{
		if (gf->write != -1)
			close(gf->write);
		gf->write = -1;
		if (gf->deleted++ > 5)
			close_socketread(snum);
		return;
	}
	bytesread = new_dgets(buffer, snum, 1, BIG_BUFFER_SIZE);
	switch (bytesread)
	{
		case -1:
			say("Lost DCC CHAT to %s [%s]", gf->nick, 
				(dgets_errno == -1) ? "Remote End Closed Connection" : 
					strerror(dgets_errno));
			break_from_list((List **)&transfer_struct, (List *)gf);
			nap_finished_file(snum, PREMATURE_FINISH);
			break;
		case 0:
			break;
		default:
			tmp = buffer;
			if ((p = strrchr(tmp, '\r')))
				*p = 0;
			if ((p = strrchr(tmp, '\n')))
				*p = 0;
			my_decrypt(tmp, strlen(tmp), gf->passwd);
			gf->received += bytesread;
#ifdef ALLOW_DCC_COMMANDS
			if ((gf->flags & NAP_DCC_COMMANDS) == NAP_DCC_COMMANDS)
			{
				if (!my_strnicmp(tmp, ".cmd ", 5) && *(tmp+6))
					parse_line("DCC", tmp+5, NULL, 0, 0, 1);
			}
#endif
			put_it(FORMAT_DCC_MSG, gf->nick, gf->ip, tmp);
			break;
	}
}
Exemplo n.º 7
0
Arquivo: send.c Projeto: jnbek/TekNap
void napfile_sendfile(int snum)
{
GetFile *gf;
unsigned char buffer[3*BIG_BUFFER_SIZE+1];
int rc, numread;
int flag = NORMAL_FINISH;
SocketList *s;

	if (!(s = get_socket(snum)) || !(gf = (GetFile *)s->info))
	{
		put_it("error get_socket(%d)", snum);
		nap_finished_file(snum, PREMATURE_FINISH);
		return;
	}
	if (gf->deleted)
	{
		if (gf->write != -1)
			close(gf->write);
		gf->write = -1;
		if (gf->deleted++ > 5)
			close_socketread(snum);
		return;
	}
	numread = read(gf->write, buffer, 2*BIG_BUFFER_SIZE);
	switch(numread)
	{
		case -1:
			flag = PREMATURE_FINISH;
			if (do_hook(NAPERROR_LIST, "%s %lu %lu \"%s\"", gf->nick, gf->received+gf->resume, gf->filesize, gf->filename) && !get_int_var(QUIET_SENDS_VAR))
				put_it("* Error sending %s (%lu/%lu) to %s ", gf->nick, gf->received+gf->resume, gf->filesize, base_name(gf->filename));
			break_from_list((List **)&transfer_struct, (List *)gf);
			close(gf->write);
			gf->write = -1;
			nap_finished_file(snum, flag);
			build_status(current_window, NULL, 0);
			send_ncommand(CMDS_UPDATE_SEND, NULL);
			return;
		case 0:
		{
			break_from_list((List **)&transfer_struct, (List *)gf);
			if ((gf->received + gf->resume) >= gf->filesize)
			{
				double speed;
				char speed1[80];
				time_t length;
				if (!(length = now - gf->starttime))
					length = 1;
				shared_stats.files_served++;
				shared_stats.filesize_served += gf->received;
				speed = gf->received / 1024.0 / length;
				if (speed > shared_stats.max_uploadspeed)
				{
					shared_stats.max_uploadspeed = speed;
					malloc_strcpy(&shared_stats.max_uploadspeed_nick, gf->nick);
				}
				sprintf(speed1, "%4.2fK/s", speed);
				if (do_hook(NAPFINISH_LIST, "%s %lu \"%s\"", gf->nick, gf->filesize, gf->filename) && !get_int_var(QUIET_SENDS_VAR))
					put_it("* Finished Sending %s (%s) [%s] at %s", gf->nick, longcomma(gf->filesize), base_name(gf->filename), speed1);
			}
			else 
			{
				flag = PREMATURE_FINISH;
				if (do_hook(NAPERROR_LIST, "%s %lu %lu \"%s\"", gf->nick, gf->received+gf->resume, gf->filesize, gf->filename) && !get_int_var(QUIET_SENDS_VAR))
					put_it("* Error sending %s (%lu/%lu) to %s ", gf->nick, gf->received+gf->resume, gf->filesize, base_name(gf->filename));
			}
			close(gf->write);
			gf->write = -1;
			nap_finished_file(snum, flag);
			build_status(current_window, NULL, 0);
			send_ncommand(CMDS_UPDATE_SEND, NULL);
			return;
		}
		default:
		{
			alarm(2);
			rc = send(snum, buffer, numread, 0);
			alarm(0);
			if (rc == -1)
			{
				if (errno == EWOULDBLOCK || errno == ENOBUFS || errno == EDEADLK)
					lseek(gf->write, -numread, SEEK_CUR);
				else
				{
					break_from_list((List **)&transfer_struct, (List *)gf);
					if (do_hook(NAPERROR_LIST, "%s %lu %lu \"%s\"", gf->nick, gf->received+gf->resume, gf->filesize, gf->filename) && !get_int_var(QUIET_SENDS_VAR))
						put_it("* Error sending %s (%lu/%lu) %s", gf->nick, gf->received+gf->resume, gf->filesize, base_name(gf->filename));
					close(gf->write);
					gf->write = -1;
					nap_finished_file(snum, PREMATURE_FINISH);
					build_status(current_window, NULL, 0);
					send_ncommand(CMDS_UPDATE_SEND, NULL);
				}
				return;
			}
			if (rc != numread)
				lseek(gf->write, -(numread - rc), SEEK_CUR);
			gf->received += rc;
			if (!(gf->received % (10 * (2*BIG_BUFFER_SIZE))))
				build_status(current_window, NULL, 0);
		}
	}
}
Exemplo n.º 8
0
void q_timer(int fd) {
	int i = 0, j = 0, k = 0, type = q_type;
	int nextpart = 0, num_players = 0, cheats = 0;
	struct quake_variable variable[50];
	struct timeval tv;
	char status[65507], temp[1024];
	char server_hostname[1024], server_maxclients[1024], server_mapname[1024];
	char server_fraglimit[1024], server_timelimit[1024], server_game[1024];

	/* ick. */
	memset(&temp, 0, sizeof(temp));
	memset(&server_hostname, 0, sizeof(server_hostname));
	memset(&server_maxclients, 0, sizeof(server_maxclients));
	memset(&server_mapname, 0, sizeof(server_mapname));
	memset(&server_fraglimit, 0, sizeof(server_fraglimit));
	memset(&server_timelimit, 0, sizeof(server_timelimit));
	memset(&server_game, 0, sizeof(server_game));

	/* now we should be expecting something back */
	memset(&status, 0, sizeof(status));
	if(recv(fd, status, 65507, 0) < 0) {
		put_it("Error receiving from %s: %s", q_server, strerror(errno));
		privmsg(q_chan, "Error receiving from %s: %s", q_server, strerror(errno));
		close_socketread(fd);
		querying = 0;
		return;
	}
	gettimeofday(&tv, NULL);
	close_socketread(fd);

	memset(&variable, 0, sizeof(variable));

	/* now we have our info, but we still need to decode it! */
	if(type == 1)
		i = 7;
	else if(type == 2)
		i = 11;
	else if(type == 3)
		i = 20;

	/* the following while loop copies all the variables from the status message
		into an array together with their value */
	while (status[i] != '\n') {
		/* check whether it's time for a new variable */
		if (status[i] == '\\') {
			if (nextpart) {
				nextpart = 0;
				variable[j].value[k] = '\0';
				j++;
			} else {
				nextpart = 1;
				variable[j].name[k] = '\0';
			}
			k = 0;
		} else {
			/* put our character in the correct position */
			if (nextpart)
				variable[j].value[k] = status[i];
			else
				variable[j].name[k] = status[i];
			k++;
		}
		i++;
	}
	variable[j].value[k] = '\0';

	/* now we can count how many players there are on the server */
	i++;
	put_it(&status[i]);
	while (i < strlen(status)) {
		if (status[i] == '\n') {
			num_players++;
		}
		i++;
	}

	for (i = 0; i < 50; i++) {
		if(type != 3) {
			if(!strcmp("hostname", variable[i].name))
				strcpy(server_hostname, variable[i].value);
			if(!strcmp("maxclients", variable[i].name))
				strcpy(server_maxclients, variable[i].value);
		} else {
			if(!strcmp("sv_hostname", variable[i].name))
				strcpy(server_hostname, variable[i].value);
			if(!strcmp("sv_maxclients", variable[i].name))
				strcpy(server_maxclients, variable[i].value);
			if(!strcmp("g_gametype", variable[i].name)) {
				switch(atoi(variable[i].name)) {
					case 0:  strcpy(server_game, "FFA"); break;
					case 1:  strcpy(server_game, "DUEL"); break;
					case 3:  strcpy(server_game, "TEAM DM"); break;
					case 4:  strcpy(server_game, "CTF"); break;
					default: strcpy(server_game, "UNKNOWN"); break;
				}
			}
		}
		if(type == 1) {
			if(!strcmp("map", variable[i].name))
				strcpy(server_mapname, variable[i].value);
			if(!strcmp("*gamedir", variable[i].name))
				strcpy(server_game, variable[i].value);
			if(!strcmp("cheats", variable[i].name))
				cheats = 1;
		}
		else {
			if(!strcmp("mapname", variable[i].name))
				strcpy(server_mapname, variable[i].value);
		}
		if(type == 2) {
			if(!strcmp("gamename", variable[i].name))
				strcpy(server_game, variable[i].value);
		}
		if(!strcmp("timelimit", variable[i].name))
			strcpy(server_timelimit, variable[i].value);
		if(!strcmp("fraglimit", variable[i].name))
			strcpy(server_fraglimit, variable[i].value);
	}
	if(type == 1) {
		snprintf(temp, 1024, "%s : players: %d/%s, ping: %d, map: %s, timelimit: %s, fraglimit: %s", server_hostname, num_players, server_maxclients, time_delta(&tv, &q_tv),  server_mapname, server_timelimit, server_fraglimit);
		if(server_game[0] != '\0') {
			char temp2[1024];
			snprintf(temp2, 1024, ", game: %s", server_game);
			strcat(temp, temp2);
		}
		if(cheats)
			strcat(temp, ", cheats enabled");
	}
	if(type == 2)
		snprintf(temp, 1024, "%s : players: %d/%s, ping: %d, map: %s, timelimit: %s, fraglimit: %s, game: %s", server_hostname, num_players, server_maxclients, time_delta(&tv, &q_tv), server_mapname, server_timelimit, server_fraglimit, server_game);
	if(type == 3)
		snprintf(temp, 1024, "%s : players: %d/%s, ping: %d, map: %s, gametype: %s, timelimit: %s, fraglimit: %s", server_hostname, num_players, server_maxclients, time_delta(&tv, &q_tv), server_mapname, server_game, server_timelimit, server_fraglimit);
	put_it(temp);
	privmsg(q_chan, temp);
	querying = 0;
}
Exemplo n.º 9
0
void q_timeout(int fd) {
	put_it("No response from %s", q_server);
	privmsg(q_chan, "No response from %s", q_server);
	close_socketread(qfd);
	querying = 0;
}
Exemplo n.º 10
0
int toc_remove_input_stream(int fd) {
	close_socketread(sock_read_id);
        return 1;
}