@@ -1213,28 +1213,37 @@ func (srv *server) initPluginHooks() error {
12131213}
12141214}
12151215if onAcceptWrappers != nil {
1216- onAccept := func (ctx context.Context ,conn net.Conn )bool {
1217- return true
1216+ onAccept := srv .hooks .OnAccept
1217+ if onAccept == nil {
1218+ onAccept = func (ctx context.Context ,conn net.Conn )bool {
1219+ return true
1220+ }
12181221}
12191222for i := len (onAcceptWrappers );i > 0 ;i -- {
12201223onAccept = onAcceptWrappers [i - 1 ](onAccept )
12211224}
12221225srv .hooks .OnAccept = onAccept
12231226}
12241227if onBasicAuthWrappers != nil {
1225- onBasicAuth := func (ctx context.Context ,client Client ,req * ConnectRequest )error {
1226- return nil
1228+ onBasicAuth := srv .hooks .OnBasicAuth
1229+ if onBasicAuth == nil {
1230+ onBasicAuth = func (ctx context.Context ,client Client ,req * ConnectRequest )error {
1231+ return nil
1232+ }
12271233}
12281234for i := len (onBasicAuthWrappers );i > 0 ;i -- {
12291235onBasicAuth = onBasicAuthWrappers [i - 1 ](onBasicAuth )
12301236}
12311237srv .hooks .OnBasicAuth = onBasicAuth
12321238}
12331239if onEnhancedAuthWrappers != nil {
1234- onEnhancedAuth := func (ctx context.Context ,client Client ,req * ConnectRequest ) (resp * EnhancedAuthResponse ,err error ) {
1235- return & EnhancedAuthResponse {
1236- Continue :false ,
1237- },nil
1240+ onEnhancedAuth := srv .hooks .OnEnhancedAuth
1241+ if onEnhancedAuth == nil {
1242+ onEnhancedAuth = func (ctx context.Context ,client Client ,req * ConnectRequest ) (resp * EnhancedAuthResponse ,err error ) {
1243+ return & EnhancedAuthResponse {
1244+ Continue :false ,
1245+ },nil
1246+ }
12381247}
12391248for i := len (onEnhancedAuthWrappers );i > 0 ;i -- {
12401249onEnhancedAuth = onEnhancedAuthWrappers [i - 1 ](onEnhancedAuth )
@@ -1243,111 +1252,157 @@ func (srv *server) initPluginHooks() error {
12431252}
12441253
12451254if onConnectedWrappers != nil {
1246- onConnected := func (ctx context.Context ,client Client ) {}
1255+ onConnected := srv .hooks .OnConnected
1256+ if onConnected == nil {
1257+ onConnected = func (ctx context.Context ,client Client ) {}
1258+ }
12471259for i := len (onConnectedWrappers );i > 0 ;i -- {
12481260onConnected = onConnectedWrappers [i - 1 ](onConnected )
12491261}
12501262srv .hooks .OnConnected = onConnected
12511263}
12521264if onSessionCreatedWrapper != nil {
1253- onSessionCreated := func (ctx context.Context ,client Client ) {}
1265+ onSessionCreated := srv .hooks .OnSessionCreated
1266+ if onSessionCreated == nil {
1267+ onSessionCreated = func (ctx context.Context ,client Client ) {}
1268+ }
12541269for i := len (onSessionCreatedWrapper );i > 0 ;i -- {
12551270onSessionCreated = onSessionCreatedWrapper [i - 1 ](onSessionCreated )
12561271}
12571272srv .hooks .OnSessionCreated = onSessionCreated
12581273}
12591274if onSessionResumedWrapper != nil {
1260- onSessionResumed := func (ctx context.Context ,client Client ) {}
1275+ onSessionResumed := srv .hooks .OnSessionResumed
1276+ if onSessionResumed == nil {
1277+ onSessionResumed = func (ctx context.Context ,client Client ) {}
1278+ }
12611279for i := len (onSessionResumedWrapper );i > 0 ;i -- {
12621280onSessionResumed = onSessionResumedWrapper [i - 1 ](onSessionResumed )
12631281}
12641282srv .hooks .OnSessionResumed = onSessionResumed
12651283}
12661284if onSessionTerminatedWrapper != nil {
1267- onSessionTerminated := func (ctx context.Context ,clientID string ,reason SessionTerminatedReason ) {}
1285+ onSessionTerminated := srv .hooks .OnSessionTerminated
1286+ if onSessionTerminated == nil {
1287+ onSessionTerminated = func (ctx context.Context ,clientID string ,reason SessionTerminatedReason ) {}
1288+ }
12681289for i := len (onSessionTerminatedWrapper );i > 0 ;i -- {
12691290onSessionTerminated = onSessionTerminatedWrapper [i - 1 ](onSessionTerminated )
12701291}
12711292srv .hooks .OnSessionTerminated = onSessionTerminated
12721293}
12731294if onSubscribeWrappers != nil {
1274- onSubscribe := func (ctx context.Context ,client Client ,req * SubscribeRequest )error {
1275- return nil
1295+ onSubscribe := srv .hooks .OnSubscribe
1296+ if onSubscribe == nil {
1297+ onSubscribe = func (ctx context.Context ,client Client ,req * SubscribeRequest )error {
1298+ return nil
1299+ }
12761300}
12771301for i := len (onSubscribeWrappers );i > 0 ;i -- {
12781302onSubscribe = onSubscribeWrappers [i - 1 ](onSubscribe )
12791303}
12801304srv .hooks .OnSubscribe = onSubscribe
12811305}
12821306if onSubscribedWrappers != nil {
1283- onSubscribed := func (ctx context.Context ,client Client ,subscription * gmqtt.Subscription ) {}
1307+ onSubscribed := srv .hooks .OnSubscribed
1308+ if onSubscribed == nil {
1309+ onSubscribed = func (ctx context.Context ,client Client ,subscription * gmqtt.Subscription ) {}
1310+ }
1311+
12841312for i := len (onSubscribedWrappers );i > 0 ;i -- {
12851313onSubscribed = onSubscribedWrappers [i - 1 ](onSubscribed )
12861314}
12871315srv .hooks .OnSubscribed = onSubscribed
12881316}
12891317if onUnsubscribeWrappers != nil {
1290- onUnsubscribe := func (ctx context.Context ,client Client ,req * UnsubscribeRequest )error {
1291- return nil
1318+ onUnsubscribe := srv .hooks .OnUnsubscribe
1319+ if onUnsubscribe == nil {
1320+ onUnsubscribe = func (ctx context.Context ,client Client ,req * UnsubscribeRequest )error {
1321+ return nil
1322+ }
12921323}
12931324for i := len (onUnsubscribeWrappers );i > 0 ;i -- {
12941325onUnsubscribe = onUnsubscribeWrappers [i - 1 ](onUnsubscribe )
12951326}
12961327srv .hooks .OnUnsubscribe = onUnsubscribe
12971328}
12981329if onUnsubscribedWrappers != nil {
1299- onUnsubscribed := func (ctx context.Context ,client Client ,topicName string ) {}
1330+ onUnsubscribed := srv .hooks .OnUnsubscribed
1331+ if onUnsubscribed == nil {
1332+ onUnsubscribed = func (ctx context.Context ,client Client ,topicName string ) {}
1333+ }
13001334for i := len (onUnsubscribedWrappers );i > 0 ;i -- {
13011335onUnsubscribed = onUnsubscribedWrappers [i - 1 ](onUnsubscribed )
13021336}
13031337srv .hooks .OnUnsubscribed = onUnsubscribed
13041338}
13051339if onMsgArrivedWrappers != nil {
1306- onMsgArrived := func (ctx context.Context ,client Client ,req * MsgArrivedRequest )error {
1307- return nil
1340+ onMsgArrived := srv .hooks .OnMsgArrived
1341+ if onMsgArrived == nil {
1342+ onMsgArrived = func (ctx context.Context ,client Client ,req * MsgArrivedRequest )error {
1343+ return nil
1344+ }
13081345}
13091346for i := len (onMsgArrivedWrappers );i > 0 ;i -- {
13101347onMsgArrived = onMsgArrivedWrappers [i - 1 ](onMsgArrived )
13111348}
13121349srv .hooks .OnMsgArrived = onMsgArrived
13131350}
13141351if OnDeliveredWrappers != nil {
1315- OnDelivered := func (ctx context.Context ,client Client ,msg * gmqtt.Message ) {}
1352+ onDelivered := srv .hooks .OnDelivered
1353+ if onDelivered == nil {
1354+ onDelivered = func (ctx context.Context ,client Client ,msg * gmqtt.Message ) {}
1355+ }
13161356for i := len (OnDeliveredWrappers );i > 0 ;i -- {
1317- OnDelivered = OnDeliveredWrappers [i - 1 ](OnDelivered )
1357+ onDelivered = OnDeliveredWrappers [i - 1 ](onDelivered )
13181358}
1319- srv .hooks .OnDelivered = OnDelivered
1359+ srv .hooks .OnDelivered = onDelivered
13201360}
13211361if OnClosedWrappers != nil {
1322- OnClosed := func (ctx context.Context ,client Client ,err error ) {}
1362+ onClosed := srv .hooks .OnClosed
1363+ if onClosed == nil {
1364+ onClosed = func (ctx context.Context ,client Client ,err error ) {}
1365+ }
13231366for i := len (OnClosedWrappers );i > 0 ;i -- {
1324- OnClosed = OnClosedWrappers [i - 1 ](OnClosed )
1367+ onClosed = OnClosedWrappers [i - 1 ](onClosed )
13251368}
1326- srv .hooks .OnClosed = OnClosed
1369+ srv .hooks .OnClosed = onClosed
13271370}
13281371if onStopWrappers != nil {
1329- onStop := func (ctx context.Context ) {}
1372+ onStop := srv .hooks .OnStop
1373+ if onStop == nil {
1374+ onStop = func (ctx context.Context ) {}
1375+ }
13301376for i := len (onStopWrappers );i > 0 ;i -- {
13311377onStop = onStopWrappers [i - 1 ](onStop )
13321378}
13331379srv .hooks .OnStop = onStop
13341380}
13351381if onMsgDroppedWrappers != nil {
1336- onMsgDropped := func (ctx context.Context ,clientID string ,msg * gmqtt.Message ,err error ) {}
1382+ onMsgDropped := srv .hooks .OnMsgDropped
1383+ if onMsgDropped == nil {
1384+ onMsgDropped = func (ctx context.Context ,clientID string ,msg * gmqtt.Message ,err error ) {}
1385+ }
13371386for i := len (onMsgDroppedWrappers );i > 0 ;i -- {
13381387onMsgDropped = onMsgDroppedWrappers [i - 1 ](onMsgDropped )
13391388}
13401389srv .hooks .OnMsgDropped = onMsgDropped
13411390}
13421391if onWillPublishWrappers != nil {
1343- onWillPublish := func (ctx context.Context ,clientID string ,req * WillMsgRequest ) {}
1392+ onWillPublish := srv .hooks .OnWillPublish
1393+ if onWillPublish == nil {
1394+ onWillPublish = func (ctx context.Context ,clientID string ,req * WillMsgRequest ) {}
1395+ }
13441396for i := len (onWillPublishWrappers );i > 0 ;i -- {
13451397onWillPublish = onWillPublishWrappers [i - 1 ](onWillPublish )
13461398}
13471399srv .hooks .OnWillPublish = onWillPublish
13481400}
13491401if onWillPublishedWrappers != nil {
1350- onWillPublished := func (ctx context.Context ,clientID string ,msg * gmqtt.Message ) {}
1402+ onWillPublished := srv .hooks .OnWillPublished
1403+ if onWillPublished == nil {
1404+ onWillPublished = func (ctx context.Context ,clientID string ,msg * gmqtt.Message ) {}
1405+ }
13511406for i := len (onWillPublishedWrappers );i > 0 ;i -- {
13521407onWillPublished = onWillPublishedWrappers [i - 1 ](onWillPublished )
13531408}