*/
#include "server.h"
-#include "utility.h"
#include <iostream>
#include <queue>
#include "clientserver.h"
#include "constants.h"
#include "voxel.h"
#include "config.h"
-#include "servercommand.h"
#include "filesys.h"
#include "mapblock.h"
#include "serverobject.h"
#include "sha1.h"
#include "base64.h"
#include "tool.h"
-#include "util/string.h"
#include "sound.h" // dummySoundManager
#include "event_manager.h"
#include "hex.h"
+#include "util/string.h"
+#include "util/pointedthing.h"
+#include "util/mathconstants.h"
+#include "rollback.h"
+#include "util/serialize.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
m_nearest_unsent_reset_timer += dtime;
if(m_nothing_to_send_pause_timer >= 0)
- {
return;
- }
+
+ Player *player = server->m_env->getPlayer(peer_id);
+ // This can happen sometimes; clients and players are not in perfect sync.
+ if(player == NULL)
+ return;
// Won't send anything if already sending
if(m_blocks_sending.size() >= g_settings->getU16
//TimeTaker timer("RemoteClient::GetNextBlocks");
- Player *player = server->m_env->getPlayer(peer_id);
-
- assert(player != NULL);
-
v3f playerpos = player->getPosition();
v3f playerspeed = player->getSpeed();
v3f playerspeeddir(0,0,0);
FOV setting. The default of 72 degrees is fine.
*/
- float camera_fov = (72.0*PI/180) * 4./3.;
+ float camera_fov = (72.0*M_PI/180) * 4./3.;
if(isBlockInSight(p, camera_pos, camera_dir, camera_fov, 10000*BS) == false)
{
continue;
/*timer_result = timer.stop(true);
if(timer_result != 0)
- infostream<<"GetNextBlocks duration: "<<timer_result<<" (!=0)"<<std::endl;*/
+ infostream<<"GetNextBlocks timeout: "<<timer_result<<" (!=0)"<<std::endl;*/
}
void RemoteClient::GotBlock(v3s16 p)
m_env(NULL),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_banmanager(path_world+DIR_DELIM+"ipban.txt"),
+ m_rollback(NULL),
+ m_rollback_sink_enabled(true),
+ m_enable_rollback_recording(false),
m_lua(NULL),
m_itemdef(createItemDefManager()),
m_nodedef(createNodeDefManager()),
infostream<<"- config: "<<m_path_config<<std::endl;
infostream<<"- game: "<<m_gamespec.path<<std::endl;
+ // Create rollback manager
+ std::string rollback_path = m_path_world+DIR_DELIM+"rollback.txt";
+ m_rollback = createRollbackManager(rollback_path, this);
+
// Add world mod search path
m_modspaths.push_front(m_path_world + DIR_DELIM + "worldmods");
// Add addon mod search path
m_env = new ServerEnvironment(new ServerMap(path_world, this), m_lua,
this, this);
-
+
// Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env);
{}
}
}
-
+
+ {
+ JMutexAutoLock envlock(m_env_mutex);
+ JMutexAutoLock conlock(m_con_mutex);
+
+ /*
+ Execute script shutdown hooks
+ */
+ scriptapi_on_shutdown(m_lua);
+ }
+
{
JMutexAutoLock envlock(m_env_mutex);
i = m_clients.getIterator();
i.atEnd() == false; i++)
{
- /*// Delete player
- // NOTE: These are removed by env destructor
- {
- u16 peer_id = i.getNode()->getKey();
- JMutexAutoLock envlock(m_env_mutex);
- m_env->removePlayer(peer_id);
- }*/
-
// Delete client
delete i.getNode()->getValue();
}
// Delete things in the reverse order of creation
delete m_env;
+ delete m_rollback;
delete m_event;
delete m_itemdef;
delete m_nodedef;
// Deinitialize scripting
infostream<<"Server: Deinitializing scripting"<<std::endl;
script_deinit(m_lua);
+
+ // Delete detached inventories
+ {
+ for(std::map<std::string, Inventory*>::iterator
+ i = m_detached_inventories.begin();
+ i != m_detached_inventories.end(); i++){
+ delete i->second;
+ }
+ }
}
void Server::start(unsigned short port)
/*
Send player inventories and HPs if necessary
*/
- if(playersao->m_teleported){
+ if(playersao->m_moved){
SendMovePlayer(client->peer_id);
- playersao->m_teleported = false;
+ playersao->m_moved = false;
}
if(playersao->m_inventory_not_sent){
UpdateCrafting(client->peer_id);
if(obj)
data_buffer.append(serializeLongString(
- obj->getClientInitializationData()));
+ obj->getClientInitializationData(client->net_proto_version)));
else
data_buffer.append(serializeLongString(""));
counter = 0.0;
m_emergethread.trigger();
+
+ // Update m_enable_rollback_recording here too
+ m_enable_rollback_recording =
+ g_settings->getBool("enable_rollback_recording");
}
}
Read and check network protocol version
*/
- u16 net_proto_version = 0;
+ u16 min_net_proto_version = 0;
if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2)
+ min_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]);
+
+ // Use same version as minimum and maximum if maximum version field
+ // doesn't exist (backwards compatibility)
+ u16 max_net_proto_version = min_net_proto_version;
+ if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2)
+ max_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2]);
+
+ // Start with client's maximum version
+ u16 net_proto_version = max_net_proto_version;
+
+ // Figure out a working version if it is possible at all
+ if(max_net_proto_version >= SERVER_PROTOCOL_VERSION_MIN ||
+ min_net_proto_version <= SERVER_PROTOCOL_VERSION_MAX)
{
- net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]);
+ // If maximum is larger than our maximum, go with our maximum
+ if(max_net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
+ net_proto_version = SERVER_PROTOCOL_VERSION_MAX;
+ // Else go with client's maximum
+ else
+ net_proto_version = max_net_proto_version;
}
+ verbosestream<<"Server: "<<peer_id<<" Protocol version: min: "
+ <<min_net_proto_version<<", max: "<<max_net_proto_version
+ <<", chosen: "<<net_proto_version<<std::endl;
+
getClient(peer_id)->net_proto_version = net_proto_version;
- if(net_proto_version == 0)
+ if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
+ net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
{
- actionstream<<"Server: An old tried to connect from "<<addr_s
+ actionstream<<"Server: A mismatched client tried to connect from "<<addr_s
<<std::endl;
SendAccessDenied(m_con, peer_id, std::wstring(
L"Your client's version is not supported.\n"
L"Server version is ")
- + narrow_to_wide(VERSION_STRING) + L"."
+ + narrow_to_wide(VERSION_STRING) + L",\n"
+ + L"server's PROTOCOL_VERSION is "
+ + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
+ + L"..."
+ + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
+ + L", client's PROTOCOL_VERSION is "
+ + narrow_to_wide(itos(min_net_proto_version))
+ + L"..."
+ + narrow_to_wide(itos(max_net_proto_version))
);
return;
}
if(g_settings->getBool("strict_protocol_version_checking"))
{
- if(net_proto_version != PROTOCOL_VERSION)
+ if(net_proto_version != LATEST_PROTOCOL_VERSION)
{
- actionstream<<"Server: A mismatched client tried to connect"
- <<" from "<<addr_s<<std::endl;
+ actionstream<<"Server: A mismatched (strict) client tried to "
+ <<"connect from "<<addr_s<<std::endl;
SendAccessDenied(m_con, peer_id, std::wstring(
L"Your client's version is not supported.\n"
L"Server version is ")
+ narrow_to_wide(VERSION_STRING) + L",\n"
- + L"server's PROTOCOL_VERSION is "
- + narrow_to_wide(itos(PROTOCOL_VERSION))
+ + L"server's PROTOCOL_VERSION (strict) is "
+ + narrow_to_wide(itos(LATEST_PROTOCOL_VERSION))
+ L", client's PROTOCOL_VERSION is "
- + narrow_to_wide(itos(net_proto_version))
+ + narrow_to_wide(itos(min_net_proto_version))
+ + L"..."
+ + narrow_to_wide(itos(max_net_proto_version))
);
return;
}
Answer with a TOCLIENT_INIT
*/
{
- SharedBuffer<u8> reply(2+1+6+8);
+ SharedBuffer<u8> reply(2+1+6+8+4);
writeU16(&reply[0], TOCLIENT_INIT);
writeU8(&reply[2], deployed);
writeV3S16(&reply[2+1], floatToInt(playersao->getPlayer()->getPosition()+v3f(0,BS/2,0), BS));
writeU64(&reply[2+1+6], m_env->getServerMap().getSeed());
+ writeF1000(&reply[2+1+6+8], g_settings->getFloat("dedicated_server_step"));
// Send as reliable
m_con.Send(peer_id, 0, reply, true);
return;
}
- getClient(peer_id)->serialization_version
- = getClient(peer_id)->pending_serialization_version;
+ RemoteClient *client = getClient(peer_id);
+ client->serialization_version =
+ getClient(peer_id)->pending_serialization_version;
/*
Send some initialization data
SendItemDef(m_con, peer_id, m_itemdef);
// Send node definitions
- SendNodeDef(m_con, peer_id, m_nodedef);
+ SendNodeDef(m_con, peer_id, m_nodedef, client->net_proto_version);
// Send media announcement
sendMediaAnnouncement(peer_id);
// Send privileges
SendPlayerPrivileges(peer_id);
+ // Send inventory formspec
+ SendPlayerInventoryFormspec(peer_id);
+
// Send inventory
UpdateCrafting(peer_id);
SendInventory(peer_id);
-
+
// Send HP
SendPlayerHP(peer_id);
+ // Send detached inventories
+ sendDetachedInventories(peer_id);
+
// Show death screen if necessary
if(player->hp == 0)
SendDeathscreen(m_con, peer_id, false, v3f(0,0,0));
std::wstring message;
message += L"*** ";
message += name;
- message += L" joined game";
+ message += L" joined the game.";
BroadcastChatMessage(message);
}
}
// Warnings about protocol version can be issued here
- if(getClient(peer_id)->net_proto_version < PROTOCOL_VERSION)
+ if(getClient(peer_id)->net_proto_version < LATEST_PROTOCOL_VERSION)
{
- SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD AND MAY WORK PROPERLY WITH THIS SERVER");
+ SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT'S "
+ L"VERSION MAY NOT BE FULLY COMPATIBLE WITH THIS SERVER!");
}
/*
v3s32 ss = readV3S32(&data[start+2+12]);
f32 pitch = (f32)readS32(&data[2+12+12]) / 100.0;
f32 yaw = (f32)readS32(&data[2+12+12+4]) / 100.0;
+ u32 keyPressed = 0;
+ if(datasize >= 2+12+12+4+4+4)
+ keyPressed = (u32)readU32(&data[2+12+12+4+4]);
v3f position((f32)ps.X/100., (f32)ps.Y/100., (f32)ps.Z/100.);
v3f speed((f32)ss.X/100., (f32)ss.Y/100., (f32)ss.Z/100.);
pitch = wrapDegrees(pitch);
player->setSpeed(speed);
player->setPitch(pitch);
player->setYaw(yaw);
+ player->keyPressed=keyPressed;
+ player->control.up = (bool)(keyPressed&1);
+ player->control.down = (bool)(keyPressed&2);
+ player->control.left = (bool)(keyPressed&4);
+ player->control.right = (bool)(keyPressed&8);
+ player->control.jump = (bool)(keyPressed&16);
+ player->control.aux1 = (bool)(keyPressed&32);
+ player->control.sneak = (bool)(keyPressed&64);
+ player->control.LMB = (bool)(keyPressed&128);
+ player->control.RMB = (bool)(keyPressed&256);
/*infostream<<"Server::ProcessData(): Moved player "<<peer_id<<" to "
<<"("<<position.X<<","<<position.Y<<","<<position.Z<<")"
return;
}
+ // If something goes wrong, this player is to blame
+ RollbackScopeActor rollback_scope(m_rollback,
+ std::string("player:")+player->getName());
+
/*
Note: Always set inventory not sent, to repair cases
where the client made a bad prediction.
delete a;
return;
}
-
- // If player is not an admin, check for ownership of src and dst
- /*if(!checkPriv(player->getName(), "server"))
- {
- std::string owner_from = getInventoryOwner(ma->from_inv);
- if(owner_from != "" && owner_from != player->getName())
- {
- infostream<<"WARNING: "<<player->getName()
- <<" tried to access an inventory that"
- <<" belongs to "<<owner_from<<std::endl;
- delete a;
- return;
- }
-
- std::string owner_to = getInventoryOwner(ma->to_inv);
- if(owner_to != "" && owner_to != player->getName())
- {
- infostream<<"WARNING: "<<player->getName()
- <<" tried to access an inventory that"
- <<" belongs to "<<owner_to<<std::endl;
- delete a;
- return;
- }
- }*/
}
/*
Handle restrictions and special cases of the drop action
delete a;
return;
}
- // If player is not an admin, check for ownership
- /*else if(!checkPriv(player->getName(), "server"))
- {
- std::string owner_from = getInventoryOwner(da->from_inv);
- if(owner_from != "" && owner_from != player->getName())
- {
- infostream<<"WARNING: "<<player->getName()
- <<" tried to access an inventory that"
- <<" belongs to "<<owner_from<<std::endl;
- delete a;
- return;
- }
- }*/
}
/*
Handle restrictions and special cases of the craft action
delete a;
return;
}
-
- // If player is not an admin, check for ownership of inventory
- /*if(!checkPriv(player->getName(), "server"))
- {
- std::string owner_craft = getInventoryOwner(ca->craft_inv);
- if(owner_craft != "" && owner_craft != player->getName())
- {
- infostream<<"WARNING: "<<player->getName()
- <<" tried to access an inventory that"
- <<" belongs to "<<owner_craft<<std::endl;
- delete a;
- return;
- }
- }*/
}
// Do the action
message += (wchar_t)readU16(buf);
}
+ // If something goes wrong, this player is to blame
+ RollbackScopeActor rollback_scope(m_rollback,
+ std::string("player:")+player->getName());
+
// Get player name of this client
std::wstring name = narrow_to_wide(player->getName());
// Whether to send to other players
bool send_to_others = false;
- // Parse commands
+ // Commands are implemented in Lua, so only catch invalid
+ // commands that were not "eaten" and send an error back
if(message[0] == L'/')
{
- size_t strip_size = 1;
- if (message[1] == L'#') // support old-style commans
- ++strip_size;
- message = message.substr(strip_size);
-
- WStrfnd f1(message);
- f1.next(L" "); // Skip over /#whatever
- std::wstring paramstring = f1.next(L"");
-
- ServerCommandContext *ctx = new ServerCommandContext(
- str_split(message, L' '),
- paramstring,
- this,
- m_env,
- player);
-
- std::wstring reply(processServerCommand(ctx));
- send_to_sender = ctx->flags & SEND_TO_SENDER;
- send_to_others = ctx->flags & SEND_TO_OTHERS;
-
- if (ctx->flags & SEND_NO_PREFIX)
- line += reply;
+ message = message.substr(1);
+ send_to_sender = true;
+ if(message.length() == 0)
+ line += L"-!- Empty command";
else
- line += L"Server: " + reply;
-
- delete ctx;
-
+ line += L"-!- Invalid command: " + str_split(message, L' ')[0];
}
else
{
line += message;
send_to_others = true;
} else {
- line += L"Server: You are not allowed to shout";
+ line += L"-!- You don't have permission to shout.";
send_to_sender = true;
}
}
bool success = scriptapi_set_password(m_lua, playername, newpwd);
if(success){
actionstream<<player->getName()<<" changes password"<<std::endl;
- SendChatMessage(peer_id, L"Password change successful");
+ SendChatMessage(peer_id, L"Password change successful.");
} else {
actionstream<<player->getName()<<" tries to change password but "
<<"it fails"<<std::endl;
- SendChatMessage(peer_id, L"Password change failed or inavailable");
+ SendChatMessage(peer_id, L"Password change failed or inavailable.");
}
}
else if(command == TOSERVER_PLAYERITEM)
// (definitions and files)
getClient(peer_id)->definitions_sent = true;
}
+ else if(command == TOSERVER_RECEIVED_MEDIA) {
+ getClient(peer_id)->definitions_sent = true;
+ }
else if(command == TOSERVER_INTERACT)
{
std::string datastring((char*)&data[2], datasize-2);
return;
}
+ /*
+ If something goes wrong, this player is to blame
+ */
+ RollbackScopeActor rollback_scope(m_rollback,
+ std::string("player:")+player->getName());
+
/*
0: start digging or punch object
*/
}
if(n.getContent() != CONTENT_IGNORE)
scriptapi_node_on_punch(m_lua, p_under, n, playersao);
+ // Cheat prevention
+ playersao->noCheatDigStart(p_under);
}
else if(pointed.type == POINTEDTHING_OBJECT)
{
*/
else if(action == 2)
{
- // Only complete digging of nodes
+ // Only digging of nodes
if(pointed.type == POINTEDTHING_NODE)
{
MapNode n(CONTENT_IGNORE);
m_emerge_queue.addBlock(peer_id,
getNodeBlockPos(p_above), BLOCK_EMERGE_FLAG_FROMDISK);
}
- if(n.getContent() != CONTENT_IGNORE)
+
+ /* Cheat prevention */
+ bool is_valid_dig = true;
+ if(!isSingleplayer() && !g_settings->getBool("disable_anticheat"))
+ {
+ v3s16 nocheat_p = playersao->getNoCheatDigPos();
+ float nocheat_t = playersao->getNoCheatDigTime();
+ playersao->noCheatDigEnd();
+ // If player didn't start digging this, ignore dig
+ if(nocheat_p != p_under){
+ infostream<<"Server: NoCheat: "<<player->getName()
+ <<" started digging "
+ <<PP(nocheat_p)<<" and completed digging "
+ <<PP(p_under)<<"; not digging."<<std::endl;
+ is_valid_dig = false;
+ }
+ // Get player's wielded item
+ ItemStack playeritem;
+ InventoryList *mlist = playersao->getInventory()->getList("main");
+ if(mlist != NULL)
+ playeritem = mlist->getItem(playersao->getWieldIndex());
+ ToolCapabilities playeritem_toolcap =
+ playeritem.getToolCapabilities(m_itemdef);
+ // Get diggability and expected digging time
+ DigParams params = getDigParams(m_nodedef->get(n).groups,
+ &playeritem_toolcap);
+ // If can't dig, try hand
+ if(!params.diggable){
+ const ItemDefinition &hand = m_itemdef->get("");
+ const ToolCapabilities *tp = hand.tool_capabilities;
+ if(tp)
+ params = getDigParams(m_nodedef->get(n).groups, tp);
+ }
+ // If can't dig, ignore dig
+ if(!params.diggable){
+ infostream<<"Server: NoCheat: "<<player->getName()
+ <<" completed digging "<<PP(p_under)
+ <<", which is not diggable with tool. not digging."
+ <<std::endl;
+ is_valid_dig = false;
+ }
+ // If time is considerably too short, ignore dig
+ // Check time only for medium and slow timed digs
+ if(params.diggable && params.time > 0.3 && nocheat_t < 0.5 * params.time){
+ infostream<<"Server: NoCheat: "<<player->getName()
+ <<" completed digging "
+ <<PP(p_under)<<" in "<<nocheat_t<<"s; expected "
+ <<params.time<<"s; not digging."<<std::endl;
+ is_valid_dig = false;
+ }
+ }
+
+ /* Actually dig node */
+
+ if(is_valid_dig && n.getContent() != CONTENT_IGNORE)
scriptapi_node_on_dig(m_lua, p_under, n, playersao);
- if (m_env->getMap().getNodeNoEx(p_under).getContent() != CONTENT_AIR)
+ // Send unusual result (that is, node not being removed)
+ if(m_env->getMap().getNodeNoEx(p_under).getContent() != CONTENT_AIR)
{
// Re-send block to revert change on client-side
RemoteClient *client = getClient(peer_id);
// Placement was handled in lua
// Apply returned ItemStack
- if(g_settings->getBool("creative_mode") == false)
- playersao->setWieldedItem(item);
+ playersao->setWieldedItem(item);
}
// If item has node placement prediction, always send the above
item, playersao, pointed))
{
// Apply returned ItemStack
- if(g_settings->getBool("creative_mode") == false)
- playersao->setWieldedItem(item);
+ playersao->setWieldedItem(item);
}
} // action == 4
+
/*
Catch invalid actions
fields[fieldname] = fieldvalue;
}
+ // If something goes wrong, this player is to blame
+ RollbackScopeActor rollback_scope(m_rollback,
+ std::string("player:")+player->getName());
+
+ // Check the target node for rollback data; leave others unnoticed
+ RollbackNode rn_old(&m_env->getMap(), p, this);
+
scriptapi_node_on_receive_fields(m_lua, p, formname, fields,
playersao);
+
+ // Report rollback data
+ RollbackNode rn_new(&m_env->getMap(), p, this);
+ if(rollback() && rn_new != rn_old){
+ RollbackAction action;
+ action.setSetNode(p, rn_old, rn_new);
+ rollback()->reportAction(action);
+ }
+ }
+ else if(command == TOSERVER_INVENTORY_FIELDS)
+ {
+ std::string datastring((char*)&data[2], datasize-2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ std::string formname = deSerializeString(is);
+ int num = readU16(is);
+ std::map<std::string, std::string> fields;
+ for(int k=0; k<num; k++){
+ std::string fieldname = deSerializeString(is);
+ std::string fieldvalue = deSerializeLongString(is);
+ fields[fieldname] = fieldvalue;
+ }
+
+ scriptapi_on_player_receive_fields(m_lua, playersao, formname, fields);
}
else
{
return meta->getInventory();
}
break;
+ case InventoryLocation::DETACHED:
+ {
+ if(m_detached_inventories.count(loc.name) == 0)
+ return NULL;
+ return m_detached_inventories[loc.name];
+ }
+ break;
default:
assert(0);
}
setBlockNotSent(blockpos);
}
break;
+ case InventoryLocation::DETACHED:
+ {
+ sendDetachedInventoryToAll(loc.name);
+ }
+ break;
default:
assert(0);
}
}
void Server::SendNodeDef(con::Connection &con, u16 peer_id,
- INodeDefManager *nodedef)
+ INodeDefManager *nodedef, u16 protocol_version)
{
DSTACK(__FUNCTION_NAME);
std::ostringstream os(std::ios_base::binary);
*/
writeU16(os, TOCLIENT_NODEDEF);
std::ostringstream tmp_os(std::ios::binary);
- nodedef->serialize(tmp_os);
+ nodedef->serialize(tmp_os, protocol_version);
std::ostringstream tmp_os2(std::ios::binary);
compressZlib(tmp_os.str(), tmp_os2);
os<<serializeLongString(tmp_os2.str());
{
Player *player = m_env->getPlayer(peer_id);
assert(player);
+ if(player->peer_id == PEER_ID_INEXISTENT)
+ return;
+
std::set<std::string> privs;
scriptapi_get_auth(m_lua, player->getName(), NULL, &privs);
m_con.Send(peer_id, 0, data, true);
}
+void Server::SendPlayerInventoryFormspec(u16 peer_id)
+{
+ Player *player = m_env->getPlayer(peer_id);
+ assert(player);
+ if(player->peer_id == PEER_ID_INEXISTENT)
+ return;
+
+ std::ostringstream os(std::ios_base::binary);
+ writeU16(os, TOCLIENT_INVENTORY_FORMSPEC);
+ os<<serializeLongString(player->inventory_formspec);
+
+ // 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);
+}
+
s32 Server::playSound(const SimpleSoundSpec &spec,
const ServerSoundParams ¶ms)
{
paths.push_back(mod.path + DIR_DELIM + "textures");
paths.push_back(mod.path + DIR_DELIM + "sounds");
paths.push_back(mod.path + DIR_DELIM + "media");
+ paths.push_back(mod.path + DIR_DELIM + "models");
}
+ std::string path_all = "textures";
+ paths.push_back(path_all + DIR_DELIM + "all");
// Collect media file information from paths into cache
for(std::list<std::string>::iterator i = paths.begin();
".png", ".jpg", ".bmp", ".tga",
".pcx", ".ppm", ".psd", ".wal", ".rgb",
".ogg",
+ ".x", ".b3d", ".md2", ".obj",
NULL
};
if(removeStringEnd(filename, supported_ext) == ""){
os<<serializeString(j->name);
os<<serializeString(j->sha1_digest);
}
+ os<<serializeString(g_settings->get("remote_media"));
// Make data buffer
std::string s = os.str();
// Send as reliable
m_con.Send(peer_id, 0, data, true);
-
}
struct SendableMedia
}
}
+void Server::sendDetachedInventory(const std::string &name, u16 peer_id)
+{
+ if(m_detached_inventories.count(name) == 0){
+ errorstream<<__FUNCTION_NAME<<": \""<<name<<"\" not found"<<std::endl;
+ return;
+ }
+ Inventory *inv = m_detached_inventories[name];
+
+ std::ostringstream os(std::ios_base::binary);
+ writeU16(os, TOCLIENT_DETACHED_INVENTORY);
+ os<<serializeString(name);
+ inv->serialize(os);
+
+ // 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);
+}
+
+void Server::sendDetachedInventoryToAll(const std::string &name)
+{
+ DSTACK(__FUNCTION_NAME);
+
+ for(core::map<u16, RemoteClient*>::Iterator
+ i = m_clients.getIterator();
+ i.atEnd() == false; i++){
+ RemoteClient *client = i.getNode()->getValue();
+ sendDetachedInventory(name, client->peer_id);
+ }
+}
+
+void Server::sendDetachedInventories(u16 peer_id)
+{
+ DSTACK(__FUNCTION_NAME);
+
+ for(std::map<std::string, Inventory*>::iterator
+ i = m_detached_inventories.begin();
+ i != m_detached_inventories.end(); i++){
+ const std::string &name = i->first;
+ //Inventory *inv = i->second;
+ sendDetachedInventory(name, peer_id);
+ }
+}
+
/*
Something random
*/
// Get a preview for crafting
ItemStack preview;
- // No crafting in creative mode
- if(g_settings->getBool("creative_mode") == false)
- getCraftingResult(&player->inventory, preview, false, this);
+ getCraftingResult(&player->inventory, preview, false, this);
// Put the new preview in
InventoryList *plist = player->inventory.getList("craftpreview");
// Uptime
os<<L", uptime="<<m_uptime.get();
// Information about clients
+ core::map<u16, RemoteClient*>::Iterator i;
+ bool first;
os<<L", clients={";
- for(core::map<u16, RemoteClient*>::Iterator
- i = m_clients.getIterator();
+ for(i = m_clients.getIterator(), first = true;
i.atEnd() == false; i++)
{
// Get client and check that it is valid
if(player != NULL)
name = narrow_to_wide(player->getName());
// Add name to information string
- os<<name<<L",";
+ if(!first)
+ os<<L",";
+ else
+ first = false;
+ os<<name;
}
os<<L"}";
if(((ServerMap*)(&m_env->getMap()))->isSavingEnabled() == false)
}
}
+void Server::reportInventoryFormspecModified(const std::string &name)
+{
+ Player *player = m_env->getPlayer(name.c_str());
+ if(!player)
+ return;
+ SendPlayerInventoryFormspec(player->peer_id);
+}
+
// Saves g_settings to configpath given at initialization
void Server::saveConfig()
{
m_emerge_queue.addBlock(PEER_ID_INEXISTENT, blockpos, flags);
}
+Inventory* Server::createDetachedInventory(const std::string &name)
+{
+ if(m_detached_inventories.count(name) > 0){
+ infostream<<"Server clearing detached inventory \""<<name<<"\""<<std::endl;
+ delete m_detached_inventories[name];
+ } else {
+ infostream<<"Server creating detached inventory \""<<name<<"\""<<std::endl;
+ }
+ Inventory *inv = new Inventory(m_itemdef);
+ assert(inv);
+ m_detached_inventories[name] = inv;
+ sendDetachedInventoryToAll(name);
+ return inv;
+}
+
+class BoolScopeSet
+{
+public:
+ BoolScopeSet(bool *dst, bool val):
+ m_dst(dst)
+ {
+ m_orig_state = *m_dst;
+ *m_dst = val;
+ }
+ ~BoolScopeSet()
+ {
+ *m_dst = m_orig_state;
+ }
+private:
+ bool *m_dst;
+ bool m_orig_state;
+};
+
+// actions: time-reversed list
+// Return value: success/failure
+bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
+ std::list<std::string> *log)
+{
+ infostream<<"Server::rollbackRevertActions(len="<<actions.size()<<")"<<std::endl;
+ ServerMap *map = (ServerMap*)(&m_env->getMap());
+ // Disable rollback report sink while reverting
+ BoolScopeSet rollback_scope_disable(&m_rollback_sink_enabled, false);
+
+ // Fail if no actions to handle
+ if(actions.empty()){
+ log->push_back("Nothing to do.");
+ return false;
+ }
+
+ int num_tried = 0;
+ int num_failed = 0;
+
+ for(std::list<RollbackAction>::const_iterator
+ i = actions.begin();
+ i != actions.end(); i++)
+ {
+ const RollbackAction &action = *i;
+ num_tried++;
+ bool success = action.applyRevert(map, this, this);
+ if(!success){
+ num_failed++;
+ std::ostringstream os;
+ os<<"Revert of step ("<<num_tried<<") "<<action.toString()<<" failed";
+ infostream<<"Map::rollbackRevertActions(): "<<os.str()<<std::endl;
+ if(log)
+ log->push_back(os.str());
+ }else{
+ std::ostringstream os;
+ os<<"Successfully reverted step ("<<num_tried<<") "<<action.toString();
+ infostream<<"Map::rollbackRevertActions(): "<<os.str()<<std::endl;
+ if(log)
+ log->push_back(os.str());
+ }
+ }
+
+ infostream<<"Map::rollbackRevertActions(): "<<num_failed<<"/"<<num_tried
+ <<" failed"<<std::endl;
+
+ // Call it done if less than half failed
+ return num_failed <= num_tried/2;
+}
+
// IGameDef interface
// Under envlock
IItemDefManager* Server::getItemDefManager()
{
return NULL;
}
+IShaderSource* Server::getShaderSource()
+{
+ return NULL;
+}
u16 Server::allocateUnknownNodeId(const std::string &name)
{
return m_nodedef->allocateDummy(name);
{
return m_event;
}
+IRollbackReportSink* Server::getRollbackReportSink()
+{
+ if(!m_enable_rollback_recording)
+ return NULL;
+ if(!m_rollback_sink_enabled)
+ return NULL;
+ return m_rollback;
+}
IWritableItemDefManager* Server::getWritableItemDefManager()
{
}
return NULL;
}
+void Server::getModNames(core::list<std::string> &modlist)
+{
+ for(core::list<ModSpec>::Iterator i = m_mods.begin(); i != m_mods.end(); i++)
+ {
+ modlist.push_back((*i).name);
+ }
+}
std::string Server::getBuiltinLuaPath()
{
return porting::path_share + DIR_DELIM + "builtin";
scriptapi_on_joinplayer(m_lua, playersao);
- /* Creative mode */
- if(g_settings->getBool("creative_mode"))
- playersao->createCreativeInventory();
-
return playersao;
}
std::wstring name = narrow_to_wide(player->getName());
message += L"*** ";
message += name;
- message += L" left game";
+ message += L" left the game.";
if(c.timeout)
message += L" (timed out)";
}