aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authoriceyrazor <iceyrazor@mailfence.com>2026-07-03 22:02:56 -0500
committericeyrazor <iceyrazor@mailfence.com>2026-07-03 22:02:56 -0500
commit0ed6c602b14554a02f7782bd5e5635b1e9d9c195 (patch)
tree54142376e4cedd1aeec259f811c04a2420a3213f /src/main.c
init
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..57e3ced
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,123 @@
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "config.c"
+#include "tinyosc.c"
+#include "tinyosc.h"
+
+/*
+ chat-loop / main.c. sends text to vrchat using osc.
+ 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/>.
+*/
+
+static volatile bool keepRunning = true;
+
+// handle Ctrl+C
+static void sigintHandler(int x)
+{
+ keepRunning = false;
+}
+
+// execute command and put output into ret_buf buffer
+void execlb(char* cmd, char* ret_buf)
+{
+ int link[2];
+ pid_t pid;
+ char buf[2048];
+
+ if (pipe(link) == -1)
+ exit(-5);
+
+ if ((pid = fork()) == -1)
+ exit(-5);
+
+ if (pid == 0) {
+
+ dup2(link[1], STDOUT_FILENO);
+ close(link[0]);
+ close(link[1]);
+ execl("/bin/sh", "sh", "-c", cmd, (char*)0);
+ exit(0);
+
+ } else {
+
+ close(link[1]);
+ int nbytes = read(link[0], buf, sizeof(buf));
+ if (nbytes > 2047)
+ nbytes = 2047;
+ snprintf(ret_buf, nbytes + 1, "%s", buf);
+ wait(NULL);
+ close(link[0]);
+ }
+}
+
+int main()
+{
+ 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
+ // register the SIGINT handler (Ctrl+C)
+ signal(SIGINT, &sigintHandler);
+
+ char* dist = (char*)malloc(sizeof(char) * 2048);
+ execlb("uname -r", dist);
+ dist[strlen(dist) - 1] = '\0';
+
+ init_arr();
+
+ char* comb_string = (char*)malloc(sizeof(char) * 2048);
+ char* song_title = (char*)malloc(sizeof(char) * 2048);
+
+ int i = 0;
+
+ while (keepRunning) {
+ execlb("src/title.sh", song_title);
+ sprintf(comb_string, "%s\nLinux %s\n%s\n%s", title, dist, arr[i], song_title);
+
+ int len = 0;
+ len = tosc_writeMessage(wbuffer, sizeof(wbuffer), "/chatbox/input", "sTF", comb_string);
+ sendto(socketfd, wbuffer, len, MSG_CONFIRM, (const struct sockaddr*)&servaddr, sizeof(servaddr));
+
+ sleep(3);
+
+ i = i + 1;
+ if (i >= arr_size)
+ i = 0;
+ }
+
+ free(comb_string);
+ free(dist);
+ free(song_title);
+
+ return 0;
+}