Clans privs

Deleting clans
New teleport icon
This commit is contained in:
jachoo 2011-10-16 00:12:37 +02:00
parent 0c5485108b
commit 72251ff000
14 changed files with 188 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 794 B

After

Width:  |  Height:  |  Size: 723 B

View File

@ -42,6 +42,8 @@ std::string privsToString(u64 privs)
os<<"shout,";
if(privs & PRIV_BAN)
os<<"ban,";
if(privs & PRIV_CLANS)
os<<"clans,";
if(os.tellp())
{
// Drop the trailing comma. (Why on earth can't
@ -74,6 +76,8 @@ u64 stringToPrivs(std::string str)
privs |= PRIV_SHOUT;
else if(s == "ban")
privs |= PRIV_BAN;
else if(s == "clans")
privs |= PRIV_CLANS;
else
return PRIV_INVALID;
}

View File

@ -39,6 +39,7 @@ const u64 PRIV_SERVER = 16; // Can manage the server (e.g. shutodwn
const u64 PRIV_SHOUT = 32; // Can broadcast chat messages to all
// players
const u64 PRIV_BAN = 64; // Can ban players
const u64 PRIV_CLANS = 128; // Can create clans
// Default privileges - these can be overriden for new players using the
// config option "default_privs" - however, this value still applies for

View File

@ -22,6 +22,14 @@ u16 ClansManager::newClan(const std::string& name, Player* player)
}
return id;
}
void ClansManager::deleteClan(u16 id)
{
if(!clanExists(id))return;
m_deleted.insert(id);
m_nameId.erase( clanNameNoEx(id) );
m_idName.erase(id);
}
bool ClansManager::clanExists(u16 id) const
{

View File

@ -26,18 +26,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h"
#include "utility.h"
#include "player.h"
//#include "player.h"
#include <map>
#include <set>
#include <string>
class Player;
class Settings;
class ClansManager {
public:
ClansManager();
u16 newClan(const std::string& name, Player* player);
void deleteClan(u16 id);
bool clanExists(u16 id) const;
bool clanExists(const std::string& name) const;
@ -54,8 +58,6 @@ public:
void save(Settings& args) const;
void load(Settings& args);
//serializacja - wysylanie
protected:
std::map<u16,std::string> m_idName;

View File

@ -1590,7 +1590,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
}
}
else if(command == TOCLIENT_PLAYER_GROUP) //j
else if(command == TOCLIENT_PLAYER_CLAN) //j
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
@ -1619,12 +1619,12 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
}
dstream<<"Client got TOCLIENT_PLAYER_GROUP - count="
dstream<<"Client got TOCLIENT_PLAYER_CLAN - count="
<< count
<<std::endl;
}
else if(command == TOCLIENT_GROUP_NAMES) //j
else if(command == TOCLIENT_CLAN_NAMES) //j
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
@ -1649,10 +1649,35 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
m_env.clansManager.setClan(id,name);
}
dstream<<"Client got TOCLIENT_GROUP_NAMES - count="
dstream<<"Client got TOCLIENT_CLAN_NAMES - count="
<< count
<<std::endl;
}
else if(command == TOCLIENT_CLAN_DELETED) //j
{
std::string datastring((char*)&data[2], datasize-2);
std::istringstream is(datastring, std::ios_base::binary);
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
/*
u16 command
u16 clan
*/
const u16 clan = readU16(is);
if(clan>0){
player->clans.erase(clan);
if(player->clanOwner == clan) player->clanOwner = 0;
m_env.clansManager.deleteClan(clan);
std::cout << "Clan " << clan << "deleted" << std::endl;
}
dstream<<"Client got TOCLIENT_CLAN_DELETED - clan="
<< clan
<<std::endl;
}
else
{
dout_client<<DTIME<<"WARNING: Client: Ignoring unknown command "

View File

@ -174,27 +174,33 @@ enum ToClientCommand
*/
TOCLIENT_PLAYER_GROUP = 0x37,
TOCLIENT_PLAYER_CLAN = 0x37,
/*
u16 command
u16 count
u8 bool kick
u16 group
u16 clan
...
*/
TOCLIENT_GROUP_NAMES = 0x38,
TOCLIENT_CLAN_NAMES = 0x38,
/*
u16 command
u16 count
u16 group id
u8 group name lenght
string group name
u16 clan id
u8 clan name lenght
string clan name
...
*/
TOCLIENT_CLAN_DELETED = 0x39,
/*
u16 command
u16 clan id
*/
};
enum ToServerCommand

View File

@ -1858,8 +1858,8 @@ void the_game(
ownershiptext += narrow_to_wide(clansManager->clanNameNoEx(block2_owner));
}
bool canModifyNeighbour = player->canModify(NULL,block2,NULL,NULL);
bool canModify = canModifyNeighbour && player->canModify(NULL,block,NULL,NULL);
bool canModifyNeighbour = player->canModify(&client.getEnv()->clansManager,NULL,block2,NULL,NULL);
bool canModify = canModifyNeighbour && player->canModify(&client.getEnv()->clansManager,NULL,block,NULL,NULL);
if(!canModify) ownershiptext += narrow_to_wide(std::string(" [X] "));

View File

@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodemetadata.h"
#include "staticobject.h"
#include "mapblock_nodemod.h"
#include "clans.h" //j
#ifndef SERVER
#include "mapblock_mesh.h"
#endif
@ -599,6 +600,12 @@ public:
{
return m_owner;
}
void actualizeOwner(const ClansManager* clansManager)
{
if(m_owner==0) return;
if(clansManager==NULL)return; //???
if(clansManager->clanDeleted(m_owner)) m_owner = 0;
}
/*

View File

@ -201,22 +201,29 @@ void Player::deSerialize(std::istream &is)
}
//j
static inline bool canModifyNoCheck(const Player* player, const MapBlock* block) {
inline bool canModifyNoCheck(const Player* player, const MapBlock* block) {
u16 owner = block->getOwner();
return owner == 0 || player->clans.find(owner) != player->clans.end();
}
static inline bool canModifyCheck(const Player* player, const MapBlock* block) {
inline bool canModifyCheck(const Player* player, const MapBlock* block) {
if(!player || !block) return false;
return canModifyNoCheck(player,block);
}
//j
bool Player::canModify(Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const
bool Player::canModify(const ClansManager* clansManager, Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const
{
if(block) return canModifyNoCheck(this,block);
if(block){
block->actualizeOwner(clansManager);
return canModifyNoCheck(this,block);
}
if(!map) return false;
if(nodepos) return canModifyCheck(this,map->getBlockNoCreateNoEx( getNodeBlockPos(*nodepos) ));
if(nodepos){
MapBlock* bl = map->getBlockNoCreateNoEx( getNodeBlockPos(*nodepos) );
if(bl) bl->actualizeOwner(clansManager);
return canModifyCheck(this,bl);
}
//if(node) return node->
return false;
}

View File

@ -161,7 +161,7 @@ public:
//j
std::set<int> clans;
u16 clanOwner;
bool canModify(Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const;
bool canModify(const ClansManager* clansManager, Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const;
protected:
char m_name[PLAYERNAME_SIZE];

View File

@ -2382,7 +2382,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
//j
if( !player->canModify(NULL,block,NULL,NULL) )
if( !player->canModify(&m_env.clansManager,NULL,block,NULL,NULL) )
{
derr_server<<"Player isn't owner of a block"<<std::endl;
return;
@ -2584,7 +2584,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
u16 item_i = readU16(&data[15]);
//j
if( !player->canModify(&m_env.getMap(),NULL,NULL,&p_under) || !player->canModify(&m_env.getMap(),NULL,NULL,&p_over) )
if( !player->canModify(&m_env.clansManager,&m_env.getMap(),NULL,NULL,&p_under) || !player->canModify(&m_env.clansManager,&m_env.getMap(),NULL,NULL,&p_over) )
{
derr_server<<"Player isn't owner of a block"<<std::endl;
RemoteClient *client = getClient(peer_id);
@ -3109,7 +3109,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
//j
if( !player->canModify(NULL,block,NULL,NULL) )
if( !player->canModify(&m_env.clansManager,NULL,block,NULL,NULL) )
{
derr_server<<"Player isn't owner of a block"<<std::endl;
return;
@ -3169,7 +3169,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(blockpos);
//j
if( !player->canModify(NULL,block,NULL,NULL) )
if( !player->canModify(&m_env.clansManager,NULL,block,NULL,NULL) )
{
derr_server<<"Player isn't owner of a block"<<std::endl;
return;
@ -3599,7 +3599,7 @@ Inventory* Server::getInventory(InventoryContext *c, std::string id)
p.Z = stoi(fn.next(","));
//j
if(!c->current_player->canModify(&m_env.getMap(),NULL,NULL,&p)){
if(!c->current_player->canModify(&m_env.clansManager,&m_env.getMap(),NULL,NULL,&p)){
dstream<<__FUNCTION_NAME<<": player isn't owner of the block "<<id<<std::endl;
return NULL;
}
@ -3993,13 +3993,13 @@ void Server::SendPlayerClan(Player *player, bool kick = false, u16 clan = 0)
u16 clan
...
*/
writeU16(os, TOCLIENT_PLAYER_GROUP);
writeU16(os, TOCLIENT_PLAYER_CLAN);
if(clan>0){
writeU16(os,1);
writeU8(os,kick);
writeU16(os,clan);
{
dstream<<"Server sending TOCLIENT_PLAYER_GROUP - "
dstream<<"Server sending TOCLIENT_PLAYER_CLAN - "
<< ((kick)?"KICK from ":"JOIN to ")
<< clan
<<std::endl;
@ -4054,12 +4054,12 @@ void Server::SendClanName(u16 peer_id, u16 clan, const std::string& name)
string clan name
...
*/
writeU16(os, TOCLIENT_GROUP_NAMES);
writeU16(os, TOCLIENT_CLAN_NAMES);
if(clan>0){
writeU16(os,1);
writeClanIdName(os,clan,name);
{
dstream<<"Server sending TOCLIENT_GROUP_NAMES - "
dstream<<"Server sending TOCLIENT_CLAN_NAMES - "
<< "id=" << clan
<< ", name=" << name
<<std::endl;
@ -4091,13 +4091,13 @@ void Server::SendClanNames(u16 peer_id, const std::map<u16,std::string>& clans)
if(count==0) return;
std::ostringstream os(std::ios_base::binary);
writeU16(os, TOCLIENT_GROUP_NAMES);
writeU16(os, TOCLIENT_CLAN_NAMES);
writeU16(os,count);
for(std::map<u16,std::string>::const_iterator it=clans.begin(); it!=clans.end(); it++)
writeClanIdName(os,it->first,it->second);
dstream<<"Server sending TOCLIENT_GROUP_NAMES - "
dstream<<"Server sending TOCLIENT_CLAN_NAMES - "
<< "count=" << count
<<std::endl;
@ -4125,6 +4125,46 @@ void Server::BroadcastPlayerClan(u16 clan, const std::string& name)
}
}
//j
void Server::SendClanDeleted(u16 peer_id, u16 clan)
{
DSTACK(__FUNCTION_NAME);
std::ostringstream os(std::ios_base::binary);
/*
u16 command
u16 clan id
*/
writeU16(os, TOCLIENT_CLAN_DELETED);
writeU16(os, clan);
dstream<<"Server sending TOCLIENT_CLAN_DELETED - "
<< "id=" << clan
<<std::endl;
// Make data buffer
std::string s = os.str();
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
// Send as reliable
m_con.Send(peer_id, 0, data, true);
}
//j
void Server::BroadcastClanDeleted(u16 clan)
{
for(core::map<u16, RemoteClient*>::Iterator
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
// Get client and check that it is valid
RemoteClient *client = i.getNode()->getValue();
assert(client->peer_id == i.getNode()->getKey());
if(client->serialization_version == SER_FMT_VER_INVALID)
continue;
SendClanDeleted(client->peer_id,clan);
}
}
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
core::list<u16> *far_players, float far_d_nodes)
{

View File

@ -431,6 +431,8 @@ public:
void SendClanName(u16 peer_id, u16 clan, const std::string& name); //j
void SendClanNames(u16 peer_id, const std::map<u16,std::string>& clans); //j
void BroadcastPlayerClan(u16 clan, const std::string& name); //j
void SendClanDeleted(u16 peer_id,u16 clan); //j
void BroadcastClanDeleted(u16 clan); //j
u64 getPlayerAuthPrivs(const std::string &name)
{

View File

@ -239,6 +239,12 @@ void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
void cmd_clanNew(std::wostringstream &os,
ServerCommandContext *ctx)
{
if((ctx->privs & PRIV_CLANS) == 0)
{
os<<L"-!- You don't have permission to do that";
return;
}
if(ctx->parms.size() != 2)
{
os<<L"-!- Bad parameter(s)";
@ -262,9 +268,46 @@ void cmd_clanNew(std::wostringstream &os,
else os<< L"-!- Error - clan '"<<ctx->parms[1]<<"' NOT added.";
}
//j
void cmd_clanDelete(std::wostringstream &os,
ServerCommandContext *ctx)
{
if((ctx->privs & PRIV_CLANS) == 0)
{
os<<L"-!- You don't have permission to do that";
return;
}
if(ctx->parms.size() != 2)
{
os<<L"-!- Bad parameter(s)";
return;
}
std::string clanName = wide_to_narrow(ctx->parms[1]);
u16 clanId = ctx->env->clansManager.clanId(clanName);
if(!clanId || clanId != ctx->player->clanOwner){
os<< L"-!- Error - only clan's admin may delete it!";
return;
}
ctx->env->clansManager.deleteClan(clanId);
ctx->player->clanOwner = 0; //only clan owner can exec this func
ctx->server->BroadcastClanDeleted(clanId);
os<< L"-!- Clan '"<<ctx->parms[1]<<"' deleted.";
}
void cmd_clanJoin(std::wostringstream &os,
ServerCommandContext *ctx)
{
if((ctx->privs & PRIV_CLANS) == 0)
{
os<<L"-!- You don't have permission to do that";
return;
}
if(ctx->parms.size() != 3)
{
os<<L"-!- Missing parameter(s)";
@ -303,6 +346,12 @@ void cmd_clanJoin(std::wostringstream &os,
void cmd_clanKick(std::wostringstream &os,
ServerCommandContext *ctx)
{
if((ctx->privs & PRIV_CLANS) == 0)
{
os<<L"-!- You don't have permission to do that";
return;
}
if(ctx->parms.size() != 3)
{
os<<L"-!- Missing parameter(s)";
@ -398,10 +447,14 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
{
cmd_me(os, ctx);
}
else if(ctx->parms[0] == L"clan-new")
else if(ctx->parms[0] == L"clan-new")
{
cmd_clanNew(os, ctx);
}
else if(ctx->parms[0] == L"clan-delete")
{
cmd_clanDelete(os, ctx);
}
else if(ctx->parms[0] == L"clan-join")
{
cmd_clanJoin(os, ctx);