Skip to content

Commit

Permalink
Merge pull request CraftyBoss#23 from Link4565/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanae6 authored Jul 24, 2022
2 parents 3c4a20a + c9b1dfa commit 5f1a911
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
30 changes: 17 additions & 13 deletions source/server/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,30 +254,34 @@ bool Client::startConnection() {

Logger::log("Sucessful Connection. Waiting to recieve init packet.\n");

bool waitingForInitPacket = true;
// wait for client init packet
while (true) {
while (waitingForInitPacket) {
if (mSocket->RECV()) {
Packet* curPacket = mSocket->mPacketQueue.popFront();
if(!mSocket->mPacketQueue.isEmpty()){

if (curPacket->mType == PacketType::CLIENTINIT) {
InitPacket* initPacket = (InitPacket*)curPacket;
Packet* curPacket = mSocket->mPacketQueue.popFront();

Logger::log("Server Max Player Size: %d\n", initPacket->maxPlayers);
if (curPacket->mType == PacketType::CLIENTINIT) {
InitPacket* initPacket = (InitPacket*)curPacket;

maxPuppets = initPacket->maxPlayers - 1;
} else {
Logger::log("First Packet was not Init!\n");
mIsConnectionActive = false;
}
Logger::log("Server Max Player Size: %d\n", initPacket->maxPlayers);

free(curPacket);
maxPuppets = initPacket->maxPlayers - 1;
} else {
Logger::log("First Packet was not Init!\n");
mIsConnectionActive = false;
}

free(curPacket);
waitingForInitPacket = false;
}

} else {
Logger::log("Recieve failed! Stopping Connection.\n");
mIsConnectionActive = false;
waitingForInitPacket = false;
}

break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/server/SocketBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SocketBase::SocketBase(const char *name)
{
strcpy(this->sockName, name);

this->sock_flags = 0;
this->sock_flags = 0x80;
}

const char *SocketBase::getStateChar() {
Expand Down
12 changes: 8 additions & 4 deletions source/server/SocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool SocketClient::SEND(Packet *packet) {
if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF)
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);

if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), this->sock_flags) > 0)) {
if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) {
return true;
} else {
Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize);
Expand Down Expand Up @@ -117,9 +117,13 @@ bool SocketClient::RECV() {
if(result > 0) {
valread += result;
} else {
Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread);
this->closeSocket();
return false;
if(this->socket_errno==11){
return true;
} else {
Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread);
this->closeSocket();
return false;
}
}
}

Expand Down

0 comments on commit 5f1a911

Please sign in to comment.