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

67 lines
2.5 KiB

package websocket
import (
"go.uber.org/zap/zapcore"
"hexmap-server/action"
"hexmap-server/state"
)
// TODO: Make all the ServerMessages implement ServerMessage.
// ServerMessageType is an enum type for the server's messages.
type ServerMessageType string
const (
ServerHelloType ServerMessageType = "HELLO"
ServerRefreshType ServerMessageType = "REFRESH"
ServerOKType ServerMessageType = "OK"
ServerFailedType ServerMessageType = "FAILED"
ServerActType ServerMessageType = "ACT"
ServerGoodbyeType ServerMessageType = GoodbyeType
)
// ServerMessage s are sent by the server to the client.
type ServerMessage interface {
zapcore.ObjectMarshaler
// ServerType returns the type constant that will be sent on the wire.
ServerType() ServerMessageType
}
// ServerHello is the action sent to establish the current state of the server when a new client connects.
type ServerHello struct {
// Version is the protocol version the server is running.
Version int `json:"version"`
// State is the complete state of the server as of when the client joined.
State state.Synced `json:"state"`
}
// ServerRefresh is the action sent to reestablish the current state of the server in response to ClientRefresh.
type ServerRefresh struct {
// State is the complete state of the server as of when the corresponding ClientRefresh was processed.
State state.Synced `json:"state"`
}
// ServerOK is the action sent when one or more client actions have been accepted and applied.
type ServerOK struct {
// IDs contains the IDs of the actions which were accepted and applied, in the order they were accepted and applied.
// This is the same as the order they were received, though other actions may have been between these that were
// rejected.
IDs []int `json:"ids"`
}
// ServerFailed is the action sent when one or more client actions have been rejected.
type ServerFailed struct {
// IDs contains the IDs of the actions which were rejected, in the order they were rejected.
// This is the same as the order they were received, though other actions may have been between these that were
// accepted and applied.
IDs []int `json:"ids"`
// Error contains the error text sent from the server about why these actions failed.
Error string `json:"error"`
}
// ServerAct is the action sent when one or more client actions from other clients have been accepted and applied.
// The client's own actions will never be included in this action.
type ServerAct struct {
// Actions contains the actions that are now being applied.
Actions []action.Syncable `json:"actions"`
}