fixed bugs
This commit is contained in:
@@ -54,9 +54,14 @@ const std::string& Client::getCommand() const {
|
||||
}
|
||||
|
||||
void Client::clearCommand() {
|
||||
command.clear();
|
||||
command = "";
|
||||
}
|
||||
|
||||
void Client::appendCommand(std::string str) {
|
||||
this->command += str;
|
||||
command += str;
|
||||
}
|
||||
|
||||
void Client::setCommand(std::string cmd) {
|
||||
command = cmd;
|
||||
}
|
@@ -38,6 +38,7 @@ class Client {
|
||||
void clearCommand();
|
||||
|
||||
void appendCommand(std::string str);
|
||||
void setCommand(std::string cmd);
|
||||
};
|
||||
|
||||
#endif
|
18
Server.cpp
18
Server.cpp
@@ -529,10 +529,11 @@ void Server::handleClientData(int fd)
|
||||
|
||||
client.appendCommand(buffer);
|
||||
|
||||
size_t newlinePos = client.getCommand().find("\n");
|
||||
size_t newlinePos = client.getCommand().find_first_of("\r\n");
|
||||
if (newlinePos != std::string::npos) {
|
||||
// Extract the complete message up to the newline character
|
||||
std::string command = client.getCommand().substr(0, newlinePos);
|
||||
client.setCommand(command);
|
||||
std::cout << "Received data from client " << fd << ": " << command << std::endl;
|
||||
int auth = getClientByFd(fd).getAuthentication();
|
||||
|
||||
@@ -556,6 +557,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: Password cannot be empty\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
std::string passwordoftheserver = getPassowrd();
|
||||
@@ -620,6 +622,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: Command requires only 1 parameter\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -663,6 +666,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: Command requires at least four parameters\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
if (dontputthesameusername(username) == true)
|
||||
@@ -713,6 +717,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = ":server.host NOTICE " + nick + " :Error: Channel start with #\r\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -793,6 +798,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: You Just missing an argument(5)\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
message = trim(message);
|
||||
@@ -828,6 +834,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: You Just missing an argument(4)\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
std::getline(iss, reason);
|
||||
@@ -872,6 +879,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: You Just missing an argument(3)\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
channelName = channelName.substr(1);
|
||||
@@ -904,6 +912,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: You Just missing an argument(2)\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
channelName = trim(channelName);
|
||||
@@ -931,6 +940,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = "Error: Command take 3 parameters\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
}
|
||||
start = trim(start);
|
||||
@@ -967,6 +977,7 @@ void Server::handleClientData(int fd)
|
||||
{
|
||||
std::string errorMessage = ":server.host NOTICE " + nick + " :Error: Channel start with #\r\n";
|
||||
send(fd, errorMessage.c_str(), errorMessage.length(), 0);
|
||||
client.clearCommand();
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -1137,11 +1148,12 @@ void Server::handleClientData(int fd)
|
||||
}
|
||||
}
|
||||
//**************** STOOOOOOP HERE TOP G ...
|
||||
// command.clear();
|
||||
}
|
||||
client.clearCommand();
|
||||
}
|
||||
}
|
||||
|
||||
if (bytesRead == 0) {
|
||||
else if (bytesRead == 0) {
|
||||
std::cout << "Client <" << fd << "> Disconnected" << std::endl;
|
||||
clientCleanup(fd);
|
||||
} else if (bytesRead == -1) {
|
||||
|
Reference in New Issue
Block a user