init
This commit is contained in:
commit
f850ef3061
9 changed files with 132 additions and 0 deletions
3
build-all
Executable file
3
build-all
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
go build ./cmd/...
|
1
clients/client.go
Normal file
1
clients/client.go
Normal file
|
@ -0,0 +1 @@
|
|||
package clients
|
5
cmd/shbot/main.go
Normal file
5
cmd/shbot/main.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
5
cmd/shclient/main.go
Normal file
5
cmd/shclient/main.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
32
cmd/shserver/main.go
Normal file
32
cmd/shserver/main.go
Normal file
|
@ -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()
|
||||
}
|
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module surdeus.su/util/shelldoor
|
||||
|
||||
go 1.22.7
|
13
servers/bot.go
Normal file
13
servers/bot.go
Normal file
|
@ -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
|
||||
}
|
13
servers/client.go
Normal file
13
servers/client.go
Normal file
|
@ -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
|
||||
}
|
57
servers/server.go
Normal file
57
servers/server.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue