You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.2 KiB
Go

10 years ago
package main
import (
"fmt"
10 years ago
"strings"
10 years ago
)
const (
E_Ok int = iota
E_No_Data
10 years ago
E_No_DB
10 years ago
E_No_Port
E_Bad_Duration
10 years ago
)
type errorGroup []error
func (e errorGroup) Error() string {
10 years ago
messages := make([]string, 0, len(e))
for i, _ := range e {
messages[i] = e[i].Error()
}
return strings.Join(messages, " && ")
10 years ago
}
func (g *errorGroup) AddError(err error) {
10 years ago
if err == nil {
return
}
if g == nil {
panic("fart")
*g = make([]error, 0, 4)
}
*g = append(*g, err)
10 years ago
}
// ErrorState represents a valid client state indicating that the client has
// hit an error. On tick, the client will be disconnected. ErrorState is both
// a valid ConnectionState and a valid error value.
type ErrorState struct {
CommandSuite
error
NopEnter
NopExit
}
func NewErrorState(e error) *ErrorState {
return &ErrorState{error: e}
}
func (e *ErrorState) Tick(c *Connection, frame int64) ConnectionState {
c.Printf("something went wrong: %v", e.error)
log_error("player hit error: %v", e.error)
c.Close()
return nil
}
func (e *ErrorState) String() string {
return fmt.Sprintf("error state: %v", e.error)
}
func (e *ErrorState) RunCommand(c *Connection, name string, args ...string) ConnectionState {
return e
}
func (e *ErrorState) FillStatus(c *Connection, s *status) {}