Example #1
0
func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) {
	name, _ := t.GetSelfName()
	fmt.Printf("[%s] New friend request from %s\n", name, hex.EncodeToString(publicKey))

	// Auto-accept friend request
	t.AddFriendNorequest(publicKey)
}
Example #2
0
func onFileSendRequest(t *golibtox.Tox, friendnumber int32, filenumber uint8, filesize uint64, filename []byte, filenameLength uint16) {
	// Accept any file send request
	t.FileSendControl(friendnumber, true, filenumber, golibtox.FILECONTROL_ACCEPT, nil)
	// Init *File handle
	f, _ := os.Create("example_" + string(filename))
	// Append f to the map[uint8]*os.File
	transfers[filenumber] = f
}
Example #3
0
func onFileControl(t *golibtox.Tox, friendnumber int32, sending bool, filenumber uint8, fileControl golibtox.FileControl, data []byte, length uint16) {
	// Finished receiving file
	if fileControl == golibtox.FILECONTROL_FINISHED {
		f := transfers[filenumber]
		f.Sync()
		f.Close()
		delete(transfers, filenumber)
		fmt.Println("Written file", filenumber)
		t.SendMessage(friendnumber, []byte("Thanks!"))
	}
}
Example #4
0
func saveData(t *golibtox.Tox, filepath string) error {
	if len(filepath) == 0 {
		return errors.New("Empty path")
	}

	data, err := t.Save()
	if err != nil {
		return err
	}

	err = ioutil.WriteFile(filepath, data, 0644)
	return err
}
Example #5
0
func loadData(t *golibtox.Tox, filepath string) error {
	if len(filepath) == 0 {
		return errors.New("Empty path")
	}

	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return err
	}

	err = t.Load(data)

	return err
}
Example #6
0
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) {
	fmt.Printf("New message from %d : %s\n", friendnumber, string(message))
	// Echo back
	t.SendMessage(friendnumber, message)
}
Example #7
0
func onFriendRequest(t *golibtox.Tox, publicKey []byte, data []byte, length uint16) {
	fmt.Printf("New friend request from %s\n", hex.EncodeToString(publicKey))
	fmt.Printf("With message: %v\n", string(data))
	// Auto-accept friend request
	t.AddFriendNorequest(publicKey)
}
Example #8
0
func onFriendMessage(t *golibtox.Tox, friendnumber int32, message []byte, length uint16) {
	name, _ := t.GetSelfName()
	friend, _ := t.GetName(friendnumber)
	fmt.Printf("[%s] New message from %s : %s\n", name, friend, string(message))
}