From a51c6f7116ddd3c8770c6145cd747739c7d5bc3f Mon Sep 17 00:00:00 2001 From: initframs Date: Sun, 22 Feb 2026 17:11:59 -0800 Subject: motd support, updated docs, measure start/stop time --- .gitignore | 1 + README.md | 36 +++++++++++++++--------------------- cmd/vsicd/main.go | 23 +++++++++++++++++++++-- 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/README.md b/README.md index cef2db5..c80bca1 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ *very* simple internet chat ## features - simple text-based protocol -- tiny and fast -- light and customizable +- tiny (5.2M) and fast (starts in 0.004s, stops in 1.005s*) +- light and customizable (toml config!) +> *note: start time measured as average over 128 starts/stops on Arch Linux (i7-4790k and 16GB DDR3) ## vsicd a vsic server written in go, designed to be completely async and have an ultra small footprint. only 1 config file and 3 commands. ```bash @@ -14,11 +15,14 @@ vsicd info # see stats like ram/cpu usage, connected clients, and more ```toml # ~/.config/vsicd/config.toml name = "my cool server" -motd = "~/.config/vsicd/motd.txt" +motd = """ +i love vsicd +irc still good though +""" # vsicd automatically trims blank lines so your config can look better :D [moderation] -banlist = "~/.config/vsicd/bans.txt" -modcmd = "python3 ~/.config/vsicd/moderation.py" +# banlist = "~/.config/vsicd/bans.txt" (in progress) +# modcmd = "python3 ~/.config/vsicd/moderation.py" (in progress) max_conns_per_ip = 4 max_msgs_per_sec = 1 @@ -26,7 +30,7 @@ max_msg_size = 4096 max_keepalive_timeout = 120 [server.tcp] -enabled = false # both are disabled by default +enabled = false # both are disabled by default, you don't need to explicitly disable them [server.tls] enabled = true @@ -34,20 +38,10 @@ port = 4570 tls_cert = "/etc/certs/example.com.crt" tcp_key = "/etc/certs/example.com.key" ``` -## vs2c -a simple and light cli-based vsic client, also written in go. simple file-based configuration -```toml -# ~/.config/vs2c/config.toml - -[servers.coolserver] -name = "cool server" -port = 4570 -tls = true -nick = "initframs" +### building vsicd +vsicd is pure go, so there's no need for C interop support :) -[servers.offtopic] -name = "offtopic lounge" -port = 4572 -tls = false -nick = "ilovevsic2642" +`-ldflags="-s -w"` removes the DWARF debugging info and the symbol table. this isn't recommended for dev, since DWARF lets you know what broke, but it reduces binary size. when reporting errors/bugs, don't use these options. +```bash +CGO_ENABLED=0 go build -ldflags="-s -w" -o vsicd ``` \ No newline at end of file diff --git a/cmd/vsicd/main.go b/cmd/vsicd/main.go index 2ebe50e..a160793 100644 --- a/cmd/vsicd/main.go +++ b/cmd/vsicd/main.go @@ -108,12 +108,23 @@ func start() { if os.Getenv("_VSICD_DAEMON") != "1" { cmd := exec.Command(os.Args[0], "start") cmd.Env = append(os.Environ(), "_VSICD_DAEMON=1") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + + logDir := filepath.Join(baseDir, "logs") + os.MkdirAll(logDir, 0755) + logFile, err := os.OpenFile(filepath.Join(logDir, "vsicd.log"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("failed to open log file:", err) + return + } + + cmd.Stdout = logFile + cmd.Stderr = logFile + if err := cmd.Start(); err != nil { fmt.Println("failed to start daemon:", err) return } + fmt.Println("vsicd started in background, pid:", cmd.Process.Pid) return } @@ -217,6 +228,14 @@ func (s *Server) handle(nc net.Conn) { vconn.Nick = nick client.Conn.WriteLine("HELLO " + nick) + if s.cfg.Motd != "" { + for _, line := range strings.Split(s.cfg.Motd, "\n") { + if line != "" { + client.Conn.WriteLine("MOTD " + line) + } + } + } + s.mu.Lock() s.clients[nick] = client s.mu.Unlock() -- cgit v1.2.3