diff options
author | Ben Harris <ben@tilde.team> | 2020-04-28 11:08:01 -0400 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-04-28 11:08:01 -0400 |
commit | 6a0b8dc22fc86a5de37278231f3f8418afc9b836 (patch) | |
tree | 2cac03089c4d15bfe5a66b30e2b2ee5be5255f49 /Sample/Client.cs | |
parent | 70e2eb8e7debc342d46a9ca08d70725cb624e19d (diff) |
Fix stateful decoder i think
Diffstat (limited to 'Sample/Client.cs')
-rw-r--r-- | Sample/Client.cs | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/Sample/Client.cs b/Sample/Client.cs deleted file mode 100644 index 933cab7..0000000 --- a/Sample/Client.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Sockets; -using IrcTokens; - -namespace TokensSample -{ - public class Client - { - private readonly byte[] _bytes; - private readonly StatefulDecoder _decoder; - private readonly StatefulEncoder _encoder; - private readonly Socket _socket; - - public Client() - { - _decoder = new StatefulDecoder(); - _encoder = new StatefulEncoder(); - _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); - _bytes = new byte[1024]; - } - - public void Start() - { - _socket.Connect("127.0.0.1", 6667); - - Send(new Line {Command = "NICK", Params = new List<string> {"tokensbot"}}); - Send(new Line {Command = "USER", Params = new List<string> {"tokensbot", "0", "*", "real name"}}); - - while (true) - { - var bytesReceived = _socket.Receive(_bytes); - - if (bytesReceived == 0) - { - Console.WriteLine("! disconnected"); - _socket.Shutdown(SocketShutdown.Both); - break; - } - - var lines = _decoder.Push(_bytes); - - foreach (var line in lines) - { - Console.WriteLine($"< {line.Format()}"); - - switch (line.Command) - { - case "PING": - Send(new Line {Command = "PONG", Params = line.Params}); - break; - case "001": - Send(new Line {Command = "JOIN", Params = new List<string> {"#test"}}); - break; - case "PRIVMSG": - Send(new Line {Command = "PRIVMSG", Params = new List<string> {line.Params[0], "hello there"}}); - break; - } - } - } - } - - private void Send(Line line) - { - Console.WriteLine($"> {line.Format()}"); - _encoder.Push(line); - while (_encoder.PendingBytes.Length > 0) - _encoder.Pop(_socket.Send(_encoder.PendingBytes)); - } - } -} |