From f850ef3061391ced69274f1db246caa8172f703e Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 26 Sep 2024 00:56:40 +0500 Subject: [PATCH] init --- build-all | 3 +++ clients/client.go | 1 + cmd/shbot/main.go | 5 ++++ cmd/shclient/main.go | 5 ++++ cmd/shserver/main.go | 32 +++++++++++++++++++++++++ go.mod | 3 +++ servers/bot.go | 13 ++++++++++ servers/client.go | 13 ++++++++++ servers/server.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 132 insertions(+) create mode 100755 build-all create mode 100644 clients/client.go create mode 100644 cmd/shbot/main.go create mode 100644 cmd/shclient/main.go create mode 100644 cmd/shserver/main.go create mode 100644 go.mod create mode 100644 servers/bot.go create mode 100644 servers/client.go create mode 100644 servers/server.go diff --git a/build-all b/build-all new file mode 100755 index 0000000..1654c5a --- /dev/null +++ b/build-all @@ -0,0 +1,3 @@ +#!/bin/sh + +go build ./cmd/... diff --git a/clients/client.go b/clients/client.go new file mode 100644 index 0000000..2ea3902 --- /dev/null +++ b/clients/client.go @@ -0,0 +1 @@ +package clients diff --git a/cmd/shbot/main.go b/cmd/shbot/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/cmd/shbot/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/cmd/shclient/main.go b/cmd/shclient/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/cmd/shclient/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/cmd/shserver/main.go b/cmd/shserver/main.go new file mode 100644 index 0000000..858c617 --- /dev/null +++ b/cmd/shserver/main.go @@ -0,0 +1,32 @@ +package main + +import ( + flags "flag" + "log" + "os" + + "surdeus.su/util/shelldoor/servers" +) + +func main() { + var ( + addr string + ) + + flags.StringVar(&addr, "addr", ":20000", "address to serve at") + + flags.Parse() + args := flags.Args() + if len(args) > 0 { + flags.Usage() + os.Exit(1) + } + + server, err := servers.NewServer(addr) + if err != nil { + log.Fatalf("servers.New(...): %s\n", err) + } + + log.Printf("Trying to serve at %q\n", addr) + server.ListenAndServe() +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..96317b2 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module surdeus.su/util/shelldoor + +go 1.22.7 diff --git a/servers/bot.go b/servers/bot.go new file mode 100644 index 0000000..af79a7d --- /dev/null +++ b/servers/bot.go @@ -0,0 +1,13 @@ +package servers + +import "net" + +type Bot struct { + conn net.Conn +} + +func NewBot(conn net.Conn) *Bot { + ret := &Bot{} + ret.conn = conn + return ret +} diff --git a/servers/client.go b/servers/client.go new file mode 100644 index 0000000..f5149fb --- /dev/null +++ b/servers/client.go @@ -0,0 +1,13 @@ +package servers + +import "net" + +type Client struct { + conn net.Conn +} + +func NewClient(conn net.Conn) *Client { + ret := &Client{} + ret.conn = conn + return ret +} diff --git a/servers/server.go b/servers/server.go new file mode 100644 index 0000000..04fc3db --- /dev/null +++ b/servers/server.go @@ -0,0 +1,57 @@ +package servers + +import ( + "log" + "net" +) + +type BotRequest struct { +} + +type BotResponse struct { +} + +type ClientRequest struct { +} + +type ClientResponse struct { + Error string + Text string +} + +type Server struct { + addr string + listenner net.Listener + bots []*Bot + clients []*Client +} + +func NewServer(addr string) (*Server, error) { + srv := &Server{} + srv.addr = addr + return srv, nil +} + +func (srv *Server) HandleConn(conn net.Conn) { + defer conn.Close() +} + +func (srv *Server) ListenAndServe() error { + var err error + srv.listenner, err = net.Listen("tcp", srv.addr) + if err != nil { + return err + } + + for { + conn, err := srv.listenner.Accept() + if err != nil { + log.Printf("listener.Accept(...): %s\n", err) + continue + } + + go srv.HandleConn(conn) + } + + return nil +}