mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-22 17:47:11 +00:00
By Pass overlord
This commit is contained in:
parent
a2f2786fa5
commit
a0cdb2f537
1 changed files with 14 additions and 10 deletions
24
main.go
24
main.go
|
|
@ -262,19 +262,22 @@ func ws(w http.ResponseWriter, r *http.Request) {
|
|||
roomID = resp.RoomID
|
||||
playerIndex = resp.PlayerIndex
|
||||
isNewRoom := false
|
||||
//log.Println("Ping from server with game:", gameName)
|
||||
//res.ID = "pong"
|
||||
|
||||
log.Println("Starting game")
|
||||
roomServerID := getServerIDOfRoom(oclient, roomID)
|
||||
log.Println("Server of RoomID ", roomID, " is ", roomServerID)
|
||||
if roomServerID != "" && wssession.ServerID != roomServerID {
|
||||
// TODO: Re -register
|
||||
go bridgeConnection(wssession, roomServerID, gameName, roomID, playerIndex)
|
||||
return
|
||||
// If we are connecting to overlord, request serverID from roomID
|
||||
if oclient != nil {
|
||||
roomServerID := getServerIDOfRoom(oclient, roomID)
|
||||
log.Println("Server of RoomID ", roomID, " is ", roomServerID)
|
||||
if roomServerID != "" && wssession.ServerID != roomServerID {
|
||||
// TODO: Re -register
|
||||
go bridgeConnection(wssession, roomServerID, gameName, roomID, playerIndex)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
roomID, isNewRoom = startSession(wssession.peerconnection, gameName, roomID, playerIndex)
|
||||
if isNewRoom {
|
||||
// Register room to overlord if we are connecting to overlord
|
||||
if isNewRoom && oclient != nil {
|
||||
oclient.send(WSPacket{
|
||||
ID: "registerRoom",
|
||||
Data: roomID,
|
||||
|
|
@ -450,7 +453,6 @@ const overlordHost = "ws://localhost:9000/wso"
|
|||
func createOverlordConnection() (*websocket.Conn, error) {
|
||||
c, _, err := websocket.DefaultDialer.Dial(overlordHost, nil)
|
||||
if err != nil {
|
||||
log.Fatal("dial:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -461,6 +463,8 @@ func NewOverlordClient() *Client {
|
|||
oc, err := createOverlordConnection()
|
||||
if err != nil {
|
||||
log.Println("Cannot connect to overlord")
|
||||
log.Println("Run as a single server")
|
||||
return nil
|
||||
}
|
||||
oclient := NewClient(oc)
|
||||
oclient.send(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue