void CFileQueue::addPacket(CString pPacket) { while (pPacket.bytesLeft() != 0) { unsigned char pId = pPacket.readGUChar(); pPacket.setRead(pPacket.readPos() - 1); if (pId == PLO_RAWDATA) { // Read packet 100. pack100 = CString() << pPacket.readString("\n") << "\n"; pack100.setRead(1); // Don't read the packet ID. prev100 = true; size100 = pack100.readGUInt(); } else { // Read the packet. If the previous packet was 100, read the specified bytes. // If it isn't level data, put it into the file buffer. CString packet; if (prev100) { packet = pPacket.readChars(size100); if (packet.readGUChar() == PLO_BOARDPACKET) normalBuffer.push(CString() << pack100 << packet); else fileBuffer.push(CString() << pack100 << packet); prev100 = false; } else { // Else, read to \n. packet = CString() << pPacket.readString("\n") << "\n"; // Certain file related packets go to the file buffer since they must be // sent in order. switch (pId) { case PLO_LARGEFILESTART: case PLO_LARGEFILEEND: case PLO_LARGEFILESIZE: fileBuffer.push(packet); break; // Everything else goes into the normal buffer. default: normalBuffer.push(packet); } } } } }
CString gs2ToGameMonkey(CString gs2Code) { CString prefix; CString parsedCode; std::vector<CString> clean = gs2Code.tokenize("\xa7"); int bracketCount = 0; for (std::vector<CString>::iterator i = clean.begin(); i != clean.end(); ++i) { CString line = *i; //Functions if (line.readChars(CString("function").length()) == "function") { CString fullFunction = line.subString(CString("function").length()+1); CString functionName = fullFunction.readString("("); CString prefix; //this. or global? prefix << "." << functionName << " = function" << fullFunction.subString(functionName.length()); parsedCode << prefix; bracketCount = 1; } else if (line.find("{") >= 0) { bracketCount++; parsedCode << line; } //Make sure this is ; on the end of } else if (line.find("}") >= 0) { bracketCount--; if (bracketCount > 1) { parsedCode << line; continue; } CString semi; while(line.subString(line.find("}")+1,1) != ";") { if (line.subString(line.find("}")+1,1) != ";") { semi << line.subString(0,line.find("}")+1) << ";" << line.subString(line.find("}")+1); line = semi; } } if (semi.isEmpty()) parsedCode << "};"; else parsedCode << semi; } else if(line.find("SPC") >= 0) { line.replaceAllI("SPC"," + \" \" + "); parsedCode << line; } else parsedCode << line; } return parsedCode; }
/* TAccount: Flag Management */ void TAccount::setFlag(CString pFlag) { CString flagName = pFlag.readString("="); CString flagValue = pFlag.readString(""); this->setFlag(flagName, flagValue); }
bool CConnection::run() { // See if we can grab any packets. rBuffer.setRead(0); while (rBuffer.length() > 1) { unsigned short plen = rBuffer.readShort(); if (plen > (unsigned short)rBuffer.length() - 2) break; CString unBuffer = rBuffer.readChars(plen); rBuffer.removeI(0, plen + 2); // Compression unsigned char ptype = (unsigned char)unBuffer.readChar(); unBuffer.removeI(0, 1); // Decrypt data if (in_codec.limitFromType(ptype)) { if (Verbose) std::cout << "** Packet compression type is not supported." << std::endl; return false; } in_codec.decrypt(unBuffer); // Uncompress if needed. const char* compression = "uncompressed"; if (ptype == COMPRESS_ZLIB) { unBuffer.zuncompressI(); compression = "zlib"; } else if (ptype == COMPRESS_BZ2) { unBuffer.bzuncompressI(); compression = "bz2"; } if (Verbose) { std::cout << std::endl;// << std::endl; std::cout << "~~~~~~~~~~~~~~~~~~~~~~~" << std::endl; std::cout << "Chunk Length: " << plen << ", data: " << unBuffer.length() << std::endl; std::cout << "Chunk Compression: " << compression << " (" << (unsigned int)ptype << ")" << std::endl; std::cout << std::endl; } int i = 0; while (!unBuffer.isEmpty()) { unBuffer.setRead(0); CString unBuffer2 = unBuffer.readString("\n"); unBuffer.removeI(0, unBuffer2.length() + 1); unsigned char pid = unBuffer2.readGUChar(); if (Verbose) std::cout << "Packet " << i++ << ": " << (unBuffer2.text() + 1) << std::endl; if (pid == 0) { FILE* f = fopen(OutputFile.text(), "wb"); if (f) { if (!Verbose) std::cout << "Got serverlist, writing to " << OutputFile.text() << std::endl; unsigned char server_count = unBuffer2.readGUChar(); for (int j = 0; j < server_count; ++j) { unsigned char type = unBuffer2.readGUChar(); CString name = unBuffer2.readChars(unBuffer2.readGUChar()); CString language = unBuffer2.readChars(unBuffer2.readGUChar()); CString description = unBuffer2.readChars(unBuffer2.readGUChar()); CString url = unBuffer2.readChars(unBuffer2.readGUChar()); CString version = unBuffer2.readChars(unBuffer2.readGUChar()); CString player_count = unBuffer2.readChars(unBuffer2.readGUChar()); CString ip = unBuffer2.readChars(unBuffer2.readGUChar()); CString port = unBuffer2.readChars(unBuffer2.readGUChar()); if (!SimpleMode) { fprintf(f, "----------------------------------\r\n"); fprintf(f, "Type: %d\r\n", type); fprintf(f, "Name: %s\r\n", name.text()); fprintf(f, "Language: %s\r\n", language.text()); fprintf(f, "Description: %s\r\n", description.text()); fprintf(f, "URL: %s\r\n", url.text()); fprintf(f, "Version: %s\r\n", version.text()); fprintf(f, "Player count: %s\r\n", player_count.text()); fprintf(f, "IP: %s\r\n", ip.text()); fprintf(f, "Port: %s\r\n", port.text()); } else fprintf(f, "%s\r\n", name.text()); } fclose(f); } } } if (Verbose) std::cout << "~~~~~~~~~~~~~~~~~~~~~~~" << std::endl; } return true; }
TNPC::TNPC(const CString& pImage, const CString& pScript, float pX, float pY, TServer* pServer, TLevel* pLevel, bool pLevelNPC, bool trimCode) : levelNPC(pLevelNPC), x(pX), y(pY), hurtX(32.0f), hurtY(32.0f), x2((int)(pX*16)), y2((int)(pY*16)), gmaplevelx(0), gmaplevely(0), id(0), rupees(0), darts(0), bombs(0), glovePower(0), bombPower(0), swordPower(0), shieldPower(0), visFlags(1), blockFlags(0), sprite(2), power(0), ap(50), image(pImage), gani("idle"), level(pLevel), server(pServer) { memset((void*)colors, 0, sizeof(colors)); memset((void*)saves, 0, sizeof(saves)); memset((void*)modTime, 0, sizeof(modTime)); // bowImage for pre-2.x clients. bowImage >> (char)0; // imagePart needs to be Graal-packed. for (int i = 0; i < 6; i++) imagePart.writeGChar(0); // Set the gmap levels. TMap* gmap = level->getMap(); if (gmap && gmap->getType() == MAPTYPE_GMAP) { gmaplevelx = (unsigned char)gmap->getLevelX(level->getLevelName()); gmaplevely = (unsigned char)gmap->getLevelY(level->getLevelName()); } // We need to alter the modTime of the following props as they should be always sent. // If we don't, they won't be sent until the prop gets modified. modTime[NPCPROP_IMAGE] = modTime[NPCPROP_SCRIPT] = modTime[NPCPROP_X] = modTime[NPCPROP_Y] = modTime[NPCPROP_VISFLAGS] = modTime[NPCPROP_ID] = modTime[NPCPROP_SPRITE] = modTime[NPCPROP_GMAPLEVELX] = modTime[NPCPROP_GMAPLEVELY] = modTime[NPCPROP_X2] = modTime[NPCPROP_Y2] = time(0); // See if the NPC sets the level as a sparring zone. if (pScript.subString(0, 12) == "sparringzone") pLevel->setSparringZone(true); // See if the NPC sets the level as singleplayer. if (pScript.subString(0, 12) == "singleplayer") pLevel->setSingleplayer(true); // Remove comments and separate clientside and serverside scripts. CString nocomments = removeComments(pScript, "\xa7"); if (server->hasNPCServer() && nocomments.find("//#CLIENTSIDE") != -1) { serverScript = nocomments.readString("//#CLIENTSIDE"); clientScript = CString("//#CLIENTSIDE\xa7") << nocomments.readString(""); } else clientScript = nocomments; // Trim the code if specified. if (trimCode) { if (!serverScript.isEmpty()) { std::vector<CString> code = serverScript.tokenize("\xa7"); serverScript.clear(); for (std::vector<CString>::iterator i = code.begin(); i != code.end(); ++i) serverScript << (*i).trim() << "\xa7"; } if (!clientScript.isEmpty()) { std::vector<CString> code = clientScript.tokenize("\xa7"); clientScript.clear(); for (std::vector<CString>::iterator i = code.begin(); i != code.end(); ++i) clientScript << (*i).trim() << "\xa7"; } } // Do joins. if (!serverScript.isEmpty()) serverScript = doJoins(serverScript, server->getFileSystem()); if (!clientScript.isEmpty()) clientScript = doJoins(clientScript, server->getFileSystem()); // Search for toweapons in the clientside code and extract the name of the weapon. weaponName = toWeaponName(clientScript); // Just a little warning for people who don't know. if (clientScript.length() > 0x2FDF) printf("WARNING: Clientside script of NPC (%s) exceeds the limit of 12255 bytes.\n", (weaponName.length() != 0 ? weaponName.text() : image.text())); // TODO: Create plugin hook so NPCServer can acquire/format code. }