2

i have source irc client from some site. this is the some code :

     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();
                    }
                }
            }
        }
    }
}

Connection is succes, but when i write for send message like "Hello world" just send "Hello". what's wrong with this code? maybe must encode string before? or?please help me. Thanks before :)

4

1 回答 1

2

IRC 命令的最后一个参数应以冒号字符 ( :) 为前缀。否则,参数的解析将在第一个空格处结束。

mandar_datos.WriteLine("PRIVMSG" + " " + canal + " " + ":Hello World");
于 2015-08-30T10:03:55.020 回答