Gateway working, beta
This commit is contained in:
@@ -2,9 +2,8 @@ package ws
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"homestead/homestead_gateway/util/cache"
|
||||
"homestead/homestead_gateway/util/queue"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -17,16 +16,46 @@ type WebsocketGateway struct {
|
||||
|
||||
upgrader websocket.Upgrader
|
||||
|
||||
cache *cache.Cache
|
||||
queue *queue.Queue[GatewayMessageOut]
|
||||
|
||||
bot *websocket.Conn
|
||||
conns *cache.ConnectionCache
|
||||
registry *Registry
|
||||
|
||||
logger *slog.Logger
|
||||
closeFn func() error
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type Registry struct {
|
||||
mu sync.RWMutex
|
||||
entries map[string]*ChannelEntry
|
||||
queueCap int
|
||||
|
||||
botMu sync.Mutex
|
||||
bot *ConnWrapper
|
||||
}
|
||||
|
||||
type ConnWrapper struct {
|
||||
Conn *websocket.Conn
|
||||
ServerID string // set for mods (the server_id)
|
||||
LastSeen time.Time
|
||||
}
|
||||
|
||||
type BoundedQueue struct {
|
||||
mu sync.Mutex
|
||||
buf []GatewayMessageOut
|
||||
start int
|
||||
length int
|
||||
capacity int
|
||||
}
|
||||
|
||||
type ChannelEntry struct {
|
||||
mu sync.Mutex
|
||||
Channel string
|
||||
Mod *ConnWrapper
|
||||
Queue *BoundedQueue
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -64,15 +93,18 @@ type GatewayAck struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
type Handshake struct {
|
||||
Type string `json:"type"` // "mod" or "bot"
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
|
||||
type ModHandshake struct {
|
||||
ServerID string `json:"server_id"`
|
||||
ServerID string `json:"server_id"`
|
||||
ChannelID string `json:"channel_id"`
|
||||
}
|
||||
|
||||
type BotHandshake struct {
|
||||
BotID string `json:"bot_id"`
|
||||
ChannelId string `json:"channel_id"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user