about summary refs log tree commit diff
path: root/TokensSample
diff options
context:
space:
mode:
Diffstat (limited to 'TokensSample')
-rw-r--r--TokensSample/Client.cs77
-rw-r--r--TokensSample/Program.cs26
-rw-r--r--TokensSample/TokensSample.csproj12
3 files changed, 0 insertions, 115 deletions
diff --git a/TokensSample/Client.cs b/TokensSample/Client.cs
deleted file mode 100644
index 1061986..0000000
--- a/TokensSample/Client.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net.Sockets;
-using System.Threading;
-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);
-            while (!_socket.Connected) Thread.Sleep(1000);
-
-            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);
-                    _socket.Close();
-                    break;
-                }
-
-                var lines = _decoder.Push(_bytes, bytesReceived);
-
-                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, SocketFlags.None));
-        }
-    }
-}
diff --git a/TokensSample/Program.cs b/TokensSample/Program.cs
deleted file mode 100644
index c3a0885..0000000
--- a/TokensSample/Program.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using System;
-using System.Collections.Generic;
-using IrcTokens;
-
-namespace TokensSample
-{
-    public class Program
-    {
-        public static void Main(string[] args)
-        {
-            // tokenization
-            var line = new Line("@id=123 :ben!~ben@hostname PRIVMSG #channel :hello there!");
-            Console.WriteLine(line);
-            Console.WriteLine(line.Format());
-
-            // formatting
-            var line2 = new Line {Command = "USER", Params = new List<string> {"user", "0", "*", "real name"}};
-            Console.WriteLine(line2);
-            Console.WriteLine(line2.Format());
-
-            // stateful example
-            var client = new Client();
-            client.Start();
-        }
-    }
-}
diff --git a/TokensSample/TokensSample.csproj b/TokensSample/TokensSample.csproj
deleted file mode 100644
index 7c66734..0000000
--- a/TokensSample/TokensSample.csproj
+++ /dev/null
@@ -1,12 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
-  <PropertyGroup>
-    <OutputType>Exe</OutputType>
-    <TargetFramework>netcoreapp3.1</TargetFramework>
-  </PropertyGroup>
-
-  <ItemGroup>
-    <ProjectReference Include="..\IrcTokens\IrcTokens.csproj" />
-  </ItemGroup>
-
-</Project>