- Timestamp:
- Feb 9, 2022, 2:16:54 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/irc.go
r761 r778 729 729 } 730 730 731 // whoxFields is the list of all WHOX field letters, by order of appearance in 732 // RPL_WHOSPCRPL messages. 733 var whoxFields = []byte("tcuihsnfdlaor") 734 731 735 type whoxInfo struct { 732 736 Token string … … 740 744 } 741 745 746 func (info *whoxInfo) get(field byte) string { 747 switch field { 748 case 't': 749 return info.Token 750 case 'c': 751 return "*" 752 case 'u': 753 return info.Username 754 case 'i': 755 return "255.255.255.255" 756 case 'h': 757 return info.Hostname 758 case 's': 759 return info.Server 760 case 'n': 761 return info.Nickname 762 case 'f': 763 return info.Flags 764 case 'd': 765 return "0" 766 case 'l': // idle time 767 return "0" 768 case 'a': 769 account := "0" // WHOX uses "0" to mean "no account" 770 if info.Account != "" && info.Account != "*" { 771 account = info.Account 772 } 773 return account 774 case 'o': 775 return "0" 776 case 'r': 777 return info.Realname 778 } 779 return "" 780 } 781 742 782 func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo) *irc.Message { 743 783 if fields == "" { … … 754 794 } 755 795 756 var params []string 757 if fieldSet['t'] { 758 params = append(params, info.Token) 759 } 760 if fieldSet['c'] { 761 params = append(params, "*") 762 } 763 if fieldSet['u'] { 764 params = append(params, info.Username) 765 } 766 if fieldSet['i'] { 767 params = append(params, "255.255.255.255") 768 } 769 if fieldSet['h'] { 770 params = append(params, info.Hostname) 771 } 772 if fieldSet['s'] { 773 params = append(params, info.Server) 774 } 775 if fieldSet['n'] { 776 params = append(params, info.Nickname) 777 } 778 if fieldSet['f'] { 779 params = append(params, info.Flags) 780 } 781 if fieldSet['d'] { 782 params = append(params, "0") 783 } 784 if fieldSet['l'] { // idle time 785 params = append(params, "0") 786 } 787 if fieldSet['a'] { 788 account := "0" // WHOX uses "0" to mean "no account" 789 if info.Account != "" && info.Account != "*" { 790 account = info.Account 791 } 792 params = append(params, account) 793 } 794 if fieldSet['o'] { 795 params = append(params, "0") 796 } 797 if fieldSet['r'] { 798 params = append(params, info.Realname) 796 var values []string 797 for _, field := range whoxFields { 798 if !fieldSet[field] { 799 continue 800 } 801 values = append(values, info.get(field)) 799 802 } 800 803 … … 802 805 Prefix: prefix, 803 806 Command: rpl_whospcrpl, 804 Params: append([]string{nick}, params...),807 Params: append([]string{nick}, values...), 805 808 } 806 809 }
Note:
See TracChangeset
for help on using the changeset viewer.