aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 08:45:13 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 01:20:26 +0800
commitd810d12355873d3eaf61ed3f7f0ae52db06c2c96 (patch)
tree5cfa6d11c31377b459b06f4e3399bcc0542c57d8 /client.go
parentSlight refactor (diff)
downloadmeseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.tar.gz
meseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.tar.zst
meseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.zip
Add basic command handling
Diffstat (limited to 'client.go')
-rw-r--r--client.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/client.go b/client.go
new file mode 100644
index 0000000..9c73444
--- /dev/null
+++ b/client.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "net"
+)
+
+type Client struct {
+ conn net.Conn
+ uid [6]byte
+}
+
+func (client *Client) Send(msg SMsg) {
+ client.SendRaw(msg.ClientSerialize())
+}
+
+// Send failures are not returned; broken connections detected and severed on
+// the next receive.
+func (client *Client) SendRaw(s string) {
+ _, err := client.conn.Write([]byte(s))
+ if err != nil {
+ // TODO: Should shut down the netFd instead but the stdlib
+ // doesn't expose a way to do this.
+ client.conn.Close()
+ }
+}