Added Command message in protobuf
This commit is contained in:
parent
599bc76379
commit
0f97acb479
8 changed files with 18 additions and 11 deletions
|
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (errflag < 0)
|
if (errflag < 0)
|
||||||
err__crash("Failed to connect to host");
|
err__crash("Failed to connect to host");
|
||||||
|
|
||||||
msg__login_req(&sockfd, "username", "passwd");
|
msg__req_login(&sockfd, "username", "passwd");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bzero(msgbuffer, sizeof msgbuffer);
|
bzero(msgbuffer, sizeof msgbuffer);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
Room *cmd__move(move_directions direction, Room *current_room) {
|
Room *cmd__move(move_direction direction, Room *current_room) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case NORTH:
|
case NORTH:
|
||||||
return current_room->north;
|
return current_room->north;
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,4 @@
|
||||||
|
|
||||||
// Returns pointer to new room based on current room and direction If room
|
// Returns pointer to new room based on current room and direction If room
|
||||||
// doesn't exist returns NULL
|
// doesn't exist returns NULL
|
||||||
Room *cmd__move(move_directions direction, Room *current_room);
|
Room *cmd__move(move_direction direction, Room *current_room);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
|
||||||
cli_sockfd = msg__accept_cli_connection(serv_sockfd);
|
cli_sockfd = msg__accept_cli_connection(serv_sockfd);
|
||||||
|
|
||||||
// Require login as first request
|
// Require login as first request
|
||||||
msg__handle_login(&serv_sockfd);
|
msg__recv_login(&serv_sockfd);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// Empty message buffer
|
// Empty message buffer
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ void msg__destroy_connection(int sockfd);
|
||||||
int msg__accept_cli_connection(int server_sockfd);
|
int msg__accept_cli_connection(int server_sockfd);
|
||||||
|
|
||||||
// Handle logins
|
// Handle logins
|
||||||
void msg__handle_login(int *con_sockfd);
|
void msg__recv_login(int *con_sockfd);
|
||||||
void msg__login_req(int *con_sockfd, char *usernm, char *passwd);
|
void msg__req_login(int *con_sockfd, char *usernm, char *passwd);
|
||||||
|
|
||||||
|
|
||||||
// send and recive commands
|
// send and recive commands
|
||||||
void msg__handle_command(int *con_sockfd);
|
void msg__recv_command(int *con_sockfd);
|
||||||
void msg__command_req(int *con_sockfd, char *usernm, char *passwd);
|
void msg__req_command(int *con_sockfd, char *usernm, char *passwd);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Make world structures accessible to both server and client
|
// Make world structures accessible to both server and client
|
||||||
|
|
||||||
// Define moveable directions
|
// Define moveable directions
|
||||||
typedef enum { NORTH, EAST, SOUTH, WEST } move_directions;
|
typedef enum { NORTH, EAST, SOUTH, WEST } move_direction;
|
||||||
|
|
||||||
// Define what a room is.
|
// Define what a room is.
|
||||||
typedef struct room {
|
typedef struct room {
|
||||||
|
|
|
||||||
6
urchin-util/protobuf/commands.proto
Normal file
6
urchin-util/protobuf/commands.proto
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "world_structures.h"
|
||||||
#include "protobuf_gen/amessage.pb-c.h"
|
#include "protobuf_gen/amessage.pb-c.h"
|
||||||
#include "protobuf_gen/player.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);
|
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];
|
uint8_t msgbuf[MAX_MSG_SIZE];
|
||||||
bzero(msgbuf, sizeof msgbuf);
|
bzero(msgbuf, sizeof msgbuf);
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ void msg__handle_login(int *con_sockfd) {
|
||||||
err__log(msg);
|
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;
|
PlayerLogin pl = PLAYER_LOGIN__INIT;
|
||||||
void *msgbuf;
|
void *msgbuf;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue