Beispiel #1
0
void AuthManager::load()
{
	JMutexAutoLock lock(m_mutex);
	
	dstream<<"AuthManager: loading from "<<m_authfilepath<<std::endl;
	std::ifstream is(m_authfilepath.c_str(), std::ios::binary);
	if(is.good() == false)
	{
		dstream<<"AuthManager: failed loading from "<<m_authfilepath<<std::endl;
		throw SerializationError("AuthManager::load(): Couldn't open file");
	}

	for(;;)
	{
		if(is.eof() || is.good() == false)
			break;

		// Read a line
		std::string line;
		std::getline(is, line, '\n');

		std::istringstream iss(line);
		
		// Read name
		std::string name;
		std::getline(iss, name, ':');

		// Read password
		std::string pwd;
		std::getline(iss, pwd, ':');

		// Read privileges
		std::string stringprivs;
		std::getline(iss, stringprivs, ':');
		u64 privs = stringToPrivs(stringprivs);
		
		// Store it
		AuthData ad;
		ad.pwd = pwd;
		ad.privs = privs;
		m_authdata[name] = ad;
	}

	m_modified = false;
}
void cmd_grantrevoke(std::wostringstream &os,
	ServerCommandContext *ctx)
{
	if(ctx->parms.size() != 3)
	{
		os<<L"-!- Missing parameter";
		return;
	}

	if((ctx->privs & PRIV_PRIVS) == 0)
	{
		os<<L"-!- You don't have permission to do that";
		return;
	}

	u64 newprivs = stringToPrivs(wide_to_narrow(ctx->parms[2]));
	if(newprivs == PRIV_INVALID)
	{
		os<<L"-!- Invalid privileges specified";
		return;
	}

	Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
	if(tp == NULL)
	{
		os<<L"-!- No such player";
		return;
	}
	
	std::string playername = wide_to_narrow(ctx->parms[1]);
	u64 privs = ctx->server->getPlayerAuthPrivs(playername);

	if(ctx->parms[0] == L"grant")
		privs |= newprivs;
	else
		privs &= ~newprivs;
	
	ctx->server->setPlayerAuthPrivs(playername, privs);
	
	os<<L"-!- Privileges change to ";
	os<<narrow_to_wide(privsToString(privs));
}
Beispiel #3
0
void cmd_grantrevoke(std::wostringstream &os,
                     ServerCommandContext *ctx)
{
    if(ctx->parms.size() != 3)
    {
        os<<L"-!- Missing parameter";
        return;
    }

    if((ctx->privs & PRIV_PRIVS) == 0)
    {
        os<<L"-!- You don't have permission to do that";
        return;
    }

    u64 newprivs = stringToPrivs(wide_to_narrow(ctx->parms[2]));
    if(newprivs == PRIV_INVALID)
    {
        os<<L"-!- Invalid privileges specified";
        return;
    }

    Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
    if(tp == NULL)
    {
        os<<L"-!- No such player";
        return;
    }

    std::string playername = wide_to_narrow(ctx->parms[1]);
    u64 privs = ctx->server->getPlayerAuthPrivs(playername);

    if(ctx->parms[0] == L"grant") {
        privs |= newprivs;
        actionstream<<ctx->player->getName()<<" grants "
                    <<wide_to_narrow(ctx->parms[2])<<" to "
                    <<playername<<std::endl;

        std::wstring msg;
        msg += narrow_to_wide(ctx->player->getName());
        msg += L" granted you the privilege \"";
        msg += ctx->parms[2];
        msg += L"\"";
        ctx->server->notifyPlayer(playername.c_str(), msg);
    } else {
        privs &= ~newprivs;
        actionstream<<ctx->player->getName()<<" revokes "
                    <<wide_to_narrow(ctx->parms[2])<<" from "
                    <<playername<<std::endl;

        std::wstring msg;
        msg += narrow_to_wide(ctx->player->getName());
        msg += L" revoked from you the privilege \"";
        msg += ctx->parms[2];
        msg += L"\"";
        ctx->server->notifyPlayer(playername.c_str(), msg);
    }

    ctx->server->setPlayerAuthPrivs(playername, privs);

    os<<L"-!- Privileges change to ";
    os<<narrow_to_wide(privsToString(privs));
}