This section is empty.


View Source
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

    View Source
    var CommandHandlers = make(map[string]func(*Client, []string))

      CommandHandlers A map to assign in-game commands to the functions they should execute.

      View Source
      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.

        View Source
        var PacketHandlers = make(map[string]handlerFunc)

          PacketHandlers A map with descriptive names for the keys, and functions to run for the value.

          View Source
          var RsaKey *rsa.PrivateKey

            RsaKey The RSA key for use in decoding the login packet


            func BroadcastLogin

            func BroadcastLogin(player *world.Player, online bool)

              BroadcastLogin Broadcasts the login status of player to the whole server.

              func DecryptRSABlock

              func DecryptRSABlock(payload []byte) []byte

                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

                  func HashPassword(password string) string

                    HashPassword Takes a plaintext password as input, returns a hexidecimal string representation of the SHAKE256 hash as output.

                    func Start

                    func Start()

                      Start Listens for and processes new clients connecting to the server. This method blocks while the server is running.

                      func Stop

                      func Stop()

                        Stop This will stop the server instance, if it is running.

                        func Tick

                        func Tick()

                          Tick One game engine 'tick'. This is to handle movement, to synchronize clients, to update movement-related state variables... Runs once per 600ms.


                          type Client

                          type Client struct {
                          	Index int
                          	Kill chan struct{}
                          	// contains filtered or unexported fields

                            Client Represents a single connecting client.

                            func NewClient

                            func NewClient(socket net.Conn) *Client

                              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

                                func (c *Client) HandleLogin(reply chan byte)

                                  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

                                  func (c *Client) HandlePacket(p *packets.Packet)

                                    HandlePacket Finds the mapped handler function for the specified packet, and calls it with the specified parameters.

                                    func (*Client) HandleRegister

                                    func (c *Client) HandleRegister(reply chan byte)

                                      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

                                      func (c *Client) IP() string

                                        IP Parses the players remote IP address and returns it as a go string. TODO: Should I remove this?

                                        func (*Client) Message

                                        func (c *Client) Message(msg string)

                                          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

                                          func (c *Client) Read(dst []byte) (int, error)

                                            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

                                            func (c *Client) ReadPacket() (*packets.Packet, error)

                                              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

                                                        func (c *Client) String() string

                                                          String Returns a string populated with some of the more identifying fields from the receiver Client.

                                                          func (*Client) TeleBubble

                                                          func (c *Client) TeleBubble(diffX, diffY int)

                                                            TeleBubble Queues a new packet to create a teleport bubble at the given offsets relative to our player.

                                                            func (*Client) Teleport

                                                            func (c *Client) Teleport(x, y int)

                                                              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

                                                                  func (c *Client) UpdateStat(id int)

                                                                    UpdateStat Builds and queues for sending a new packet containing our players stat information for given skill ID

                                                                    func (*Client) Write

                                                                    func (c *Client) Write(b []byte) int

                                                                      Write Writes data to the client's socket from `b`. Returns the length of the written bytes.

                                                                      func (*Client) WritePacket

                                                                      func (c *Client) WritePacket(p packets.Packet)

                                                                        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) Broadcast

                                                                          func (m *ClientMap) Broadcast(action func(*Client))

                                                                            Broadcast Calls action for every active client in the collection.

                                                                            func (*ClientMap) ContainsHash

                                                                            func (m *ClientMap) ContainsHash(hash uint64) bool

                                                                              ContainsHash Returns true if there is a client mapped to this username hash is in this collection, otherwise returns false.

                                                                              func (*ClientMap) FromIndex

                                                                              func (m *ClientMap) FromIndex(index int) (*Client, bool)

                                                                                FromIndex Returns the client with the index `index` if it exists and true, otherwise returns nil and false.

                                                                                func (*ClientMap) FromUserHash

                                                                                func (m *ClientMap) FromUserHash(hash uint64) (*Client, bool)

                                                                                  FromUserHash Returns the client with the base37 username `hash` if it exists and true, otherwise returns nil and false.

                                                                                  func (*ClientMap) NextIndex

                                                                                  func (m *ClientMap) NextIndex() int

                                                                                    NextIndex Returns the lowest available index for the client to be mapped to.

                                                                                    func (*ClientMap) Put

                                                                                    func (m *ClientMap) Put(c *Client)

                                                                                      Put Puts a client into the map.

                                                                                      func (*ClientMap) Remove

                                                                                      func (m *ClientMap) Remove(c *Client)

                                                                                        Remove Removes a client from the map.

                                                                                        func (*ClientMap) Size

                                                                                        func (m *ClientMap) Size() int

                                                                                          Size Returns the size of the active client collection.

                                                                                          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.


                                                                                            Path Synopsis