IRC Bot加入命令不起作用

时间:2014-09-16 01:56:59

标签: c# irc tcplistener

我在使用C#创建机器人时遇到问题。如果我在从服务器回复ping之前让bot加入了频道,它将无法连接到正确的频道。我应该何时尝试将JOIN命令发送到服务器?

public void Connect()
{
    client = new TcpClient(server, 6667);
    stream = client.GetStream();
    reader = new StreamReader(stream);
    writer = new StreamWriter(stream);

    sendData("USER", System.Environment.MachineName + " 0 * :UnrealMegashark's Bot");
    sendData("NICK", nick);
    //It doesn't connect to the server here
    sendData("JOIN", channel);

    string[] ex;
    string data;

    while (true)
    {
        data = reader.ReadLine();
        Console.WriteLine(data);
        char[] charSeparator = new char[] { ' ' };
        ex = data.Split(charSeparator, 5);

        if (ex[0] == "PING")
        {
            sendData("PONG", ex[1]);
        }

    }
}

public void sendData(string command, string parameter)
{
    writer.WriteLine(cmd + " " + param ?? "");
    writer.Flush();
    Console.WriteLine(cmd + " " + param ?? "");
}

0 个答案:

没有答案