Added Command message in protobuf

This commit is contained in:
Warwick 2023-08-16 10:45:34 +01:00
parent 599bc76379
commit 0f97acb479
8 changed files with 18 additions and 11 deletions

View file

@ -58,7 +58,7 @@ int main(int argc, char *argv[]) {
if (errflag < 0)
err__crash("Failed to connect to host");
msg__login_req(&sockfd, "username", "passwd");
msg__req_login(&sockfd, "username", "passwd");
while (1) {
bzero(msgbuffer, sizeof msgbuffer);

View file

@ -1,6 +1,6 @@
#include "command.h"
Room *cmd__move(move_directions direction, Room *current_room) {
Room *cmd__move(move_direction direction, Room *current_room) {
switch (direction) {
case NORTH:
return current_room->north;

View file

@ -6,4 +6,4 @@
// Returns pointer to new room based on current room and direction If room
// doesn't exist returns NULL
Room *cmd__move(move_directions direction, Room *current_room);
Room *cmd__move(move_direction direction, Room *current_room);

View file

@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
cli_sockfd = msg__accept_cli_connection(serv_sockfd);
// Require login as first request
msg__handle_login(&serv_sockfd);
msg__recv_login(&serv_sockfd);
while (1) {
// Empty message buffer

View file

@ -21,10 +21,10 @@ void msg__destroy_connection(int sockfd);
int msg__accept_cli_connection(int server_sockfd);
// Handle logins
void msg__handle_login(int *con_sockfd);
void msg__login_req(int *con_sockfd, char *usernm, char *passwd);
void msg__recv_login(int *con_sockfd);
void msg__req_login(int *con_sockfd, char *usernm, char *passwd);
// send and recive commands
void msg__handle_command(int *con_sockfd);
void msg__command_req(int *con_sockfd, char *usernm, char *passwd);
void msg__recv_command(int *con_sockfd);
void msg__req_command(int *con_sockfd, char *usernm, char *passwd);

View file

@ -2,7 +2,7 @@
// Make world structures accessible to both server and client
// Define moveable directions
typedef enum { NORTH, EAST, SOUTH, WEST } move_directions;
typedef enum { NORTH, EAST, SOUTH, WEST } move_direction;
// Define what a room is.
typedef struct room {

View file

@ -0,0 +1,6 @@
syntax = "proto2";
message command {
optional int32 move_direction = 1; // For now this int directly maps onto the enum type
// TODO: Add other optional structures to be processed as command data
}

View file

@ -1,4 +1,5 @@
#include "message.h"
#include "world_structures.h"
#include "protobuf_gen/amessage.pb-c.h"
#include "protobuf_gen/player.pb-c.h"
@ -43,7 +44,7 @@ void msg__amsg_test(int a) {
amessage__free_unpacked(msg2, NULL);
}
void msg__handle_login(int *con_sockfd) {
void msg__recv_login(int *con_sockfd) {
uint8_t msgbuf[MAX_MSG_SIZE];
bzero(msgbuf, sizeof msgbuf);
@ -65,7 +66,7 @@ void msg__handle_login(int *con_sockfd) {
err__log(msg);
}
void msg__login_req(int *con_sockfd, char *usernm, char *passwd) {
void msg__req_login(int *con_sockfd, char *usernm, char *passwd) {
PlayerLogin pl = PLAYER_LOGIN__INIT;
void *msgbuf;
unsigned len;