连接接收数据包事件名称修改
This commit is contained in:
parent
481ccc182a
commit
b0117a11ad
|
@ -5,15 +5,15 @@ import (
|
||||||
"minotaur/utils/log"
|
"minotaur/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReceivePacketEventHandle func(conn *Conn, packet []byte)
|
type ConnectionReceivePacketEventHandle func(conn *Conn, packet []byte)
|
||||||
type ConnectionOpenedEventHandle func(conn *Conn)
|
type ConnectionOpenedEventHandle func(conn *Conn)
|
||||||
type ConnectionClosedEventHandle func(conn *Conn)
|
type ConnectionClosedEventHandle func(conn *Conn)
|
||||||
|
|
||||||
type event struct {
|
type event struct {
|
||||||
*Server
|
*Server
|
||||||
receivePacketEventHandles []ReceivePacketEventHandle
|
connectionReceivePacketEventHandles []ConnectionReceivePacketEventHandle
|
||||||
connectionOpenedEventHandles []ConnectionOpenedEventHandle
|
connectionOpenedEventHandles []ConnectionOpenedEventHandle
|
||||||
connectionClosedEventHandles []ConnectionClosedEventHandle
|
connectionClosedEventHandles []ConnectionClosedEventHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegConnectionClosedEvent 在连接关闭后将立刻执行被注册的事件处理函数
|
// RegConnectionClosedEvent 在连接关闭后将立刻执行被注册的事件处理函数
|
||||||
|
@ -44,22 +44,22 @@ func (slf *event) OnConnectionOpenedEvent(conn *Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegReceivePacketEvent 在接收到数据包时将立刻执行被注册的事件处理函数
|
// RegConnectionReceivePacketEvent 在接收到数据包时将立刻执行被注册的事件处理函数
|
||||||
func (slf *event) RegReceivePacketEvent(handle ReceivePacketEventHandle) {
|
func (slf *event) RegConnectionReceivePacketEvent(handle ConnectionReceivePacketEventHandle) {
|
||||||
if slf.network == NetworkHttp {
|
if slf.network == NetworkHttp {
|
||||||
panic(ErrNetworkIncompatibleHttp)
|
panic(ErrNetworkIncompatibleHttp)
|
||||||
}
|
}
|
||||||
slf.receivePacketEventHandles = append(slf.receivePacketEventHandles, handle)
|
slf.connectionReceivePacketEventHandles = append(slf.connectionReceivePacketEventHandles, handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *event) OnReceivePacketEvent(conn *Conn, packet []byte) {
|
func (slf *event) OnConnectionReceivePacketEvent(conn *Conn, packet []byte) {
|
||||||
for _, handle := range slf.receivePacketEventHandles {
|
for _, handle := range slf.connectionReceivePacketEventHandles {
|
||||||
handle(conn, packet)
|
handle(conn, packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *event) check() {
|
func (slf *event) check() {
|
||||||
if len(slf.receivePacketEventHandles) == 0 {
|
if len(slf.connectionReceivePacketEventHandles) == 0 {
|
||||||
log.Warn("Server", zap.String("ReceivePacketEvent", "Invalid server, no packets processed"))
|
log.Warn("Server", zap.String("ConnectionReceivePacketEvent", "Invalid server, no packets processed"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ func (slf *Server) dispatchMessage(msg *message) {
|
||||||
switch msg.t {
|
switch msg.t {
|
||||||
case MessageTypePacket:
|
case MessageTypePacket:
|
||||||
conn, packet := msg.t.deconstructPacket(msg.attrs...)
|
conn, packet := msg.t.deconstructPacket(msg.attrs...)
|
||||||
slf.OnReceivePacketEvent(conn, packet)
|
slf.OnConnectionReceivePacketEvent(conn, packet)
|
||||||
case MessageTypeError:
|
case MessageTypeError:
|
||||||
err, action := msg.t.deconstructError(msg.attrs...)
|
err, action := msg.t.deconstructError(msg.attrs...)
|
||||||
switch action {
|
switch action {
|
||||||
|
|
Loading…
Reference in New Issue