From b3c1a9a929d5f57e3c760087ec9e9950bd1e7aff Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 5 May 2020 21:32:08 -0400 Subject: move example projects into a subfolder --- Examples/States/Program.cs | 12 ++++ Examples/States/StatesSample.csproj | 12 ++++ Examples/Tokens/Client.cs | 77 ++++++++++++++++++++++++++ Examples/Tokens/Program.cs | 26 +++++++++ Examples/Tokens/TokensSample.csproj | 12 ++++ IrcSharp.sln | 4 +- IrcTokens/README.md | 96 ++++++++++++++++++++++++++++++++ README.md | 106 ++++-------------------------------- StatesSample/Program.cs | 12 ---- StatesSample/StatesSample.csproj | 12 ---- TokensSample/Client.cs | 77 -------------------------- TokensSample/Program.cs | 26 --------- TokensSample/TokensSample.csproj | 12 ---- 13 files changed, 247 insertions(+), 237 deletions(-) create mode 100644 Examples/States/Program.cs create mode 100644 Examples/States/StatesSample.csproj create mode 100644 Examples/Tokens/Client.cs create mode 100644 Examples/Tokens/Program.cs create mode 100644 Examples/Tokens/TokensSample.csproj create mode 100644 IrcTokens/README.md delete mode 100644 StatesSample/Program.cs delete mode 100644 StatesSample/StatesSample.csproj delete mode 100644 TokensSample/Client.cs delete mode 100644 TokensSample/Program.cs delete mode 100644 TokensSample/TokensSample.csproj diff --git a/Examples/States/Program.cs b/Examples/States/Program.cs new file mode 100644 index 0000000..8fc42b8 --- /dev/null +++ b/Examples/States/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace StatesSample +{ + public static class Program + { + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Examples/States/StatesSample.csproj b/Examples/States/StatesSample.csproj new file mode 100644 index 0000000..ac7b5b7 --- /dev/null +++ b/Examples/States/StatesSample.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/Examples/Tokens/Client.cs b/Examples/Tokens/Client.cs new file mode 100644 index 0000000..1061986 --- /dev/null +++ b/Examples/Tokens/Client.cs @@ -0,0 +1,77 @@ +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 {"tokensbot"}}); + Send(new Line {Command = "USER", Params = new List {"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 {"#test"}}); + break; + case "PRIVMSG": + Send(new Line + { + Command = "PRIVMSG", Params = new List {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/Examples/Tokens/Program.cs b/Examples/Tokens/Program.cs new file mode 100644 index 0000000..c3a0885 --- /dev/null +++ b/Examples/Tokens/Program.cs @@ -0,0 +1,26 @@ +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 {"user", "0", "*", "real name"}}; + Console.WriteLine(line2); + Console.WriteLine(line2.Format()); + + // stateful example + var client = new Client(); + client.Start(); + } + } +} diff --git a/Examples/Tokens/TokensSample.csproj b/Examples/Tokens/TokensSample.csproj new file mode 100644 index 0000000..a0e98fd --- /dev/null +++ b/Examples/Tokens/TokensSample.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/IrcSharp.sln b/IrcSharp.sln index 0573020..8174c7c 100644 --- a/IrcSharp.sln +++ b/IrcSharp.sln @@ -5,11 +5,11 @@ VisualStudioVersion = 16.0.30011.22 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IrcTokens", "IrcTokens\IrcTokens.csproj", "{9E812F45-B2CD-42D2-8378-EBEBF8697905}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TokensSample", "TokensSample\TokensSample.csproj", "{A45DA39B-6B47-4713-8049-3B36E0235B67}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TokensSample", "Examples\Tokens\TokensSample.csproj", "{A45DA39B-6B47-4713-8049-3B36E0235B67}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IrcStates", "IrcStates\IrcStates.csproj", "{233E3CB4-61F1-4368-9139-7E9F4A58ED2D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatesSample", "StatesSample\StatesSample.csproj", "{BC9F6696-9D83-4F7A-9E15-CE4D3626C1AF}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StatesSample", "Examples\States\StatesSample.csproj", "{BC9F6696-9D83-4F7A-9E15-CE4D3626C1AF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1A85EB22-D7B4-417F-AC3B-DAFD97DDEA08}" ProjectSection(SolutionItems) = preProject diff --git a/IrcTokens/README.md b/IrcTokens/README.md new file mode 100644 index 0000000..94780eb --- /dev/null +++ b/IrcTokens/README.md @@ -0,0 +1,96 @@ +# irctokens + +this is a c\# port of jesopo's [irctokens]( +https://github.com/jesopo/irctokens) + +## usage + +### tokenization + + using IrcTokens; + + ... + + var line = new Line("@id=123 :ben!~ben@host.tld PRIVMSG #channel :hello there!"); + Console.WriteLine(line); + Console.WriteLine(line.Format()); + +### formatting + + var line = new Line {Command = "USER", Params = new List {"user", "0", "*", "real name"}}; + Console.WriteLine(line); + Console.WriteLine(line.Format()); + +### stateful + +see the full example in [Examples/Tokens/Client.cs](Examples/Tokens/Client.cs) + + 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 {"tokensbot"}}); + Send(new Line {Command = "USER", Params = new List {"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 {"#test"}}); + break; + case "PRIVMSG": + Send(new Line + { + Command = "PRIVMSG", Params = new List {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/README.md b/README.md index 309faed..1a559ec 100644 --- a/README.md +++ b/README.md @@ -1,102 +1,16 @@ -# irctokens +# IrcSharp -[![Build Status](https://drone.tildegit.org/api/badges/ben/ircsharp/status.svg)](https://drone.tildegit.org/ben/ircsharp) +[![Build Status](https://drone.tildegit.org/api/badges/ben/irctokens/status.svg)](https://drone.tildegit.org/ben/irctokens) -this is a c\# port of jesopo's [irctokens]( -https://github.com/jesopo/irctokens) +this is a collection of c\# projects to tokenize, parse, and maintain +state for IRC clients. -## usage +unless otherwise noted, this is mostly a port of jesopo's python libraries. -### tokenization +- [irctokens](https://github.com/jesopo/irctokens) +- [ircstates](https://github.com/jesopo/ircstates) +- [ircrobots](https://github.com/jesopo/ircrobots) - using IrcTokens; - - ... - - var line = new Line("@id=123 :ben!~ben@host.tld PRIVMSG #channel :hello there!"); - Console.WriteLine(line); - Console.WriteLine(line.Format()); - -### formatting - - var line = new Line {Command = "USER", Params = new List {"user", "0", "*", "real name"}}; - Console.WriteLine(line); - Console.WriteLine(line.Format()); - -### stateful - -see the full example in [TokensSample/Client.cs](TokensSample/Client.cs) - - 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 {"tokensbot"}}); - Send(new Line {Command = "USER", Params = new List {"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 {"#test"}}); - break; - case "PRIVMSG": - Send(new Line - { - Command = "PRIVMSG", Params = new List {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)); - } - } - -## contact - -come say hi on [\#irctokens on irc.tilde.chat](https://web.tilde.chat/?join=irctokens) +discussion and support on irc: [#irctokens]( +https://web.tilde.chat/?join=irctokens) diff --git a/StatesSample/Program.cs b/StatesSample/Program.cs deleted file mode 100644 index 8fc42b8..0000000 --- a/StatesSample/Program.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace StatesSample -{ - public static class Program - { - private static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } - } -} diff --git a/StatesSample/StatesSample.csproj b/StatesSample/StatesSample.csproj deleted file mode 100644 index 3107344..0000000 --- a/StatesSample/StatesSample.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - 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 {"tokensbot"}}); - Send(new Line {Command = "USER", Params = new List {"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 {"#test"}}); - break; - case "PRIVMSG": - Send(new Line - { - Command = "PRIVMSG", Params = new List {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 {"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 @@ - - - - Exe - netcoreapp3.1 - - - - - - - -- cgit 1.4.1