package middleware

import (
	"log/slog"
	"slgserver/constant"
	"slgserver/net"
)

func CheckRole() net.MiddlewareFunc {
	return func(next net.HandlerFunc) net.HandlerFunc {
		return func(req *net.WsMsgReq, rsp *net.WsMsgRsp) {

			_, err := req.Conn.GetProperty("role")
			if err != nil {
				rsp.Body.Code = constant.RoleNotInConnect
		slog.Warn("connect not found role",
			"msgName", req.Body.Name)
				return
			}
			next(req, rsp)
		}
	}
}