Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions broker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ func (h *Hrotti) Stop() {

func (h *Hrotti) InitClient(conn net.Conn) {
var sendSessionID bool
//////////////修改///////////////////////
defer func() {
if err := recover(); err != nil {
ERROR.Println(err)
}
}()
//////////////修改///////////////////////
/*var cph fixedHeader

//create a bufio conn from the network connection
Expand Down
15 changes: 15 additions & 0 deletions packets/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ type ConnectPacket struct {
Password []byte
uuid uuid.UUID
}
//////////////////////修改//////////////////////////
var userName string
var password string
func SetUserName(name string) {
userName = name
}

func SetPassWord(pwd string) {
password = pwd
}
//////////////////////修改//////////////////////////
func (c *ConnectPacket) String() string {
str := fmt.Sprintf("%s\n", c.FixedHeader)
str += fmt.Sprintf("protocolversion: %d protocolname: %s cleansession: %t willflag: %t WillQos: %d WillRetain: %t Usernameflag: %t Passwordflag: %t keepalivetimer: %d\nclientId: %s\nwilltopic: %s\nwillmessage: %s\nUsername: %s\nPassword: %s\n", c.ProtocolVersion, c.ProtocolName, c.CleanSession, c.WillFlag, c.WillQos, c.WillRetain, c.UsernameFlag, c.PasswordFlag, c.KeepaliveTimer, c.ClientIdentifier, c.WillTopic, c.WillMessage, c.Username, c.Password)
Expand Down Expand Up @@ -89,6 +99,11 @@ func (c *ConnectPacket) Unpack(b io.Reader) {
}

func (c *ConnectPacket) Validate() byte {
//////////////////////修改//////////////////////////
if string(c.Password) != password || c.Username != userName{
return CONN_REF_BAD_USER_PASS
}
//////////////////////修改//////////////////////////
if c.PasswordFlag && !c.UsernameFlag {
return CONN_REF_BAD_USER_PASS
}
Expand Down