func AudioFragmentHandle(buffer []byte, User *model.User, userCache *model.UserCache, Conn *net.Conn) error { DestUuid, err := core.UuidToString(buffer[12:28]) if err != nil { err = fmt.Errorf("AudioFragmentHandle Error : %v", err) fmt.Println(err.Error()) return err } var destUser *model.User if destUser = userCache.Query(DestUuid); destUser == nil { err = fmt.Errorf("Don't have the destUser : %v", DestUuid) fmt.Println(err.Error()) return err } DestUuidBuff, err := core.StringToUuid(User.Uuid) if err != nil { err = fmt.Errorf("AudioFragmentHandle Error : %v", err) fmt.Println(err.Error()) return err } copy(buffer[12:28], DestUuidBuff[0:16]) n, err := destUser.Write(buffer) if n == 0 || err != nil { err = errors.New("Write to " + DestUuid + " error") return err } fmt.Println("send audio ok") return nil }
func TextHandle(buffer []byte, User *model.User, userCache *model.UserCache, Conn *net.Conn) error { text := core.TextMsg{} err := text.Decode(buffer) if err != nil { err = fmt.Errorf("TextHandle Error : %v", err) fmt.Println(err.Error()) return err } var destUser *model.User if destUser = userCache.Query(text.DestUuid); destUser == nil { err = fmt.Errorf("Don't have the destUser : %v", text.DestUuid) fmt.Println(err.Error()) return err } text.DestUuid = User.Uuid requestBuff, err := text.Encode() if err != nil { err = fmt.Errorf("TextHandle Error : %v", err) fmt.Println(err.Error()) return err } n, err := destUser.Write(requestBuff) if err != nil || n == 0 { err = errors.New("Write to " + text.DestUuid + " error") return err } fmt.Println("send text ok") return nil }
func FileRequestHandle(buffer []byte, Conn *net.Conn, userCache *model.UserCache, User *model.User) error { fileRequest := core.FileMsgRequest{} err := fileRequest.Decode(buffer) if err != nil { err = fmt.Errorf("FileRequestHandle Error: %v", err) fmt.Println(err.Error()) return err } if fileRequest.Number != core.FILE_REQ_SEND_FILE { err = errors.New("Not the file request number") fmt.Println(err.Error()) return err } var destUser *model.User //这里的DestID应该是请求接收方 if destUser = userCache.Query(fileRequest.DestUuid); destUser == nil { err = fmt.Errorf("Don't have the DestUser : %v", fileRequest.DestUuid) fmt.Println(err.Error()) return err } //下面这一部分是向请求接收方设置参数,已请求接收方的角度来看,DestID为当前用户的Uuid fileRequest.DestUuid = User.Uuid //服务器发送发起方的请求给请求接收方 fileRequest.QCHeadBase.Number = core.FILE_RES_SEND_TRAN response, err := fileRequest.Encode() if err != nil { err = fmt.Errorf("FileRequestHandle Error: %v", err) fmt.Println(err.Error()) return err } //向目标用户的流中写入数据 n, err := destUser.Write(response) if err != nil || n == 0 { err = errors.New("Write file response fail") fmt.Println(err.Error()) return err } return nil }