fix order of nick and user in example
This commit is contained in:
parent
80afa2c0ae
commit
f1c4ed9ae8
|
@ -1,36 +1,36 @@
|
||||||
using IrcTokens;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using IrcTokens;
|
||||||
|
|
||||||
namespace TokensSample
|
namespace TokensSample
|
||||||
{
|
{
|
||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
private readonly Socket _socket;
|
private readonly byte[] _bytes;
|
||||||
private readonly StatefulDecoder _decoder;
|
private readonly StatefulDecoder _decoder;
|
||||||
private readonly StatefulEncoder _encoder;
|
private readonly StatefulEncoder _encoder;
|
||||||
private readonly byte[] _bytes;
|
private readonly Socket _socket;
|
||||||
|
|
||||||
public Client()
|
public Client()
|
||||||
{
|
{
|
||||||
_decoder = new StatefulDecoder();
|
_decoder = new StatefulDecoder();
|
||||||
_encoder = new StatefulEncoder();
|
_encoder = new StatefulEncoder();
|
||||||
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
|
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
|
||||||
_bytes = new byte[1024];
|
_bytes = new byte[1024];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
_socket.Connect("127.0.0.1", 6667);
|
_socket.Connect("127.0.0.1", 6667);
|
||||||
|
|
||||||
Send(new Line { Command = "USER", Params = new List<string> { "username", "0", "*", "real name" } });
|
Send(new Line {Command = "NICK", Params = new List<string> {"tokensbot"}});
|
||||||
Send(new Line { Command = "NICK", Params = new List<string> { "tokensbot" } });
|
Send(new Line {Command = "USER", Params = new List<string> {"username", "0", "*", "real name"}});
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var bytesReceived = _socket.Receive(_bytes);
|
var bytesReceived = _socket.Receive(_bytes);
|
||||||
var lines = _decoder.Push(_bytes);
|
var lines = _decoder.Push(_bytes);
|
||||||
|
|
||||||
if (bytesReceived == 0)
|
if (bytesReceived == 0)
|
||||||
{
|
{
|
||||||
|
@ -46,10 +46,10 @@ namespace TokensSample
|
||||||
switch (line.Command)
|
switch (line.Command)
|
||||||
{
|
{
|
||||||
case "PING":
|
case "PING":
|
||||||
Send(new Line { Command = "PONG", Params = line.Params });
|
Send(new Line {Command = "PONG", Params = line.Params});
|
||||||
break;
|
break;
|
||||||
case "001":
|
case "001":
|
||||||
Send(new Line { Command = "JOIN", Params = new List<string> { "#channel" } });
|
Send(new Line {Command = "JOIN", Params = new List<string> {"#channel"}});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,7 @@ namespace TokensSample
|
||||||
{
|
{
|
||||||
Console.WriteLine($"> {line.Format()}");
|
Console.WriteLine($"> {line.Format()}");
|
||||||
_encoder.Push(line);
|
_encoder.Push(line);
|
||||||
while (_encoder.PendingBytes.Length > 0)
|
while (_encoder.PendingBytes.Length > 0) _encoder.Pop(_socket.Send(_encoder.PendingBytes));
|
||||||
{
|
|
||||||
_encoder.Pop(_socket.Send(_encoder.PendingBytes));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using IrcTokens;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using IrcTokens;
|
||||||
|
|
||||||
namespace TokensSample
|
namespace TokensSample
|
||||||
{
|
{
|
||||||
|
@ -14,11 +14,7 @@ namespace TokensSample
|
||||||
Console.WriteLine(line.Format());
|
Console.WriteLine(line.Format());
|
||||||
|
|
||||||
// formatting
|
// formatting
|
||||||
var line2 = new Line
|
var line2 = new Line {Command = "USER", Params = new List<string> {"user", "0", "*", "real name"}};
|
||||||
{
|
|
||||||
Command = "USER",
|
|
||||||
Params = new List<string> { "user", "0", "*", "real name" }
|
|
||||||
};
|
|
||||||
Console.WriteLine(line2);
|
Console.WriteLine(line2);
|
||||||
Console.WriteLine(line2.Format());
|
Console.WriteLine(line2.Format());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue