aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-07 21:13:28 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-07 21:13:28 +0800
commit8c18330aa3976aa981bbe4f135960a92b5923fb6 (patch)
tree6b1548fce387c3d86f110732f971d85f64990c9a /main.go
downloadmeseircd-8c18330aa3976aa981bbe4f135960a92b5923fb6.tar.gz
meseircd-8c18330aa3976aa981bbe4f135960a92b5923fb6.tar.zst
meseircd-8c18330aa3976aa981bbe4f135960a92b5923fb6.zip
Initial commit
Diffstat (limited to 'main.go')
-rw-r--r--main.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..0898bd5
--- /dev/null
+++ b/main.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "bufio"
+ "log"
+ "log/slog"
+ "net"
+)
+
+type Client struct {
+ conn net.Conn
+}
+
+func main() {
+ listener, err := net.Listen("tcp", ":6667")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer listener.Close()
+
+ for {
+ conn, err := listener.Accept()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ client := &Client{
+ conn: conn,
+ }
+ go func() {
+ defer func() {
+ raised := recover()
+ if raised != nil {
+ slog.Error("connection routine panicked", "raised", raised)
+ }
+ }()
+ client.handleConnection()
+ }()
+ }
+}
+
+func (client *Client) handleConnection() {
+ reader := bufio.NewReader(client.conn)
+ for {
+ line, err := reader.ReadString('\n')
+ if err != nil {
+ slog.Error("error while reading from connection", "error", err)
+ client.conn.Close()
+ return
+ }
+ _, _ = parseIRCMsg(line)
+ }
+}