Example #1
0
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum)
{
	CString message = Packet.ReadNT();
	if (message.at(0) == '/')
	{
		CString command = message.substr(1, message.find(" ")-1);
		if ((command.compare("list") == 0)||(command.compare("have") == 0))
		{
			if (command.compare("list") == 0)
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT(ListPlayers());
				SendNetPacket(clientNum, Reply);
			}
			else
			{
				message = "";
				message += Client[clientNum]->Player[0].name;
				if (Client[clientNum]->twoPlayers)
					message += "&";
				message += Client[clientNum]->Player[1].name;
				message += " forces has song.";
				Client[clientNum]->forceHas = true;
				ServerChat(message);
			}
		}
		else
		{
			if (clientNum == 0)
			{
				if (command.compare("force_start") == 0)
					ForceStart();
				if (command.compare("kick") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Kick(name);
				}
				if (command.compare("ban") == 0)
				{
					CString name = message.substr(message.find(" ")+1);
					Ban(name);
				}
			}
			else
			{
				Reply.ClearPacket();
				Reply.Write1(NSCCM + NSServerOffset);
				Reply.WriteNT("You do not have permission to use server commands.");
				SendNetPacket(clientNum, Reply);
			}
		}
	}
	else
		RelayChat(message, clientNum);
}
Example #2
0
bool getline(CString &_str, CString &line){
  if(_str.size()==0)  return false;
  CString::size_type pLeft=0, pRight = _str.find('\n');
  line = _str.substr( pLeft, pRight );
  _str = _str.erase(0,pRight+1);
  return true;
};
Example #3
0
void CFileTreeCtrl::setSelectedFullPath(const std::wstring &sPath)
{
    populate();

    SetRedraw(FALSE);
    SetCursor(LoadCursor(NULL, IDC_WAIT));

    SelectItem(m_hRoot);
    Expand(m_hRoot, TVE_EXPAND);

    // Traverse Tree
    HTREEITEM hItem = m_hRoot;
    HTREEITEM hChildItem;
    HTREEITEM hNextItem;

    std::vector<std::wstring> tokens;
    std::vector<std::wstring>::const_iterator iterToken;
    Utils::tokenize(sPath, tokens, L"\\/");

    CString sItemValue;
    for(iterToken = tokens.begin(); iterToken != tokens.end(); ++iterToken)
    {
        hChildItem = GetChildItem(hItem);

        while (hChildItem != NULL)
        {
            hNextItem = GetNextItem(hChildItem, TVGN_NEXT);

            std::wstring sItemValue = GetItemText(hChildItem);
            std::wstring::size_type pos = sItemValue.find(L"\\", 0);
            if(pos != std::wstring::npos)
                sItemValue.erase(pos);

            if(sItemValue == *iterToken)
            {
                break;
            }

            hChildItem = hNextItem;
        }

        hItem = hChildItem;

        if(hItem != NULL)
        {
            // Found a matching item, select it and force expansion to populate tree
            SelectItem(hItem);
            Expand(hItem, TVE_EXPAND);
        }
        else
        {
            // Didn't find a matching item
            break;
        }
    }

    SetCursor(LoadCursor (NULL, IDC_ARROW));
    SetRedraw(TRUE);
}
Example #4
0
File: User.cpp Project: johnfb/znc
bool CUser::SetStatusPrefix(const CString& s) {
	if ((!s.empty()) && (s.length() < 6) && (s.find(' ') == CString::npos)) {
		m_sStatusPrefix = (s.empty()) ? "*" : s;
		return true;
	}

	return false;
}
Example #5
0
void CClient::ParsePass(const CString& sAuthLine) {
    // [user[@identifier][/network]:]password

    const size_t uColon = sAuthLine.find(":");
    if (uColon != CString::npos) {
        m_sPass = sAuthLine.substr(uColon + 1);

        ParseUser(sAuthLine.substr(0, uColon));
    } else {
        m_sPass = sAuthLine;
    }
}
Example #6
0
File: log.cpp Project: sorbits/znc
bool CLogMod::OnLoad(const CString& sArgs, CString& sMessage)
{
	// Use load parameter as save path
	m_sLogPath = sArgs;

	// Add default filename to path if it's a folder
	if (GetType() == CModInfo::UserModule) {
		if (m_sLogPath.Right(1) == "/" || m_sLogPath.find("$WINDOW") == string::npos || m_sLogPath.find("$NETWORK") == string::npos) {
			if (!m_sLogPath.empty()) {
				m_sLogPath += "/";
			}
			m_sLogPath += "$NETWORK_$WINDOW_%Y%m%d.log";
		}
	} else if (GetType() == CModInfo::NetworkModule) {
		if (m_sLogPath.Right(1) == "/" || m_sLogPath.find("$WINDOW") == string::npos) {
			if (!m_sLogPath.empty()) {
				m_sLogPath += "/";
			}
			m_sLogPath += "$WINDOW_%Y%m%d.log";
		}
	} else {
		if (m_sLogPath.Right(1) == "/" || m_sLogPath.find("$USER") == string::npos || m_sLogPath.find("$WINDOW") == string::npos || m_sLogPath.find("$NETWORK") == string::npos) {
			if (!m_sLogPath.empty()) {
				m_sLogPath += "/";
			}
			m_sLogPath += "$USER_$NETWORK_$WINDOW_%Y%m%d.log";
		}
	}

	// Check if it's allowed to write in this path in general
	m_sLogPath = CDir::CheckPathPrefix(GetSavePath(), m_sLogPath);
	if (m_sLogPath.empty())
	{
		sMessage = "Invalid log path ["+m_sLogPath+"].";
		return false;
	} else {
		sMessage = "Logging to ["+m_sLogPath+"].";
		return true;
	}
}
Example #7
0
	void HandleMessage(CNick& Nick, const CString& sMessage) {
		CString sNickServName = (!GetNV("NickServName").empty()) ? GetNV("NickServName") : "NickServ";
		if (!GetNV("Password").empty()
				&& Nick.NickEquals(sNickServName)
				&& (sMessage.find("msg") != CString::npos
				 || sMessage.find("authenticate") != CString::npos
				 || sMessage.find("choose a different nickname") != CString::npos
				 || sMessage.find("please choose a different nick") != CString::npos
				 || sMessage.find("If this is your nick, identify yourself with") != CString::npos
				 || sMessage.find("If this is your nick, type") != CString::npos
				 || sMessage.find("This is a registered nickname, please identify") != CString::npos
				 || sMessage.StripControls_n().find("type /NickServ IDENTIFY password") != CString::npos)
				&& sMessage.AsUpper().find("IDENTIFY") != CString::npos
				&& sMessage.find("help") == CString::npos) {
			MCString msValues;
			msValues["password"] = GetNV("Password");
			PutIRC(CString::NamedFormat(GetNV("IdentifyCmd"), msValues));
		}
	}
Example #8
0
bool
CConfig::isValidScreenName(const CString& name) const
{
	// name is valid if matches validname
	//  name      ::= [_A-Za-z0-9] | [_A-Za-z0-9][-_A-Za-z0-9]*[_A-Za-z0-9]
	//  domain    ::= . name
	//  validname ::= name domain*

	// check each dot separated part
	CString::size_type b = 0;
	for (;;) {
		// find end of part
		CString::size_type e = name.find('.', b);
		if (e == CString::npos) {
			e = name.size();
		}

		// part may not be empty
		if (e - b < 1) {
			return false;
		}

		// check first and last characters
		if (!(isalnum(name[b]) || name[b] == '_') ||
			!(isalnum(name[e - 1]) || name[e - 1] == '_')) {
			return false;
		}

		// check interior characters
		for (CString::size_type i = b; i < e; ++i) {
			if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') {
				return false;
			}
		}

		// next part
		if (e == name.size()) {
			// no more parts
			break;
		}
		b = e + 1;
	}

	return true;
}
Example #9
0
File: Modules.cpp Project: md-5/znc
bool CModules::FindModPath(const CString& sModule, CString& sModPath,
		CString& sDataPath) {
	CString sMod = sModule;
	CString sDir = sMod;
	if (sModule.find(".") == CString::npos)
		sMod += ".so";

	ModDirList dirs = GetModDirs();

	while (!dirs.empty()) {
		sModPath = dirs.front().first + sMod;
		sDataPath = dirs.front().second;
		dirs.pop();

		if (CFile::Exists(sModPath)) {
			sDataPath += sDir;
			return true;
		}
	}

	return false;
}
Example #10
0
CString CChan::GetModeArg(CString& sArgs) const {
	CString sRet = sArgs.substr(0, sArgs.find(' '));
	sArgs = (sRet.size() < sArgs.size()) ? sArgs.substr(sRet.size() +1) : "";
	return sRet;
}
Example #11
0
//
// AT command handle
//
void at_command_handle(CStream *p_serial, CString &str) {
	str.makeUpper();

	// finds command with command list. and return the index of the command list, if found.
	switch( str.find(at_cmd_list, ATCMD_COUNT) ) {
	case 0: // set interval in millisecond.
		m_beacon.interval = str.parseInt(10);
		str = "OK\n";
		break;

	case 1: // get interval
		str.printf("%dms\n", m_beacon.interval);
		break;

	case 2: // set tx power
		m_beacon.tx_power =(BLE_TX_POWER_T) str.parseInt(9);
		str = "OK\n";
		break;

	case 3: // get tx power
		str.printf("%ddBm\n", m_beacon.tx_power);
		break;

	case 4:	// set company id
		m_beacon.company_id = str.parseHex(6);
		str = "OK\n";
		break;

	case 5:	// get company id
		str.printf("0x%04X\n", m_beacon.company_id);
		break;

	case 6:	// set major value
		msb_value_set(m_beacon.data.major, str.parseInt(7));
		str = "OK\n";
		break;

	case 7: // get major value
		str.printf("%d\n", msb_value_get(m_beacon.data.major));
		break;

	case 8: // set minor value
		msb_value_set(m_beacon.data.minor, str.parseInt(7));
		str = "OK\n";
		break;

	case 9:	// get minor value
		str.printf("%d\n", msb_value_get(m_beacon.data.minor));
		break;

	case 10:// set measure rssi
		m_beacon.data.meas_rssi = str.parseInt(6);
		str = "OK\n";
		break;

	case 11:// get measure rssi
		str.printf("%d\n", m_beacon.data.meas_rssi);
		break;

	case 12:// save
		m_p_sgBeacon->write(&m_beacon, sizeof(m_beacon));
		str = "OK\n";
		break;

	case 13:// reset
		system_reset();
		break;

	case 14:// goto DFU
		gotoDFU();
		break;

	default:// command not found
		str = "ERROR\n";
		break;
	}

	// response to stream
	p_serial->write(str.getBuffer(), str.length());
}
Example #12
0
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.
}
Example #13
0
bool CServer::IsValidHostName(const CString& sHostName) {
	return (!sHostName.empty() && (sHostName.find(' ') == CString::npos));
}
Example #14
0
void CChihlee::runAnalysis(const char *szInput, JSONObject &jsonResp)
{
	CFileHandler file;
	CString strWord = szInput;
	CResponsePacket respPacket;
	CString strText;
	CString strSound;
	CString strScreen;

	strWord.replace("笑訊", "校訓");
	strWord.replace("校去", "校訓");
	strWord.replace("治理", "致理");

	ofstream csWordFile("/chihlee/jetty/webapps/chihlee/Text.txt", ios::trunc);
	strText.format("%s\n          \n          ", szInput);
	csWordFile << strText.getBuffer() << endl;
	csWordFile.close();
	remove("/chihlee/jetty/webapps/chihlee/map.jpg");

	//=============== 校園導覽 =================================//
	if (0 <= strWord.find("導覽") || 0 <= strWord.find("地圖") || 0 <= strWord.find("參觀") || 0 <= strWord.find("校園"))
	{
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_1.wav";
		strScreen = "/chihlee/jetty/webapps/chihlee/img/map.jpg";
	}

	//=============== 廁所怎麼走 =================================//
	if (0 <= strWord.find("廁所") || 0 <= strWord.find("洗手間") || 0 <= strWord.find("大便") || 0 <= strWord.find("小便")
			|| 0 <= strWord.find("方便間"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_2.wav";
	}

	//=============== 我想找電動輪椅充電 =================================//
	if (0 <= strWord.find("電動輪椅") || 0 <= strWord.find("輪椅充電") || 0 <= strWord.find("充電") || 0 <= strWord.find("沒電"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_3.wav";
	}

	//=============== 圖書館怎麼走 =================================//
	if (0 <= strWord.find("圖書館") || 0 <= strWord.find("圖館") || 0 <= strWord.find("書館") || 0 <= strWord.find("看書"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/wc_map.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_4.wav";
	}

	//=============== 校訓 =================================//
	if (0 <= strWord.find("校訓") || 0 <= strWord.find("誠信") || 0 <= strWord.find("致理科大"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/motto.png";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_5.wav";
	}

	//=============== 吉祥物 =================================//
	if (0 <= strWord.find("吉祥物") || 0 <= strWord.find("喜鵲"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/character.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_6.wav";
	}

	//=============== 校歌 =================================//
	if (0 <= strWord.find("校歌") || 0 <= strWord.find("學生活動"))
	{
		strScreen = "/chihlee/jetty/webapps/chihlee/img/song.jpg";
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_7.wav";
	}

	//================ 謝謝你的解說=====================//
	if (0 <= strWord.find("謝謝") || 0 <= strWord.find("感謝") || 0 <= strWord.find("掰掰") || 0 <= strWord.find("拜拜")
			|| 0 <= strWord.find("謝啦") || 0 <= strWord.find("謝拉"))
	{
		remove("/chihlee/jetty/webapps/chihlee/map.jpg");
		strSound = "/chihlee/jetty/webapps/chihlee/wav/wav_8.wav";
	}

	file.copyFile(strScreen.getBuffer(), "/chihlee/jetty/webapps/chihlee/map.jpg");
	playSound(strSound.getBuffer());

	respPacket.setActivity<int>("type", RESP_TTS).setActivity<const char*>("lang", "zh").setActivity<const char*>("tts",
			"").format(jsonResp);
}