forked from cfoust/sour
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
118 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cfoust/sour/pkg/game" | ||
"github.com/cfoust/sour/pkg/maps" | ||
"github.com/cfoust/sour/svc/cluster/clients" | ||
"github.com/cfoust/sour/svc/cluster/servers" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func (server *Cluster) GoHome(ctx context.Context, client *clients.Client) error { | ||
gameServer, err := server.manager.NewServer(ctx, "", true) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to create home server") | ||
return err | ||
} | ||
|
||
err = gameServer.StartAndWait(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gameServer.SendCommand(fmt.Sprintf("serverdesc \"Sour %s\"", game.Blue("Home"))) | ||
gameServer.SendCommand("publicserver 1") | ||
|
||
// New empty map | ||
gameServer.SendCommand("emptymap") | ||
|
||
// Load the user's world or create a new one | ||
editing := servers.NewEditingState() | ||
gameServer.Editing = editing | ||
|
||
map_ := maps.NewMap() | ||
gz, err := map_.EncodeOGZ() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = editing.LoadMapBytes(gz) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
go editing.PollEdits(ctx) | ||
|
||
connected, err := client.ConnectToServer(gameServer, false, true) | ||
result := <-connected | ||
if result == false || err != nil { | ||
return fmt.Errorf("client never joined") | ||
} | ||
|
||
p := game.Packet{} | ||
p.Put(game.N_SENDMAP) | ||
p = append(p, gz...) | ||
|
||
client.Send(game.GamePacket{ | ||
Channel: 2, | ||
Data: p, | ||
}) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters