From 3b9e5d2ecee337efb3431fb4da6a658f6aa8b065 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sun, 3 May 2020 19:34:07 -0400 Subject: [PATCH] Debug chat issues --- server/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/main.cpp b/server/main.cpp index cac7b58..0db8c10 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -90,13 +90,17 @@ int main (int argc, char ** argv) std::cout << "Invalid packet recieved!" < incomingPeerID; if(usernames[peer_id] != "") { - std::string chat_message((char*)event.packet->data); + //Parse input string + std::stringstream ss((char*)event.packet->data); + std::string chat_message; + std::getline(ss, chat_message, '\n'); std::string resp = "<" + usernames[peer_id] + "> " + chat_message; const char* data = resp.c_str(); @@ -105,9 +109,10 @@ int main (int argc, char ** argv) ENetPacket* packet = enet_packet_create(data, strlen(data) + 1, ENET_PACKET_FLAG_RELIABLE); enet_host_broadcast(server, 1, packet); } + enet_packet_destroy (event.packet); } - enet_packet_destroy (event.packet); + break; case ENET_EVENT_TYPE_DISCONNECT: