Esempio n. 1
0
void cmd_privs(std::wostringstream &os,
               ServerCommandContext *ctx)
{
    if(ctx->parms.size() == 1)
    {
        // Show our own real privs, without any adjustments
        // made for admin status
        os<<L"-!- " + narrow_to_wide(privsToString(
                                         ctx->server->getPlayerAuthPrivs(ctx->player->getName())));
        return;
    }

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

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

    os<<L"-!- " + narrow_to_wide(privsToString(ctx->server->getPlayerAuthPrivs(tp->getName())));
}
Esempio n. 2
0
void AuthManager::save()
{
	JMutexAutoLock lock(m_mutex);
	
	dstream<<"AuthManager: saving to "<<m_authfilepath<<std::endl;
	std::ofstream os(m_authfilepath.c_str(), std::ios::binary);
	if(os.good() == false)
	{
		dstream<<"AuthManager: failed saving to "<<m_authfilepath<<std::endl;
		throw SerializationError("AuthManager::save(): Couldn't open file");
	}
	
	for(core::map<std::string, AuthData>::Iterator
			i = m_authdata.getIterator();
			i.atEnd()==false; i++)
	{
		std::string name = i.getNode()->getKey();
		if(name == "")
			continue;
		AuthData ad = i.getNode()->getValue();
		os<<name<<":"<<ad.pwd<<":"<<privsToString(ad.privs)<<"\n";
	}

	m_modified = false;
}
Esempio n. 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;
	else
		privs &= ~newprivs;
	
	ctx->server->setPlayerAuthPrivs(playername, privs);
	
	os<<L"-!- Privileges change to ";
	os<<narrow_to_wide(privsToString(privs));
}
Esempio n. 4
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));
}