我有源irc客户端从一些网站。这是一些代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text.RegularExpressions;
namespace tes_irc
{
class Program
{
static string[] usuarios;
static void Main(string[] args)
{
NetworkStream conexion;
TcpClient irc;
StreamReader leer_datos;
StreamWriter mandar_datos;
string host = "irc.dal.net";
string nickname = "testing";
string canal = "#gsgsge";
string code = "";
leer_datos = new StreamReader(conexion);
mandar_datos = new StreamWriter(conexion);
mandar_datos.WriteLine("NICK " + nickname);
mandar_datos.Flush();
mandar_datos.WriteLine("USER " + nickname + " 1 1 1 1");
mandar_datos.Flush();
mandar_datos.WriteLine("JOIN " + canal);
mandar_datos.Flush();
while (true) // Mi bucle eterno
{
while ((code = leer_datos.ReadLine()) != null)
{
Console.WriteLine("Code : " + code);
Match regex = Regex.Match(code, "PING(.*)", RegexOptions.IgnoreCase);
if (regex.Success)
{
Console.WriteLine("hehe");
string te_doy_pong = "PONG " + regex.Groups[1].Value;
mandar_datos.WriteLine(te_doy_pong);
mandar_datos.Flush();
}
regex = Regex.Match(code, ":(.*) 353 (.*) = (.*) :(.*)", RegexOptions.IgnoreCase);
if (regex.Success)
{
string usuarios_lista = regex.Groups[4].Value;
usuarios = usuarios_lista.Split(' ');
foreach (string usuario in usuarios)
{
Console.Write("[+] User : " + usuario);
}
mandar_datos.WriteLine("PRIVMSG" + " " + canal + " " + "Hello World");
mandar_datos.Flush();
}
}
}
}
}
}
连接是成功的,但当我写发送消息,如"Hello world"只是发送"Hello"。这段代码有什么问题?也许之前必须对字符串进行编码?还是?请帮帮我。
IRC命令的最后一个参数应该以冒号字符(:
)作为前缀。否则,参数解析将在第一个空格处结束。
mandar_datos.WriteLine("PRIVMSG" + " " + canal + " " + ":Hello World");