Client can now actually send messages via command
Client can now specify the recipient of a message and type it. Messages for offline users are saved, unaccesible for now.
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char alphs[] = {'-', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
|
||||
'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
|
||||
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
|
||||
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '\0'};
|
||||
|
||||
// Generate an id used for messages. Could be less than 16 chars, but thats what
|
||||
// fits into the `command` field of `msgbuf_t`.
|
||||
void get_id(char *id_buf) {
|
||||
int alph_size = strlen(alphs) - 1;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int random_num;
|
||||
do {
|
||||
random_num = rand();
|
||||
} while (random_num >= (RAND_MAX - RAND_MAX % alph_size));
|
||||
|
||||
random_num %= alph_size;
|
||||
id_buf[i] = alphs[random_num];
|
||||
}
|
||||
id_buf[15] = '\0';
|
||||
}
|
||||
Reference in New Issue
Block a user