Mike 2 лет назад
Родитель
Сommit
2ab90407e5

+ 2 - 2
server/auth_service.go

@@ -66,7 +66,7 @@ func (rt AuthService) handleAuthConnection(rwc io.ReadWriteCloser) {
 		rt.Logger.Error(err.Error())
 		return
 	}
-	if err := sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, &seq, rwc); err != nil {
+	if err := sendSNAC(0, msg.Frame, msg.Body, &seq, rwc); err != nil {
 		rt.Logger.Error(err.Error())
 		return
 	}
@@ -99,7 +99,7 @@ func (rt AuthService) handleAuthConnection(rwc io.ReadWriteCloser) {
 		rt.Logger.Error(err.Error())
 		return
 	}
-	if err := sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, &seq, rwc); err != nil {
+	if err := sendSNAC(0, msg.Frame, msg.Body, &seq, rwc); err != nil {
 		rt.Logger.Error(err.Error())
 		return
 	}

+ 2 - 2
server/bos_service.go

@@ -68,7 +68,7 @@ func (rt BOSService) handleNewConnection(ctx context.Context, rwc io.ReadWriteCl
 	ctx = context.WithValue(ctx, "screenName", sess.ScreenName())
 
 	msg := rt.WriteOServiceHostOnline()
-	if err := sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, &seq, rwc); err != nil {
+	if err := sendSNAC(0, msg.Frame, msg.Body, &seq, rwc); err != nil {
 		rt.Logger.ErrorContext(ctx, "error WriteOServiceHostOnline")
 		return
 	}
@@ -77,7 +77,7 @@ func (rt BOSService) handleNewConnection(ctx context.Context, rwc io.ReadWriteCl
 		return rt.route(ctx, sess, r, w, seq)
 	}
 	fnAlertHandler := func(ctx context.Context, msg oscar.SNACMessage, w io.Writer, seq *uint32) error {
-		return sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, seq, w)
+		return sendSNAC(0, msg.Frame, msg.Body, seq, w)
 	}
 	dispatchIncomingMessages(ctx, sess, seq, rwc, rt.Logger, fnClientReqHandler, fnAlertHandler)
 }

+ 1 - 1
server/buddy.go

@@ -35,7 +35,7 @@ func (rt *BuddyRouter) RouteBuddy(ctx context.Context, SNACFrame oscar.SNACFrame
 		}
 		outSNAC := rt.RightsQueryHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	default:
 		return ErrUnsupportedSubGroup
 	}

+ 1 - 1
server/chat.go

@@ -43,7 +43,7 @@ func (rt *ChatRouter) RouteChat(ctx context.Context, sess *state.Session, chatID
 		}
 		rt.Logger.InfoContext(ctx, "user sent a chat message")
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	default:
 		return ErrUnsupportedSubGroup
 	}

+ 3 - 3
server/chat_nav.go

@@ -34,7 +34,7 @@ func (rt *ChatNavRouter) RouteChatNav(ctx context.Context, sess *state.Session,
 	case oscar.ChatNavRequestChatRights:
 		outSNAC := rt.RequestChatRightsHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, nil, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.ChatNavRequestRoomInfo:
 		inSNAC := oscar.SNAC_0x0D_0x04_ChatNavRequestRoomInfo{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -45,7 +45,7 @@ func (rt *ChatNavRouter) RouteChatNav(ctx context.Context, sess *state.Session,
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.ChatNavCreateRoom:
 		inSNAC := oscar.SNAC_0x0E_0x02_ChatRoomInfoUpdate{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -58,7 +58,7 @@ func (rt *ChatNavRouter) RouteChatNav(ctx context.Context, sess *state.Session,
 		roomName, _ := inSNAC.GetString(oscar.ChatTLVRoomName)
 		rt.Logger.InfoContext(ctx, "user started a chat room", slog.String("roomName", roomName))
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	default:
 		return ErrUnsupportedSubGroup
 	}

+ 2 - 2
server/chat_service.go

@@ -70,7 +70,7 @@ func (rt ChatService) handleNewConnection(ctx context.Context, rw io.ReadWriter)
 	ctx = context.WithValue(ctx, "screenName", chatSess.ScreenName())
 
 	msg := rt.WriteOServiceHostOnline()
-	if err := sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, &seq, rw); err != nil {
+	if err := sendSNAC(0, msg.Frame, msg.Body, &seq, rw); err != nil {
 		rt.Logger.ErrorContext(ctx, "error WriteOServiceHostOnline")
 		return
 	}
@@ -79,7 +79,7 @@ func (rt ChatService) handleNewConnection(ctx context.Context, rw io.ReadWriter)
 		return rt.route(ctx, chatSess, r, w, seq, chatID)
 	}
 	fnAlertHandler := func(ctx context.Context, msg oscar.SNACMessage, w io.Writer, seq *uint32) error {
-		return sendSNAC(oscar.SNACFrame{}, msg.Frame, msg.Body, seq, w)
+		return sendSNAC(0, msg.Frame, msg.Body, seq, w)
 	}
 	dispatchIncomingMessages(ctx, chatSess, seq, rw, rt.Logger, fnClientReqHandler, fnAlertHandler)
 }

+ 7 - 9
server/connection.go

@@ -24,16 +24,14 @@ type (
 	clientReqHandler func(ctx context.Context, r io.Reader, w io.Writer, u *uint32) error
 )
 
-func sendSNAC(originsnac oscar.SNACFrame, snacFrame oscar.SNACFrame, snacOut any, sequence *uint32, w io.Writer) error {
-	if originsnac.RequestID != 0 {
-		snacFrame.RequestID = originsnac.RequestID
-	}
+func sendSNAC(requestID uint32, frame oscar.SNACFrame, body any, sequence *uint32, w io.Writer) error {
+	frame.RequestID = requestID
 
 	snacBuf := &bytes.Buffer{}
-	if err := oscar.Marshal(snacFrame, snacBuf); err != nil {
+	if err := oscar.Marshal(frame, snacBuf); err != nil {
 		return err
 	}
-	if err := oscar.Marshal(snacOut, snacBuf); err != nil {
+	if err := oscar.Marshal(body, snacBuf); err != nil {
 		return err
 	}
 
@@ -61,15 +59,15 @@ func sendSNAC(originsnac oscar.SNACFrame, snacFrame oscar.SNACFrame, snacOut any
 	return nil
 }
 
-func sendInvalidSNACErr(snac oscar.SNACFrame, w io.Writer, sequence *uint32) error {
+func sendInvalidSNACErr(frame oscar.SNACFrame, w io.Writer, sequence *uint32) error {
 	snacFrameOut := oscar.SNACFrame{
-		FoodGroup: snac.FoodGroup,
+		FoodGroup: frame.FoodGroup,
 		SubGroup:  0x01, // error subgroup for all SNACs
 	}
 	snacPayloadOut := oscar.SNACError{
 		Code: oscar.ErrorCodeInvalidSnac,
 	}
-	return sendSNAC(snac, snacFrameOut, snacPayloadOut, sequence, w)
+	return sendSNAC(frame.RequestID, snacFrameOut, snacPayloadOut, sequence, w)
 }
 
 func consumeFLAPFrames(r io.Reader, msgCh chan incomingMessage, errCh chan error) {

+ 6 - 6
server/feedbag.go

@@ -42,14 +42,14 @@ func (rt FeedbagRouter) RouteFeedbag(ctx context.Context, sess *state.Session, S
 		}
 		outSNAC := rt.RightsQueryHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.FeedbagQuery:
 		inSNAC, err := rt.QueryHandler(ctx, sess)
 		if err != nil {
 			return err
 		}
 		rt.logRequest(ctx, SNACFrame, inSNAC)
-		return sendSNAC(SNACFrame, inSNAC.Frame, inSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, inSNAC.Frame, inSNAC.Body, sequence, w)
 	case oscar.FeedbagQueryIfModified:
 		inSNAC := oscar.SNAC_0x13_0x05_FeedbagQueryIfModified{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -60,7 +60,7 @@ func (rt FeedbagRouter) RouteFeedbag(ctx context.Context, sess *state.Session, S
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.FeedbagUse:
 		rt.logRequest(ctx, SNACFrame, nil)
 		return nil
@@ -74,7 +74,7 @@ func (rt FeedbagRouter) RouteFeedbag(ctx context.Context, sess *state.Session, S
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.FeedbagUpdateItem:
 		inSNAC := oscar.SNAC_0x13_0x09_FeedbagUpdateItem{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -85,7 +85,7 @@ func (rt FeedbagRouter) RouteFeedbag(ctx context.Context, sess *state.Session, S
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.FeedbagDeleteItem:
 		inSNAC := oscar.SNAC_0x13_0x0A_FeedbagDeleteItem{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -96,7 +96,7 @@ func (rt FeedbagRouter) RouteFeedbag(ctx context.Context, sess *state.Session, S
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.FeedbagStartCluster:
 		inSNAC := oscar.SNAC_0x13_0x11_FeedbagStartCluster{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {

+ 3 - 3
server/icbm.go

@@ -39,7 +39,7 @@ func (rt *ICBMRouter) RouteICBM(ctx context.Context, sess *state.Session, SNACFr
 	case oscar.ICBMParameterQuery:
 		outSNAC := rt.ParameterQueryHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, outSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.ICBMChannelMsgToHost:
 		inSNAC := oscar.SNAC_0x04_0x06_ICBMChannelMsgToHost{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -54,7 +54,7 @@ func (rt *ICBMRouter) RouteICBM(ctx context.Context, sess *state.Session, SNACFr
 			return nil
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.ICBMEvilRequest:
 		inSNAC := oscar.SNAC_0x04_0x08_ICBMEvilRequest{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -65,7 +65,7 @@ func (rt *ICBMRouter) RouteICBM(ctx context.Context, sess *state.Session, SNACFr
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.ICBMClientErr:
 		inSNAC := oscar.SNAC_0x04_0x0B_ICBMClientErr{}
 		rt.logRequest(ctx, SNACFrame, inSNAC)

+ 4 - 4
server/locate.go

@@ -36,7 +36,7 @@ func (rt LocateRouter) RouteLocate(ctx context.Context, sess *state.Session, SNA
 	case oscar.LocateRightsQuery:
 		outSNAC := rt.RightsQueryHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, nil, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.LocateSetInfo:
 		inSNAC := oscar.SNAC_0x02_0x04_LocateSetInfo{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -51,7 +51,7 @@ func (rt LocateRouter) RouteLocate(ctx context.Context, sess *state.Session, SNA
 		}
 		outSNAC := rt.SetDirInfoHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.LocateGetDirInfo:
 		inSNAC := oscar.SNAC_0x02_0x0B_LocateGetDirInfo{}
 		rt.logRequest(ctx, SNACFrame, inSNAC)
@@ -63,7 +63,7 @@ func (rt LocateRouter) RouteLocate(ctx context.Context, sess *state.Session, SNA
 		}
 		outSNAC := rt.SetKeywordInfoHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.LocateUserInfoQuery2:
 		inSNAC := oscar.SNAC_0x02_0x15_LocateUserInfoQuery2{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -74,7 +74,7 @@ func (rt LocateRouter) RouteLocate(ctx context.Context, sess *state.Session, SNA
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	default:
 		return ErrUnsupportedSubGroup
 	}

+ 5 - 5
server/oservice.go

@@ -42,7 +42,7 @@ func (rt OServiceRouter) RouteOService(ctx context.Context, sess *state.Session,
 	case oscar.OServiceRateParamsQuery:
 		outSNAC := rt.RateParamsQueryHandler(ctx)
 		rt.logRequestAndResponse(ctx, SNACFrame, nil, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.OServiceRateParamsSubAdd:
 		inSNAC := oscar.SNAC_0x01_0x08_OServiceRateParamsSubAdd{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -54,7 +54,7 @@ func (rt OServiceRouter) RouteOService(ctx context.Context, sess *state.Session,
 	case oscar.OServiceUserInfoQuery:
 		outSNAC := rt.UserInfoQueryHandler(ctx, sess)
 		rt.logRequestAndResponse(ctx, SNACFrame, nil, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.OServiceIdleNotification:
 		inSNAC := oscar.SNAC_0x01_0x11_OServiceIdleNotification{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -69,7 +69,7 @@ func (rt OServiceRouter) RouteOService(ctx context.Context, sess *state.Session,
 		}
 		outSNAC := rt.ClientVersionsHandler(ctx, inSNAC)
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.OServiceSetUserInfoFields:
 		inSNAC := oscar.SNAC_0x01_0x1E_OServiceSetUserInfoFields{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {
@@ -80,7 +80,7 @@ func (rt OServiceRouter) RouteOService(ctx context.Context, sess *state.Session,
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	default:
 		return ErrUnsupportedSubGroup
 	}
@@ -118,7 +118,7 @@ func (rt OServiceBOSRouter) RouteOService(ctx context.Context, sess *state.Sessi
 			return err
 		}
 		rt.logRequestAndResponse(ctx, SNACFrame, inSNAC, outSNAC.Frame, outSNAC.Body)
-		return sendSNAC(SNACFrame, outSNAC.Frame, outSNAC.Body, sequence, w)
+		return sendSNAC(SNACFrame.RequestID, outSNAC.Frame, outSNAC.Body, sequence, w)
 	case oscar.OServiceClientOnline:
 		inSNAC := oscar.SNAC_0x01_0x02_OServiceClientOnline{}
 		if err := oscar.Unmarshal(&inSNAC, r); err != nil {