aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clients.go21
-rw-r--r--main.go6
-rw-r--r--servers.go2
3 files changed, 26 insertions, 3 deletions
diff --git a/clients.go b/clients.go
index d142157..1a363cc 100644
--- a/clients.go
+++ b/clients.go
@@ -2,6 +2,7 @@ package main
import (
"net"
+ "log/slog"
)
type Client struct {
@@ -11,21 +12,27 @@ type Client struct {
Ident string
Host string
Server Server
+ State ClientState
}
-func (client *Client) Send(msg SMsg) {
- client.SendRaw(msg.ClientSerialize())
+func (client *Client) Send(msg SMsg) error {
+ return client.SendRaw(msg.ClientSerialize())
}
// Send failures are not returned; broken connections detected and severed on
// the next receive.
-func (client *Client) SendRaw(s string) {
+func (client *Client) SendRaw(s string) error {
+ if client.conn == nil {
+ panic("not implemented")
+ }
+ slog.Debug("send", "line", s, "conn", client.conn)
_, 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()
}
+ return nil
}
func (client Client) ClientSource() string {
@@ -36,3 +43,11 @@ func (client Client) ClientSource() string {
func (client Client) ServerSource() string {
return string(client.Server.SID[:]) + string(client.UID[:])
}
+
+type ClientState uint8
+
+const (
+ ClientStateRemote ClientState = iota
+ ClientStatePreRegistration
+ ClientStateRegistered
+)
diff --git a/main.go b/main.go
index 34d132e..fdff8b2 100644
--- a/main.go
+++ b/main.go
@@ -5,9 +5,13 @@ import (
"log"
"log/slog"
"net"
+ "os"
)
func main() {
+ logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
+ slog.SetDefault(logger)
+
self = Server{
conn: nil,
SID: [3]byte{'1', 'H', 'C'},
@@ -29,6 +33,7 @@ func main() {
client := &Client{
conn: &conn,
Server: self,
+ State: ClientStatePreRegistration,
}
go func() {
defer func() {
@@ -56,6 +61,7 @@ messageLoop:
(*client.conn).Close()
return
}
+ slog.Debug("recv", "line", line, "conn", client.conn)
msg, err := parseIRCMsg(line)
if err != nil {
switch err {
diff --git a/servers.go b/servers.go
index eb91072..e878911 100644
--- a/servers.go
+++ b/servers.go
@@ -2,6 +2,7 @@ package main
import (
"net"
+ "log/slog"
)
type Server struct {
@@ -22,6 +23,7 @@ func (server *Server) SendRaw(s string) error {
// TODO: Propagate across mesh
return ErrNotConnectedServer
}
+ slog.Debug("send", "line", s, "conn", server.conn)
_, err := (*server.conn).Write([]byte(s))
if err != nil {
// TODO: Should shut down the netFd instead but the stdlib