Ejemplo n.º 1
0
/*  ReadDataFromLine()   - Reads the Attribute and the Value from a passed line of text
    
    Parameters

        LPWSTR pwszLine         - Line to read
        BSTR * pbsAttrib        - Attribute NAME to return
        BSTR * pbsValue         - Value of the attribute
*/
HRESULT ReadDataFromLine(LPWSTR pwszLine,BSTR * pbsAttrib, BSTR * pbsValue)
{
    int x;
    int iLen = wcslen(pwszLine);    

    *pbsAttrib = NULL;
    *pbsValue  = NULL;

    // Remove any tabs still in the line:
    RemoveSpecialChars(pwszLine);
    
    // If this line is a comment or blank, bail..
    if (pwszLine[0] == L'/' || iLen == 0)
        return S_FALSE;
        
    // Make a temp string to save our string 
    LPWSTR pwszTempAttrib = new WCHAR [iLen +1];
	if ( !pwszTempAttrib )
		return E_FAIL;

    pwszTempAttrib[0]= NULL;

    for (x = 0; x< iLen; x++)
        switch(pwszLine[x])
        {
             case L' ':
             case L'\t':
             {
                // NULL terminate the copy we are building
                pwszTempAttrib[x] = L'\0';
                x++;
                goto DoneReadDataFromLine;  
                break;
             }
             case NULL:    // if we hit the end of the string- there is NOT a value there
             {
                wprintf(L"\n!!!Attribute missing value [%s]\n",pwszLine);
				delete [] pwszTempAttrib;
                return E_FAIL;
             }
             default:
             {
                pwszTempAttrib[x] = pwszLine[x];   
             }
        }

DoneReadDataFromLine:
    // Trim off any preceding spaces..
    Trim((LPWSTR)pwszLine +x);

    // Grab the END of the passed line, and put it in the 
    // Value BSTR
    *pbsValue = SysAllocString((LPWSTR)pwszLine +x);
    
    // Alloc a new BSTR to return for this attribute
    *pbsAttrib= SysAllocString(pwszTempAttrib);
    if (iLen)
        delete [] pwszTempAttrib ;   
    return S_OK;         
}
Ejemplo n.º 2
0
std::string ProcessSetName(const std::vector<std::string>& params, int sender_id)
{
	// Check params
	int p_id;
	std::string ch = CheckIDParams(params, &ProcessSetName, &p_id);
	if (ch.size() != 0)
		return ch;

	// Get the sender
	CServerConnection *sender = cServer->getClient(sender_id);
	if (!sender)
		return "Name could not be changed";

	// Check if we can change the name
	if (!sender->getRights()->NameChange && !sender->getRights()->Override)
		return "You don't have sufficient privileges to change user nick";

	// Get the name
	std::string name;
	for (std::vector<std::string>::const_iterator it = params.begin() + 2; it != params.end(); it++)  {
		name += *it;
		name += ' ';
	}
	name.erase(name.size() - 1);  // erase the last space

	name = RemoveSpecialChars(name); // Strip unicode characters
	if (name.size() > 32)  // Check if not too long
		name.erase(32, std::string::npos);

	// Get the target worm
	CWorm *tw = cServer->getWorms() + p_id;
	if (!tw->isUsed())
		return "The worm with specified ID does not exist";

	// Check no other user has this name
	CWorm *w = cServer->getWorms();
	for(int i=0; i < MAX_WORMS; i++, w++) {
		if(!w->isUsed())
			continue;
		if(!stringcasecmp(name, w->getName()) && w->getID() != p_id)
			return "Another player is already using this nick";
	}

	// Set the name
	std::string oldname = tw->getName();
	tw->setName(name);

	// Send the update
	cServer->UpdateWorm(tw);

	// Send the notification
	cServer->SendGlobalText(oldname + " is now known as " + name, TXT_NORMAL);

	return "";
}
Ejemplo n.º 3
0
std::string ProcessSetMyName(const std::vector<std::string>& params, int sender_id)
{
	// Check params
	if (params.size() < GetCommand(&ProcessSetMyName)->iMinParamCount)
		return "Not enough parameters";

	// Get the sender
	CServerConnection *sender = cServer->getClient(sender_id);
	if (!sender)
		return "Name could not be changed";

	// Check if we can change the name
	if (!sender->getRights()->NameChange && !tLXOptions->bAllowNickChange && !sender->getRights()->Override)
		return "You don't have sufficient privileges to change your nick";

	if(sender->getNumWorms() == 0)
		return "Your client doesn't have any worms";
	
	// Get the name
	std::string name;
	for (std::vector<std::string>::const_iterator it = params.begin(); it != params.end(); it++)  {
		if(it != params.begin()) name += ' ';
		name += *it;
	}

	name = RemoveSpecialChars(name); // Strip unicode characters
	if (name.size() > 32)  // Check if not too long
		name.erase(32, std::string::npos);

	// Check no other user has this name
	CWorm *w = cServer->getWorms();
	for(int i=0; i < MAX_WORMS; i++, w++) {
		if(!w->isUsed())
			continue;
		if(!stringcasecmp(name, w->getName()) && w->getID() != sender_id)
			return "Another player is already using this nick";
	}

	// Set the name
	std::string oldname = sender->getWorm(0)->getName();
	sender->getWorm(0)->setName(name);

	// Send the update
	cServer->UpdateWorm(sender->getWorm(0));

	// Send the notification
	cServer->SendGlobalText(oldname + " is now known as " + name, TXT_NORMAL);
	notes << "worm rename: " << sender->getWorm(0)->getID() << ":" << oldname << " renamed to " << sender->getWorm(0)->getName() << endl;
	
	return "";
}