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