Fuck vnext json nesting

pull/5101/head
RPRX 2025-09-09 12:37:22 +00:00 committed by GitHub
parent 9fb7375615
commit eda8be601f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 36 additions and 6 deletions

View File

@ -203,13 +203,30 @@ type VLessOutboundVnext struct {
} }
type VLessOutboundConfig struct { type VLessOutboundConfig struct {
Vnext []*VLessOutboundVnext `json:"vnext"` Address *Address `json:"address"`
Port uint16 `json:"port"`
Level uint32 `json:"level"`
Email string `json:"email"`
Id string `json:"id"`
Flow string `json:"flow"`
Seed string `json:"seed"`
Encryption string `json:"encryption"`
Reverse *vless.Reverse `json:"reverse"`
Vnext []*VLessOutboundVnext `json:"vnext"`
} }
// Build implements Buildable // Build implements Buildable
func (c *VLessOutboundConfig) Build() (proto.Message, error) { func (c *VLessOutboundConfig) Build() (proto.Message, error) {
config := new(outbound.Config) config := new(outbound.Config)
if c.Address != nil {
c.Vnext = []*VLessOutboundVnext{
{
Address: c.Address,
Port: c.Port,
Users: []json.RawMessage{{}},
},
}
}
if len(c.Vnext) != 1 { if len(c.Vnext) != 1 {
return nil, errors.New(`VLESS settings: "vnext" should have one and only one member`) return nil, errors.New(`VLESS settings: "vnext" should have one and only one member`)
} }
@ -228,12 +245,25 @@ func (c *VLessOutboundConfig) Build() (proto.Message, error) {
} }
for idx, rawUser := range rec.Users { for idx, rawUser := range rec.Users {
user := new(protocol.User) user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil { if c.Address != nil {
return nil, errors.New(`VLESS users: invalid user`).Base(err) user.Level = c.Level
user.Email = c.Email
} else {
if err := json.Unmarshal(rawUser, user); err != nil {
return nil, errors.New(`VLESS users: invalid user`).Base(err)
}
} }
account := new(vless.Account) account := new(vless.Account)
if err := json.Unmarshal(rawUser, account); err != nil { if c.Address != nil {
return nil, errors.New(`VLESS users: invalid user`).Base(err) account.Id = c.Id
account.Flow = c.Flow
//account.Seed = c.Seed
account.Encryption = c.Encryption
account.Reverse = c.Reverse
} else {
if err := json.Unmarshal(rawUser, account); err != nil {
return nil, errors.New(`VLESS users: invalid user`).Base(err)
}
} }
u, err := uuid.ParseString(account.Id) u, err := uuid.ParseString(account.Id)