This commit is contained in:
@@ -36,21 +36,21 @@ func Listen(address string) (*Server, error) {
|
||||
|
||||
type TCPServerMux struct {
|
||||
mu sync.RWMutex
|
||||
listeners map[uint16]func(data []byte) error
|
||||
functions map[uint16]func(data []byte) (uint16, []byte, error)
|
||||
listeners map[uint32]func(data []byte) error
|
||||
functions map[uint32]func(data []byte) (uint32, []byte, error)
|
||||
}
|
||||
|
||||
func NewTCPServerMux(maxClients int) *TCPServerMux {
|
||||
m := &TCPServerMux{
|
||||
mu: sync.RWMutex{},
|
||||
listeners: make(map[uint16]func(data []byte) error),
|
||||
functions: make(map[uint16]func(data []byte) (uint16, []byte, error)),
|
||||
listeners: make(map[uint32]func(data []byte) error),
|
||||
functions: make(map[uint32]func(data []byte) (uint32, []byte, error)),
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) handleListener(messageType uint16, data []byte) (bool, error) {
|
||||
func (m *TCPServerMux) handleListener(messageType uint32, data []byte) (bool, error) {
|
||||
m.mu.RLock()
|
||||
handler, ok := m.listeners[messageType]
|
||||
m.mu.RUnlock()
|
||||
@@ -63,7 +63,7 @@ func (m *TCPServerMux) handleListener(messageType uint16, data []byte) (bool, er
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) handleFunction(connection net.Conn, messageType uint16, data []byte) (bool, error) {
|
||||
func (m *TCPServerMux) handleFunction(connection net.Conn, messageType uint32, data []byte) (bool, error) {
|
||||
m.mu.RLock()
|
||||
function, ok := m.functions[messageType]
|
||||
m.mu.RUnlock()
|
||||
@@ -75,7 +75,7 @@ func (m *TCPServerMux) handleFunction(connection net.Conn, messageType uint16, d
|
||||
err = binary.Write(connection, binary.LittleEndian, Packet{
|
||||
Version: 1,
|
||||
MessageType: responseType,
|
||||
DataLength: uint16(len(responseData)),
|
||||
DataLength: uint64(len(responseData)),
|
||||
})
|
||||
if err != nil {
|
||||
return true, err
|
||||
@@ -116,13 +116,13 @@ func (m *TCPServerMux) HandleConnection(connection net.Conn) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) ListenFor(messageType uint16, handler func(data []byte) error) {
|
||||
func (m *TCPServerMux) ListenFor(messageType uint32, handler func(data []byte) error) {
|
||||
m.mu.Lock()
|
||||
m.listeners[messageType] = handler
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
func (m *TCPServerMux) HandleCall(messageType uint16, handler func(data []byte) (uint16, []byte, error)) {
|
||||
func (m *TCPServerMux) HandleCall(messageType uint32, handler func(data []byte) (uint32, []byte, error)) {
|
||||
m.mu.Lock()
|
||||
m.functions[messageType] = handler
|
||||
m.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user