-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
74 lines (61 loc) · 1.84 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package goseq
import (
"errors"
"io"
"time"
)
// ServerType is the type of server being queried.
type ServerType byte
const (
Dedicated ServerType = ServerType(byte('D'))
Listen ServerType = ServerType(byte('L')) // "Non dedicated"
SourceTV ServerType = ServerType(byte('P'))
)
// ServerEnvironment is the OS the server is running on.
type ServerEnvironment byte
const (
Linux ServerEnvironment = ServerEnvironment(byte('l'))
Windows ServerEnvironment = ServerEnvironment(byte('w'))
Mac ServerEnvironment = ServerEnvironment(byte('o'))
)
const (
// NoAddress represents a address that has yet to be
// set by the server implementation.
NoAddress string = "address-not-set.example.org:0"
)
var (
NoAddressSet error = errors.New("The server does not have a remote address set.")
)
// Server represents a Source server.
type Server interface {
Address() string
// Ping returns the connection latency of a server.
Ping(timeout time.Duration) (time.Duration, error)
// Info returns the Source Info query result.
Info(timeout time.Duration) (ServerInfo, error)
// Players retrieves the players currently on a server.
Players(timeout time.Duration) ([]Player, error)
// Rules returns the server-defined rules of the server.
// These are mostly Convar settings.
Rules(timeout time.Duration) (RuleMap, error)
SetAddress(string) error
}
// NewServer returns a Server that uses the network
// as its data source.
func NewServer() Server {
return &iserver{
src: &sourceRemote{},
}
}
// implementation of Server
type iserver struct {
src source
}
func (serv *iserver) Address() string { return serv.src.address() }
func (s *iserver) SetAddress(a string) error { return s.src.setAddress(a) }
func (s *iserver) getConnection() (io.ReadWriteCloser, error) {
return s.src.connection()
}
type wrChallengeResponse struct {
Magic [4]byte
}