Merge from celeron, many new features and bugs fixed
This commit is contained in:
parent
0d367550bc
commit
b8c0827434
@ -44,6 +44,8 @@ std::string privsToString(u64 privs)
|
|||||||
os<<"ban,";
|
os<<"ban,";
|
||||||
if(privs & PRIV_CLANS)
|
if(privs & PRIV_CLANS)
|
||||||
os<<"clans,";
|
os<<"clans,";
|
||||||
|
if(privs & PRIV_CLANS_ADMIN)
|
||||||
|
os<<"clans_admin,";
|
||||||
if(os.tellp())
|
if(os.tellp())
|
||||||
{
|
{
|
||||||
// Drop the trailing comma. (Why on earth can't
|
// Drop the trailing comma. (Why on earth can't
|
||||||
@ -78,6 +80,8 @@ u64 stringToPrivs(std::string str)
|
|||||||
privs |= PRIV_BAN;
|
privs |= PRIV_BAN;
|
||||||
else if(s == "clans")
|
else if(s == "clans")
|
||||||
privs |= PRIV_CLANS;
|
privs |= PRIV_CLANS;
|
||||||
|
else if(s == "clans_admin")
|
||||||
|
privs |= PRIV_CLANS_ADMIN;
|
||||||
else
|
else
|
||||||
return PRIV_INVALID;
|
return PRIV_INVALID;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ const u64 PRIV_SERVER = 16; // Can manage the server (e.g. shutodwn
|
|||||||
const u64 PRIV_SHOUT = 32; // Can broadcast chat messages to all
|
const u64 PRIV_SHOUT = 32; // Can broadcast chat messages to all
|
||||||
// players
|
// players
|
||||||
const u64 PRIV_BAN = 64; // Can ban players
|
const u64 PRIV_BAN = 64; // Can ban players
|
||||||
const u64 PRIV_CLANS = 128; // Can create clans
|
const u64 PRIV_CLANS = 128; // Can create clans
|
||||||
|
const u64 PRIV_CLANS_ADMIN = 256; // Can delete clans
|
||||||
|
|
||||||
// Default privileges - these can be overriden for new players using the
|
// Default privileges - these can be overriden for new players using the
|
||||||
// config option "default_privs" - however, this value still applies for
|
// config option "default_privs" - however, this value still applies for
|
||||||
|
105
src/clans.cpp
105
src/clans.cpp
@ -36,8 +36,7 @@ u16 ClansManager::newClan(const std::string& name, Player* player)
|
|||||||
if(clanExists(name)) return 0;
|
if(clanExists(name)) return 0;
|
||||||
if(m_maxId == 0xFFFF) return 0; //j: szukanie jakiegos wolnego?
|
if(m_maxId == 0xFFFF) return 0; //j: szukanie jakiegos wolnego?
|
||||||
u16 id = ++m_maxId;
|
u16 id = ++m_maxId;
|
||||||
m_idName[id] = name;
|
setClan(id,name,false);
|
||||||
m_nameId[name] = id;
|
|
||||||
if(player){
|
if(player){
|
||||||
player->clanOwner = id;
|
player->clanOwner = id;
|
||||||
player->clans.insert(id);
|
player->clans.insert(id);
|
||||||
@ -49,18 +48,18 @@ void ClansManager::deleteClan(u16 id)
|
|||||||
{
|
{
|
||||||
if(!clanExists(id))return;
|
if(!clanExists(id))return;
|
||||||
m_deleted.insert(id);
|
m_deleted.insert(id);
|
||||||
m_nameId.erase( clanNameNoEx(id) );
|
m_names.erase( clanNameNoEx(id) );
|
||||||
m_idName.erase(id);
|
m_ids.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClansManager::clanExists(u16 id) const
|
bool ClansManager::clanExists(u16 id) const
|
||||||
{
|
{
|
||||||
return m_idName.find(id) != m_idName.end();
|
return m_ids.find(id) != m_ids.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClansManager::clanExists(const std::string& name) const
|
bool ClansManager::clanExists(const std::string& name) const
|
||||||
{
|
{
|
||||||
return m_nameId.find(name) != m_nameId.end();
|
return m_names.find(name) != m_names.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClansManager::clanDeleted(u16 id) const
|
bool ClansManager::clanDeleted(u16 id) const
|
||||||
@ -70,16 +69,16 @@ bool ClansManager::clanDeleted(u16 id) const
|
|||||||
|
|
||||||
u16 ClansManager::clanId(const std::string& name) const
|
u16 ClansManager::clanId(const std::string& name) const
|
||||||
{
|
{
|
||||||
std::map<std::string,u16>::const_iterator it = m_nameId.find(name);
|
std::map<std::string,Clan*>::const_iterator it = m_names.find(name);
|
||||||
if(it==m_nameId.end()) return 0;
|
if(it==m_names.end()) return 0;
|
||||||
return it->second;
|
return it->second->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& ClansManager::clanName(u16 id) const
|
const std::string& ClansManager::clanName(u16 id) const
|
||||||
{
|
{
|
||||||
std::map<u16,std::string>::const_iterator it = m_idName.find(id);
|
std::map<u16,Clan>::const_iterator it = m_ids.find(id);
|
||||||
if(it==m_idName.end()) throw BaseException("Clan doesn't exist");
|
if(it==m_ids.end()) throw BaseException("Clan doesn't exist");
|
||||||
return it->second;
|
return it->second.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& ClansManager::clanNameNoEx(u16 id) const
|
const std::string& ClansManager::clanNameNoEx(u16 id) const
|
||||||
@ -92,33 +91,41 @@ const std::string& ClansManager::clanNameNoEx(u16 id) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<u16,std::string>& ClansManager::getNames() const
|
const std::map<u16,Clan>& ClansManager::getClans() const
|
||||||
{
|
{
|
||||||
return m_idName;
|
return m_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClansManager::setClan(u16 id, const std::string& name)
|
const std::set<u16>& ClansManager::getDeleted() const
|
||||||
{
|
{
|
||||||
m_idName[id] = name;
|
return m_deleted;
|
||||||
m_nameId[name] = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ClansManager::save(Settings& args) const
|
void ClansManager::save(Settings& args) const
|
||||||
{
|
{
|
||||||
args.setS32("clans-maxId",m_maxId);
|
args.setS32("clans-maxId",m_maxId);
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
for(std::map<u16,std::string>::const_iterator it=m_idName.begin(); it!=m_idName.end(); it++){
|
for(std::map<u16,Clan>::const_iterator it=m_ids.begin(); it!=m_ids.end(); it++){
|
||||||
os << it->first << ' ' << it->second << ' ';
|
os << it->first << ' ' << it->second.name << ' ';
|
||||||
}
|
}
|
||||||
args.set("clans-names",os.str());
|
args.set("clans-names",os.str());
|
||||||
|
|
||||||
std::ostringstream os2;
|
std::ostringstream os2;
|
||||||
for(std::set<u16>::const_iterator it=m_deleted.begin(); it!=m_deleted.end(); it++){
|
for(std::map<u16,Clan>::const_iterator it=m_ids.begin(); it!=m_ids.end(); it++){
|
||||||
os2 << *it << ' ';
|
if(!it->second.hasSpawnPoint) continue;
|
||||||
|
os2 << it->first << ' '
|
||||||
|
<< it->second.spawnPoint.X << ' '
|
||||||
|
<< it->second.spawnPoint.Y << ' '
|
||||||
|
<< it->second.spawnPoint.Z << ' ';
|
||||||
}
|
}
|
||||||
args.set("clans-deleted",os2.str());
|
args.set("clans-spawn",os2.str());
|
||||||
|
|
||||||
|
std::ostringstream os3;
|
||||||
|
for(std::set<u16>::const_iterator it=m_deleted.begin(); it!=m_deleted.end(); it++){
|
||||||
|
os3 << *it << ' ';
|
||||||
|
}
|
||||||
|
args.set("clans-deleted",os3.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClansManager::load(Settings& args)
|
void ClansManager::load(Settings& args)
|
||||||
@ -133,8 +140,22 @@ void ClansManager::load(Settings& args)
|
|||||||
std::string name;
|
std::string name;
|
||||||
is >> id >> name;
|
is >> id >> name;
|
||||||
if(id == 0 || name.length() == 0) continue;
|
if(id == 0 || name.length() == 0) continue;
|
||||||
m_idName[id] = name;
|
setClan(id,name,false);
|
||||||
m_nameId[name] = id;
|
}
|
||||||
|
|
||||||
|
if(args.exists("clans-spawn")){
|
||||||
|
s = args.get("clans-spawn");
|
||||||
|
std::istringstream is3(s);
|
||||||
|
while(is3.good() && !is3.eof()){
|
||||||
|
u16 id;
|
||||||
|
v3f spawn;
|
||||||
|
is3 >> id >> spawn.X >> spawn.Y >> spawn.Z;
|
||||||
|
if(id == 0) continue;
|
||||||
|
Clan* clan = getClan(id);
|
||||||
|
if(!clan) continue;
|
||||||
|
clan->hasSpawnPoint = true;
|
||||||
|
clan->spawnPoint = spawn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s = args.get("clans-deleted");
|
s = args.get("clans-deleted");
|
||||||
@ -143,15 +164,45 @@ void ClansManager::load(Settings& args)
|
|||||||
u16 id;
|
u16 id;
|
||||||
is2 >> id;
|
is2 >> id;
|
||||||
if(id == 0 ) continue;
|
if(id == 0 ) continue;
|
||||||
|
deleteClan(id);
|
||||||
m_deleted.insert(id);
|
m_deleted.insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(...){
|
}catch(...){
|
||||||
//TODO: what to do?
|
//TODO: what to do?
|
||||||
m_maxId = 0;
|
m_maxId = 0;
|
||||||
m_idName.clear();
|
m_names.clear();
|
||||||
m_nameId.clear();
|
m_ids.clear();
|
||||||
m_deleted.clear();
|
m_deleted.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Clan* ClansManager::getClan(u16 id)
|
||||||
|
{
|
||||||
|
std::map<u16,Clan>::iterator it = m_ids.find(id);
|
||||||
|
if(it==m_ids.end()) return NULL;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Clan* ClansManager::getClan(u16 id) const
|
||||||
|
{
|
||||||
|
std::map<u16,Clan>::const_iterator it = m_ids.find(id);
|
||||||
|
if(it==m_ids.end()) return NULL;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClansManager::setClan(u16 id, const std::string& name, bool hasSpawnPoint, v3f spawnPoint)
|
||||||
|
{
|
||||||
|
Clan& clan = m_ids[id];
|
||||||
|
clan.name = name;
|
||||||
|
clan.id = id;
|
||||||
|
clan.hasSpawnPoint = hasSpawnPoint;
|
||||||
|
clan.spawnPoint = spawnPoint;
|
||||||
|
m_names[name] = &clan;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClansManager::addDeleted(u16 id)
|
||||||
|
{
|
||||||
|
m_deleted.insert(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
26
src/clans.h
26
src/clans.h
@ -35,6 +35,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
class Player;
|
class Player;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
|
||||||
|
struct Clan {
|
||||||
|
u16 id;
|
||||||
|
std::string name;
|
||||||
|
v3f spawnPoint;
|
||||||
|
bool hasSpawnPoint;
|
||||||
|
|
||||||
|
Clan():id(0),name("?"),spawnPoint(0,0,0),hasSpawnPoint(false){}
|
||||||
|
|
||||||
|
inline void deleteSpawnPoint(){hasSpawnPoint=false;}
|
||||||
|
inline void setSpawnPoint(const v3f& pos){spawnPoint=pos;hasSpawnPoint=true;}
|
||||||
|
};
|
||||||
|
|
||||||
class ClansManager {
|
class ClansManager {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -51,17 +63,23 @@ public:
|
|||||||
u16 clanId(const std::string& name) const;
|
u16 clanId(const std::string& name) const;
|
||||||
const std::string& clanName(u16 id) const; //throws if not existing clan
|
const std::string& clanName(u16 id) const; //throws if not existing clan
|
||||||
const std::string& clanNameNoEx(u16 id) const;
|
const std::string& clanNameNoEx(u16 id) const;
|
||||||
|
|
||||||
|
Clan* getClan(u16 id);
|
||||||
|
const Clan* getClan(u16 id) const;
|
||||||
|
|
||||||
const std::map<u16,std::string>& getNames() const;
|
const std::map<u16,Clan>& getClans() const;
|
||||||
void setClan(u16 id, const std::string& name);
|
const std::set<u16>& getDeleted() const;
|
||||||
|
|
||||||
|
void setClan(u16 id, const std::string& name, bool hasSpawnPoint, v3f spawnPoint = v3f());
|
||||||
|
void addDeleted(u16 id);
|
||||||
|
|
||||||
void save(Settings& args) const;
|
void save(Settings& args) const;
|
||||||
void load(Settings& args);
|
void load(Settings& args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::map<u16,std::string> m_idName;
|
std::map<u16,Clan> m_ids;
|
||||||
std::map<std::string,u16> m_nameId;
|
std::map<std::string,Clan*> m_names;
|
||||||
std::set<u16> m_deleted;
|
std::set<u16> m_deleted;
|
||||||
u16 m_maxId;
|
u16 m_maxId;
|
||||||
|
|
||||||
|
@ -1544,13 +1544,53 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
std::string name;
|
std::string name;
|
||||||
for(u8 j=0; j<len; j++)
|
for(u8 j=0; j<len; j++)
|
||||||
name += (char)readU8(is);
|
name += (char)readU8(is);
|
||||||
m_env.clansManager.setClan(id,name);
|
m_env.clansManager.setClan(id,name,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
dstream<<"Client got TOCLIENT_CLAN_NAMES - count="
|
dstream<<"Client got TOCLIENT_CLAN_NAMES - count="
|
||||||
<< count
|
<< count
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
}
|
}
|
||||||
|
else if(command == TOCLIENT_CLANS) //j
|
||||||
|
{
|
||||||
|
std::string datastring((char*)&data[2], datasize-2);
|
||||||
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
|
/*
|
||||||
|
u16 command
|
||||||
|
u16 count
|
||||||
|
|
||||||
|
u16 clan id
|
||||||
|
u8 clan name lenght (NOTE: if = 0 -> clan is deleted!!!)
|
||||||
|
string clan name
|
||||||
|
#v3f1000 clan spawn point (NOTE: if > X 32000 -> spawn point not set!)
|
||||||
|
|
||||||
|
...
|
||||||
|
*/
|
||||||
|
|
||||||
|
const u16 count = readU16(is);
|
||||||
|
for(u16 i=0; i<count; i++){
|
||||||
|
u16 id = readU16(is);
|
||||||
|
u8 len = readU8(is);
|
||||||
|
if(len>0){
|
||||||
|
std::string name;
|
||||||
|
for(u8 j=0; j<len; j++)
|
||||||
|
name += (char)readU8(is);
|
||||||
|
m_env.clansManager.setClan(id,name,false);
|
||||||
|
}else{
|
||||||
|
//clan deleted
|
||||||
|
m_env.clansManager.deleteClan(id);
|
||||||
|
m_env.clansManager.addDeleted(id);
|
||||||
|
}
|
||||||
|
/*v3f spawn = readV3F1000(is);
|
||||||
|
if(spawn.X > 32000) m_env.clansManager.getClan(id)->deleteSpawnPoint();
|
||||||
|
else m_env.clansManager.getClan(id)->setSpawnPoint(spawn);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
dstream<<"Client got TOCLIENT_CLANS - count="
|
||||||
|
<< count
|
||||||
|
<<std::endl;
|
||||||
|
}
|
||||||
else if(command == TOCLIENT_CLAN_DELETED) //j
|
else if(command == TOCLIENT_CLAN_DELETED) //j
|
||||||
{
|
{
|
||||||
std::string datastring((char*)&data[2], datasize-2);
|
std::string datastring((char*)&data[2], datasize-2);
|
||||||
@ -1576,6 +1616,27 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
<< clan
|
<< clan
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
}
|
}
|
||||||
|
else if(command == TOCLIENT_CLAN_SPAWNPOINT) //j
|
||||||
|
{
|
||||||
|
std::string datastring((char*)&data[2], datasize-2);
|
||||||
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
|
/*
|
||||||
|
u16 command
|
||||||
|
u16 clan id
|
||||||
|
v3f1000 clan spawn point X,Y,Z (NOTE: if X > 32000 -> spawn point not set!)
|
||||||
|
*/
|
||||||
|
|
||||||
|
const u16 clan = readU16(is);
|
||||||
|
if(clan>0 && m_env.clansManager.clanExists(clan)){
|
||||||
|
v3f spawn = readV3F1000(is);
|
||||||
|
if(spawn.X > 32000) m_env.clansManager.getClan(clan)->deleteSpawnPoint();
|
||||||
|
else m_env.clansManager.getClan(clan)->setSpawnPoint(spawn);
|
||||||
|
}
|
||||||
|
|
||||||
|
dstream<<"Client got TOCLIENT_SPAWNPOINT"
|
||||||
|
<<std::endl;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
infostream<<"Client: Ignoring unknown command "
|
infostream<<"Client: Ignoring unknown command "
|
||||||
|
@ -214,11 +214,33 @@ enum ToClientCommand
|
|||||||
u16 command
|
u16 command
|
||||||
u16 clan id
|
u16 clan id
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
TOCLIENT_CLANS = 0x3B,
|
||||||
|
/*
|
||||||
|
u16 command
|
||||||
|
u16 count
|
||||||
|
|
||||||
|
u16 clan id
|
||||||
|
u8 clan name lenght (NOTE: if = 0 -> clan is deleted!!!)
|
||||||
|
string clan name
|
||||||
|
#v3f1000 clan spawn point X,Y,Z (NOTE: if X > 32000 -> spawn point not set!)
|
||||||
|
|
||||||
|
...
|
||||||
|
*/
|
||||||
|
|
||||||
|
TOCLIENT_CLAN_SPAWNPOINT = 0x3C,
|
||||||
|
/*
|
||||||
|
u16 command
|
||||||
|
u16 clan id
|
||||||
|
v3f1000 clan spawn point X,Y,Z (NOTE: if X > 32000 -> spawn point not set!)
|
||||||
|
*/
|
||||||
#else //def CELERON55_COMPATIBLE
|
#else //def CELERON55_COMPATIBLE
|
||||||
TOCLIENT_DEATHSCREEN = 0x3A,
|
TOCLIENT_DEATHSCREEN = 0x3A,
|
||||||
TOCLIENT_PLAYER_CLAN = 0x37,
|
TOCLIENT_PLAYER_CLAN = 0x37,
|
||||||
TOCLIENT_CLAN_NAMES = 0x38,
|
TOCLIENT_CLAN_NAMES = 0x38,
|
||||||
TOCLIENT_CLAN_DELETED = 0x39,
|
TOCLIENT_CLAN_DELETED = 0x39,
|
||||||
|
TOCLIENT_CLANS = 0x3B,
|
||||||
|
TOCLIENT_CLAN_SPAWNPOINT = 0x3C,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1069,6 +1069,13 @@ static void explodeSquare(Map *map, v3s16 p0, v3s16 size)
|
|||||||
MapNode n = map->getNodeNoEx(p);
|
MapNode n = map->getNodeNoEx(p);
|
||||||
if(n.getContent() == CONTENT_IGNORE)
|
if(n.getContent() == CONTENT_IGNORE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//j
|
||||||
|
//disallow mobs to destroy clans' terrain
|
||||||
|
MapBlock* block = map->getBlockNoCreateNoEx( getNodeBlockPos(p) );
|
||||||
|
if(!block || block->getOwner() != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
//map->removeNodeWithEvent(p);
|
//map->removeNodeWithEvent(p);
|
||||||
map->removeNodeAndUpdate(p, modified_blocks);
|
map->removeNodeAndUpdate(p, modified_blocks);
|
||||||
}
|
}
|
||||||
|
@ -1759,6 +1759,9 @@ void the_game(
|
|||||||
u16 block_owner = block ? block->getOwner() : 0;
|
u16 block_owner = block ? block->getOwner() : 0;
|
||||||
u16 block2_owner = block2 ? block2->getOwner() : 0;
|
u16 block2_owner = block2 ? block2->getOwner() : 0;
|
||||||
|
|
||||||
|
bool canModifyNeighbour = player->canModify(&client.getEnv()->clansManager,NULL,block2,NULL,NULL);
|
||||||
|
bool canModify = canModifyNeighbour && player->canModify(&client.getEnv()->clansManager,NULL,block,NULL,NULL);
|
||||||
|
|
||||||
if(block_owner || block2_owner )
|
if(block_owner || block2_owner )
|
||||||
ownershiptext = L"Property of clan ";
|
ownershiptext = L"Property of clan ";
|
||||||
|
|
||||||
@ -1770,9 +1773,6 @@ void the_game(
|
|||||||
ownershiptext += narrow_to_wide(clansManager->clanNameNoEx(block2_owner));
|
ownershiptext += narrow_to_wide(clansManager->clanNameNoEx(block2_owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
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] "));
|
if(!canModify) ownershiptext += narrow_to_wide(std::string(" [X] "));
|
||||||
|
|
||||||
//jTODO: remove it
|
//jTODO: remove it
|
||||||
|
104
src/player.cpp
104
src/player.cpp
@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <ITextSceneNode.h>
|
#include <ITextSceneNode.h>
|
||||||
#endif
|
#endif
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "content_mapnode.h"
|
||||||
|
#include "content_nodemeta.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -118,12 +120,20 @@ void Player::serialize(std::ostream &os)
|
|||||||
args.setV3F("position", m_position);
|
args.setV3F("position", m_position);
|
||||||
args.setBool("craftresult_is_preview", craftresult_is_preview);
|
args.setBool("craftresult_is_preview", craftresult_is_preview);
|
||||||
args.setS32("hp", hp);
|
args.setS32("hp", hp);
|
||||||
//j
|
|
||||||
|
//j CLANS
|
||||||
|
|
||||||
|
args.setS32("clanOwner",clanOwner);
|
||||||
|
|
||||||
std::ostringstream clansStrStream;
|
std::ostringstream clansStrStream;
|
||||||
for(std::set<int>::const_iterator it=clans.begin(); it!=clans.end(); it++)
|
for(std::set<u16>::const_iterator it=clans.begin(); it!=clans.end(); it++)
|
||||||
clansStrStream << *it << ' ';
|
clansStrStream << *it << ' ';
|
||||||
args.set("clans",clansStrStream.str());
|
args.set("clans",clansStrStream.str());
|
||||||
args.setS32("clanOwner",clanOwner);
|
|
||||||
|
std::ostringstream clansModeratorStrStream;
|
||||||
|
for(std::set<u16>::const_iterator it=clansModerator.begin(); it!=clansModerator.end(); it++)
|
||||||
|
clansModeratorStrStream << *it << ' ';
|
||||||
|
args.set("clansModerator",clansModeratorStrStream.str());
|
||||||
|
|
||||||
args.writeLines(os);
|
args.writeLines(os);
|
||||||
|
|
||||||
@ -190,6 +200,8 @@ void Player::deSerialize(std::istream &is)
|
|||||||
}*/
|
}*/
|
||||||
//j
|
//j
|
||||||
try{
|
try{
|
||||||
|
clanOwner = args.getU16("clanOwner");
|
||||||
|
|
||||||
std::string clansStr = args.get("clans");
|
std::string clansStr = args.get("clans");
|
||||||
std::istringstream clansStrStream(clansStr);
|
std::istringstream clansStrStream(clansStr);
|
||||||
while(clansStrStream.good() && !clansStrStream.eof()){
|
while(clansStrStream.good() && !clansStrStream.eof()){
|
||||||
@ -199,7 +211,18 @@ void Player::deSerialize(std::istream &is)
|
|||||||
int i = atoi(s.c_str());
|
int i = atoi(s.c_str());
|
||||||
if(i>=0 && i<=0xFFFF) clans.insert(i);
|
if(i>=0 && i<=0xFFFF) clans.insert(i);
|
||||||
}
|
}
|
||||||
clanOwner = args.getU16("clanOwner");
|
|
||||||
|
if(args.exists("clansModerator")){
|
||||||
|
std::string clansModeratorStr = args.get("clansModerator");
|
||||||
|
std::istringstream clansModeratorStrStream(clansModeratorStr);
|
||||||
|
while(clansModeratorStrStream.good() && !clansModeratorStrStream.eof()){
|
||||||
|
std::string s;
|
||||||
|
clansModeratorStrStream >> s;
|
||||||
|
if(s.length() == 0) continue;
|
||||||
|
int i = atoi(s.c_str());
|
||||||
|
if(i>=0 && i<=0xFFFF) clansModerator.insert(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}catch(SettingNotFoundException& e){}
|
}catch(SettingNotFoundException& e){}
|
||||||
|
|
||||||
inventory.deSerialize(is);
|
inventory.deSerialize(is);
|
||||||
@ -208,7 +231,7 @@ void Player::deSerialize(std::istream &is)
|
|||||||
//j
|
//j
|
||||||
inline bool canModifyNoCheck(const Player* player, const MapBlock* block) {
|
inline bool canModifyNoCheck(const Player* player, const MapBlock* block) {
|
||||||
u16 owner = block->getOwner();
|
u16 owner = block->getOwner();
|
||||||
return owner == 0 || player->clans.find(owner) != player->clans.end();
|
return owner == 0 || player->isClanMember(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool canModifyCheck(const Player* player, const MapBlock* block) {
|
inline bool canModifyCheck(const Player* player, const MapBlock* block) {
|
||||||
@ -233,6 +256,49 @@ bool Player::canModify(const ClansManager* clansManager, Map* map, MapBlock* blo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<bool,v3f> Player::findSpawnPos(const ClansManager& clansManager)
|
||||||
|
{
|
||||||
|
if(clans.size() == 0) return std::make_pair(false,v3f());
|
||||||
|
/*std::vector<v3f> positions;
|
||||||
|
for(std::set<u16>::const_iterator it=clans.begin(); it!=clans.end(); it++){
|
||||||
|
const Clan* clan = clansManager.getClan(*it);
|
||||||
|
if(clan && clan->hasSpawnPoint) positions.push_back(clan->spawnPoint);
|
||||||
|
}
|
||||||
|
if(positions.size()==0)return std::make_pair(false,v3f());
|
||||||
|
int i = rand() % positions.size();
|
||||||
|
return std::make_pair(true,positions[i]);*/
|
||||||
|
v3f p;
|
||||||
|
f32 p_dist = 99999999;
|
||||||
|
v3f playerPos = getPosition();
|
||||||
|
for(std::set<u16>::const_iterator it=clans.begin(); it!=clans.end(); it++){
|
||||||
|
const Clan* clan = clansManager.getClan(*it);
|
||||||
|
if(clan && clan->hasSpawnPoint){
|
||||||
|
f32 d = playerPos.getDistanceFrom(clan->spawnPoint);
|
||||||
|
if(d < p_dist){
|
||||||
|
p_dist = d;
|
||||||
|
p = clan->spawnPoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(p_dist==99999999)return std::make_pair(false,v3f());
|
||||||
|
return std::make_pair(true,p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::actualizeClans(const ClansManager& clansManager)
|
||||||
|
{
|
||||||
|
if(!clansManager.clanExists(clanOwner))clanOwner = 0;
|
||||||
|
std::set<u16> del;
|
||||||
|
for(std::set<u16>::const_iterator it=clans.begin(); it!=clans.end(); it++)
|
||||||
|
if(!clansManager.clanExists(*it))del.insert(*it);
|
||||||
|
for(std::set<u16>::const_iterator it=del.begin(); it!=del.end(); it++)
|
||||||
|
clans.erase(*it);
|
||||||
|
del.clear();
|
||||||
|
for(std::set<u16>::const_iterator it=clansModerator.begin(); it!=clansModerator.end(); it++)
|
||||||
|
if(!clansManager.clanExists(*it))del.insert(*it);
|
||||||
|
for(std::set<u16>::const_iterator it=del.begin(); it!=del.end(); it++)
|
||||||
|
clansModerator.erase(*it);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RemotePlayer
|
RemotePlayer
|
||||||
*/
|
*/
|
||||||
@ -564,7 +630,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
|
|||||||
is_unloaded = true;
|
is_unloaded = true;
|
||||||
// Doing nothing here will block the player from
|
// Doing nothing here will block the player from
|
||||||
// walking over map borders
|
// walking over map borders
|
||||||
}
|
}
|
||||||
|
|
||||||
core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
|
core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
|
||||||
|
|
||||||
@ -777,6 +843,32 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
|
|||||||
collision_info->push_back(info);
|
collision_info->push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check if standing on a teleport
|
||||||
|
TODO: should it be at the beginning or at the end of this func?
|
||||||
|
*/
|
||||||
|
v3s16 standPos = floatToInt(position - v3f(0,BS/2,0), BS);
|
||||||
|
MapNode standNode = map.getNodeNoEx(standPos);
|
||||||
|
if(standNode.getContent() == CONTENT_TELEPORT){
|
||||||
|
SignNodeMetadata* meta = (SignNodeMetadata*)map.getNodeMetadata(standPos);
|
||||||
|
if(meta){
|
||||||
|
v3f t;
|
||||||
|
std::string text = meta->getText();
|
||||||
|
str_replace_char(text,',',' ');
|
||||||
|
std::istringstream is(text);
|
||||||
|
is >> t.X >> t.Y >> t.Z;
|
||||||
|
|
||||||
|
//TODO: map limits!
|
||||||
|
if( t.X > 32000 || t.X < -32000 ||
|
||||||
|
t.Y > 32000 || t.Y < -32000 ||
|
||||||
|
t.Z > 32000 || t.Z < -32000 ||
|
||||||
|
(t.X == 0 && t.Y == 0 && t.Z == 0)
|
||||||
|
) return;
|
||||||
|
|
||||||
|
setPosition(t*BS);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
||||||
|
17
src/player.h
17
src/player.h
@ -168,9 +168,24 @@ public:
|
|||||||
u16 peer_id;
|
u16 peer_id;
|
||||||
|
|
||||||
//j
|
//j
|
||||||
std::set<int> clans;
|
std::set<u16> clans;
|
||||||
|
std::set<u16> clansModerator;
|
||||||
u16 clanOwner;
|
u16 clanOwner;
|
||||||
bool canModify(const ClansManager* clansManager, Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const;
|
bool canModify(const ClansManager* clansManager, Map* map, MapBlock* block, MapNode* node, v3s16* nodepos) const;
|
||||||
|
inline bool isClanMember(u16 clan) const {
|
||||||
|
if(clan==0)return false; //do we need this?
|
||||||
|
return clans.find(clan) != clans.end();
|
||||||
|
}
|
||||||
|
inline bool isClanModerator(u16 clan) const {
|
||||||
|
if(clan==0)return false; //do we need this?
|
||||||
|
return clan==clanOwner || clansModerator.find(clan) != clansModerator.end();
|
||||||
|
}
|
||||||
|
inline bool isClanOwner(u16 clan) const {
|
||||||
|
if(clan==0)return false; //do we need this?
|
||||||
|
return clan == clanOwner;
|
||||||
|
}
|
||||||
|
std::pair<bool,v3f> findSpawnPos(const ClansManager& clansManager);
|
||||||
|
void actualizeClans(const ClansManager& clansManager);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char m_name[PLAYERNAME_SIZE];
|
char m_name[PLAYERNAME_SIZE];
|
||||||
|
109
src/server.cpp
109
src/server.cpp
@ -2068,8 +2068,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
|
|
||||||
// Send HP & clans
|
// Send HP & clans
|
||||||
SendPlayerHP(player);
|
SendPlayerHP(player);
|
||||||
|
player->actualizeClans(m_env.clansManager);
|
||||||
SendPlayerClan(player,false,0);
|
SendPlayerClan(player,false,0);
|
||||||
SendClanNames(player->peer_id,m_env.clansManager.getNames());
|
SendClans(player->peer_id,m_env.clansManager.getClans(),m_env.clansManager.getDeleted());
|
||||||
|
|
||||||
// Send time of day
|
// Send time of day
|
||||||
{
|
{
|
||||||
@ -3007,7 +3008,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//player must be in this clan or clan is null
|
//player must be in this clan or clan is null
|
||||||
if(clan && player->clans.find(clan) == player->clans.end())
|
if(clan && !player->isClanMember(clan))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
block->setOwner(clan);
|
block->setOwner(clan);
|
||||||
@ -3882,10 +3883,11 @@ void Server::SendPlayerClan(Player *player, bool kick = false, u16 clan = 0)
|
|||||||
//send all clans
|
//send all clans
|
||||||
u16 count = (u16)player->clans.size();
|
u16 count = (u16)player->clans.size();
|
||||||
writeU16(os,count);
|
writeU16(os,count);
|
||||||
for(std::set<int>::const_iterator it=player->clans.begin(); it!=player->clans.end(); it++){
|
for(std::set<u16>::const_iterator it=player->clans.begin(); it!=player->clans.end(); it++){
|
||||||
writeU8(os,false);
|
writeU8(os,false);
|
||||||
writeU16(os,*it);
|
writeU16(os,*it);
|
||||||
}
|
}
|
||||||
|
//TODO: send admin/moderator/member info // hmm... do we need that?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make data buffer
|
// Make data buffer
|
||||||
@ -3903,11 +3905,11 @@ void writeClanIdName(std::ostringstream& os, u16 id, const std::string& name){
|
|||||||
u8 clan name lenght
|
u8 clan name lenght
|
||||||
string clan name
|
string clan name
|
||||||
*/
|
*/
|
||||||
if(name.length() > 0xFFFF) throw BaseException("too long clan name");
|
if(name.length() > 0xFF) throw BaseException("too long clan name");
|
||||||
|
|
||||||
writeU16(os,id);
|
writeU16(os,id);
|
||||||
|
|
||||||
u16 len = (u16)name.length();
|
u8 len = (u8)name.length();
|
||||||
writeU8(os,len);
|
writeU8(os,len);
|
||||||
|
|
||||||
//for(int i=0; i<len; i++) writeU8(name[i]);
|
//for(int i=0; i<len; i++) writeU8(name[i]);
|
||||||
@ -3948,7 +3950,36 @@ void Server::SendClanName(u16 peer_id, u16 clan, const std::string& name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//j
|
//j
|
||||||
void Server::SendClanNames(u16 peer_id, const std::map<u16,std::string>& clans)
|
//if clan = NULL -> clan is deleted
|
||||||
|
void writeClan(std::ostringstream& os, u16 id, const Clan* clan){
|
||||||
|
/*
|
||||||
|
u16 clan id
|
||||||
|
u8 clan name lenght (NOTE: if = 0 -> clan is deleted!!!)
|
||||||
|
string clan name
|
||||||
|
#v3f1000 clan spawn point (NOTE: if > X 32000 -> spawn point not set!)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(clan==NULL){
|
||||||
|
writeU16(os,id);
|
||||||
|
writeU8(os,0);
|
||||||
|
//writeV3F1000(os,v3f(32500));
|
||||||
|
}else{
|
||||||
|
if(clan->name.length() > 0xFF) throw BaseException("too long clan name");
|
||||||
|
|
||||||
|
writeU16(os,id);
|
||||||
|
|
||||||
|
u8 len = (u8)clan->name.length();
|
||||||
|
writeU8(os,len);
|
||||||
|
|
||||||
|
os << clan->name;
|
||||||
|
|
||||||
|
/*if(clan->hasSpawnPoint) writeV3F1000(os,clan->spawnPoint);
|
||||||
|
else writeV3F1000(os,v3f(32500));*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//j
|
||||||
|
void Server::SendClans(u16 peer_id, const std::map<u16,Clan>& clans, const std::set<u16>& deleted)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
/*
|
/*
|
||||||
@ -3956,22 +3987,27 @@ void Server::SendClanNames(u16 peer_id, const std::map<u16,std::string>& clans)
|
|||||||
u16 count
|
u16 count
|
||||||
|
|
||||||
u16 clan id
|
u16 clan id
|
||||||
u8 clan name lenght
|
u8 clan name lenght (NOTE: if = 0 -> clan is deleted!!!)
|
||||||
string clan name
|
string clan name
|
||||||
|
#v3f1000 clan spawn point (NOTE: if > X 32000 -> spawn point not set!)
|
||||||
|
|
||||||
...
|
...
|
||||||
*/
|
*/
|
||||||
u16 count = (u16)clans.size();
|
u16 count = (u16)clans.size() + (u16)deleted.size();
|
||||||
|
|
||||||
if(count==0) return;
|
if(count==0) return;
|
||||||
|
|
||||||
std::ostringstream os(std::ios_base::binary);
|
std::ostringstream os(std::ios_base::binary);
|
||||||
writeU16(os, TOCLIENT_CLAN_NAMES);
|
writeU16(os, TOCLIENT_CLANS);
|
||||||
writeU16(os,count);
|
writeU16(os,count);
|
||||||
|
|
||||||
for(std::map<u16,std::string>::const_iterator it=clans.begin(); it!=clans.end(); it++)
|
for(std::map<u16,Clan>::const_iterator it=clans.begin(); it!=clans.end(); it++)
|
||||||
writeClanIdName(os,it->first,it->second);
|
writeClan(os,it->first,&it->second);
|
||||||
|
|
||||||
dstream<<"Server sending TOCLIENT_CLAN_NAMES - "
|
for(std::set<u16>::const_iterator it=deleted.begin(); it!=deleted.end(); it++)
|
||||||
|
writeClan(os,*it,NULL);
|
||||||
|
|
||||||
|
dstream<<"Server sending TOCLIENT_CLANS - "
|
||||||
<< "count=" << count
|
<< "count=" << count
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
|
|
||||||
@ -3983,7 +4019,7 @@ void Server::SendClanNames(u16 peer_id, const std::map<u16,std::string>& clans)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//j
|
//j
|
||||||
void Server::BroadcastPlayerClan(u16 clan, const std::string& name)
|
void Server::BroadcastClanName(u16 clan, const std::string& name)
|
||||||
{
|
{
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(core::map<u16, RemoteClient*>::Iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.getIterator();
|
||||||
@ -4039,6 +4075,48 @@ void Server::BroadcastClanDeleted(u16 clan)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//j
|
||||||
|
//void Server::SendClanSpawn(u16 peer_id, u16 clan, v3f spawn)
|
||||||
|
//{
|
||||||
|
// DSTACK(__FUNCTION_NAME);
|
||||||
|
// std::ostringstream os(std::ios_base::binary);
|
||||||
|
// /*
|
||||||
|
// u16 command
|
||||||
|
// u16 clan id
|
||||||
|
// v3f1000 clan spawn point X,Y,Z (NOTE: if X > 32000 -> spawn point not set!)
|
||||||
|
// */
|
||||||
|
// writeU16(os, TOCLIENT_CLAN_SPAWNPOINT);
|
||||||
|
// writeU16(os, clan);
|
||||||
|
// writeV3F1000(os, spawn);
|
||||||
|
//
|
||||||
|
// 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::BroadcastClanSpawn(u16 clan, v3f spawn)
|
||||||
|
//{
|
||||||
|
// 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;
|
||||||
|
//
|
||||||
|
// SendClanSpawn(client->peer_id,clan,spawn);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
||||||
core::list<u16> *far_players, float far_d_nodes)
|
core::list<u16> *far_players, float far_d_nodes)
|
||||||
{
|
{
|
||||||
@ -4310,8 +4388,9 @@ void Server::HandlePlayerHP(Player *player, s16 damage)
|
|||||||
|
|
||||||
void Server::RespawnPlayer(Player *player)
|
void Server::RespawnPlayer(Player *player)
|
||||||
{
|
{
|
||||||
v3f pos = findSpawnPos(m_env.getServerMap());
|
std::pair<bool,v3f> pos = player->findSpawnPos(m_env.clansManager);
|
||||||
player->setPosition(pos);
|
if(!pos.first) pos.second = findSpawnPos(m_env.getServerMap());
|
||||||
|
player->setPosition(pos.second);
|
||||||
player->hp = 20;
|
player->hp = 20;
|
||||||
SendMovePlayer(player);
|
SendMovePlayer(player);
|
||||||
SendPlayerHP(player);
|
SendPlayerHP(player);
|
||||||
|
@ -428,10 +428,12 @@ public:
|
|||||||
void BroadcastChatMessage(const std::wstring &message); //j - moved from private
|
void BroadcastChatMessage(const std::wstring &message); //j - moved from private
|
||||||
void SendPlayerClan(Player *player, bool kick, u16 clan); //j; if clan=0, all clans are sent
|
void SendPlayerClan(Player *player, bool kick, u16 clan); //j; if clan=0, all clans are sent
|
||||||
void SendClanName(u16 peer_id, u16 clan, const std::string& name); //j
|
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 SendClans(u16 peer_id, const std::map<u16,Clan>& clans, const std::set<u16>& deleted); //j
|
||||||
void BroadcastPlayerClan(u16 clan, const std::string& name); //j
|
void BroadcastClanName(u16 clan, const std::string& name); //j
|
||||||
void SendClanDeleted(u16 peer_id,u16 clan); //j
|
void SendClanDeleted(u16 peer_id,u16 clan); //j
|
||||||
void BroadcastClanDeleted(u16 clan); //j
|
void BroadcastClanDeleted(u16 clan); //j
|
||||||
|
//void SendClanSpawn(u16 peer_id,u16 clan, v3f spawn); //j
|
||||||
|
//void BroadcastClanSpawn(u16 clan, v3f spawn); //j
|
||||||
|
|
||||||
u64 getPlayerAuthPrivs(const std::string &name)
|
u64 getPlayerAuthPrivs(const std::string &name)
|
||||||
{
|
{
|
||||||
|
@ -310,106 +310,98 @@ void cmd_clearobjects(std::wostringstream &os,
|
|||||||
void cmd_clanNew(std::wostringstream &os,
|
void cmd_clanNew(std::wostringstream &os,
|
||||||
ServerCommandContext *ctx)
|
ServerCommandContext *ctx)
|
||||||
{
|
{
|
||||||
if((ctx->privs & PRIV_CLANS) == 0)
|
try{
|
||||||
{
|
if((ctx->privs & PRIV_CLANS) == 0)
|
||||||
os<<L"-!- You don't have permission to do that";
|
throw BaseException("You don't have permission to do that");
|
||||||
return;
|
|
||||||
|
if(ctx->parms.size() != 2)
|
||||||
|
throw BaseException("Missing parameter(s) - should be /clan-new clan");
|
||||||
|
|
||||||
|
if(ctx->player->clanOwner)
|
||||||
|
throw BaseException("You can define only one clan!");
|
||||||
|
//TODO: show actual player's owned clan (so he can delete it and create new)
|
||||||
|
|
||||||
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
|
|
||||||
|
u16 clanId = ctx->env->clansManager.newClan(clanName,ctx->player);
|
||||||
|
|
||||||
|
if(clanId>0){
|
||||||
|
ctx->server->BroadcastClanName(clanId,clanName);
|
||||||
|
ctx->server->SendPlayerClan(ctx->player,false,clanId);
|
||||||
|
os<< L"-!- Clan '"<<ctx->parms[1]<<"' added.";
|
||||||
|
}
|
||||||
|
else throw BaseException("Clan already exists or other error");
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - clan NOT added (" << msg << L")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ctx->parms.size() != 2)
|
|
||||||
{
|
|
||||||
os<<L"-!- Bad parameter(s)";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx->player->clanOwner){
|
|
||||||
os<< L"-!- Error - you can define only one clan!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
|
||||||
|
|
||||||
u16 clanId = ctx->env->clansManager.newClan(clanName,ctx->player);
|
|
||||||
|
|
||||||
if(clanId>0){
|
|
||||||
ctx->server->BroadcastPlayerClan(clanId,clanName);
|
|
||||||
ctx->server->SendPlayerClan(ctx->player,false,clanId);
|
|
||||||
os<< L"-!- Clan '"<<ctx->parms[1]<<"' added.";
|
|
||||||
}
|
|
||||||
else os<< L"-!- Error - clan '"<<ctx->parms[1]<<"' NOT added.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//j
|
//j
|
||||||
void cmd_clanDelete(std::wostringstream &os,
|
void cmd_clanDelete(std::wostringstream &os,
|
||||||
ServerCommandContext *ctx)
|
ServerCommandContext *ctx)
|
||||||
{
|
{
|
||||||
if((ctx->privs & PRIV_CLANS) == 0)
|
try{
|
||||||
{
|
if((ctx->privs & PRIV_CLANS) == 0)
|
||||||
os<<L"-!- You don't have permission to do that";
|
throw BaseException("You don't have permission to do that");
|
||||||
return;
|
|
||||||
|
if(ctx->parms.size() != 2)
|
||||||
|
throw BaseException("Missing parameter(s) - should be /clan-delete clan");
|
||||||
|
|
||||||
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
|
u16 clanId = ctx->env->clansManager.clanId(clanName);
|
||||||
|
|
||||||
|
if(!clanId)
|
||||||
|
throw BaseException("Bad clan name or clan deleted");
|
||||||
|
|
||||||
|
if( (ctx->privs & PRIV_CLANS_ADMIN) == 0 && clanId != ctx->player->clanOwner)
|
||||||
|
throw BaseException("Only clan's owner may delete it!");
|
||||||
|
|
||||||
|
ctx->env->clansManager.deleteClan(clanId);
|
||||||
|
if(ctx->player->clanOwner == clanId) ctx->player->clanOwner = 0;
|
||||||
|
else; //TODO: find clan's real owner and inform reset his clanOwner variable
|
||||||
|
|
||||||
|
ctx->server->BroadcastClanDeleted(clanId);
|
||||||
|
os<< L"-!- Clan '"<<ctx->parms[1]<<"' deleted.";
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - clan not deleted (" << msg << L")";
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
void cmd_clanJoin(std::wostringstream &os,
|
||||||
ServerCommandContext *ctx)
|
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)";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
/*int clan_i = stoi(ctx->parms[1]);
|
|
||||||
if( clan_i < 0 || clan_i > 0xFFFF ) throw 0;
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
u16 clan = (u16)clan_i;*/
|
|
||||||
|
if(ctx->parms.size() != 3) throw BaseException("Missing parameter(s) - should be /clan-join clan player");
|
||||||
|
|
||||||
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
u16 clan = ctx->env->clansManager.clanId(clanName);
|
u16 clan = ctx->env->clansManager.clanId(clanName);
|
||||||
if(!clan) throw 0;
|
if(!clan) throw BaseException("Bad clan name or clan deleted");
|
||||||
|
|
||||||
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
||||||
if(playerName.length()==0) throw 0;
|
if(playerName.length()==0) throw BaseException("Bad player name");
|
||||||
|
|
||||||
if(ctx->player->clans.find(clan) == ctx->player->clans.end()) throw 0; //j!
|
if(!ctx->player->isClanModerator(clan)) throw BaseException("Only clan moderator can do this");
|
||||||
|
|
||||||
Player* player = ctx->env->getPlayer(playerName.c_str());
|
Player* player = ctx->env->getPlayer(playerName.c_str());
|
||||||
|
|
||||||
if(!player) throw 0;
|
if(!player) throw BaseException("Bad player name or player disconnected");
|
||||||
|
|
||||||
player->clans.insert(clan);
|
player->clans.insert(clan);
|
||||||
ctx->server->SendPlayerClan(player,false,clan);
|
ctx->server->SendPlayerClan(player,false,clan);
|
||||||
|
|
||||||
os<< L"-!- clan-join - success";
|
os<< L"-!- clan-join - success";
|
||||||
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" joined clan " + ctx->parms[1]);
|
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" joined clan " + ctx->parms[1]);
|
||||||
}catch(...){
|
|
||||||
os<< L"-!- Error - player not added to clan.";
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - player not added to clan (" << msg << L")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -417,47 +409,163 @@ void cmd_clanJoin(std::wostringstream &os,
|
|||||||
void cmd_clanKick(std::wostringstream &os,
|
void cmd_clanKick(std::wostringstream &os,
|
||||||
ServerCommandContext *ctx)
|
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)";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
/*int clan_i = stoi(ctx->parms[1]);
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
if( clan_i < 0 || clan_i > 0xFFFF ) throw 0;
|
|
||||||
u16 clan = (u16)clan_i;*/
|
if(ctx->parms.size() != 3) throw BaseException("Missing parameter(s) - should be /clan-kick clan player");
|
||||||
|
|
||||||
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
u16 clan = ctx->env->clansManager.clanId(clanName);
|
u16 clan = ctx->env->clansManager.clanId(clanName);
|
||||||
if(!clan) throw 0; //clan must exist
|
if(!clan) throw BaseException("Bad clan name or clan deleted"); //clan must exist
|
||||||
|
|
||||||
if(ctx->player->clans.find(clan) == ctx->player->clans.end()) throw 0; //sender must be in this clan
|
if(!ctx->player->isClanModerator(clan)) throw BaseException("Only clan moderator can do this"); //sender must be moderator of this clan
|
||||||
|
|
||||||
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
||||||
if(playerName.length()==0) throw 0;
|
if(playerName.length()==0) throw BaseException("Bad player name");
|
||||||
Player* player = ctx->env->getPlayer(playerName.c_str());
|
Player* player = ctx->env->getPlayer(playerName.c_str());
|
||||||
if(!player) throw 0; //player must exist
|
if(!player) throw BaseException("Bad player name or player disconnected"); //player must exist
|
||||||
|
|
||||||
if(player->clanOwner == clan) throw 0; //player can't be owner of that clan
|
if(player->clanOwner == clan) throw BaseException("Clan's owner cannot be kicked out"); //player can't be owner of that clan
|
||||||
|
|
||||||
player->clans.erase(clan);
|
player->clans.erase(clan);
|
||||||
|
player->clansModerator.erase(clan);
|
||||||
ctx->server->SendPlayerClan(player,true,clan);
|
ctx->server->SendPlayerClan(player,true,clan);
|
||||||
|
|
||||||
os<< L"-!- clan-kick - success";
|
os<< L"-!- clan-kick - success";
|
||||||
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" kicked from clan " + ctx->parms[1]);
|
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" kicked from clan " + ctx->parms[1]);
|
||||||
}catch(...){
|
|
||||||
os<< L"-!- Error - player not kicked from clan.";
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - player not kicked from clan. (" << msg << L")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmd_clanPromote(std::wostringstream &os,
|
||||||
|
ServerCommandContext *ctx)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
|
|
||||||
|
if(ctx->parms.size() != 3) throw BaseException("Missing parameter(s) - should be /clan-promote clan player");
|
||||||
|
|
||||||
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
|
u16 clan = ctx->env->clansManager.clanId(clanName);
|
||||||
|
if(!clan) throw BaseException("Bad clan name or clan deleted"); //clan must exist
|
||||||
|
|
||||||
|
if(!ctx->player->isClanOwner(clan)) throw BaseException("Only clan owner can do this"); //must be admin
|
||||||
|
|
||||||
|
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
||||||
|
if(playerName.length()==0) throw BaseException("Bad player name");
|
||||||
|
|
||||||
|
Player* player = ctx->env->getPlayer(playerName.c_str());
|
||||||
|
if(!player) throw BaseException("Bad player name or player disconnected"); //player must exist
|
||||||
|
|
||||||
|
if(!player->isClanMember(clan)){
|
||||||
|
player->clans.insert(clan);
|
||||||
|
ctx->server->SendPlayerClan(player,false,clan);
|
||||||
|
}
|
||||||
|
|
||||||
|
player->clansModerator.insert(clan);
|
||||||
|
|
||||||
|
os<< L"-!- clan-promote - success";
|
||||||
|
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" was promoted in clan " + ctx->parms[1]);
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - can't promote player. (" << msg << L")";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_clanDegrade(std::wostringstream &os,
|
||||||
|
ServerCommandContext *ctx)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
|
|
||||||
|
if(ctx->parms.size() != 3) throw BaseException("Missing parameter(s) - should be /clan-degrade clan player");
|
||||||
|
|
||||||
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
|
u16 clan = ctx->env->clansManager.clanId(clanName);
|
||||||
|
if(!clan) throw BaseException("Bad clan name or clan deleted"); //clan must exist
|
||||||
|
|
||||||
|
if(!ctx->player->isClanOwner(clan)) throw BaseException("Only clan owner can do this"); //must be admin
|
||||||
|
|
||||||
|
std::string playerName = wide_to_narrow(ctx->parms[2]);
|
||||||
|
if(playerName.length()==0) throw BaseException("Bad player name");
|
||||||
|
|
||||||
|
Player* player = ctx->env->getPlayer(playerName.c_str());
|
||||||
|
if(!player) throw BaseException("Bad player name or player disconnected"); //player must exist
|
||||||
|
|
||||||
|
if(!player->isClanModerator(clan)) throw BaseException("Player is not a moderator");
|
||||||
|
|
||||||
|
player->clansModerator.erase(clan);
|
||||||
|
|
||||||
|
os<< L"-!- clan-degrade - success";
|
||||||
|
ctx->server->BroadcastChatMessage(L"-!- Player " + ctx->parms[2] + L" was degraded in clan " + ctx->parms[1]);
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - can't degrade player. (" << msg << L")";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_clanSpawn(std::wostringstream &os,
|
||||||
|
ServerCommandContext *ctx)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
|
|
||||||
|
if(ctx->parms.size() != 2) throw BaseException("Missing parameter(s) - should be /clan-spawn clan");
|
||||||
|
|
||||||
|
std::string clanName = wide_to_narrow(ctx->parms[1]);
|
||||||
|
u16 clan = ctx->env->clansManager.clanId(clanName);
|
||||||
|
if(!clan) throw BaseException("Bad clan name or clan deleted"); //clan must exist
|
||||||
|
|
||||||
|
if(!ctx->player->isClanModerator(clan)) throw BaseException("Only clan moderator can do this"); //must be admin
|
||||||
|
|
||||||
|
v3f pos = ctx->player->getPosition();
|
||||||
|
ctx->env->clansManager.getClan(clan)->setSpawnPoint(pos);
|
||||||
|
|
||||||
|
//ctx->server->BroadcastClanSpawn(clan,pos);
|
||||||
|
|
||||||
|
os << L"-!- clan-spawn - success";
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - can't change clan's spawn point. (" << msg << L")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_clanInfo(std::wostringstream &os,
|
||||||
|
ServerCommandContext *ctx)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
if((ctx->privs & PRIV_CLANS) == 0) throw BaseException("You don't have permission to do that");
|
||||||
|
|
||||||
|
const ClansManager& cm = ctx->env->clansManager;
|
||||||
|
const Player& p = *ctx->player;
|
||||||
|
|
||||||
|
if(p.clans.size()>0){
|
||||||
|
os << L"-!- Your clans: ";
|
||||||
|
|
||||||
|
for(std::set<u16>::const_iterator it=p.clans.begin(); it!=p.clans.end(); it++){
|
||||||
|
if(!cm.clanExists(*it))continue;
|
||||||
|
if(it!=p.clans.begin()) os << L", ";
|
||||||
|
os << narrow_to_wide(cm.clanNameNoEx(*it));
|
||||||
|
if(p.isClanOwner(*it)) os << L" (owner)";
|
||||||
|
else if(p.isClanModerator(*it)) os << L" (moderator)";
|
||||||
|
}
|
||||||
|
}else os << L"You don't belong to any clan.";
|
||||||
|
|
||||||
|
}catch(BaseException& ex){
|
||||||
|
std::wstring msg = narrow_to_wide(std::string(ex.what()));
|
||||||
|
os << L"-!- Error - can't get clans info. (" << msg << L")";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring processServerCommand(ServerCommandContext *ctx)
|
std::wstring processServerCommand(ServerCommandContext *ctx)
|
||||||
{
|
{
|
||||||
@ -503,21 +611,21 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
|
|||||||
else if(ctx->parms[0] == L"clearobjects")
|
else if(ctx->parms[0] == L"clearobjects")
|
||||||
cmd_clearobjects(os, ctx);
|
cmd_clearobjects(os, ctx);
|
||||||
else if(ctx->parms[0] == L"clan-new")
|
else if(ctx->parms[0] == L"clan-new")
|
||||||
{
|
|
||||||
cmd_clanNew(os, ctx);
|
cmd_clanNew(os, ctx);
|
||||||
}
|
|
||||||
else if(ctx->parms[0] == L"clan-delete")
|
else if(ctx->parms[0] == L"clan-delete")
|
||||||
{
|
|
||||||
cmd_clanDelete(os, ctx);
|
cmd_clanDelete(os, ctx);
|
||||||
}
|
|
||||||
else if(ctx->parms[0] == L"clan-join")
|
else if(ctx->parms[0] == L"clan-join")
|
||||||
{
|
|
||||||
cmd_clanJoin(os, ctx);
|
cmd_clanJoin(os, ctx);
|
||||||
}
|
|
||||||
else if(ctx->parms[0] == L"clan-kick")
|
else if(ctx->parms[0] == L"clan-kick")
|
||||||
{
|
|
||||||
cmd_clanKick(os, ctx);
|
cmd_clanKick(os, ctx);
|
||||||
}
|
else if(ctx->parms[0] == L"clan-promote")
|
||||||
|
cmd_clanPromote(os, ctx);
|
||||||
|
else if(ctx->parms[0] == L"clan-degrade")
|
||||||
|
cmd_clanDegrade(os, ctx);
|
||||||
|
else if(ctx->parms[0] == L"clan-spawn")
|
||||||
|
cmd_clanSpawn(os, ctx);
|
||||||
|
else if(ctx->parms[0] == L"clan-info")
|
||||||
|
cmd_clanInfo(os, ctx);
|
||||||
else
|
else
|
||||||
os<<L"-!- Invalid command: " + ctx->parms[0];
|
os<<L"-!- Invalid command: " + ctx->parms[0];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user