Пример #1
0
void WizAnimateAction::setTogetherIcon(const QString& strIconBaseName)
{
    CString strFileName;
    if (WizIsHighPixel()) {
        strFileName  = ::WizGetSkinResourceFileName(Utils::WizStyleHelper::themeName(), strIconBaseName + "@2x");
    } else {
        strFileName  = ::WizGetSkinResourceFileName(Utils::WizStyleHelper::themeName(), strIconBaseName);
    }

    if (strFileName.isEmpty())
        return;

    QPixmap pix(strFileName);
    int startX = 0;
    int pixHeight = pix.height();
    while (1)
    {
        QPixmap p =  pix.copy(startX, 0, pixHeight, pixHeight);
        if (p.isNull())
            return;

        QIcon icon(p);
        m_icons.push_back(icon);

        startX += pixHeight;
        if (startX >= pix.width())
            return;
    }
}
Пример #2
0
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;
}
Пример #3
0
BOOL WizCombineHtmlText(CString& strTextTo, QString lpszTextFrom)
{
    if (strTextTo.isEmpty())
    {
        strTextTo = lpszTextFrom;
        return TRUE;
    }
    //
    /*
    ////强制获得正文////
    */
    int nInsertPos = (int)WizStrRStrI_Pos(strTextTo, WizGetHtmlContentHiddenTagEnd());
    if (-1 == nInsertPos)
        nInsertPos = (int)WizStrRStrI_Pos(strTextTo, _T("</body"));
    if (-1 == nInsertPos)
        nInsertPos = (int)WizStrRStrI_Pos(strTextTo, _T("</html"));
    if (-1 == nInsertPos)
        nInsertPos = (int)strTextTo.length();
    //
    CString strFrom;
    if (!WizHtmlGetContentByHiddenTag(lpszTextFrom, strFrom))
    {
        if (!WizHTMLGetBodyTextWithoutBodyTag(lpszTextFrom, strFrom))
            return FALSE;
    }
    //
    strTextTo.insert(nInsertPos, strFrom);
    //
    return TRUE;
}
Пример #4
0
BOOL Util::InsertSVMQ(CString strQueueName, CString strMessage, CString strLabel)
{
      MutexLock lock(g_InsertMQLock);
      if(strLabel.isEmpty())
         strLabel="SVMQ";

      void *pqueue=NULL;
      int err=0;
      CString strError="";
      if((err=OpenQueue(g_SVMQAddress.getText(), (char *)strQueueName, &pqueue))>0)
      {
           if((err=Push(pqueue, strLabel, strMessage))>0)
	   {
	       CloseQueue(pqueue);
	       return TRUE;
	   }else
	   {
	      CloseQueue(pqueue);
	      strError.Format("Send Message error errorid:%d",err);
	      throw MSException((char *)strError);
	      
	   }
	   
          
      }else
      {
          puts("Open queue failed");
          strError.Format("Open queue failed errorid:%d",err);
	  throw MSException(strError.getText());
      }
      
      return TRUE;

}
Пример #5
0
bool CWizIndexBase::GetChildTagsSize(const CString &strParentTagGUID, int &size)
{
    CString strWhere = strParentTagGUID.isEmpty() ?
                       WizFormatString0(_T("TAG_GROUP_GUID is null")) :
                       WizFormatString1(_T("TAG_GROUP_GUID='%1'"), strParentTagGUID);

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_TAG, "COUNT(*)", strWhere);
    return SQLToSize(strSQL, size);
}
Пример #6
0
bool CWizIndexBase::GetChildTags(const CString& strParentTagGUID, CWizTagDataArray& arrayTag)
{
    CString strWhere = strParentTagGUID.isEmpty() ?
                       WizFormatString0(_T("TAG_GROUP_GUID is null")) :
                       WizFormatString1(_T("TAG_GROUP_GUID='%1'"), strParentTagGUID);

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG, strWhere);
    return SQLToTagDataArray(strSQL, arrayTag);
}
bool CWizCategoryViewAllTagsItem::accept(CWizDatabase& db, const WIZDOCUMENTDATA& data)
{
    CString strTagGUIDs = db.GetDocumentTagGUIDsString(data.strGUID);
    if (strTagGUIDs.isEmpty() && data.strKbGUID == kbGUID()) {
        return true;
    }

    return false;
}
Пример #8
0
void CWindow_Console::addLine()
{
    CString text = m_line->getText();

    if (!text.isEmpty())
    {
        m_line->clear();
        Game::console->sendCommand(text);
    }
}
Пример #9
0
void CEncryption::decrypt(CString& pBuf) {
	// If we don't have anything, just return.
	if (pBuf.isEmpty()) return;

	// Apply the correct decryption algorithm.
	switch (m_gen)
	{
		// No encryption.
		case ENCRYPT_GEN_1:
		case ENCRYPT_GEN_2:
			return;

		// Single byte insertion/zlib compression.
		case ENCRYPT_GEN_3:
		{
			m_iterator *= 0x8088405;
			m_iterator += m_key;
			int pos = ((m_iterator & 0x0FFFF) % pBuf.length());
			pBuf.removeI(pos, 1);
		}
		break;

		// Partial packet encryption/none, zlib, bz2 compression methods.
		// Gen 4 is only bz2.
		case ENCRYPT_GEN_4:
		case ENCRYPT_GEN_5:
		{
			const uint8_t* iterator = reinterpret_cast<const uint8_t*>(&m_iterator);

			for (int32_t i = 0; i < pBuf.length(); ++i)
			{
				if (i % 4 == 0)
				{
					if (m_limit == 0) return;
					m_iterator *= 0x8088405;
					m_iterator += m_key;
					if (m_limit > 0) m_limit--;
				}

				pBuf[i] ^= iterator[i%4];
			}
		}
		break;

		// Future encryption method.
		case ENCRYPT_GEN_6:
			return;
	}
}
Пример #10
0
void CConnection::sendPacket(const CString& pBuffer, bool appendNL)
{
	// Is Data?
	if (pBuffer.isEmpty())
		return;

	// Add to buffer.
	sBuffer << pBuffer;

	// Append '\n'.
	if (appendNL)
	{
		if (pBuffer[pBuffer.length()-1] != '\n')
			sBuffer << "\n";
	}
}
Пример #11
0
CLogControl::CLogControl() :
	mCurrentEntry(NULL)
{
	static CNumber threadID;
	++threadID;
	CString threadName = CThread::thread().name();
	CString logFileName = LESTR("thread - ") + threadID.valueAsString();
	if (!threadName.isEmpty())
	{
		logFileName += " - " + threadName;
	}

	logFileName += LESTR(".log");

	attachToFile(logFileName, 0);
}
Пример #12
0
CString CEncryption::encrypt(CString pBuf)
{
	// If we don't have anything, just return.
	if (pBuf.isEmpty()) return pBuf;

	switch (m_gen)
	{
		// No encryption.
		case ENCRYPT_GEN_1:
		case ENCRYPT_GEN_2:
			break;

		// Single byte insertion.
		case ENCRYPT_GEN_3:
		{
			m_iterator *= 0x8088405;
			m_iterator += m_key;
			int pos = ((m_iterator & 0x0FFFF) % pBuf.length());
			return CString() << pBuf.subString(0, pos) << ")" << pBuf.subString(pos);
			break;
		}

		// Partial packet encryption/none, zlib, bz2 compression methods.
		// Gen 4 is only bz2.
		case ENCRYPT_GEN_4:
		case ENCRYPT_GEN_5:
		{
			const uint8_t* iterator = reinterpret_cast<const uint8_t*>(&m_iterator);

			for (int32_t i = 0; i < pBuf.length(); ++i)
			{
				if (i % 4 == 0)
				{
					if (m_limit == 0) return pBuf;
					m_iterator *= 0x8088405;
					m_iterator += m_key;
					if (m_limit > 0) m_limit--;
				}

				pBuf[i] ^= iterator[i%4];
			}
			return pBuf;
			break;
		}
	}
	return pBuf;
}
Пример #13
0
void WizAnimateAction::setSingleIcons(const QString& strIconBaseName)
{
    int index = 1;
    while (1)
    {
        CString strFileName = ::WizGetSkinResourceFileName(Utils::WizStyleHelper::themeName(), strIconBaseName + WizIntToStr(index));
        if (strFileName.isEmpty())
            return;
        QIcon icon(strFileName);
        if (icon.isNull())
            return;

        m_icons.push_back(icon);

        index++;
    }
}
Пример #14
0
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 << "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 = flagList.begin(); i != flagList.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";
	newFile << "LOADONLY " << CString((int)(isLoadOnly == true ? 1 : 0)) << "\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;

	// Get the file name for the account.
	CString accountFileName = server->getAccountsFileSystem()->fileExistsAs(CString() << accountName << ".txt");
	if (accountFileName.isEmpty()) accountFileName = CString() << accountName << ".txt";

	// Save the account now.
	CString accpath = CString() << server->getServerPath() << "accounts/" << accountFileName;
	CFileSystem::fixPathSeparators(&accpath);
	if (!newFile.save(accpath))
		server->getRCLog().out("** Error saving account: %s\n", accountName.text());

	return true;
}
Пример #15
0
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;
}
Пример #16
0
int main(int argc, char *argv[])
{
	// Shut down the server if we get a kill signal.
	signal( SIGINT, (sighandler_t) shutdownServer );
	signal( SIGTERM, (sighandler_t) shutdownServer );

	// Grab the base path to the server executable.
	getBasePath();

	// Initialize data directory.
	filesystem[0].addDir("global");
	filesystem[1].addDir("global/heads");
	filesystem[2].addDir("global/bodies");
	filesystem[3].addDir("global/swords");
	filesystem[4].addDir("global/shields");

	// Definitions
	CSocket playerSock, playerSockOld, serverSock;
	playerList.clear();
	serverList.clear();

	// Load Settings
	settings = new CSettings(homepath + "settings.ini");
	if (!settings->isOpened())
	{
		serverlog.out( "[Error] Could not load settings.\n" );
		return ERR_SETTINGS;
	}

	// Load ip bans.
	ipBans = CString::loadToken(homepath + "ipbans.txt", "\n", true);
	serverlog.out("Loaded following IP bans:\n");
	for (std::vector<CString>::iterator i = ipBans.begin(); i != ipBans.end(); ++i)
		serverlog.out("\t%s\n", i->text());

	// Load server types.
	serverTypes = CString::loadToken("servertypes.txt", "\n", true);

	// Server sock.
	serverSock.setType( SOCKET_TYPE_SERVER );
	serverSock.setProtocol( SOCKET_PROTOCOL_TCP );
	serverSock.setDescription( "serverSock" );
	CString serverInterface = settings->getStr("gserverInterface");
	if (serverInterface == "AUTO") serverInterface.clear();
	if ( serverSock.init( (serverInterface.isEmpty() ? 0 : serverInterface.text()), settings->getStr("gserverPort").text() ) )
	{
		serverlog.out( "[Error] Could not initialize sockets.\n" );
		return ERR_LISTEN;
	}

	// Player sock.
	playerSock.setType( SOCKET_TYPE_SERVER );
	playerSock.setProtocol( SOCKET_PROTOCOL_TCP );
	playerSock.setDescription( "playerSock" );
	CString playerInterface = settings->getStr("clientInterface");
	if (playerInterface == "AUTO") playerInterface.clear();
	if ( playerSock.init( (playerInterface.isEmpty() ? 0 : playerInterface.text()), settings->getStr("clientPort").text() ) )
	{
		serverlog.out( "[Error] Could not initialize sockets.\n" );
		return ERR_LISTEN;
	}

	// Player sock.
	playerSockOld.setType( SOCKET_TYPE_SERVER );
	playerSockOld.setProtocol( SOCKET_PROTOCOL_TCP );
	playerSockOld.setDescription( "playerSockOld" );
	if ( playerSockOld.init( (playerInterface.isEmpty() ? 0 : playerInterface.text()), settings->getStr("clientPortOld").text() ) )
	{
		serverlog.out( "[Error] Could not initialize sockets.\n" );
		return ERR_LISTEN;
	}

	// Connect sockets.
	if ( serverSock.connect() || playerSock.connect() || playerSockOld.connect() )
	{
		serverlog.out( "[Error] Could not connect sockets.\n" );
		return ERR_SOCKETS;
	}

	// MySQL-Connect
#ifndef NO_MYSQL
	mySQL = new CMySQL(settings->getStr("server").text(), settings->getStr("user").text(), settings->getStr("password").text(), settings->getStr("database").text(), settings->getStr("sockfile").text());
	vBmySQL =  new CMySQL(settings->getStr("server").text(), settings->getStr("vbuser").text(), settings->getStr("vbpassword").text(), settings->getStr("vbdatabase").text(), settings->getStr("sockfile").text());
	if (!mySQL->ping())
	{
		serverlog.out( "[Error] No response from MySQL.\n" );
		return ERR_MYSQL;
	}

	// Truncate servers table from MySQL.
	CString query;
	query << "TRUNCATE TABLE " << settings->getStr("serverlist");
	mySQL->add_simple_query(query);
	query = CString("TRUNCATE TABLE ") << settings->getStr("securelogin");
	mySQL->add_simple_query(query);
	mySQL->update();
#endif

	// Create Packet-Functions
	createPLFunctions();
	createSVFunctions();

	// Flavor text
	serverlog.out( CString() << "Graal Reborn - List Server V2\n"
					<< "List server started..\n"
					<< "Client port: " << CString(settings->getInt("clientport")) << "\n"
					<< "GServer port: " << CString(settings->getInt("gserverport")) << "\n" );
#ifdef NO_MYSQL
	// Notify the user that they are running in No MySQL mode
	serverlog.out( CString() << "Running in No MySQL mode, all account and guild checks are disabled.\n");
#endif

	// Main Loop
	time_t t5min = time(0);
	while (running)
	{
		// Make sure MySQL is active
#ifndef NO_MYSQL
		if (!mySQL->ping())
			serverlog.out( "[Error] No response from MySQL.\n" );
		mySQL->update();
#endif

		// Accept New Connections
		acceptSock(playerSock, SOCK_PLAYER);
		acceptSock(playerSockOld, SOCK_PLAYEROLD);
		acceptSock(serverSock, SOCK_SERVER);

		// Player Sockets
		for ( std::vector<TPlayer*>::iterator iter = playerList.begin(); iter != playerList.end(); )
		{
			TPlayer* player = (TPlayer*)*iter;
			if ( player->doMain() == false )
			{
				player->sendCompress();
				delete player;
				iter = playerList.erase( iter );
			}
			else
				++iter;
		}

		// Server Sockets
		for ( std::vector<TServer*>::iterator iter = serverList.begin(); iter != serverList.end() ; )
		{
			TServer* server = (TServer*)*iter;
			if (server == 0)
			{
				serverlog.out(CString() << "Server disconnected: [Orphaned server]\n");
				iter = serverList.erase(iter);
				continue;
			}

			// Check for a timed out server.
			if ((int)server->getLastData() >= 300)
			{
				serverlog.out(CString() << "Server disconnected: " << server->getName() << " [Timed out]\n");
				server->sendCompress();
				delete server;
				iter = serverList.erase(iter);
				continue;
			}

			// Execute server stuff.
			if (server->doMain() == false)
			{
				serverlog.out(CString() << "Server disconnected: " << server->getName() << "\n");
				server->sendCompress();
				delete server;
				iter = serverList.erase(iter);
				continue;
			}
			
			++iter;
		}

		// Every 5 minutes...
		// Reload ip bans.
		// Resync the file system.
		if ((int)difftime(time(0), t5min) > (5*60))
		{
			ipBans = CString::loadToken("ipbans.txt", "\n", true);
			serverTypes = CString::loadToken("servertypes.txt", "\n", true);
			for (int i = 0; i < 5; ++i)
				filesystem[i].resync();
			t5min = time(0);
		}

		// Wait
		wait(100);
	}

	// Remove all servers.
	// This guarantees the server deconstructors are called.
	for ( std::vector<TServer*>::iterator iter = serverList.begin(); iter != serverList.end() ; )
	{
		TServer* server = (TServer*)*iter;
		delete server;
		iter = serverList.erase( iter );
	}

	return ERR_SUCCESS;
}
Пример #17
0
bool TAccount::loadAccount(const CString& pAccount, bool ignoreNickname)
{
	// Just in case this account was loaded offline through RC.
	accountName = pAccount;

	bool loadedFromDefault = false;
	CFileSystem* accfs = server->getAccountsFileSystem();
	std::vector<CString> fileData;

	CString accountText = server->getPluginManager().LoadAccount(pAccount);
	if (!accountText.isEmpty())
		fileData = accountText.tokenize("\n");
	else
	{
		// Find the account in the file system.
		CString accpath(accfs->findi(CString() << pAccount << ".txt"));
		if (accpath.length() == 0)
		{
			accpath = CString() << server->getServerPath() << "accounts/defaultaccount.txt";
			CFileSystem::fixPathSeparators(&accpath);
			loadedFromDefault = true;
		}

		// Load file.
		fileData = CString::loadToken(accpath, "\n");
		if (fileData.size() == 0 || fileData[0].trim() != "GRACC001")
			return false;
	}

	// Clear Lists
	for (int i = 0; i < 30; ++i) attrList[i].clear();
	chestList.clear();
	mFlagList.clear();
	folderList.clear();
	weaponList.clear();

	// Parse File
	for (unsigned int i = 0; i < fileData.size(); i++)
	{
		// Trim Line
		fileData[i].trimI();

		// Declare Variables;
		CString section, val;
		int sep;

		// Seperate Section & Value
		sep = fileData[i].find(' ');
		section = fileData[i].subString(0, sep);
		if (sep != -1)
			val = fileData[i].subString(sep + 1);

		if (section == "NAME") continue;
		else if (section == "NICK") { if (!ignoreNickname) nickName = val; }
		else if (section == "COMMUNITYNAME") communityName = val;
		else if (section == "LEVEL") levelName = val;
		else if (section == "X") { x = (float)strtofloat(val); x2 = (int)(x * 16); }
		else if (section == "Y") { y = (float)strtofloat(val); y2 = (int)(y * 16); }
		else if (section == "Z") { z = (float)strtofloat(val); z2 = (int)(z * 16); }
		else if (section == "MAXHP") maxPower = (int)strtoint(val);
		else if (section == "HP") power = (float)strtofloat(val);
		else if (section == "RUPEES") gralatc = strtoint(val);
		else if (section == "ANI") gani = val;
		else if (section == "ARROWS") arrowc = strtoint(val);
		else if (section == "BOMBS") bombc = strtoint(val);
		else if (section == "GLOVEP") glovePower = strtoint(val);
		else if (section == "SHIELDP") shieldPower = strtoint(val);
		else if (section == "SWORDP") swordPower = strtoint(val);
		else if (section == "BOWP") bowPower = strtoint(val);
		else if (section == "BOW") bowImage = val;
		else if (section == "HEAD") headImg = val;
		else if (section == "BODY") bodyImg = val;
		else if (section == "SWORD") swordImg = val;
		else if (section == "SHIELD") shieldImg = val;
		else if (section == "COLORS") { std::vector<CString> t = val.tokenize(","); for (int i = 0; i < (int)t.size() && i < 5; i++) colors[i] = (unsigned char)strtoint(t[i]); }
		else if (section == "SPRITE") sprite = strtoint(val);
		else if (section == "STATUS") status = strtoint(val);
		else if (section == "MP") mp = strtoint(val);
		else if (section == "AP") ap = strtoint(val);
		else if (section == "APCOUNTER") apCounter = strtoint(val);
		else if (section == "ONSECS") onlineTime = strtoint(val);
		else if (section == "IP") { if (accountIp == 0) accountIp = strtolong(val); }
		else if (section == "LANGUAGE") { language = val; if (language.isEmpty()) language = "English"; }
		else if (section == "KILLS") kills = strtoint(val);
		else if (section == "DEATHS") deaths = strtoint(val);
		else if (section == "RATING") rating = (float)strtofloat(val);
		else if (section == "DEVIATION") deviation = (float)strtofloat(val);
		else if (section == "OLDDEVIATION") oldDeviation = (float)strtofloat(val);
		else if (section == "LASTSPARTIME") lastSparTime = strtolong(val);
		else if (section == "FLAG") setFlag(val);
		else if (section == "ATTR1") attrList[0] = val;
		else if (section == "ATTR2") attrList[1] = val;
		else if (section == "ATTR3") attrList[2] = val;
		else if (section == "ATTR4") attrList[3] = val;
		else if (section == "ATTR5") attrList[4] = val;
		else if (section == "ATTR6") attrList[5] = val;
		else if (section == "ATTR7") attrList[6] = val;
		else if (section == "ATTR8") attrList[7] = val;
		else if (section == "ATTR9") attrList[8] = val;
		else if (section == "ATTR10") attrList[9] = val;
		else if (section == "ATTR11") attrList[10] = val;
		else if (section == "ATTR12") attrList[11] = val;
		else if (section == "ATTR13") attrList[12] = val;
		else if (section == "ATTR14") attrList[13] = val;
		else if (section == "ATTR15") attrList[14] = val;
		else if (section == "ATTR16") attrList[15] = val;
		else if (section == "ATTR17") attrList[16] = val;
		else if (section == "ATTR18") attrList[17] = val;
		else if (section == "ATTR19") attrList[18] = val;
		else if (section == "ATTR20") attrList[19] = val;
		else if (section == "ATTR21") attrList[20] = val;
		else if (section == "ATTR22") attrList[21] = val;
		else if (section == "ATTR23") attrList[22] = val;
		else if (section == "ATTR24") attrList[23] = val;
		else if (section == "ATTR25") attrList[24] = val;
		else if (section == "ATTR26") attrList[25] = val;
		else if (section == "ATTR27") attrList[26] = val;
		else if (section == "ATTR28") attrList[27] = val;
		else if (section == "ATTR29") attrList[28] = val;
		else if (section == "ATTR30") attrList[29] = val;
		else if (section == "WEAPON") weaponList.push_back(val);
		else if (section == "CHEST") chestList.push_back(val);
		else if (section == "BANNED") isBanned = (strtoint(val) == 0 ? false : true);
		else if (section == "BANREASON") banReason = val;
		else if (section == "BANLENGTH") banLength = val;
		else if (section == "COMMENTS") accountComments = val;
		else if (section == "EMAIL") email = val;
		else if (section == "LOCALRIGHTS") adminRights = strtoint(val);
		else if (section == "IPRANGE") adminIp = val;
		else if (section == "FOLDERRIGHT") folderList.push_back(val);
		else if (section == "LASTFOLDER") lastFolder = val;
	}

	// Comment out this line if you are actually going to use community names.
	communityName = accountName;

	// If we loaded from the default account, save our account now and add it to the file system.
	if (loadedFromDefault)
	{
		saveAccount();
		accfs->addFile(CString() << "accounts/" << pAccount << ".txt");
	}

	return true;
}
Пример #18
0
void
WGrid::paintEvent(QPaintEvent * pEvent)
	{
	QRect rcPaint = pEvent->rect();
	const int xPaintLeft = rcPaint.left();
	const int xPaintRight = rcPaint.right();
	const int yPaintBottom = rcPaint.bottom();
	Assert(xPaintLeft >= 0 && xPaintLeft <= m_cxDisplay);
	Assert(xPaintRight >= 0 && xPaintRight <= m_cxDisplay);
	Assert(yPaintBottom >= 0 && yPaintBottom <= m_cyDisplay);

	OPainter oPainter(viewport());

	if (m_cxWidthColumns == 0)
		_ColumnsRecalculateWidths();

	// Find the column to start drawing
	int cxSkip = m_xScrollStart + xPaintLeft;
	CGridColumn ** ppColumnStop;
	CGridColumn ** prgpColumns = m_arraypColumnsDisplay.PrgpGetColumnsStop(OUT &ppColumnStop);
	CGridColumn ** ppColumnStart = prgpColumns;
	while (ppColumnStart != ppColumnStop)
		{
		cxSkip -= ppColumnStart[0]->m_cxWidth;
		if (cxSkip <= 0)
			break;
		ppColumnStart++;
		} // while

	CString sText;
	if (m_cyHeightHeaderTop > 0)
		{
		//QRect rcHeader(0, 0, rcClient.width(), m_cy)
		oPainter.setPen(d_coGrayDark);
		oPainter.DrawLineHorizontal(xPaintLeft, xPaintRight, 0);
		oPainter.DrawLineHorizontal(xPaintLeft, xPaintRight, m_cyHeightHeaderTop);
		oPainter.DrawLineVertical(0, 0, m_cyHeightHeaderTop);

		// Draw the columns of the header
		CGridColumn ** ppColumn = ppColumnStart;
		int xLeft = 0;
		while (ppColumn != ppColumnStop)
			{
			CGridColumn * pColumn = *ppColumn++;
			sText.InitFromStringU(pColumn->m_strName);
			const int cxWidth = pColumn->m_cxWidth;
			oPainter.drawText(xLeft, 0, cxWidth, m_cyHeightHeaderTop, Qt::AlignHCenter | Qt::AlignVCenter, sText);

			// Display all the data for a column
			oPainter.setPen(d_coBlack);
			int yTop = m_cyHeightHeaderTop;
			PFn_GridCellGetText pfnGetText = pColumn->m_pfnGetText;
			if (pfnGetText != NULL)
				{
				CGridRow ** ppRowStop;
				CGridRow ** ppRow = m_arraypRowsDisplay.PrgpGetRowsStop(OUT &ppRowStop);
				while (ppRow != ppRowStop)
					{
					CGridRow * pRow = *ppRow++;
					sText = pfnGetText(pRow->m_pvDataRow, pColumn, eGridCellTextDisplay);
					if (!sText.isEmpty())
						{
						oPainter.drawText(xLeft + 2, yTop, cxWidth, m_cyHeightHeaderTop, Qt::AlignLeft | Qt::AlignVCenter, sText);
						yTop += m_cyHeightRow;
						if (yTop >= yPaintBottom)
							break;	// Don't draw the rows outside of the drawing area
						}
					} // while
				} // if

			xLeft += cxWidth;
			if (xLeft > xPaintRight)
				break;	// No need to draw anything outside of the drawing area
			oPainter.DrawLineVertical(xLeft, 0, m_cyHeightHeaderTop);
			} // while
		} // if

	// Draw the gridlines
	oPainter.setPen(d_coGrayDark);
	int yTop = m_cyHeightHeaderTop;
	while (yTop < yPaintBottom)
		{
		yTop += m_cyHeightRow;
		oPainter.DrawLineHorizontal(xPaintLeft, xPaintRight, yTop);
		}
	/*
	oPainter.setPen(d_coOrange);
	oPainter.drawText(rcClient, Qt::AlignHCenter | Qt::AlignVCenter, "Under Development");
	*/
	} // paintEvent()
Пример #19
0
// -- Function: Load Weapon -- //
TWeapon * TWeapon::loadWeapon(const CString& pWeapon, TServer *server)
{
	// File Path
	CString fileName = server->getServerPath() << "weapons/" << pWeapon;

	// Load File
	CString fileData;
	fileData.load(fileName);
	fileData.removeAllI("\r");

	// Grab some information.
	bool has_script = (fileData.find("SCRIPT") != -1 ? true : false);
	bool has_scriptend = (fileData.find("SCRIPTEND") != -1 ? true : false);
	bool found_scriptend = false;

	// Parse into lines.
	std::vector<CString> fileLines = fileData.tokenize("\n");
	if (fileLines.size() == 0 || fileLines[0].trim() != "GRAWP001")
		return 0;

	// Definitions
	CString weaponImage, weaponName, weaponScript;
	std::vector<std::pair<CString, CString> > byteCode;

	// Parse File
	std::vector<CString>::iterator i = fileLines.begin();
	while (i != fileLines.end())
	{
		// Find Command
		CString curCommand = i->readString();

		// Parse Line
		if (curCommand == "REALNAME")
			weaponName = i->readString("");
		else if (curCommand == "IMAGE")
			weaponImage = i->readString("");
		else if (curCommand == "BYTECODE")
		{
			CString fname = i->readString("");
			CString bytecode;
			bytecode.load(server->getServerPath() << "weapon_bytecode/" << fname);

			if (!bytecode.isEmpty())
				byteCode.push_back(std::pair<CString, CString>(fname, bytecode));
		}
		else if (curCommand == "SCRIPT")
		{
			++i;
			while (i != fileLines.end())
			{
				if (*i == "SCRIPTEND")
				{
					found_scriptend = true;
					break;
				}
				weaponScript << *i << "\xa7";
				++i;
			}
		}
		if (i != fileLines.end()) ++i;
	}

	// Valid Weapon Name?
	if (weaponName.isEmpty())
		return 0;

	// Give a warning if our weapon was malformed.
	if (has_scriptend && !found_scriptend)
	{
		server->getServerLog().out("[%s] WARNING: Weapon %s is malformed.\n", server->getName().text(), weaponName.text());
		server->getServerLog().out("[%s] SCRIPTEND needs to be on its own line.\n", server->getName().text());
	}

	// Give a warning if both a script and a bytecode was found.
	if (!weaponScript.isEmpty() && !byteCode.empty())
		server->getServerLog().out("[%s] WARNING: Weapon %s includes both script and bytecode.  Using bytecode.\n", server->getName().text(), weaponName.text());

	TWeapon* ret = new TWeapon(server, weaponName, weaponImage, weaponScript, 0);
	if (byteCode.size() != 0)
		ret->mByteCode = byteCode;

	return ret;
}