static void normalizeAbsoluteName (nameData_t* d) { ___BTPUSH; while (d->name[d->index] != 0) { int nextFileNamePart = identifyFilenamePart (d->name + d->index); switch (nextFileNamePart) { case DOT: if (d->name[d->index + 1] != 0) { shrinkName (d, d->index - 1, d->index + 1); } else { d->name[d->index] = 0; } break; case DOTDOT: { bool zeroAfterDots = d->name[d->index + 2] == 0; if (d->indexCount > 1) { shrinkName (d, d->indices[d->indexCount - 2], d->index + 2); d->index = d->indices[d->indexCount - 2]; d->indexCount -= zeroAfterDots + 1; d->index += !zeroAfterDots; } else { if (zeroAfterDots) { d->name[1] = 0; } else { shrinkName (d, 0, d->index + 2); } d->indexCount = 0; d->index = 1; } } break; case EMPTY: shrinkName (d, d->index, d->index + 1); break; default: while (!(d->name[d->index] == 0 || d->name[d->index] == '/')) { ++d->index; } if (d->name[d->index] != 0) { d->indices[d->indexCount] = d->index; ++d->indexCount; ++d->index; } } } if (d->index > 1 && d->name[d->index - 1] == '/') { d->name[d->index - 1] = 0; } else { d->indices[d->indexCount] = d->index; ++d->indexCount; } ___BTPOP; }
void Client::registerToServer(const std::string& name, const std::string& password, const sf::IpAddress& address, sf::Uint16 port) { std::string shrinkedName = shrinkName(name); // The local socket used only to register, it does not need to be keeped as attribute sf::TcpSocket socket; // if connection does not work, don't go further if(socket.connect(address, port) != sf::Socket::Done) throw UnableToConnectException("unable to connect to server on port " + std::to_string(port) + "."); sendRegisteringToken(shrinkedName, password, socket); }
void Client::initServer(const std::string& name, const sf::IpAddress& address, sf::Uint16 port) { // If client is already connected to a server, do not try to re-connect it. // We talk here about a socket connexion, not the authentication. if(_isConnected) throw UnableToConnectException("already connected."); _name = shrinkName(name); _serverAddress = address; _serverPort = port; // if connection does not work, don't go further if(_socket.connect(address, port) != sf::Socket::Done) throw UnableToConnectException("unable to connect to server on port " + std::to_string(port) + "."); if(!_userTerminal.hasKnownTerminal()) std::cout << "Warning: as no known terminal has been found, chat is disabled" << std::endl; else initListener(); // creates the new thread which listens for entring chat conenctions sf::sleep(SOCKET_TIME_SLEEP); // wait a quarter second to let the listening thread init the port }
static void normalizeRelativeName (nameData_t* d) { ___BTPUSH; while (d->name[d->index] != 0) { int nextFileNamePart = identifyFilenamePart (d->name + d->index); switch (nextFileNamePart) { case DOT: if (d->index > 0) { shrinkName (d, d->index - 1, d->index + 1); if (d->name[d->index - 1] == 0) { d->indexCount -= d->indexCount > 0; --d->index; } } else if (d->nameLength > 1) { shrinkName (d, 0, 2); } else { ++d->index; } break; case DOTDOT: { bool zeroAfterDots = d->name[d->index + 2] == 0; if (d->indexCount > 1) { shrinkName (d, d->indices[d->indexCount - 2], d->index + 2); d->index = d->indices[d->indexCount - 2] + !zeroAfterDots; d->indexCount -= (zeroAfterDots || 3 * d->parentDirs == d->index) + 1; } else if (d->indexCount == 0) { ++d->parentDirs; d->index += 2 + !zeroAfterDots; } else if (zeroAfterDots) { d->indexCount = 0; d->name[0] = '.'; d->name[1] = 0; d->index = 1; } else { d->indexCount = 0; shrinkName (d, 0, d->index + 3); d->index = 0; } } break; case EMPTY: shrinkName (d, d->index, d->index + 1); break; default: if (d->index > 0 && 3 * d->parentDirs == d->index) { d->indices[d->indexCount] = d->index - 1; ++d->indexCount; } while (!(d->name[d->index] == 0 || d->name[d->index] == '/')) { ++d->index; } if (d->name[d->index] != 0) { d->indices[d->indexCount] = d->index; ++d->indexCount; ++d->index; } } } if (d->index == 0) { d->name[0] = '.'; d->name[1] = 0; d->index = 1; } else if (d->name[d->index - 1] == '/') { d->indexCount -= d->indexCount > 0; --d->index; d->name[d->index] = 0; } d->indices[d->indexCount] = d->index; ++d->indexCount; ___BTPOP; }