aboutsummaryrefslogtreecommitdiff
path: root/src/ramen
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2025-01-09 16:32:55 -0800
committerPreston Pan <ret2pop@gmail.com>2025-01-09 16:32:55 -0800
commitef9ab1fd141f4057d41f2d6ed8ab8d67c44894d5 (patch)
treee4005b7a641303b021eb54c2aae5676b5f92a72d /src/ramen
parent1fd608288ee47c2c560817f12f14b21069fed2f6 (diff)
save stateHEADmain
Diffstat (limited to 'src/ramen')
-rw-r--r--src/ramen/main.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/ramen/main.c b/src/ramen/main.c
index e98b452..799a5b2 100644
--- a/src/ramen/main.c
+++ b/src/ramen/main.c
@@ -12,20 +12,21 @@
#include <sys/time.h>
#include <unistd.h>
-#include "../include/tsv.h"
-#include "../include/array.h"
#include "../include/better_string.h"
#include "../include/hash_table.h"
#include "../include/helpers.h"
+#include "../include/list.h"
#include "../include/opcodes.h"
#include "../include/protocol.h"
+#include "../include/tsv.h"
+#include "../include/opcodes.h"
int PORT = DEFAULT_PORT;
int nfds = 1;
struct pollfd fds[MAX_CONNECTIONS * 2];
-ht_t *USERS;
ht_t *CHAN;
+ht_t *USERS;
void handle_sigint(int sig) {
for (int i = 0; i < nfds; i++) {
@@ -33,20 +34,19 @@ void handle_sigint(int sig) {
close(fds[i].fd);
}
}
-
exit(0);
}
-array_t *parse_args(char *buf) {
+list_t *tokenize_buf(char *buf) {
tsv_t *tsv = init_tsv(buf);
string_t *s = tsv_next(tsv);
- array_t *a = init_array();
+ list_t *a = init_list();
+
while (s) {
- array_push(a, s);
+ list_push_back(a, s);
s = tsv_next(tsv);
}
- a = array_reverse(a);
return a;
}
@@ -156,8 +156,29 @@ int main(int argc, char **argv) {
printf("Connection closed\n");
close_conn = true;
} else {
- /* echo server -- replace this with buffer parsing */
- /* TODO: reply to client based on user input */
+ list_t *tokens = tokenize_buf(buffer);
+ string_t *opcode = list_pop_front(tokens);
+ int op = encode_server_opcode(opcode->buf);
+
+ switch (op) {
+ case CO_NCK:
+ break;
+ case CO_JN:
+ break;
+ case CO_NOP:
+ break;
+ case CO_PST:
+ break;
+ case CO_DM:
+ break;
+ case CO_QT:
+ break;
+ case CO_LVE:
+ break;
+ default:
+ break;
+ }
+
fd_send = send(local_fds[i].fd, buffer, fd_recv, 0);
if (fd_send < 0) {
perror("send()");
@@ -174,14 +195,13 @@ int main(int argc, char **argv) {
}
if (compress_array) {
- printf("switching...\n");
int cur_nfds = nfds;
nfds = 0;
for (int i = 0; i < cur_nfds; i++) {
- if (local_fds[i].fd != 0) {
- local_fds2[nfds] = local_fds[i];
- nfds ++;
- }
+ if (local_fds[i].fd != 0) {
+ local_fds2[nfds] = local_fds[i];
+ nfds++;
+ }
}
local_fds1 = local_fds2;