plString cdUp(plString path) { // Check for root paths, we can't go up from there! #ifdef WIN32 if (path.mid(1) == ":\\") return path; #else if (path == "/") return path; #endif // Not very robust, but it works for one level of parent scanning if (path.empty()) return ".." PATHSEPSTR; // Strip the ending slash, if necessary, and then go up one dir if (path[path.len()-1] == PATHSEP) path = path.left(path.len() - 1); plString up = path.beforeLast(PATHSEP); if (path[0] == PATHSEP) { // Absolute path specified -- make sure we keep it that way return up + PATHSEP; } else { // Relative path specified return up.empty() ? "" : up + PATHSEP; } }
uint32_t pnAuthClient::sendAcctLoginRequest(uint32_t serverChallenge, uint32_t clientChallenge, const plString& acctName, const plString& password, const plString& authToken, const plString& os) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_AcctLoginRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fUint = clientChallenge; msg[2].fString = plwcsdup(acctName.wstr()); pnSha1Hash hash; if (acctName.find('@') != -1 && acctName.find("@gametap") == -1 && acctName.find("@magiquest") == -1) { hash = NCHashLoginInfo(acctName, password, serverChallenge, clientChallenge); } else { hash = pnSha1Hash::Sha1(password.cstr(), password.len()); hash.swapBytes(); // Cyan uses a different byte order for this case } memcpy(msg[3].fData, &hash, sizeof(hash)); msg[4].fString = plwcsdup(authToken.wstr()); msg[5].fString = plwcsdup(os.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
plMD5Hash plMD5::hashString(const plString& str) { plMD5 ctx; size_t size = str.len(); unsigned char buf[64]; size_t pos = 0; while (pos + 64 <= size) { memcpy(buf, str.cstr() + pos, 64); ctx.processBlock(buf); pos += 64; } // Final block size_t lastSize = size - pos; memcpy(buf, str.cstr() + pos, lastSize); if (lastSize >= 56) { memcpy(buf + lastSize, kPadArray, 64 - lastSize); ctx.processBlock(buf); memset(buf, 0, sizeof(buf)); } else { unsigned int padBytes = 56 - lastSize; memcpy(buf + lastSize, kPadArray, padBytes); } unsigned int bitSize[2]; bitSize[0] = LESWAP32((size << 3)); bitSize[1] = LESWAP32((size >> 29)); memcpy(buf + 56, bitSize, sizeof(bitSize)); ctx.processBlock(buf); plMD5Hash hash; hash.fHash[0] = ctx.fA; hash.fHash[1] = ctx.fB; hash.fHash[2] = ctx.fC; hash.fHash[3] = ctx.fD; return hash; };