mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-19 01:24:26 +00:00
(experimental feature) Before a worker can start, it should have a configuration file. In case if such a file is not found it may request configuration from the coordinator to which it connected. Added example logic if a worker is needed to be blocked until a successful packet exchange with a coordinator is being made. * Add error return for config loader * Add config loaded flag to worker * Add zone flag * Add a custom mutex lock with timout * Refactor worker runtime * Refactor internal api * Extract monitoring server config * Extract worker HTTP(S) server * Add generic sub-server interface * Add internal coordinator API * Add internal routes and handlers to worker * Add internal worker API * Refactor worker run * Migrate serverId call to new API * Add packet handler to cws * Extract handlers for internal worker routes in coordinator * Pass worker to the worker internal heandlers * Cleanup worker handlers in coordinator * Add closeRoom packet handler to the API * Add GetRoom packet handler to the API * Add RegisterRoom packet handler to the API * Add IceCandidate packet handler to the API (internal and browser) * Add Heartbeat packet handler to the API (internal and browser) * Rename worker routes init function * Extract worker/coordinator internal ws handlers * Update timed locker * Allow sequential timed locks * Add config request from workers * Add nil check for the route registration functions
39 lines
1,008 B
Go
39 lines
1,008 B
Go
package coordinator
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/giongto35/cloud-game/v2/pkg/cws"
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type WorkerClient struct {
|
|
*cws.Client
|
|
|
|
WorkerID string
|
|
Address string // ip address of worker
|
|
// public server used for ping check (Cannot use worker address because they are not publicly exposed)
|
|
PingServer string
|
|
StunTurnServer string
|
|
IsAvailable bool
|
|
Zone string
|
|
}
|
|
|
|
// NewWorkerClient returns a client connecting to worker.
|
|
// This connection exchanges information between workers and server.
|
|
func NewWorkerClient(c *websocket.Conn, workerID string) *WorkerClient {
|
|
return &WorkerClient{
|
|
Client: cws.NewClient(c),
|
|
WorkerID: workerID,
|
|
IsAvailable: true,
|
|
}
|
|
}
|
|
|
|
func (wc *WorkerClient) Printf(format string, args ...interface{}) {
|
|
log.Printf(fmt.Sprintf("Worker %s] %s", wc.WorkerID, format), args...)
|
|
}
|
|
|
|
func (wc *WorkerClient) Println(args ...interface{}) {
|
|
log.Println(fmt.Sprintf("Worker %s] %s", wc.WorkerID, fmt.Sprint(args...)))
|
|
}
|