// -- Function: Save Weapon -- // bool TWeapon::saveWeapon(TServer* server) { // Don't save default weapons / empty weapons if (this->isDefault() || mWeaponName.isEmpty()) return false; // Prevent the loading/saving of filenames with illegal characters. CString name = mWeaponName; name.replaceAllI("\\", "_"); name.replaceAllI("/", "_"); name.replaceAllI("*", "@"); name.replaceAllI(":", ";"); name.replaceAllI("?", "!"); CString filename = server->getServerPath() << "weapons/weapon" << name << ".txt"; // Format the weapon script. CString script(mWeaponScript); if (script[script.length() - 1] != '\xa7') script << "\xa7"; script.replaceAllI("\xa7", "\r\n"); // Write the File. CString output = "GRAWP001\r\n"; output << "REALNAME " << mWeaponName << "\r\n"; output << "IMAGE " << mWeaponImage << "\r\n"; for (unsigned int i = 0; i < mByteCode.size(); ++i) output << "BYTECODE " << mByteCode[i].first << "\r\n"; if (!script.isEmpty()) { output << "SCRIPT\r\n"; output << script; output << "SCRIPTEND\r\n"; } // Save it. return output.save(filename); }
int main(int argc, char *argv[]) { #ifdef PSPSDK pspDebugScreenInit(); SetupCallbacks(); #else // Shut down the server if we get a kill signal. signal( SIGINT, (sighandler_t) shutdownServer ); signal( SIGTERM, (sighandler_t) shutdownServer ); #endif /* Setup Data-Directory */ dataDir = CBuffer(argv[0]).replaceAll("\\", "/"); dataDir = dataDir.copy(0, dataDir.findl('/') + 1); programDir = dataDir; dataDir << "world/"; /* Main Initiating */ adminNames.load( __admin, sizeof(__admin) / sizeof(const char*) ); colourNames.load( __colours, sizeof(__colours) / sizeof(const char*) ); clothCommands.load( __cloths, sizeof(__cloths) / sizeof(const char*) ); defaultFiles.load( __defaultfiles, sizeof(__defaultfiles) / sizeof(const char*) ); playerIds.add(0); playerIds.add(0); npcIds.add(0); srand((int)time(NULL)); /* Load Important Files */ updateFile("rchelp.txt"); updateFile("rcmessage.txt"); updateFile("rules.txt"); updateFile("serverflags.txt"); updateFile("servermessage.html"); updateFile("foldersconfig.txt"); /* Load Settings */ if (!loadSettings("serveroptions.txt")) { errorOut("errorlog.txt", "Unable to load server settings.."); return 1; } /* Load Weapons */ if (!loadWeapons("weapons.txt")) { errorOut("errorlog.txt", "Unable to load weapons from weapons.txt.."); return 1; } /* Initialize Sockets */ serverSock.setType( SOCKET_TYPE_SERVER ); serverSock.setProtocol( SOCKET_PROTOCOL_TCP ); serverSock.setOptions( SOCKET_OPTION_NONBLOCKING ); serverSock.setDescription( "serverSock" ); CString empty; if ( serverSock.init( empty, serverPort ) ) return 1; // Connect server socket. if ( serverSock.connect() ) { errorOut("errorlog.txt", CString() << "SOCK ERROR: Unable to listen on port: " << serverPort); return 1; } /* Server Finished Loading */ printf("GServer 2 by 39ster\nSpecial thanks to Marlon, Agret, Pac300, 39ster and others for porting the \noriginal 1.39 gserver to 2.1\nServer listening on port: %s\nServer version: Build %s\n\n", serverPort.text(), listServerFields[3].text()); errorOut("serverlog.txt", "Server started"); if ( listServerFields[5] == "localhost" ) errorOut("serverlog.txt", "[DEBUG_LOCALHOSTMODE] Localhost mode is activated.\nListserver communication & account authentication are disabled.", true); serverRunning = true; if ( !(listServerFields[5] == "localhost") ) if (!lsConnected) ListServer_Connect(); while (serverRunning) { long long second = time(NULL); while (second == time(NULL)) { acceptNewPlayers(serverSock); for (int i = 0; i < newPlayers.count(); i ++) { CPlayer* player = (CPlayer*)newPlayers[i]; player->main(); if (player->deleteMe) { delete player; i--; } } for(int i = 0; i < playerList.count(); i++) { CPlayer* player = (CPlayer*)playerList[i]; player->main(); if(player->deleteMe) { delete player; i--; } } // Was moved so it can process faster. - Joey ListServer_Main(); wait(10); } doTimer(); gameTime ++; NOLEVEL->reset(); // Every 30 seconds if (gameTime % 30 == 0) { ListServer_Send(CPacket() << (char)SLSPING << "\n"); } // Every 10 seconds if (gameTime % 10 == 0) { CPacket pPacket; CString file; for (int i = 0; i < playerList.count(); i++) { CPlayer *player = (CPlayer *)playerList[i]; file << player->accountName << "," << player->nickName << "," << player->levelName << "," << toString(player->x) << "," << toString(player->y) << "," << toString(player->ap) << "\n"; } file.save("logs/playerlist.txt"); serverFlags.save("serverflags.txt"); } //Every 5 seconds? int current = getNWTime(); if (nwTime != current) { nwTime = current; for (int i = 0; i < playerList.count(); i++) { CPacket out; out << (char)NEWWORLDTIME; out.writeByte4(current); ((CPlayer*)playerList[i])->sendPacket(out); } } } }
bool TAccount::saveAccount() { // Don't save 'Load Only' or RC Accounts if (isLoadOnly) return false; CString newFile = "GRACC001\r\n"; newFile << "NAME " << accountName << "\r\n"; newFile << "NICK " << nickName << "\r\n"; newFile << "COMMUNITYNAME " << accountName /*communityName*/ << "\r\n"; newFile << "LEVEL " << levelName << "\r\n"; newFile << "X " << CString(x) << "\r\n"; newFile << "Y " << CString(y) << "\r\n"; newFile << "Z " << CString(z) << "\r\n"; newFile << "MAXHP " << CString(maxPower) << "\r\n"; newFile << "HP " << CString(power) << "\r\n"; newFile << "RUPEES " << CString(gralatc) << "\r\n"; newFile << "ANI " << gani << "\r\n"; newFile << "ARROWS " << CString(arrowc) << "\r\n"; newFile << "BOMBS " << CString(bombc) << "\r\n"; newFile << "GLOVEP " << CString(glovePower) << "\r\n"; newFile << "SHIELDP " << CString(shieldPower) << "\r\n"; newFile << "SWORDP " << CString(swordPower) << "\r\n"; newFile << "BOWP " << CString(bowPower) << "\r\n"; newFile << "BOW " << bowImage << "\r\n"; newFile << "HEAD " << headImg << "\r\n"; newFile << "BODY " << bodyImg << "\r\n"; newFile << "SWORD " << swordImg << "\r\n"; newFile << "SHIELD " << shieldImg << "\r\n"; newFile << "COLORS " << CString(colors[0]) << "," << CString(colors[1]) << "," << CString(colors[2]) << "," << CString(colors[3]) << "," << CString(colors[4]) << "\r\n"; newFile << "SPRITE " << CString(sprite) << "\r\n"; newFile << "STATUS " << CString(status) << "\r\n"; newFile << "MP " << CString(mp) << "\r\n"; newFile << "AP " << CString(ap) << "\r\n"; newFile << "APCOUNTER " << CString(apCounter) << "\r\n"; newFile << "ONSECS " << CString(onlineTime) << "\r\n"; newFile << "IP " << CString(accountIp) << "\r\n"; newFile << "LANGUAGE " << language << "\r\n"; newFile << "KILLS " << CString(kills) << "\r\n"; newFile << "DEATHS " << CString(deaths) << "\r\n"; newFile << "RATING " << CString(rating) << "\r\n"; newFile << "DEVIATION " << CString(deviation) << "\r\n"; newFile << "OLDDEVIATION " << CString(oldDeviation) << "\r\n"; newFile << "LASTSPARTIME " << CString((unsigned long)lastSparTime) << "\r\n"; // Attributes for (unsigned int i = 0; i < 30; i++) { if (attrList[i].length() > 0) newFile << "ATTR" << CString(i+1) << " " << attrList[i] << "\r\n"; } // Chests for (unsigned int i = 0; i < chestList.size(); i++) newFile << "CHEST " << chestList[i] << "\r\n"; // Weapons for (unsigned int i = 0; i < weaponList.size(); i++) newFile << "WEAPON " << weaponList[i] << "\r\n"; // Flags for (std::map<CString, CString>::const_iterator i = mFlagList.begin(); i != mFlagList.end(); ++i) { newFile << "FLAG " << i->first; if (!i->second.isEmpty()) newFile << "=" << i->second; newFile << "\r\n"; } // Account Settings newFile << "\r\n"; newFile << "BANNED " << CString((int)(isBanned == true ? 1 : 0)) << "\r\n"; newFile << "BANREASON " << banReason << "\r\n"; newFile << "BANLENGTH " << banLength << "\r\n"; newFile << "COMMENTS " << accountComments << "\r\n"; newFile << "EMAIL " << email << "\r\n"; newFile << "LOCALRIGHTS " << CString(adminRights) << "\r\n"; newFile << "IPRANGE " << adminIp << "\r\n"; // Folder Rights for (unsigned int i = 0; i < folderList.size(); i++) newFile << "FOLDERRIGHT " << folderList[i] << "\r\n"; newFile << "LASTFOLDER " << lastFolder << "\r\n"; // See if a plugin saves the account. if (server->getPluginManager().SaveAccount(accountName.text(), newFile.text())) return true; // Save the account now. CString accpath = CString() << server->getServerPath() << "accounts/" << accountName << ".txt"; CFileSystem::fixPathSeparators(&accpath); if (!newFile.save(accpath)) server->getRCLog().out("** Error saving account: %s\n", accountName.text()); return true; }
void ListServer_Main() { static CBuffer packetBuffer; CStringList lines; if ( listServerFields[5] == "localhost" ) return; if (!lsConnected) return; // Read any new data into the socket. if ( listServer.getData() == -1 ) { errorOut( "serverlog.txt", "Disconnected from list server." ); lsConnected = false; return; } // Grab all the data from the socket buffer. packetBuffer << listServer.getBuffer(); listServer.getBuffer().clear(); // Search for a packet. If none is found, break out of the loop. while (packetBuffer.length() != 0) { CPacket line; if (!nextIsRaw) { int lineEnd = packetBuffer.find( '\n' ); if ( lineEnd == -1 ) return; // Copy the packet out and remove the \n line = packetBuffer.copy( 0, lineEnd + 1 ); packetBuffer.remove(0, line.length()); line.remove(line.length() - 1, 1); } else { if (packetBuffer.length() < rawPacketSize) return; line.writeBytes(packetBuffer.readChars(rawPacketSize), rawPacketSize); packetBuffer.remove(0, line.length()); line.remove(line.length() - 1, 1); nextIsRaw = false; } packetBuffer.setRead(0); int messageId = line.readByte1(); switch (messageId) { case GSVOLD: { printf("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - Old version, please upgrade.\n", getTimeStr(1).text(), GSERVER_BUILD, line.readByte2()); break; } case GSVCURRENT: { printf("[%s] SERVER VERSION CHECK - Current: %i, Latest: %i - You are up to date :)\n", getTimeStr(1).text(), GSERVER_BUILD, GSERVER_BUILD); break; } case GSVACCOUNT: { CString accountName = line.readChars(line.readByte1()); CString errorMsg = line.readString(""); for (int i = 0; i < newPlayers.count(); i++) { CPlayer *player = (CPlayer *)newPlayers[i]; if (player->accountName.comparei(accountName) == 0) { // The serverlist will return case sensitive account names. // This helps case sensitive file systems open/save the correct // acount. player->accountName = accountName; if (errorMsg == "SUCCESS") { player->sendAccount(); } else { player->sendPacket(CPacket() << (char)DISMESSAGE << errorMsg); player->deleteMe = true; } break; } } break; } case GSVGUILD: { int playerId = line.readByte2(); CPlayer *player = (CPlayer *)playerIds[playerId]; if (player != NULL) { CString nick = line.readChars((unsigned char)line.readByte1()); CString guild = nick.copy( nick.findl( '(' ) ).remove( ")" ); if ( globalGuilds == false ) { if ( globalGuildList.find( guild ) != -1 ) player->setNick(nick, false); } else player->setNick(nick, false); } break; } case GSVPROFILE: /* Unsure if this works, temp */ { CPacket profile; CPlayer *player1 = (CPlayer *)playerIds[line.readByte2()]; CPlayer *player2 = findPlayerId(line.readChars(line.readByte1())); if (player1 == NULL || player2 == NULL) return; profile << (char)player2->accountName.length() << player2->accountName << line.readString(""); int time = player2->onlineSecs; CString line2; //Online time line2 << toString((int)time/3600) << " hrs "; line2 << toString((int)(time/60)%60) << " mins "; line2 << toString((int)time%60) << " secs"; profile << (char)line2.length() << line2; for (int i = 0; i < profileList.count(); i++) { CStringList a; a.load(profileList[i].text(), ":="); if (a[0].length() < 1) continue; CString n; if (a[1] == "playerkills") n = toString(player2->kills); else if (a[1] == "playerdeaths") n = toString(player2->deaths); else if (a[1] == "playerfullhearts") { if ( (float)(int)player2->maxPower == (float)player2->maxPower ) n = toString((int)player2->maxPower); else { n = toString(player2->maxPower); n = n.copy( 0, n.length() - 1 ); } } else if (a[1] == "playerrating") n = toString((int)player2->rating) << "/" << toString((int)player2->deviation); else if (a[1] == "playerap") n = toString(player2->ap); else if (a[1] == "playerrupees") n = toString(player2->rubins); else if (a[1] == "playerswordpower") n = toString(player2->swordPower); else if (a[1] == "canspin") n = (player2->status & 64 ? "true" : "false"); else if (a[1] == "playerhearts") { if ( (float)(int)player2->power == (float)player2->power ) n = toString((int)player2->power); else { n = toString(player2->power); n = n.copy( 0, n.length() - 1 ); } } else if (a[1] == "playerdarts") n = toString(player2->darts); else if (a[1] == "playerbombs") n = toString(player2->bombs); else if (a[1] == "playermp") n = toString(player2->magicPoints); else if (a[1] == "playershieldpower") n = toString(player2->shieldPower); else if (a[1] == "playerglovepower") n = toString(player2->glovePower); else { for (int i = 0; i < player2->myFlags.count(); i++) { CStringList b; b.load(player2->myFlags[i].text(), "="); if (b[0] == a[1]) { n = b[1]; break; } } } profile << (char)(a[0].length() + n.length() + 2) << a[0] << ":=" << n; } player1->sendPacket(CPacket() << (char)DPROFILE << profile); break; } case GSVMSG: printf("[%s] %s\n", getTimeStr(1).text(), line.readString("")); break; case GSVFILESTART3: { unsigned char pTy = (unsigned char)line.readByte1(); CString fileData, fileName = CString() << dataDir << "global" << fSep; switch (pTy) { case 0: // head fileName << "heads" << fSep; break; case 1: // body fileName << "bodies" << fSep; break; case 2: // sword fileName << "swords" << fSep; break; case 3: // shield fileName << "shields" << fSep; break; } fileName << line.readChars(line.readByte1()); fileData.save(fileName.text()); break; } case GSVFILEDATA3: { unsigned char pTy = (unsigned char)line.readByte1(); CString fileData, fileName, newData, shortName; shortName = line.readChars(line.readByte1()); fileName = CString() << dataDir << "global" << fSep; switch (pTy) { case 0: // head fileName << "heads" << fSep; break; case 1: // body fileName << "bodies" << fSep; break; case 2: // sword fileName << "swords" << fSep; break; case 3: // shield fileName << "shields" << fSep; break; } fileName << shortName.text(); newData.writeBytes(line.readChars(line.bytesLeft()), line.bytesLeft()); fileData.load(fileName.text()); fileData << newData; fileData.save(fileName.text()); break; } case GSVFILEEND3: { CPlayer *player = (CPlayer *)playerIds[line.readByte2()]; int type = line.readByte1(); char doCompress = line.readByte1(); time_t modTime = line.readByte5(); int fileLength = line.readByte5(); CString shortName = line.readString(""); CString fileName = CString() << dataDir << "global" << fSep; switch (type) { case 0: // head fileName << "heads" << fSep; break; case 1: // body fileName << "bodies" << fSep; break; case 2: // sword fileName << "swords" << fSep; break; case 3: // shield fileName << "shields" << fSep; break; } fileName << shortName.text(); // If the file was sent compressed, we need to uncompress it. if (doCompress == 1) { // Open the file so we can uncompress it. CString fileData; fileData.load(fileName.text()); // Uncompress the file. char* buffer = new char[fileLength]; memset((void*)buffer, 0, fileLength); int cLen = fileLength; int error = uncompress((Bytef*)buffer,(uLongf*)&cLen,(const Bytef*)fileData.text(), fileData.length()); if (error != Z_OK) printf("Failed to decompress file: %s\n", shortName.text()); // Save the file now. fileData.clear(); fileData.writeBytes(buffer, cLen); fileData.save(fileName.text()); delete [] buffer; } // Set the file mod time. if (setFileModTime(fileName.text(), modTime) == false) printf("** [WARNING] Could not set modification time on file %s\n", shortName.text()); if (player) { player->fileList.add(new COutFile(shortName, 0)); switch (type) { case 0: // head player->headImage = shortName; player->updateProp(HEADGIF); break; case 1: // body player->bodyImage = shortName; player->updateProp(BODYIMG); break; case 2: // sword player->swordImage = shortName; player->updateProp(SWORDPOWER); break; case 3: // shield player->shieldImage = shortName; player->updateProp(SHIELDPOWER); break; } } break; } case GSVPING: // Sent every 60 seconds, do nothing. break; case GSVRAWDATA: nextIsRaw = true; rawPacketSize = line.readByte3(); break; default: printf("[%s] Invalid List Server Message: %i\n", getTimeStr(1).text(), messageId); break; } } }