#include "mineral.h"
#include "config.h"
#include "servercommand.h"
+#include "filesys.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
*/
if(stepped_blocks.find(p) == NULL)
{
- block->stepObjects(dtime, true, server->getDayNightRatio());
+ block->stepObjects(dtime, true, server->m_env.getDayNightRatio());
stepped_blocks.insert(p, true);
block->setChangedFlag();
}
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_thread(this),
m_emergethread(this),
- m_time_of_day(9000),
m_time_counter(0),
m_time_of_day_send_timer(0),
m_uptime(0),
m_con_mutex.Init();
m_step_dtime_mutex.Init();
m_step_dtime = 0.0;
-
+
+ // Register us to receive map edit events
m_env.getMap().addEventReceiver(this);
+ // If file exists, load environment metadata
+ if(fs::PathExists(m_mapsavedir+"/env_meta.txt"))
+ {
+ dstream<<"Server: Loading environment metadata"<<std::endl;
+ m_env.loadMeta(m_mapsavedir);
+ }
+
// Load players
+ dstream<<"Server: Loading players"<<std::endl;
m_env.deSerializePlayers(m_mapsavedir);
}
*/
dstream<<"Server: Saving players"<<std::endl;
m_env.serializePlayers(m_mapsavedir);
+
+ /*
+ Save environment metadata
+ */
+ dstream<<"Server: Saving environment metadata"<<std::endl;
+ m_env.saveMeta(m_mapsavedir);
/*
Stop threads
}
/*
- Update m_time_of_day
+ Update m_time_of_day and overall game time
*/
{
+ JMutexAutoLock envlock(m_env_mutex);
+
m_time_counter += dtime;
f32 speed = g_settings.getFloat("time_speed") * 24000./(24.*3600);
u32 units = (u32)(m_time_counter*speed);
m_time_counter -= (f32)units / speed;
- m_time_of_day.set((m_time_of_day.get() + units) % 24000);
+
+ m_env.setTimeOfDay((m_env.getTimeOfDay() + units) % 24000);
//dstream<<"Server: m_time_of_day = "<<m_time_of_day.get()<<std::endl;
//Player *player = m_env.getPlayer(client->peer_id);
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
- m_time_of_day.get());
+ m_env.getTimeOfDay());
// Send as reliable
m_con.Send(client->peer_id, 0, data, true);
}
// Save players
m_env.serializePlayers(m_mapsavedir);
+
+ // Save environment metadata
+ m_env.saveMeta(m_mapsavedir);
}
}
}
if(datasize == 2+1+PLAYERNAME_SIZE)
{
// old version - assume blank password
- *password = 0;
+ password[0] = 0;
}
else
{
// Send time of day
{
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
- m_time_of_day.get());
+ m_env.getTimeOfDay());
m_con.Send(peer->id, 0, data, true);
}
// Whether to send to other players
bool send_to_others = false;
+ // Local player gets all privileges regardless of
+ // what's set on their account.
+ u64 privs = player->privs;
+ if(g_settings.get("name") == player->getName())
+ privs = PRIV_ALL;
+
// Parse commands
std::wstring commandprefix = L"/#";
if(message.substr(0, commandprefix.size()) == commandprefix)
message = message.substr(commandprefix.size());
- // Local player gets all privileges regardless of
- // what's set on their account.
- u64 privs = player->privs;
- if(g_settings.get("name") == player->getName())
- privs = PRIV_ALL;
-
ServerCommandContext *ctx = new ServerCommandContext(
str_split(message, L' '),
this,
}
else
{
- line += L"<";
- /*if(is_operator)
- line += L"@";*/
- line += name;
- line += L"> ";
- line += message;
- send_to_others = true;
+ if(privs & PRIV_SHOUT)
+ {
+ line += L"<";
+ line += name;
+ line += L"> ";
+ line += message;
+ send_to_others = true;
+ }
+ else
+ {
+ line += L"Server: You are not allowed to shout";
+ send_to_sender = true;
+ }
}
if(line != L"")
SendPlayerHP(player);
}
+ else if(command == TOSERVER_PASSWORD)
+ {
+ /*
+ [0] u16 TOSERVER_PASSWORD
+ [2] u8[28] old password
+ [30] u8[28] new password
+ */
+
+ if(datasize != 2+PASSWORD_SIZE*2)
+ return;
+ char password[PASSWORD_SIZE];
+ for(u32 i=0; i<PASSWORD_SIZE-1; i++)
+ password[i] = data[2+i];
+ password[PASSWORD_SIZE-1] = 0;
+ if(strcmp(player->getPassword(),password))
+ {
+ // Wrong old password supplied!!
+ SendChatMessage(peer_id, L"Invalid old password supplied. Password NOT changed.");
+ return;
+ }
+ for(u32 i=0; i<PASSWORD_SIZE-1; i++)
+ password[i] = data[30+i];
+ player->updatePassword(password);
+ SendChatMessage(peer_id, L"Password change successful");
+ }
else
{
derr_server<<"WARNING: Server::ProcessData(): Ignoring "
}
}
+ // Fence
+ if(!found)
+ {
+ ItemSpec specs[9];
+ specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
+ specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
+ specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
+ specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
+ specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
+ specs[9] = ItemSpec(ITEM_CRAFT, "Stick");
+ if(checkItemCombination(items, specs))
+ {
+ rlist->addItem(new MaterialItem(CONTENT_FENCE, 2));
+ found = true;
+ }
+ }
+
// Sign
if(!found)
{
CONTENT_TREE,
CONTENT_LEAVES,
CONTENT_GLASS,
+ CONTENT_FENCE,
CONTENT_MESE,
CONTENT_WATERSOURCE,
CONTENT_CLOUD,
player->updateName(name);
player->updatePassword(password);
+ if(g_settings.exists("default_privs"))
+ player->privs = g_settings.getU64("default_privs");
+
/*
Set player position
*/