Update
This commit is contained in:
parent
156b005a0b
commit
8a7ccc8fd9
@ -1,8 +1,8 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cimeyclust.com/steel/pkg/net/packets"
|
||||
"cimeyclust.com/steel/pkg/network/packets"
|
||||
"cimeyclust.com/steel/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
@ -379,7 +379,7 @@ func (conn *Conn) SetReadDeadline(t time.Time) error {
|
||||
}
|
||||
|
||||
// SetWriteDeadline has no behaviour. It is merely there to satisfy the
|
||||
// net.Conn interface.
|
||||
// network.Conn interface.
|
||||
func (conn *Conn) SetWriteDeadline(time.Time) error {
|
||||
return nil
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"cimeyclust.com/steel/pkg/utils"
|
||||
@ -1,4 +1,4 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -1,8 +1,9 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cimeyclust.com/steel/pkg/net/packets"
|
||||
"cimeyclust.com/steel/pkg/cmd"
|
||||
"cimeyclust.com/steel/pkg/network/packets"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
@ -31,15 +32,11 @@ type ListenConfig struct {
|
||||
|
||||
// Listener implements a RakNet connection listener. It follows the same
|
||||
// methods as those implemented by the TCPListener in the net package. Listener
|
||||
// implements the net.Listener interface.
|
||||
// implements the network.Listener interface.
|
||||
type Listener struct {
|
||||
once sync.Once
|
||||
closed chan struct{}
|
||||
|
||||
// log is a logger that errors from packet decoding are logged to. It may be
|
||||
// set to a logger that simply discards the messages.
|
||||
log *slog.Logger
|
||||
|
||||
conn net.PacketConn
|
||||
// incoming is a channel of incoming connections. Connections that end up in
|
||||
// here will also end up in the connections map.
|
||||
@ -86,12 +83,8 @@ func (l ListenConfig) Listen(address string) (*Listener, error) {
|
||||
conn: conn,
|
||||
incoming: make(chan *Conn),
|
||||
closed: make(chan struct{}),
|
||||
log: slog.Default(),
|
||||
id: listenerID.Add(1),
|
||||
}
|
||||
if l.ErrorLog != nil {
|
||||
listener.log = l.ErrorLog
|
||||
}
|
||||
|
||||
go listener.listen()
|
||||
return listener, nil
|
||||
@ -172,7 +165,7 @@ func (listener *Listener) listen() {
|
||||
// ownership has been taken by the buffer, but we can do this anyway
|
||||
// because we copy the data later.
|
||||
if err := listener.handle(buf, addr); err != nil {
|
||||
listener.log.Error("listener: handle packet: "+err.Error(), "address", addr.String())
|
||||
cmd.Logger.Error(fmt.Sprintf("listener: handle packet: %v from %s", err, addr.String()))
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
@ -298,8 +291,17 @@ func (listener *Listener) handleUnconnectedPing(b *bytes.Buffer, addr net.Addr)
|
||||
if err := pk.Read(b); err != nil {
|
||||
return fmt.Errorf("error reading unconnected ping: %v", err)
|
||||
}
|
||||
cmd.Logger.Info(fmt.Sprintf("Buffer length: %v", b.Len()))
|
||||
b.Reset()
|
||||
|
||||
cmd.Logger.Info(fmt.Sprintf("Received unconnected ping from %s", addr.String()))
|
||||
// Log pongData if it is set.
|
||||
if data := listener.pongData.Load(); data != nil {
|
||||
cmd.Logger.Info(fmt.Sprintf("Pong data: %v", data))
|
||||
} else {
|
||||
cmd.Logger.Info("No pong data set")
|
||||
}
|
||||
cmd.Logger.Info(fmt.Sprintf("Ping data: "))
|
||||
(&packets.UnconnectedPong{ServerGUID: listener.id, SendTimestamp: pk.SendTimestamp, Data: *listener.pongData.Load()}).Write(b)
|
||||
_, err := listener.conn.WriteTo(b.Bytes(), addr)
|
||||
return err
|
||||
@ -1,4 +1,4 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"cimeyclust.com/steel/pkg/cmd"
|
||||
@ -34,9 +34,7 @@ func Run(baseCtx context.Context, addr string) {
|
||||
listener.Close()
|
||||
}()
|
||||
for {
|
||||
cmd.Logger.Info("Waiting for connection...")
|
||||
conn, err := listener.Accept()
|
||||
cmd.Logger.Info("Connection accepted")
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@ -61,8 +59,9 @@ func handleRequest(conn net.Conn) {
|
||||
// Close the connection when you're done with it.
|
||||
defer conn.Close()
|
||||
|
||||
cmd.Logger.Info("Tet")
|
||||
b := make([]byte, 1024*1024*4)
|
||||
_, _ = conn.Read(b)
|
||||
n, _ := conn.Read(b)
|
||||
cmd.Logger.Info(fmt.Sprintf("Current n: %v", n))
|
||||
cmd.Logger.Info(fmt.Sprintf("Received: %v", b))
|
||||
_, _ = conn.Write([]byte{1, 2, 3})
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import "cimeyclust.com/steel/pkg/utils"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package net
|
||||
package network
|
||||
|
||||
import (
|
||||
"cimeyclust.com/steel/pkg/net/packets"
|
||||
"cimeyclust.com/steel/pkg/network/packets"
|
||||
"cimeyclust.com/steel/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
4
steel.go
4
steel.go
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"cimeyclust.com/steel/pkg/cmd"
|
||||
"cimeyclust.com/steel/pkg/net"
|
||||
"cimeyclust.com/steel/pkg/network"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -36,7 +36,7 @@ func main() {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
net.Run(ctx, "localhost:19132")
|
||||
network.Run(ctx, "0.0.0.0:19132")
|
||||
}()
|
||||
|
||||
// Handles Ctrl+C
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user