in Stable-Diffusion-UI-Agones/agones-sidecar/main.go [202:324]
func handleResponse(txt string, s *sdk.SDK, cancel context.CancelFunc) (response string, addACK bool, responseError error) {
parts := strings.Split(strings.TrimSpace(txt), " ")
response = txt
addACK = true
responseError = nil
switch parts[0] {
// shuts down the gameserver
case "EXIT":
// handle elsewhere, as we respond before exiting
return
// turns off the health pings
case "UNHEALTHY":
cancel()
case "GAMESERVER":
response = gameServerName(s)
addACK = false
case "READY":
ready(s)
case "ALLOCATE":
allocate(s)
case "RESERVE":
if len(parts) != 2 {
response = "Invalid RESERVE, should have 1 argument"
responseError = fmt.Errorf("Invalid RESERVE, should have 1 argument")
}
if dur, err := time.ParseDuration(parts[1]); err != nil {
response = fmt.Sprintf("%s\n", err)
responseError = err
} else {
reserve(s, dur)
}
case "WATCH":
watchGameServerEvents(s)
case "LABEL":
switch len(parts) {
case 1:
// legacy format
setLabel(s, "timestamp", strconv.FormatInt(time.Now().Unix(), 10))
case 3:
setLabel(s, parts[1], parts[2])
default:
response = "Invalid LABEL command, must use zero or 2 arguments"
responseError = fmt.Errorf("Invalid LABEL command, must use zero or 2 arguments")
}
case "CRASH":
log.Print("Crashing.")
os.Exit(1)
return "", false, nil
case "ANNOTATION":
switch len(parts) {
case 1:
// legacy format
setAnnotation(s, "timestamp", time.Now().UTC().String())
case 3:
setAnnotation(s, parts[1], parts[2])
default:
response = "Invalid ANNOTATION command, must use zero or 2 arguments"
responseError = fmt.Errorf("Invalid ANNOTATION command, must use zero or 2 arguments")
}
case "PLAYER_CAPACITY":
switch len(parts) {
case 1:
response = getPlayerCapacity(s)
addACK = false
case 2:
if cap, err := strconv.Atoi(parts[1]); err != nil {
response = fmt.Sprintf("%s", err)
responseError = err
} else {
setPlayerCapacity(s, int64(cap))
}
default:
response = "Invalid PLAYER_CAPACITY, should have 0 or 1 arguments"
responseError = fmt.Errorf("Invalid PLAYER_CAPACITY, should have 0 or 1 arguments")
}
case "PLAYER_CONNECT":
if len(parts) < 2 {
response = "Invalid PLAYER_CONNECT, should have 1 arguments"
responseError = fmt.Errorf("Invalid PLAYER_CONNECT, should have 1 arguments")
return
}
playerConnect(s, parts[1])
case "PLAYER_DISCONNECT":
if len(parts) < 2 {
response = "Invalid PLAYER_DISCONNECT, should have 1 arguments"
responseError = fmt.Errorf("Invalid PLAYER_DISCONNECT, should have 1 arguments")
return
}
playerDisconnect(s, parts[1])
case "PLAYER_CONNECTED":
if len(parts) < 2 {
response = "Invalid PLAYER_CONNECTED, should have 1 arguments"
responseError = fmt.Errorf("Invalid PLAYER_CONNECTED, should have 1 arguments")
return
}
response = playerIsConnected(s, parts[1])
addACK = false
case "GET_PLAYERS":
response = getConnectedPlayers(s)
addACK = false
case "PLAYER_COUNT":
response = getPlayerCount(s)
addACK = false
}
return
}