command.go 967 B

1234567891011121314151617181920212223242526272829303132
  1. package outbound
  2. import (
  3. "time"
  4. v2net "github.com/v2ray/v2ray-core/common/net"
  5. "github.com/v2ray/v2ray-core/common/protocol"
  6. )
  7. func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
  8. primary := protocol.NewID(cmd.ID)
  9. alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
  10. account := &protocol.VMessAccount{
  11. ID: primary,
  12. AlterIDs: alters,
  13. }
  14. user := protocol.NewUser(account, cmd.Level, "")
  15. dest := v2net.TCPDestination(cmd.Host, cmd.Port)
  16. until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
  17. this.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
  18. }
  19. func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
  20. switch typedCommand := cmd.(type) {
  21. case *protocol.CommandSwitchAccount:
  22. if typedCommand.Host == nil {
  23. typedCommand.Host = dest.Address()
  24. }
  25. this.handleSwitchAccount(typedCommand)
  26. default:
  27. }
  28. }