Compare commits

...

5 Commits

Author SHA1 Message Date
Ilya Zhuravlev 222f4969f0 say no to underground spawn 2011-11-15 16:27:35 +04:00
Perttu Ahola 09f2408158 Better spawn position finding and checking 2011-11-13 17:03:50 +08:00
Ilya Zhuravlev dd172f2fd7 Mese & jungles are disabled now. 2011-11-10 18:17:23 +04:00
Ilya Zhuravlev caee667a6d fix logout-login-3-blocks-down bug 2011-11-09 20:49:40 +04:00
Ilya Zhuravlev 74cb3cfa1b white list with rights, should work now 2011-11-09 20:16:01 +04:00
7 changed files with 106 additions and 28 deletions

View File

@ -42,6 +42,8 @@ std::string privsToString(u64 privs)
os<<"shout,";
if(privs & PRIV_BAN)
os<<"ban,";
if (privs & PRIV_WHITELIST)
os << "whitelist,";
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 == "whitelist")
privs |= PRIV_WHITELIST;
else
return PRIV_INVALID;
}

View File

@ -40,6 +40,8 @@ const u64 PRIV_SHOUT = 32; // Can broadcast chat messages to all
// players
const u64 PRIV_BAN = 64; // Can ban players
const u64 PRIV_WHITELIST = 128; // can add players to whitelist (actually, it is registering, but auto-registration was disabled for this server)
// Default privileges - these can be overriden for new players using the
// config option "default_privs" - however, this value still applies for
// players that existed before the privileges system was added.

View File

@ -783,14 +783,14 @@ void the_game(
// Update client and server
client.step(0.1);
client.step(0.0001);
if(server != NULL)
server->step(0.1);
server->step(0.0001);
// Delay a bit
sleep_ms(100);
time_counter += 0.1;
sleep_ms(1);
time_counter += 0.0001;
}
}
catch(con::PeerNotFoundException &e)

View File

@ -1674,7 +1674,8 @@ void make_block(BlockMakeData *data)
/*
Add meseblocks
*/
for(s16 i=0; i<approx_ground_depth/4; i++)
/* NO WAY! */
/*for(s16 i=0; i<approx_ground_depth/4; i++)
{
if(mineralrandom.next()%50 == 0)
{
@ -1691,7 +1692,7 @@ void make_block(BlockMakeData *data)
}
}
}
}*/
/*
Add others
*/
@ -2076,8 +2077,9 @@ void make_block(BlockMakeData *data)
*/
float surface_humidity = surface_humidity_2d(data->seed, p2d_center);
bool is_jungle = surface_humidity > 0.75;
// Amount of trees
//bool is_jungle = surface_humidity > 0.75;
bool is_jungle = false;
// Amount of trees
u32 tree_count = block_area_nodes * tree_amount_2d(data->seed, p2d_center);
if(is_jungle)
tree_count *= 5;

View File

@ -4140,8 +4140,7 @@ v3f findSpawnPos(ServerMap &map)
{
//return v3f(50,50,50)*BS;
v2s16 nodepos;
s16 groundheight = 0;
v3s16 nodepos;
#if 0
nodepos = v2s16(0,0);
@ -4154,13 +4153,11 @@ v3f findSpawnPos(ServerMap &map)
{
s32 range = 1 + i;
// We're going to try to throw the player to this position
nodepos = v2s16(-range + (myrand()%(range*2)),
v2s16 nodepos2d = v2s16(-range + (myrand()%(range*2)),
-range + (myrand()%(range*2)));
v2s16 sectorpos = getNodeSectorPos(nodepos);
// Get sector (NOTE: Don't get because it's slow)
//m_env.getMap().emergeSector(sectorpos);
//v2s16 sectorpos = getNodeSectorPos(nodepos2d);
// Get ground height at point (fallbacks to heightmap function)
groundheight = map.findGroundLevel(nodepos);
s16 groundheight = map.findGroundLevel(nodepos2d) + 1;
// Don't go underwater
if(groundheight < WATER_LEVEL)
{
@ -4173,22 +4170,33 @@ v3f findSpawnPos(ServerMap &map)
//infostream<<"-> Underwater"<<std::endl;
continue;
}
// Found a good place
//infostream<<"Searched through "<<i<<" places."<<std::endl;
break;
nodepos = v3s16(nodepos2d.X, groundheight-2, nodepos2d.Y);
bool is_good = false;
s32 air_count = 0;
for(s32 i=0; i<10; i++){
v3s16 blockpos = getNodeBlockPos(nodepos);
map.emergeBlock(blockpos, true);
MapNode n = map.getNodeNoEx(nodepos);
if(n.getContent() == CONTENT_AIR){
air_count++;
if(air_count >= 2){
is_good = true;
nodepos.Y -= 1;
break;
}
}
nodepos.Y++;
}
if(is_good){
// Found a good place
//infostream<<"Searched through "<<i<<" places."<<std::endl;
break;
}
}
#endif
// If no suitable place was not found, go above water at least.
if(groundheight < WATER_LEVEL)
groundheight = WATER_LEVEL;
return intToFloat(v3s16(
nodepos.X,
groundheight + 3,
nodepos.Y
), BS);
return intToFloat(nodepos, BS);
}
Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id)

View File

@ -463,6 +463,25 @@ public:
return;
}
void addUser(const std::string &playername, const std::string &checkpwd)
{
m_authmanager.add(playername);
m_authmanager.setPassword(playername, translatePassword(playername, narrow_to_wide(checkpwd)));
//m_authmanager.setPrivs(playername,
// stringToPrivs(g_settings->get("default_privs")));
m_authmanager.save();
}
void changePassword(const std::string &playername, const std::string &checkpwd)
{
m_authmanager.setPassword(playername, translatePassword(playername, narrow_to_wide(checkpwd)));
//m_authmanager.setPrivs(playername,
// stringToPrivs(g_settings->get("default_privs")));
m_authmanager.save();
}
std::string getBanDescription(const std::string &ip_or_name)
{
return m_banmanager.getBanDescription(ip_or_name);

View File

@ -305,6 +305,45 @@ void cmd_clearobjects(std::wostringstream &os,
ctx->flags |= SEND_TO_OTHERS;
}
std::string generate_pwd() {
std::string result = "";
for (int i = 0; i < 5; ++i) {
result += ('a' + myrand() % 26);
}
return result;
}
void cmd_whitelist(std::wostringstream &os, ServerCommandContext *ctx)
{
if((ctx->privs & PRIV_WHITELIST) == 0)
{
os<<L"-!- You don't have permission to do that";
return;
}
if(ctx->parms.size() < 2)
{
os<<L"-!- Please, specify a nickname! ";
return;
}
std::string playername = wide_to_narrow(ctx->parms[1]).c_str();
Player *player = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
if(player == NULL)
{
std::string password = generate_pwd();
os<<L"-!- Adding new player, name: " << narrow_to_wide(playername) << L" password: " << narrow_to_wide(password);
ctx->server->addUser(playername, password);
return;
} else {
std::string password = generate_pwd();
os<<L"-!- Changing password for: " << narrow_to_wide(playername) << L" new password is: " << narrow_to_wide(password);
ctx->server->changePassword(playername, password);
return;
}
}
std::wstring processServerCommand(ServerCommandContext *ctx)
{
@ -328,6 +367,8 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
os<<L" grant revoke";
if(privs & PRIV_BAN)
os<<L" ban unban";
if (privs & PRIV_WHITELIST)
os << L" white";
}
else if(ctx->parms[0] == L"status")
cmd_status(os, ctx);
@ -349,6 +390,8 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
cmd_me(os, ctx);
else if(ctx->parms[0] == L"clearobjects")
cmd_clearobjects(os, ctx);
else if (ctx->parms[0] == L"white")
cmd_whitelist(os, ctx);
else
os<<L"-!- Invalid command: " + ctx->parms[0];