Documentation ¶
Index ¶
- Variables
- func BroadcastLogin(player *world.Player, online bool)
- func DecryptRSABlock(payload []byte) []byte
- func GenerateSessionID() uint64
- func HashPassword(password string) string
- func Start()
- func Stop()
- func Tick()
- type Client
- func (c *Client) Destroy()
- func (c *Client) HandleLogin(reply chan byte)
- func (c *Client) HandlePacket(p *packets.Packet)
- func (c *Client) HandleRegister(reply chan byte)
- func (c *Client) IP() string
- func (c *Client) Message(msg string)
- func (c *Client) Read(dst []byte) (int, error)
- func (c *Client) ReadPacket() (*packets.Packet, error)
- func (c *Client) ResetUpdateFlags()
- func (c *Client) SeedOpcodeCipher(clientSeed uint64, serverSeed uint64) *IsaacStream
- func (c *Client) StartNetworking()
- func (c *Client) StartReader()
- func (c *Client) StartWriter()
- func (c *Client) String() string
- func (c *Client) TeleBubble(diffX, diffY int)
- func (c *Client) Teleport(x, y int)
- func (c *Client) UpdatePlane()
- func (c *Client) UpdatePositions()
- func (c *Client) UpdateStat(id int)
- func (c *Client) Write(b []byte) int
- func (c *Client) WritePacket(p packets.Packet)
- type ClientMap
- func (m *ClientMap) Broadcast(action func(*Client))
- func (m *ClientMap) ContainsHash(hash uint64) bool
- func (m *ClientMap) FromIndex(index int) (*Client, bool)
- func (m *ClientMap) FromUserHash(hash uint64) (*Client, bool)
- func (m *ClientMap) NextIndex() int
- func (m *ClientMap) Put(c *Client)
- func (m *ClientMap) Remove(c *Client)
- func (m *ClientMap) Size() int
- type IsaacStream
Constants ¶
This section is empty.
Variables ¶
var Clients = &ClientMap{usernames: make(map[uint64]*Client), indices: make(map[int]*Client)}
Clients Collection containing all of the active clients, by index and username hash, guarded by a mutex
var CommandHandlers = make(map[string]func(*Client, []string))
CommandHandlers A map to assign in-game commands to the functions they should execute.
var Flags struct { Verbose []bool `short:"v" long:"verbose" description:"Display more verbose output"` Port int `short:"p" long:"port" description:"The port for the server to listen on,"` Config string `short:"c" long:"config" description:"Specify the configuration file to load server settings from" default:"config.toml"` UseCipher bool `short:"e" long:"encryption" description:"Enable command opcode encryption using ISAAC to encrypt packet opcodes."` }
Flags This is used to interface with the go-flags package from some guy on github.
var PacketHandlers = make(map[string]handlerFunc)
PacketHandlers A map with descriptive names for the keys, and functions to run for the value.
var RsaKey *rsa.PrivateKey
RsaKey The RSA key for use in decoding the login packet
Functions ¶
func BroadcastLogin ¶
BroadcastLogin Broadcasts the login status of player to the whole server.
func DecryptRSABlock ¶
DecryptRSABlock Attempts to decrypt the payload buffer. Returns the decrypted buffer upon success, otherwise returns nil.
func GenerateSessionID ¶
func GenerateSessionID() uint64
GenerateSessionID Generates a new 64-bit long using the systems CSPRNG. For use as a seed with the ISAAC cipher (or similar secure stream cipher) used to encrypt packet data.
func HashPassword ¶
HashPassword Takes a plaintext password as input, returns a hexidecimal string representation of the SHAKE256 hash as output.
Types ¶
type Client ¶
type Client struct { Index int Kill chan struct{} // contains filtered or unexported fields }
Client Represents a single connecting client.
func NewClient ¶
NewClient Creates a new instance of a Client, launches goroutines to handle I/O for it, and returns a reference to it.
func (*Client) Destroy ¶
func (c *Client) Destroy()
Destroy Wrapper around Client.destroy to prevent multiple channel closes causing a panic.
func (*Client) HandleLogin ¶
HandleLogin This method will block until a byte is sent down the reply channel with the login response to send to the client, or if this doesn't occur, it will timeout after 10 seconds.
func (*Client) HandlePacket ¶
HandlePacket Finds the mapped handler function for the specified packet, and calls it with the specified parameters.
func (*Client) HandleRegister ¶
HandleRegister This method will block until a byte is sent down the reply channel with the registration response to send to the client, or if this doesn't occur, it will timeout after 10 seconds.
func (*Client) IP ¶
IP Parses the players remote IP address and returns it as a go string. TODO: Should I remove this?
func (*Client) Message ¶
Message Builds a new game packet to display a message in the clients chat box with msg as its contents, and queues it in the outgoing packet queue.
func (*Client) Read ¶
Read Reads data off of the client's socket into 'dst'. Returns length read into dst upon success. Otherwise, returns -1 with a meaningful error message.
func (*Client) ReadPacket ¶
ReadPacket Attempts to read and parse the next 3 bytes of incoming data for the 16-bit length and 8-bit opcode of the next packet frame the client is sending us.
func (*Client) ResetUpdateFlags ¶
func (c *Client) ResetUpdateFlags()
ResetUpdateFlags Resets the players movement updating synchronization variables.
func (*Client) SeedOpcodeCipher ¶
func (c *Client) SeedOpcodeCipher(clientSeed uint64, serverSeed uint64) *IsaacStream
SeedOpcodeCipher Initialize the ISAAC+ PRNG for use as a stream cipher for this client.
func (*Client) StartNetworking ¶
func (c *Client) StartNetworking()
StartNetworking Starts up 3 new goroutines; one for reading incoming data from the socket, one for writing outgoing data to the socket, and one for client state updates and parsing plus handling incoming packets. When the clients kill signal is sent through the kill channel, the state update and packet handling goroutine will wait for both the reader and writer goroutines to complete their operations before unregistering the client.
func (*Client) StartReader ¶
func (c *Client) StartReader()
StartReader Starts the clients socket reader goroutine. Takes a waitgroup as an argument to facilitate synchronous destruction.
func (*Client) StartWriter ¶
func (c *Client) StartWriter()
StartWriter Starts the clients socket writer goroutine.
func (*Client) String ¶
String Returns a string populated with some of the more identifying fields from the receiver Client.
func (*Client) TeleBubble ¶
TeleBubble Queues a new packet to create a teleport bubble at the given offsets relative to our player.
func (*Client) Teleport ¶
Teleport Moves the client's player to x,y in the game world, and sends a teleport bubble animation packet to all of the view-area clients.
func (*Client) UpdatePlane ¶
func (c *Client) UpdatePlane()
UpdatePlane Updates the client about the plane that its player is on.
func (*Client) UpdatePositions ¶
func (c *Client) UpdatePositions()
UpdatePositions Updates the client about entities in it's view-area (16x16 tiles in the game world surrounding the player). Should be run every game engine tick.
func (*Client) UpdateStat ¶
UpdateStat Builds and queues for sending a new packet containing our players stat information for given skill ID
func (*Client) Write ¶
Write Writes data to the client's socket from `b`. Returns the length of the written bytes.
func (*Client) WritePacket ¶
WritePacket This is a method to send a packet to the client. If this is a bare packet, the packet payload will be written as-is. If this is not a bare packet, the packet will have the first 3 bytes changed to the appropriate values for the client to parse the length and opcode for this packet.
type ClientMap ¶
type ClientMap struct {
// contains filtered or unexported fields
}
ClientMap A thread-safe concurrent collection type for storing client references.
func (*ClientMap) ContainsHash ¶
ContainsHash Returns true if there is a client mapped to this username hash is in this collection, otherwise returns false.
func (*ClientMap) FromIndex ¶
FromIndex Returns the client with the index `index` if it exists and true, otherwise returns nil and false.
func (*ClientMap) FromUserHash ¶
FromUserHash Returns the client with the base37 username `hash` if it exists and true, otherwise returns nil and false.
func (*ClientMap) NextIndex ¶
NextIndex Returns the lowest available index for the client to be mapped to.
type IsaacStream ¶
type IsaacStream struct {
// contains filtered or unexported fields
}
IsaacStream Container struct for 2 instances of the ISAAC+ CSPRNG, one for incoming data, the other outgoing data.