func handle_login(user *types.User, msg []byte) (ack []byte, err error) { if !user.Coder.Shaked { err = errors.New("handle_login: not shaked") return } // msg[0]: msgType uid := binary.BigEndian.Uint32(msg[1:5]) password := string(msg[5:]) if true { // TODO: 向hub服务器发送用户名密码请求登录(http接口?) fmt.Println("Login:"******"login failed") ack = zpack.Pack('>', []interface{}{byte(2), byte(1)}) } return }
func handle_shake(user *types.User, msg []byte) (ack []byte, err error) { // msg[0]: msgType subType := msg[1] if subType == 0 { ack = zpack.Pack('>', []interface{}{byte(0), byte(1), user.Coder.CryptKey}) } else if subType == 2 { user.Coder.Shaked = true fmt.Println("Shaked:") } else { err = errors.New("handle_shake: unknown subType") } return }
func handle_getoffchat(user *types.User, msg []byte) (ack []byte, err error) { if !user.Coder.Shaked && !user.Logined { err = errors.New("not shaked or not logined.") return } // msg[0]: msgType // maxSize maxSize := binary.BigEndian.Uint32(msg[1:5]) uid := user.UID // TODO: 通过uid获取离线消息data data := func(uid uint32, maxSize uint32) (data []byte) { return zpack.Pack('>', []interface{}{byte(3), uid, uint32(10002), byte(0), uint32(2), uint64(time.Now().UnixNano() / 1000000), byte(98), byte(99), byte(100), byte('\b'), byte('\r'), byte('\n'), uint32(10002), byte(0), uint32(2), uint64(time.Now().UnixNano() / 1000000), byte(100), byte(101), byte(102)}) }(uid, maxSize) user.MQ <- data return }