From 5eae4da33dc766025c440f9be30d7e4a016e635c Mon Sep 17 00:00:00 2001 From: Arc676/Alessandro Vinciguerra Date: Sun, 2 Sep 2018 21:48:40 +0200 Subject: [PATCH] Don't allow spaces in usernames Update PROTOCOL and README Added -f flag to clean target in frontend Makefile --- PROTOCOL.md | 3 +++ README.md | 8 +++++--- lib/socktalkserver.cpp | 2 +- stclient/Makefile | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index 908ebdd..0a42ebf 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -19,9 +19,12 @@ Once a successful socket connection is established, the registration process beg - The username cannot be one of the five reserved usernames (Server, Error, Info, Notice, TERM) - The username cannot be in use by another connected client +- The username cannot contain spaces If the username can be used, the server replies with `"K"`. Otherwise, it replies with `"N"`. If registration fails, the server drops the connection immediately. Clients should terminate or give up connecting at this point. A new connection must be made to re-register. +The connecting client must provide a username within 5 seconds. If the server is forced to wait longer than this duration, the connection is dropped. + ## Communication ### Format diff --git a/README.md b/README.md index a9463f2..39b875a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ The SockTalk protocol is a simple, open-source network communication protocol. C Compiling SockTalk requires that the OpenSSL library be installed. ## Frontend commands -- "/close" from server side closes server socket. -- "/disconnect" from client side disconnects from server. -- "/help" gives a list of commands supported by the server. + +- `/close` - from server side closes server socket. +- `/disconnect` - from client side disconnects from server. +- `/help` - gives a list of commands supported by the server. +- `/kick`, `/ban`, `/unban` - prompts for a username and kicks/bans/unbans the user with the given username ## Legal diff --git a/lib/socktalkserver.cpp b/lib/socktalkserver.cpp index 2dd8623..e8de2e9 100644 --- a/lib/socktalkserver.cpp +++ b/lib/socktalkserver.cpp @@ -225,7 +225,7 @@ void SockTalkServer::addHandler(SockTalkClientHandler* ch) { } bool SockTalkServer::isReservedName(const std::string &username) { - return username == "Server" || username == "Info" || username == "Error" || username == "Notice" || username == "TERM"; + return username == "Server" || username == "Info" || username == "Error" || username == "Notice" || username == "TERM" || username.find(" ") != std::string::npos; } bool SockTalkServer::registerName(const std::string &username, const std::string &IP) { diff --git a/stclient/Makefile b/stclient/Makefile index bafcbb3..72ecc54 100644 --- a/stclient/Makefile +++ b/stclient/Makefile @@ -15,4 +15,4 @@ server: $(CC) $(FLAGS) $(LD) server.cpp $(LIB) $(THREAD) -o server clean: - rm server client + rm -f server client