af1e193958
* Code cleanup of routes config loader and API server (#424) (cherry picked from commit1ee3eb4de3) * Refactored server setup and run out of main (#425) (cherry picked from commit05c57c3b85) * Code cleanup in and around connector (#427) (cherry picked from commitb3e88db48c) * Update away from deprecated k8s NewInformer * Tidy up couple of k8s docs examples
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"net"
|
|
)
|
|
|
|
type PlayerInfo struct {
|
|
Name string `json:"name"`
|
|
Uuid uuid.UUID `json:"uuid"`
|
|
}
|
|
|
|
func (p *PlayerInfo) String() string {
|
|
if p == nil {
|
|
return ""
|
|
}
|
|
|
|
return fmt.Sprintf("%s/%s", p.Name, p.Uuid)
|
|
}
|
|
|
|
type ClientInfo struct {
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
}
|
|
|
|
func ClientInfoFromAddr(addr net.Addr) *ClientInfo {
|
|
if addr == nil {
|
|
return nil
|
|
}
|
|
|
|
return &ClientInfo{
|
|
Host: addr.(*net.TCPAddr).IP.String(),
|
|
Port: addr.(*net.TCPAddr).Port,
|
|
}
|
|
}
|
|
|
|
type ConnectionNotifier interface {
|
|
// NotifyMissingBackend is called when an inbound connection is received for a server that does not have a backend.
|
|
NotifyMissingBackend(ctx context.Context, clientAddr net.Addr, server string, playerInfo *PlayerInfo) error
|
|
|
|
// NotifyFailedBackendConnection is called when the backend connection failed.
|
|
NotifyFailedBackendConnection(ctx context.Context,
|
|
clientAddr net.Addr, serverAddress string, playerInfo *PlayerInfo, backendHostPort string, err error) error
|
|
|
|
// NotifyConnected is called when the backend connection succeeded.
|
|
NotifyConnected(ctx context.Context,
|
|
clientAddr net.Addr, serverAddress string, playerInfo *PlayerInfo, backendHostPort string) error
|
|
|
|
// NotifyDisconnected is called when the backend connection terminates.
|
|
NotifyDisconnected(ctx context.Context,
|
|
clientAddr net.Addr, serverAddress string, playerInfo *PlayerInfo, backendHostPort string) error
|
|
}
|