From e37181fe35d720b2957605cf10bb4e96e2c0d08b Mon Sep 17 00:00:00 2001 From: Warwick Date: Fri, 28 Jul 2023 14:40:55 +0100 Subject: [PATCH] Added some player message objects to start thinking about initial messages --- protobuf/amessage.proto | 4 ---- src/server/main.c | 7 +++---- urchin-util/include/message.h | 7 +++++++ urchin-util/protobuf/amessage.proto | 6 ++++-- urchin-util/protobuf/player.proto | 17 +++++++++++++++++ 5 files changed, 31 insertions(+), 10 deletions(-) delete mode 100644 protobuf/amessage.proto create mode 100644 urchin-util/protobuf/player.proto diff --git a/protobuf/amessage.proto b/protobuf/amessage.proto deleted file mode 100644 index 5885125..0000000 --- a/protobuf/amessage.proto +++ /dev/null @@ -1,4 +0,0 @@ -message AMessage { - required int32 a=1; - optional int32 b=2; -} diff --git a/src/server/main.c b/src/server/main.c index d158c1d..fb06a99 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -2,6 +2,7 @@ // learn C. #include +#include #include //sockaddr_in #include #include // Keeping for conversion functions @@ -11,6 +12,8 @@ #include int main(int argc, char *argv[]) { + int a = 1; + msg_amsg_test(a); // Set up containers for file descriptor id's int sockfd, clientsockfd, portno, errflag; @@ -34,10 +37,6 @@ int main(int argc, char *argv[]) { error_crash("Can't open socket."); } - error_warn("Can't open socket."); - int a = 1; - msg_amsg_test(a); - // Make sure there is no junk data in serve_addr bzero((char *)&serv_addr, sizeof serv_addr); diff --git a/urchin-util/include/message.h b/urchin-util/include/message.h index 789e222..28e67b2 100644 --- a/urchin-util/include/message.h +++ b/urchin-util/include/message.h @@ -6,3 +6,10 @@ #include void msg_amsg_test(int a); + +// Creates a socket set's it up to listen to listen on the specified port and +// returns the file descriptor +int msg_create_serv_connection(int portno); + +// Creates a socket for the client and returns the file descriptor +int msg_accept_cli_connection(); diff --git a/urchin-util/protobuf/amessage.proto b/urchin-util/protobuf/amessage.proto index 5885125..6fb3040 100644 --- a/urchin-util/protobuf/amessage.proto +++ b/urchin-util/protobuf/amessage.proto @@ -1,4 +1,6 @@ +syntax = "proto2"; + message AMessage { - required int32 a=1; - optional int32 b=2; + required int32 a = 1; + optional int32 b = 2; } diff --git a/urchin-util/protobuf/player.proto b/urchin-util/protobuf/player.proto new file mode 100644 index 0000000..75ce9ce --- /dev/null +++ b/urchin-util/protobuf/player.proto @@ -0,0 +1,17 @@ +syntax = "proto2"; + +message Item { + required string id = 1; +} + +message PlayerStatus { + required int32 id = 1; + optional int32 health = 2; + repeated Item inventory = 3; +} + +// Sending plain text passwords is bad +message PlayerLogin { + required string username = 1; + required string password = 2; +}