aboutsummaryrefslogtreecommitdiff
path: root/src/type.c
blob: 19548e9a9024e4f3ccd037078d32b0b6463b15cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <arpa/inet.h>
#include <sys/select.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

#include "tinyosc.h"
#include "tinyosc.c"

/*
    type.c. sends text to vrchat using osc from user input.
    Copyright (C) 2026 iceyrazor

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/


int main(int argc, char **argv){
    char wbuffer[2048]; // declare a 2Kb buffer to read packet data into
    int port=9000;
    struct sockaddr_in servaddr;

    int socketfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (socketfd < 0) {
        perror("ERROR:");
        return -1;
    }

    servaddr.sin_family = AF_INET;              // IPv4
    servaddr.sin_port   = htons(port);          // Server port
    servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Server IP

    size_t size=0;
    for (int i=1; i < argc; i++){
        size+=strlen(argv[i])+1;
    }
    char *send_str=(char*)malloc(sizeof(char)*size+1);
    send_str[0]='\0';
    for (int i=1; i < argc; i++){
        strcat(send_str,argv[i]);
        strcat(send_str," ");
    }

    int len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", send_str);
    sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr *)&servaddr, sizeof(servaddr));

    free(send_str);

    return 0;
}