commit f4925dd158164c89b8e1f067e0ccb5b4337226de Author: Travis Avey Date: Fri May 15 13:37:50 2026 -0400 adding source code from first video migration from gitlab diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3b6f67 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# C3hat + +## Chat App in C3 + +Hello, this is a very basic chat application built in C3 for learning and fun. Don't take this repo seriously. Of course I am learning C3 so if there is something that could be done better in the C3 way let me know! + +## Videos + +This will be a series on my YouTube channel: [here](https://www.youtube.com/@aveydotdev) +### Roadmap + +#### Server +- [ ] Accept Connection +- [ ] Threading +- [ ] Broadcast messages to all clients +- [ ] Parse Commands +- [ ] Channels or Chat Rooms +- [ ] Private Messages + +#### Client +- [ ] Send Messages +- [ ] Stay Connected to Server +- [ ] Send Commands +- [ ] Join Channels or Chat Rooms +- [ ] Send Private Messages +- [ ] GUI + +The GUI will be necessary because when a user is typing and someone else sends a message the user will have their message over written by the incoming message. This could be handled with threading, but learning C3 and creating a simple GUI will be a lesson opportunity. + +## Why + +I decided to build this because it's fun and secondly to really learn a language it's a good idea to build something more than trivial. Your "hello world" application isn't teaching you much about the language you are learning outside of printing to standard out, compiling and/or running. diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/.gitkeep b/lib/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/project.json b/project.json new file mode 100644 index 0000000..3501872 --- /dev/null +++ b/project.json @@ -0,0 +1,45 @@ +{ + // Language version of C3. + "langrev": "1", + // Warnings used for all targets. + "warnings": [ "no-unused" ], + // Directories where C3 library files may be found. + "dependency-search-paths": [ "lib" ], + // Libraries to use for all targets. + "dependencies": [ ], + // Authors, optionally with email. + "authors": [ "John Doe " ], + // Version using semantic versioning. + "version": "0.1.0", + // Sources compiled for all targets. + "sources": [ "src/**" ], + // Test sources compiled for all targets. + "test-sources": [ "test/**" ], + // C sources if the project also compiles C sources + // relative to the project file. + // "c-sources": [ "csource/**" ], + // Include directories for C sources relative to the project file. + // "c-include-dirs": [ "csource/include" ], + // Build location, relative to project file. + "build-dir": "build", + // Output location, relative to project file. + "output": "build", + // Architecture and OS target. + // You can use 'c3c --list-targets' to list all valid targets. + // "target": "windows-x64", + // Targets. + "targets": { + "c3hat": { + // Executable or library. + "type": "executable", + // Additional libraries, sources + // and overrides of global settings here. + }, + }, + // Global settings. + // CPU name, used for optimizations in the LLVM backend. + "cpu": "generic", + // Optimization: "O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz". + "opt": "O0" + // See resources/examples/project_all_settings.json and 'c3c --list-project-properties' to see more properties. +} \ No newline at end of file diff --git a/resources/.gitkeep b/resources/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/.gitkeep b/scripts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c3 b/src/main.c3 new file mode 100644 index 0000000..c356b16 --- /dev/null +++ b/src/main.c3 @@ -0,0 +1,61 @@ +module c3hat; +import std::io; +import std::net; +import std::collections; + +fn int main(String[] args) { + String host = "localhost"; + uint port = 9500; + uint backlog = 100; + bool shouldQuit = false; + const int BUFFSIZE = 4096; + + TcpServerSocket? server = tcp::listen( + host, port, backlog, + SocketOption.REUSEADDR, + ip_protocol: IpProtocol.IPV4); + + if (catch err = server) { + io::printfn("unable to create server socket %s", err); + return -1; + } + + defer { + if (catch err = server.close()) { + io::printfn("error closing socket %s", err); + } + } + + while (!shouldQuit) { + TcpSocket? client = tcp::accept(&server); + if (catch err = client) { + io::printfn("error accepting client %s", err); + continue; + } + defer { + if (catch err = client.close()) { + io::printfn("error closing client socket %s", err); + } + } + char[BUFFSIZE] buffer; + + List{String} data; + data.init(mem); + while (try usz read = client.read(&buffer)) { + //io::printfn("buffer %s", (String)buffer[:read]); + data.push((String)buffer[:read]); + if (read < BUFFSIZE) { + break; + } + } + + foreach (item : data) { + io::printfn("%s", item); + if (item.contains("quit")) { + shouldQuit = true; + } + } + } + + return 0; +} diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29