Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# see https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners for more information
* @Unity-Technologies/multiplayer-services
* @Unity-Technologies/multiplay
3 changes: 3 additions & 0 deletions simple-game-server-go/internal/game/allocated.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (g *Game) allocated(allocationID string) {
c := g.Config()
port, _ := c.Port.Int64()
maxPlayers, _ := strconv.ParseInt(c.Extra["maxPlayers"], 10, 32)

if maxPlayers == 0 {
maxPlayers = defaultMaxPlayers
}
Expand Down Expand Up @@ -114,8 +115,10 @@ func (g *Game) handleClient(client *net.TCPConn) {
"current_players": currentPlayers,
}).Info("client disconnected")
}()

for {
buf := make([]byte, 16)

if _, err := client.Read(buf); err != nil {
return
}
Expand Down
5 changes: 5 additions & 0 deletions simple-game-server-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func parseFlags(args []string) (string, string, string, error) {
// If no valid targets are provided, it defaults to writing to stdout.
func logWritersFromTargets(logTargets string, logFile string, logger *logrus.Logger) io.Writer {
targets := make([]io.Writer, 0)

for _, t := range splitAndTrim(logTargets) {
switch t {
case "stdout":
Expand All @@ -54,6 +55,7 @@ func logWritersFromTargets(logTargets string, logFile string, logger *logrus.Log
targets = append(targets, f)
}
}

// logFile takes precedence
if logFile != "" {
f, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
Expand All @@ -63,6 +65,7 @@ func logWritersFromTargets(logTargets string, logFile string, logger *logrus.Log
logger.WithError(err).Warning("could not open log file for writing")
}
}

if len(targets) == 0 {
return os.Stdout
}
Expand All @@ -72,6 +75,7 @@ func logWritersFromTargets(logTargets string, logFile string, logger *logrus.Log
// splitAndTrim splits a string by the OS-specific path list separator and trims each part.
func splitAndTrim(s string) []string {
parts := make([]string, 0)

for _, p := range filepath.SplitList(s) {
for _, t := range splitComma(p) {
trimmed := filepath.Clean(t)
Expand All @@ -86,6 +90,7 @@ func splitAndTrim(s string) []string {
// splitComma splits a string by commas and trims each part, returning a slice of non-empty strings.
func splitComma(s string) []string {
res := make([]string, 0)

for _, t := range strings.Split(s, ",") {
trimmed := strings.TrimSpace(t)
if trimmed != "" && trimmed != "." {
Expand Down
Loading