command.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package outbound
  2. import (
  3. "time"
  4. v2net "v2ray.com/core/common/net"
  5. "v2ray.com/core/common/protocol"
  6. "v2ray.com/core/proxy/vmess"
  7. "github.com/golang/protobuf/ptypes"
  8. )
  9. func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
  10. account := &vmess.AccountPB{
  11. Id: cmd.ID.String(),
  12. AlterId: uint32(cmd.AlterIds),
  13. }
  14. anyAccount, _ := ptypes.MarshalAny(account)
  15. user := &protocol.User{
  16. Email: "",
  17. Level: cmd.Level,
  18. Account: anyAccount,
  19. }
  20. dest := v2net.TCPDestination(cmd.Host, cmd.Port)
  21. until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
  22. this.serverList.AddServer(protocol.NewServerSpec(vmess.NewAccount, dest, protocol.BeforeTime(until), user))
  23. }
  24. func (this *VMessOutboundHandler) handleCommand(dest v2net.Destination, cmd protocol.ResponseCommand) {
  25. switch typedCommand := cmd.(type) {
  26. case *protocol.CommandSwitchAccount:
  27. if typedCommand.Host == nil {
  28. typedCommand.Host = dest.Address
  29. }
  30. this.handleSwitchAccount(typedCommand)
  31. default:
  32. }
  33. }