summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientpackethandler.cpp31
-rw-r--r--src/network/connection.cpp145
-rw-r--r--src/network/connection.h62
-rw-r--r--src/network/networkpacket.cpp3
-rw-r--r--src/network/networkprotocol.h59
-rw-r--r--src/network/serverpackethandler.cpp181
6 files changed, 207 insertions, 274 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 86091bc88..0498f4048 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -24,10 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "map.h"
#include "mapsector.h"
+#include "minimap.h"
#include "nodedef.h"
#include "serialization.h"
#include "server.h"
-#include "strfnd.h"
+#include "util/strfnd.h"
#include "network/clientopcodes.h"
#include "util/serialize.h"
#include "util/srp.h"
@@ -551,6 +552,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
*pkt >> pos >> pitch >> yaw;
+ player->got_teleported = true;
player->setPosition(pos);
infostream << "Client got TOCLIENT_MOVE_PLAYER"
@@ -578,7 +580,7 @@ void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
void Client::handleCommand_PlayerItem(NetworkPacket* pkt)
{
- infostream << "Client: WARNING: Ignoring TOCLIENT_PLAYERITEM" << std::endl;
+ warningstream << "Client: Ignoring TOCLIENT_PLAYERITEM" << std::endl;
}
void Client::handleCommand_DeathScreen(NetworkPacket* pkt)
@@ -621,7 +623,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
// Mesh update thread must be stopped while
// updating content definitions
- sanity_check(!m_mesh_update_thread.IsRunning());
+ sanity_check(!m_mesh_update_thread.isRunning());
for (u16 i = 0; i < num_files; i++) {
std::string name, sha1_base64;
@@ -639,7 +641,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
*pkt >> str;
Strfnd sf(str);
- while(!sf.atend()) {
+ while(!sf.at_end()) {
std::string baseurl = trim(sf.next(","));
if (baseurl != "")
m_media_downloader->addRemoteServer(baseurl);
@@ -694,7 +696,7 @@ void Client::handleCommand_Media(NetworkPacket* pkt)
// Mesh update thread must be stopped while
// updating content definitions
- sanity_check(!m_mesh_update_thread.IsRunning());
+ sanity_check(!m_mesh_update_thread.isRunning());
for (u32 i=0; i < num_files; i++) {
std::string name;
@@ -710,7 +712,7 @@ void Client::handleCommand_Media(NetworkPacket* pkt)
void Client::handleCommand_ToolDef(NetworkPacket* pkt)
{
- infostream << "Client: WARNING: Ignoring TOCLIENT_TOOLDEF" << std::endl;
+ warningstream << "Client: Ignoring TOCLIENT_TOOLDEF" << std::endl;
}
void Client::handleCommand_NodeDef(NetworkPacket* pkt)
@@ -720,7 +722,7 @@ void Client::handleCommand_NodeDef(NetworkPacket* pkt)
// Mesh update thread must be stopped while
// updating content definitions
- sanity_check(!m_mesh_update_thread.IsRunning());
+ sanity_check(!m_mesh_update_thread.isRunning());
// Decompress node definitions
std::string datastring(pkt->getString(0), pkt->getSize());
@@ -737,7 +739,7 @@ void Client::handleCommand_NodeDef(NetworkPacket* pkt)
void Client::handleCommand_CraftItemDef(NetworkPacket* pkt)
{
- infostream << "Client: WARNING: Ignoring TOCLIENT_CRAFTITEMDEF" << std::endl;
+ warningstream << "Client: Ignoring TOCLIENT_CRAFTITEMDEF" << std::endl;
}
void Client::handleCommand_ItemDef(NetworkPacket* pkt)
@@ -747,7 +749,7 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt)
// Mesh update thread must be stopped while
// updating content definitions
- sanity_check(!m_mesh_update_thread.IsRunning());
+ sanity_check(!m_mesh_update_thread.isRunning());
// Decompress item definitions
std::string datastring(pkt->getString(0), pkt->getSize());
@@ -1094,8 +1096,19 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
+ bool was_minimap_visible = player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE;
+
player->hud_flags &= ~mask;
player->hud_flags |= flags;
+
+ m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
+
+ // Hide minimap if it has been disabled by the server
+ if (m_minimap_disabled_by_server && was_minimap_visible) {
+ // defers a minimap update, therefore only call it if really
+ // needed, by checking that minimap was visible before
+ m_mapper->setMinimapMode(MINIMAP_MODE_OFF);
+ }
}
void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index 7794ce10f..f7452d8e4 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -42,10 +42,10 @@ namespace con
#undef DEBUG_CONNECTION_KBPS
#else
/* this mutex is used to achieve log message consistency */
-JMutex log_message_mutex;
+Mutex log_message_mutex;
#define LOG(a) \
{ \
- JMutexAutoLock loglock(log_message_mutex); \
+ MutexAutoLock loglock(log_message_mutex); \
a; \
}
#define PROFILE(a) a
@@ -209,7 +209,7 @@ ReliablePacketBuffer::ReliablePacketBuffer(): m_list_size(0) {}
void ReliablePacketBuffer::print()
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
LOG(dout_con<<"Dump of ReliablePacketBuffer:" << std::endl);
unsigned int index = 0;
for(std::list<BufferedPacket>::iterator i = m_list.begin();
@@ -223,7 +223,7 @@ void ReliablePacketBuffer::print()
}
bool ReliablePacketBuffer::empty()
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
return m_list.empty();
}
@@ -256,7 +256,7 @@ RPBSearchResult ReliablePacketBuffer::notFound()
}
bool ReliablePacketBuffer::getFirstSeqnum(u16& result)
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
if (m_list.empty())
return false;
BufferedPacket p = *m_list.begin();
@@ -266,7 +266,7 @@ bool ReliablePacketBuffer::getFirstSeqnum(u16& result)
BufferedPacket ReliablePacketBuffer::popFirst()
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
if (m_list.empty())
throw NotFoundException("Buffer is empty");
BufferedPacket p = *m_list.begin();
@@ -283,7 +283,7 @@ BufferedPacket ReliablePacketBuffer::popFirst()
}
BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
RPBSearchResult r = findPacket(seqnum);
if (r == notFound()) {
LOG(dout_con<<"Sequence number: " << seqnum
@@ -294,7 +294,7 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
RPBSearchResult next = r;
- next++;
+ ++next;
if (next != notFound()) {
u16 s = readU16(&(next->data[BASE_HEADER_SIZE+1]));
m_oldest_non_answered_ack = s;
@@ -311,7 +311,7 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
}
void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected)
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
if (p.data.getSize() < BASE_HEADER_SIZE + 3) {
errorstream << "ReliablePacketBuffer::insert(): Invalid data size for "
"reliable packet" << std::endl;
@@ -358,7 +358,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected)
/* this is true e.g. on wrap around */
if (seqnum < next_expected) {
while(((s < seqnum) || (s >= next_expected)) && (i != m_list.end())) {
- i++;
+ ++i;
if (i != m_list.end())
s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
}
@@ -367,7 +367,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected)
else
{
while(((s < seqnum) && (s >= next_expected)) && (i != m_list.end())) {
- i++;
+ ++i;
if (i != m_list.end())
s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
}
@@ -411,7 +411,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected)
void ReliablePacketBuffer::incrementTimeouts(float dtime)
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
{
@@ -423,7 +423,7 @@ void ReliablePacketBuffer::incrementTimeouts(float dtime)
std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout,
unsigned int max_packets)
{
- JMutexAutoLock listlock(m_list_mutex);
+ MutexAutoLock listlock(m_list_mutex);
std::list<BufferedPacket> timed_outs;
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
@@ -446,7 +446,7 @@ std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout,
IncomingSplitBuffer::~IncomingSplitBuffer()
{
- JMutexAutoLock listlock(m_map_mutex);
+ MutexAutoLock listlock(m_map_mutex);
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
i != m_buf.end(); ++i)
{
@@ -459,7 +459,7 @@ IncomingSplitBuffer::~IncomingSplitBuffer()
*/
SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
{
- JMutexAutoLock listlock(m_map_mutex);
+ MutexAutoLock listlock(m_map_mutex);
u32 headersize = BASE_HEADER_SIZE + 7;
if (p.data.getSize() < headersize) {
errorstream << "Invalid data size for split packet" << std::endl;
@@ -546,7 +546,7 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
{
std::list<u16> remove_queue;
{
- JMutexAutoLock listlock(m_map_mutex);
+ MutexAutoLock listlock(m_map_mutex);
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
i != m_buf.end(); ++i)
{
@@ -562,7 +562,7 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
for(std::list<u16>::iterator j = remove_queue.begin();
j != remove_queue.end(); ++j)
{
- JMutexAutoLock listlock(m_map_mutex);
+ MutexAutoLock listlock(m_map_mutex);
LOG(dout_con<<"NOTE: Removing timed out unreliable split packet"<<std::endl);
delete m_buf[*j];
m_buf.erase(*j);
@@ -605,13 +605,13 @@ Channel::~Channel()
u16 Channel::readNextIncomingSeqNum()
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
return next_incoming_seqnum;
}
u16 Channel::incNextIncomingSeqNum()
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
u16 retval = next_incoming_seqnum;
next_incoming_seqnum++;
return retval;
@@ -619,18 +619,18 @@ u16 Channel::incNextIncomingSeqNum()
u16 Channel::readNextSplitSeqNum()
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
return next_outgoing_split_seqnum;
}
void Channel::setNextSplitSeqNum(u16 seqnum)
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
next_outgoing_split_seqnum = seqnum;
}
u16 Channel::getOutgoingSequenceNumber(bool& successful)
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
u16 retval = next_outgoing_seqnum;
u16 lowest_unacked_seqnumber;
@@ -670,7 +670,7 @@ u16 Channel::getOutgoingSequenceNumber(bool& successful)
u16 Channel::readOutgoingSequenceNumber()
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
return next_outgoing_seqnum;
}
@@ -686,32 +686,32 @@ bool Channel::putBackSequenceNumber(u16 seqnum)
void Channel::UpdateBytesSent(unsigned int bytes, unsigned int packets)
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
current_bytes_transfered += bytes;
current_packet_successfull += packets;
}
void Channel::UpdateBytesReceived(unsigned int bytes) {
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
current_bytes_received += bytes;
}
void Channel::UpdateBytesLost(unsigned int bytes)
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
current_bytes_lost += bytes;
}
void Channel::UpdatePacketLossCounter(unsigned int count)
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
current_packet_loss += count;
}
void Channel::UpdatePacketTooLateCounter()
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
current_packet_too_late++;
}
@@ -731,7 +731,7 @@ void Channel::UpdateTimers(float dtime,bool legacy_peer)
bool reasonable_amount_of_data_transmitted = false;
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
packet_loss = current_packet_loss;
//packet_too_late = current_packet_too_late;
packets_successfull = current_packet_successfull;
@@ -802,7 +802,7 @@ void Channel::UpdateTimers(float dtime,bool legacy_peer)
if (bpm_counter > 10.0)
{
{
- JMutexAutoLock internal(m_internal_mutex);
+ MutexAutoLock internal(m_internal_mutex);
cur_kbps =
(((float) current_bytes_transfered)/bpm_counter)/1024.0;
current_bytes_transfered = 0;
@@ -903,7 +903,7 @@ bool PeerHelper::operator!=(void* ptr)
bool Peer::IncUseCount()
{
- JMutexAutoLock lock(m_exclusive_access_mutex);
+ MutexAutoLock lock(m_exclusive_access_mutex);
if (!m_pending_deletion)
{
@@ -917,7 +917,7 @@ bool Peer::IncUseCount()
void Peer::DecUseCount()
{
{
- JMutexAutoLock lock(m_exclusive_access_mutex);
+ MutexAutoLock lock(m_exclusive_access_mutex);
sanity_check(m_usage > 0);
m_usage--;
@@ -978,7 +978,7 @@ void Peer::RTTStatistics(float rtt, std::string profiler_id,
bool Peer::isTimedOut(float timeout)
{
- JMutexAutoLock lock(m_exclusive_access_mutex);
+ MutexAutoLock lock(m_exclusive_access_mutex);
u32 current_time = porting::getTimeMs();
float dtime = CALC_DTIME(m_last_timeout_check,current_time);
@@ -992,7 +992,7 @@ bool Peer::isTimedOut(float timeout)
void Peer::Drop()
{
{
- JMutexAutoLock usage_lock(m_exclusive_access_mutex);
+ MutexAutoLock usage_lock(m_exclusive_access_mutex);
m_pending_deletion = true;
if (m_usage != 0)
return;
@@ -1051,7 +1051,7 @@ void UDPPeer::reportRTT(float rtt)
if (timeout > RESEND_TIMEOUT_MAX)
timeout = RESEND_TIMEOUT_MAX;
- JMutexAutoLock usage_lock(m_exclusive_access_mutex);
+ MutexAutoLock usage_lock(m_exclusive_access_mutex);
resend_timeout = timeout;
}
@@ -1255,8 +1255,9 @@ SharedBuffer<u8> UDPPeer::addSpiltPacket(u8 channel,
/* Connection Threads */
/******************************************************************************/
-ConnectionSendThread::ConnectionSendThread( unsigned int max_packet_size,
- float timeout) :
+ConnectionSendThread::ConnectionSendThread(unsigned int max_packet_size,
+ float timeout) :
+ Thread("ConnectionSend"),
m_connection(NULL),
m_max_packet_size(max_packet_size),
m_timeout(timeout),
@@ -1266,11 +1267,9 @@ ConnectionSendThread::ConnectionSendThread( unsigned int max_packet_size,
{
}
-void * ConnectionSendThread::Thread()
+void * ConnectionSendThread::run()
{
- assert(m_connection != NULL);
- ThreadStarted();
- log_register_thread("ConnectionSend");
+ assert(m_connection);
LOG(dout_con<<m_connection->getDesc()
<<"ConnectionSend thread started"<<std::endl);
@@ -1281,21 +1280,19 @@ void * ConnectionSendThread::Thread()
PROFILE(std::stringstream ThreadIdentifier);
PROFILE(ThreadIdentifier << "ConnectionSend: [" << m_connection->getDesc() << "]");
- porting::setThreadName("ConnectionSend");
-
/* if stop is requested don't stop immediately but try to send all */
/* packets first */
- while(!StopRequested() || packetsQueued()) {
+ while(!stopRequested() || packetsQueued()) {
BEGIN_DEBUG_EXCEPTION_HANDLER
PROFILE(ScopeProfiler sp(g_profiler, ThreadIdentifier.str(), SPT_AVG));
m_iteration_packets_avaialble = m_max_data_packets_per_iteration;
/* wait for trigger or timeout */
- m_send_sleep_semaphore.Wait(50);
+ m_send_sleep_semaphore.wait(50);
/* remove all triggers */
- while(m_send_sleep_semaphore.Wait(0)) {}
+ while(m_send_sleep_semaphore.wait(0)) {}
lasttime = curtime;
curtime = porting::getTimeMs();
@@ -1319,7 +1316,7 @@ void * ConnectionSendThread::Thread()
/* send non reliable packets */
sendPackets(dtime);
- END_DEBUG_EXCEPTION_HANDLER(errorstream);
+ END_DEBUG_EXCEPTION_HANDLER
}
PROFILE(g_profiler->remove(ThreadIdentifier.str()));
@@ -1328,7 +1325,7 @@ void * ConnectionSendThread::Thread()
void ConnectionSendThread::Trigger()
{
- m_send_sleep_semaphore.Post();
+ m_send_sleep_semaphore.post();
}
bool ConnectionSendThread::packetsQueued()
@@ -1763,7 +1760,7 @@ void ConnectionSendThread::disconnect()
for (std::list<u16>::iterator i = peerids.begin();
i != peerids.end();
- i++)
+ ++i)
{
sendAsPacket(*i, 0,data,false);
}
@@ -1843,7 +1840,7 @@ void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer<u8> data)
for (std::list<u16>::iterator i = peerids.begin();
i != peerids.end();
- i++)
+ ++i)
{
send(*i, channelnum, data);
}
@@ -1855,7 +1852,7 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
for (std::list<u16>::iterator i = peerids.begin();
i != peerids.end();
- i++)
+ ++i)
{
PeerHelper peer = m_connection->getPeerNoEx(*i);
@@ -1984,7 +1981,7 @@ void ConnectionSendThread::sendPackets(float dtime)
}
else if (
( peer->m_increment_packets_remaining > 0) ||
- (StopRequested())) {
+ (stopRequested())) {
rawSendAsPacket(packet.peer_id, packet.channelnum,
packet.data, packet.reliable);
peer->m_increment_packets_remaining--;
@@ -2014,15 +2011,14 @@ void ConnectionSendThread::sendAsPacket(u16 peer_id, u8 channelnum,
}
ConnectionReceiveThread::ConnectionReceiveThread(unsigned int max_packet_size) :
+ Thread("ConnectionReceive"),
m_connection(NULL)
{
}
-void * ConnectionReceiveThread::Thread()
+void * ConnectionReceiveThread::run()
{
- assert(m_connection != NULL);
- ThreadStarted();
- log_register_thread("ConnectionReceive");
+ assert(m_connection);
LOG(dout_con<<m_connection->getDesc()
<<"ConnectionReceive thread started"<<std::endl);
@@ -2030,15 +2026,13 @@ void * ConnectionReceiveThread::Thread()
PROFILE(std::stringstream ThreadIdentifier);
PROFILE(ThreadIdentifier << "ConnectionReceive: [" << m_connection->getDesc() << "]");
- porting::setThreadName("ConnectionReceive");
-
#ifdef DEBUG_CONNECTION_KBPS
u32 curtime = porting::getTimeMs();
u32 lasttime = curtime;
float debug_print_timer = 0.0;
#endif
- while(!StopRequested()) {
+ while(!stopRequested()) {
BEGIN_DEBUG_EXCEPTION_HANDLER
PROFILE(ScopeProfiler sp(g_profiler, ThreadIdentifier.str(), SPT_AVG));
@@ -2103,8 +2097,9 @@ void * ConnectionReceiveThread::Thread()
}
}
#endif
- END_DEBUG_EXCEPTION_HANDLER(errorstream);
+ END_DEBUG_EXCEPTION_HANDLER
}
+
PROFILE(g_profiler->remove(ThreadIdentifier.str()));
return NULL;
}
@@ -2684,8 +2679,8 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout,
m_sendThread.setParent(this);
m_receiveThread.setParent(this);
- m_sendThread.Start();
- m_receiveThread.Start();
+ m_sendThread.start();
+ m_receiveThread.start();
}
@@ -2694,8 +2689,8 @@ Connection::~Connection()
{
m_shutting_down = true;
// request threads to stop
- m_sendThread.Stop();
- m_receiveThread.Stop();
+ m_sendThread.stop();
+ m_receiveThread.stop();
//TODO for some unkonwn reason send/receive threads do not exit as they're
// supposed to be but wait on peer timeout. To speed up shutdown we reduce
@@ -2703,8 +2698,8 @@ Connection::~Connection()
m_sendThread.setPeerTimeout(0.5);
// wait for threads to finish
- m_sendThread.Wait();
- m_receiveThread.Wait();
+ m_sendThread.wait();
+ m_receiveThread.wait();
// Delete peers
for(std::map<u16, Peer*>::iterator
@@ -2724,7 +2719,7 @@ void Connection::putEvent(ConnectionEvent &e)
PeerHelper Connection::getPeer(u16 peer_id)
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id);
if (node == m_peers.end()) {
@@ -2739,7 +2734,7 @@ PeerHelper Connection::getPeer(u16 peer_id)
PeerHelper Connection::getPeerNoEx(u16 peer_id)
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id);
if (node == m_peers.end()) {
@@ -2755,7 +2750,7 @@ PeerHelper Connection::getPeerNoEx(u16 peer_id)
/* find peer_id for address */
u16 Connection::lookupPeer(Address& sender)
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
std::map<u16, Peer*>::iterator j;
j = m_peers.begin();
for(; j != m_peers.end(); ++j)
@@ -2794,7 +2789,7 @@ bool Connection::deletePeer(u16 peer_id, bool timeout)
/* lock list as short as possible */
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
if (m_peers.find(peer_id) == m_peers.end())
return false;
peer = m_peers[peer_id];
@@ -2852,7 +2847,7 @@ void Connection::Connect(Address address)
bool Connection::Connected()
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
if (m_peers.size() != 1)
return false;
@@ -2987,7 +2982,7 @@ u16 Connection::createPeer(Address& sender, MTProtocols protocol, int fd)
/*
Find an unused peer id
*/
- JMutexAutoLock lock(m_peers_mutex);
+ MutexAutoLock lock(m_peers_mutex);
bool out_of_ids = false;
for(;;) {
// Check if exists
@@ -3038,9 +3033,9 @@ u16 Connection::createPeer(Address& sender, MTProtocols protocol, int fd)
void Connection::PrintInfo(std::ostream &out)
{
- m_info_mutex.Lock();
+ m_info_mutex.lock();
out<<getDesc()<<": ";
- m_info_mutex.Unlock();
+ m_info_mutex.unlock();
}
void Connection::PrintInfo()
@@ -3091,7 +3086,7 @@ UDPPeer* Connection::createServerPeer(Address& address)
UDPPeer *peer = new UDPPeer(PEER_ID_SERVER, address, this);
{
- JMutexAutoLock lock(m_peers_mutex);
+ MutexAutoLock lock(m_peers_mutex);
m_peers[peer->id] = peer;
m_peer_ids.push_back(peer->id);
}
diff --git a/src/network/connection.h b/src/network/connection.h
index 15ea7e20f..fe2c9819d 100644
--- a/src/network/connection.h
+++ b/src/network/connection.h
@@ -349,7 +349,7 @@ private:
u16 m_oldest_non_answered_ack;
- JMutex m_list_mutex;
+ Mutex m_list_mutex;
};
/*
@@ -372,7 +372,7 @@ private:
// Key is seqnum
std::map<u16, IncomingSplitPacket*> m_buf;
- JMutex m_map_mutex;
+ Mutex m_map_mutex;
};
struct OutgoingPacket
@@ -519,32 +519,32 @@ public:
void UpdateTimers(float dtime, bool legacy_peer);
const float getCurrentDownloadRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return cur_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return cur_kbps; };
const float getMaxDownloadRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return max_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return max_kbps; };
const float getCurrentLossRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; };
+ { MutexAutoLock lock(m_internal_mutex); return cur_kbps_lost; };
const float getMaxLossRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return max_kbps_lost; };
+ { MutexAutoLock lock(m_internal_mutex); return max_kbps_lost; };
const float getCurrentIncomingRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return cur_incoming_kbps; };
const float getMaxIncomingRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return max_incoming_kbps; };
const float getAvgDownloadRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return avg_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return avg_kbps; };
const float getAvgLossRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; };
+ { MutexAutoLock lock(m_internal_mutex); return avg_kbps_lost; };
const float getAvgIncomingRateKB()
- { JMutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; };
+ { MutexAutoLock lock(m_internal_mutex); return avg_incoming_kbps; };
const unsigned int getWindowSize() const { return window_size; };
void setWindowSize(unsigned int size) { window_size = size; };
private:
- JMutex m_internal_mutex;
+ Mutex m_internal_mutex;
int window_size;
u16 next_incoming_seqnum;
@@ -675,7 +675,7 @@ class Peer {
};
virtual ~Peer() {
- JMutexAutoLock usage_lock(m_exclusive_access_mutex);
+ MutexAutoLock usage_lock(m_exclusive_access_mutex);
FATAL_ERROR_IF(m_usage != 0, "Reference counting failure");
};
@@ -692,15 +692,15 @@ class Peer {
virtual bool getAddress(MTProtocols type, Address& toset) = 0;
void ResetTimeout()
- {JMutexAutoLock lock(m_exclusive_access_mutex); m_timeout_counter=0.0; };
+ {MutexAutoLock lock(m_exclusive_access_mutex); m_timeout_counter=0.0; };
bool isTimedOut(float timeout);
void setSentWithID()
- { JMutexAutoLock lock(m_exclusive_access_mutex); m_has_sent_with_id = true; };
+ { MutexAutoLock lock(m_exclusive_access_mutex); m_has_sent_with_id = true; };
bool hasSentWithID()
- { JMutexAutoLock lock(m_exclusive_access_mutex); return m_has_sent_with_id; };
+ { MutexAutoLock lock(m_exclusive_access_mutex); return m_has_sent_with_id; };
unsigned int m_increment_packets_remaining;
unsigned int m_increment_bytes_remaining;
@@ -744,7 +744,7 @@ class Peer {
bool IncUseCount();
void DecUseCount();
- JMutex m_exclusive_access_mutex;
+ Mutex m_exclusive_access_mutex;
bool m_pending_deletion;
@@ -826,10 +826,10 @@ protected:
unsigned int maxtransfer);
float getResendTimeout()
- { JMutexAutoLock lock(m_exclusive_access_mutex); return resend_timeout; }
+ { MutexAutoLock lock(m_exclusive_access_mutex); return resend_timeout; }
void setResendTimeout(float timeout)
- { JMutexAutoLock lock(m_exclusive_access_mutex); resend_timeout = timeout; }
+ { MutexAutoLock lock(m_exclusive_access_mutex); resend_timeout = timeout; }
bool Ping(float dtime,SharedBuffer<u8>& data);
Channel channels[CHANNEL_COUNT];
@@ -910,14 +910,14 @@ struct ConnectionEvent
}
};
-class ConnectionSendThread : public JThread {
+class ConnectionSendThread : public Thread {
public:
friend class UDPPeer;
ConnectionSendThread(unsigned int max_packet_size, float timeout);
- void * Thread ();
+ void *run();
void Trigger();
@@ -961,7 +961,7 @@ private:
unsigned int m_max_packet_size;
float m_timeout;
std::queue<OutgoingPacket> m_outgoing_queue;
- JSemaphore m_send_sleep_semaphore;
+ Semaphore m_send_sleep_semaphore;
unsigned int m_iteration_packets_avaialble;
unsigned int m_max_commands_per_iteration;
@@ -969,24 +969,24 @@ private:
unsigned int m_max_packets_requeued;
};
-class ConnectionReceiveThread : public JThread {
+class ConnectionReceiveThread : public Thread {
public:
ConnectionReceiveThread(unsigned int max_packet_size);
- void * Thread ();
+ void *run();
- void setParent(Connection* parent) {
- assert(parent != NULL); // Pre-condition
+ void setParent(Connection *parent) {
+ assert(parent); // Pre-condition
m_connection = parent;
}
private:
- void receive ();
+ void receive();
// Returns next data from a buffer if possible
// If found, returns true; if not, false.
// If found, sets peer_id and dst
- bool getFromBuffers (u16 &peer_id, SharedBuffer<u8> &dst);
+ bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst);
bool checkIncomingBuffers(Channel *channel, u16 &peer_id,
SharedBuffer<u8> &dst);
@@ -1054,7 +1054,7 @@ protected:
std::list<u16> getPeerIDs()
{
- JMutexAutoLock peerlock(m_peers_mutex);
+ MutexAutoLock peerlock(m_peers_mutex);
return m_peer_ids;
}
@@ -1075,12 +1075,12 @@ private:
std::map<u16, Peer*> m_peers;
std::list<u16> m_peer_ids;
- JMutex m_peers_mutex;
+ Mutex m_peers_mutex;
ConnectionSendThread m_sendThread;
ConnectionReceiveThread m_receiveThread;
- JMutex m_info_mutex;
+ Mutex m_info_mutex;
// Backwards compatibility
PeerHandler *m_bc_peerhandler;
diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp
index b5e451cdb..388afc18e 100644
--- a/src/network/networkpacket.cpp
+++ b/src/network/networkpacket.cpp
@@ -77,6 +77,9 @@ void NetworkPacket::putRawString(const char* src, u32 len)
m_data.resize(m_datasize);
}
+ if (len == 0)
+ return;
+
memcpy(&m_data[m_read_offset], src, len);
m_read_offset += len;
}
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 82c82f79e..177b97680 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -132,16 +132,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO
PROTOCOL_VERSION 26:
Add TileDef tileable_horizontal, tileable_vertical flags
+ PROTOCOL_VERSION 27:
+ backface_culling: backwards compatibility for playing with
+ newer client on pre-27 servers.
+ Add nodedef v3 - connected nodeboxes
*/
-#define LATEST_PROTOCOL_VERSION 26
+#define LATEST_PROTOCOL_VERSION 27
// Server's supported network protocol range
#define SERVER_PROTOCOL_VERSION_MIN 13
#define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Client's supported network protocol range
-#define CLIENT_PROTOCOL_VERSION_MIN 13
+// The minimal version depends on whether
+// send_pre_v25_init is enabled or not
+#define CLIENT_PROTOCOL_VERSION_MIN 25
+#define CLIENT_PROTOCOL_VERSION_MIN_LEGACY 13
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Constant that differentiates the protocol from random data and other protocols
@@ -208,7 +215,6 @@ enum ToClientCommand
TOCLIENT_BLOCKDATA = 0x20, //TODO: Multiple blocks
TOCLIENT_ADDNODE = 0x21,
/*
- u16 command
v3s16 position
serialized mapnode
u8 keep_metadata // Added in protocol version 22
@@ -255,7 +261,6 @@ enum ToClientCommand
/*
Sent as unreliable.
- u16 command
u16 number of player positions
for each player:
u16 peer_id
@@ -271,7 +276,6 @@ enum ToClientCommand
TOCLIENT_TIME_OF_DAY = 0x29,
/*
- u16 command
u16 time (0-23999)
Added in a later version:
f1000 time_speed
@@ -281,14 +285,12 @@ enum ToClientCommand
TOCLIENT_CHAT_MESSAGE = 0x30,
/*
- u16 command
u16 length
wstring message
*/
TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD = 0x31,
/*
- u16 command
u16 count of removed objects
for all removed objects {
u16 id
@@ -304,7 +306,6 @@ enum ToClientCommand
TOCLIENT_ACTIVE_OBJECT_MESSAGES = 0x32,
/*
- u16 command
for all objects
{
u16 id
@@ -315,13 +316,11 @@ enum ToClientCommand
TOCLIENT_HP = 0x33,
/*
- u16 command
u8 hp
*/
TOCLIENT_MOVE_PLAYER = 0x34,
/*
- u16 command
v3f1000 player position
f1000 player pitch
f1000 player yaw
@@ -329,14 +328,12 @@ enum ToClientCommand
TOCLIENT_ACCESS_DENIED_LEGACY = 0x35,
/*
- u16 command
u16 reason_length
wstring reason
*/
TOCLIENT_PLAYERITEM = 0x36, // Obsolete
/*
- u16 command
u16 count of player items
for all player items {
u16 peer id
@@ -347,14 +344,12 @@ enum ToClientCommand
TOCLIENT_DEATHSCREEN = 0x37,
/*
- u16 command
u8 bool set camera point target
v3f1000 camera point target (to point the death cause or whatever)
*/
TOCLIENT_MEDIA = 0x38,
/*
- u16 command
u16 total number of texture bunches
u16 index of this bunch
u32 number of files in this bunch
@@ -370,21 +365,18 @@ enum ToClientCommand
TOCLIENT_TOOLDEF = 0x39,
/*
- u16 command
u32 length of the next item
serialized ToolDefManager
*/
TOCLIENT_NODEDEF = 0x3a,
/*
- u16 command
u32 length of the next item
serialized NodeDefManager
*/
TOCLIENT_CRAFTITEMDEF = 0x3b,
/*
- u16 command
u32 length of the next item
serialized CraftiItemDefManager
*/
@@ -392,7 +384,6 @@ enum ToClientCommand
TOCLIENT_ANNOUNCE_MEDIA = 0x3c,
/*
- u16 command
u32 number of files
for each texture {
u16 length of name
@@ -404,14 +395,12 @@ enum ToClientCommand
TOCLIENT_ITEMDEF = 0x3d,
/*
- u16 command
u32 length of next item
serialized ItemDefManager
*/
TOCLIENT_PLAY_SOUND = 0x3f,
/*
- u16 command
s32 sound_id
u16 len
u8[len] sound name
@@ -424,13 +413,11 @@ enum ToClientCommand
TOCLIENT_STOP_SOUND = 0x40,
/*
- u16 command
s32 sound_id
*/
TOCLIENT_PRIVILEGES = 0x41,
/*
- u16 command
u16 number of privileges
for each privilege
u16 len
@@ -439,7 +426,6 @@ enum ToClientCommand
TOCLIENT_INVENTORY_FORMSPEC = 0x42,
/*
- u16 command
u32 len
u8[len] formspec
*/
@@ -463,7 +449,6 @@ enum ToClientCommand
TOCLIENT_MOVEMENT = 0x45,
/*
- u16 command
f1000 movement_acceleration_default
f1000 movement_acceleration_air
f1000 movement_acceleration_fast
@@ -480,7 +465,6 @@ enum ToClientCommand
TOCLIENT_SPAWN_PARTICLE = 0x46,
/*
- u16 command
v3f1000 pos
v3f1000 velocity
v3f1000 acceleration
@@ -494,7 +478,6 @@ enum ToClientCommand
TOCLIENT_ADD_PARTICLESPAWNER = 0x47,
/*
- u16 command
u16 amount
f1000 spawntime
v3f1000 minpos
@@ -516,13 +499,11 @@ enum ToClientCommand
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48,
/*
- u16 command
u16 id
*/
TOCLIENT_HUDADD = 0x49,
/*
- u16 command
u32 id
u8 type
v2f1000 pos
@@ -542,13 +523,11 @@ enum ToClientCommand
TOCLIENT_HUDRM = 0x4a,
/*
- u16 command
u32 id
*/
TOCLIENT_HUDCHANGE = 0x4b,
/*
- u16 command
u32 id
u8 stat
[v2f1000 data |
@@ -559,14 +538,12 @@ enum ToClientCommand
TOCLIENT_HUD_SET_FLAGS = 0x4c,
/*
- u16 command
u32 flags
u32 mask
*/
TOCLIENT_HUD_SET_PARAM = 0x4d,
/*
- u16 command
u16 param
u16 len
u8[len] value
@@ -574,13 +551,11 @@ enum ToClientCommand
TOCLIENT_BREATH = 0x4e,
/*
- u16 command
u16 breath
*/
TOCLIENT_SET_SKY = 0x4f,
/*
- u16 command
u8[4] color (ARGB)
u8 len
u8[len] type
@@ -592,14 +567,12 @@ enum ToClientCommand
TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
/*
- u16 command
u8 do_override (boolean)
u16 day-night ratio 0...65535
*/
TOCLIENT_LOCAL_PLAYER_ANIMATIONS = 0x51,
/*
- u16 command
v2s32 stand/idle
v2s32 walk
v2s32 dig
@@ -609,14 +582,12 @@ enum ToClientCommand
TOCLIENT_EYE_OFFSET = 0x52,
/*
- u16 command
v3f1000 first
v3f1000 third
*/
TOCLIENT_DELETE_PARTICLESPAWNER = 0x53,
/*
- u16 command
u32 id
*/
@@ -624,7 +595,6 @@ enum ToClientCommand
/*
Belonging to AUTH_MECHANISM_LEGACY_PASSWORD and AUTH_MECHANISM_SRP.
- u16 command
std::string bytes_s
std::string bytes_B
*/
@@ -735,7 +705,6 @@ enum ToServerCommand
TOSERVER_SIGNTEXT = 0x30, // Old signs, obsolete
/*
- u16 command
v3s16 blockpos
s16 id
u16 textlen
@@ -749,14 +718,12 @@ enum ToServerCommand
TOSERVER_CHAT_MESSAGE = 0x32,
/*
- u16 command
u16 length
wstring message
*/
TOSERVER_SIGNNODETEXT = 0x33, // obsolete
/*
- u16 command
v3s16 p
u16 textlen
textdata
@@ -773,7 +740,6 @@ enum ToServerCommand
TOSERVER_DAMAGE = 0x35,
/*
- u16 command
u8 amount
*/
@@ -818,14 +784,12 @@ enum ToServerCommand
TOSERVER_REMOVED_SOUNDS = 0x3a,
/*
- u16 command
u16 len
s32[len] sound_id
*/
TOSERVER_NODEMETA_FIELDS = 0x3b,
/*
- u16 command
v3s16 p
u16 len
u8[len] form name (reserved for future use)
@@ -839,7 +803,6 @@ enum ToServerCommand
TOSERVER_INVENTORY_FIELDS = 0x3c,
/*
- u16 command
u16 len
u8[len] form name (reserved for future use)
u16 number of fields
@@ -852,7 +815,6 @@ enum ToServerCommand
TOSERVER_REQUEST_MEDIA = 0x40,
/*
- u16 command
u16 number of files requested
for each file {
u16 length of name
@@ -862,12 +824,11 @@ enum ToServerCommand
TOSERVER_RECEIVED_MEDIA = 0x41,
/*
- u16 command
+ <no payload data>
*/
TOSERVER_BREATH = 0x42,
/*
- u16 command
u16 breath
*/
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index f756d80ef..1bcb78a8a 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -103,7 +103,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
// Use the highest version supported by both
u8 depl_serial_v = std::min(client_max, our_max);
// If it's lower than the lowest supported, give up.
- if (depl_serial_v < SER_FMT_VER_LOWEST)
+ if (depl_serial_v < SER_FMT_VER_LOWEST_READ)
depl_serial_v = SER_FMT_VER_INVALID;
if (depl_serial_v == SER_FMT_VER_INVALID) {
@@ -261,9 +261,9 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
auth_mechs |= AUTH_MECHANISM_FIRST_SRP;
} else {
// Take care of default passwords.
- client->enc_pwd = getSRPVerifier(playerName, default_password);
+ client->enc_pwd = get_encoded_srp_verifier(playerName, default_password);
auth_mechs |= AUTH_MECHANISM_SRP;
- // Create auth, but only on successful login
+ // Allocate player in db, but only on successful login.
client->create_player_on_auth_success = true;
}
}
@@ -347,7 +347,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
// Use the highest version supported by both
int deployed = std::min(client_max, our_max);
// If it's lower than the lowest supported, give up.
- if (deployed < SER_FMT_VER_LOWEST)
+ if (deployed < SER_FMT_VER_LOWEST_READ)
deployed = SER_FMT_VER_INVALID;
if (deployed == SER_FMT_VER_INVALID) {
@@ -549,7 +549,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
std::string raw_default_password =
g_settings->get("default_password");
std::string initial_password =
- translatePassword(playername, raw_default_password);
+ translate_password(playername, raw_default_password);
// If default_password is empty, allow any initial password
if (raw_default_password.length() == 0)
@@ -568,8 +568,10 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
}
if (given_password != checkpwd) {
- actionstream << "Server: " << playername << " supplied wrong password"
- << std::endl;
+ actionstream << "Server: User " << playername
+ << " at " << addr_s
+ << " supplied wrong password (auth mechanism: legacy)."
+ << std::endl;
DenyAccess_Legacy(pkt->getPeerId(), L"Wrong password");
return;
}
@@ -760,14 +762,14 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
RemoteClient *client = getClient(pkt->getPeerId());
- for (u16 i = 0; i < count; i++) {
- if ((s16)pkt->getSize() < 1 + (i + 1) * 6)
- throw con::InvalidIncomingDataException
+ if ((s16)pkt->getSize() < 1 + (int)count * 6) {
+ throw con::InvalidIncomingDataException
("GOTBLOCKS length is too short");
- v3s16 p;
+ }
+ for (u16 i = 0; i < count; i++) {
+ v3s16 p;
*pkt >> p;
-
client->GotBlock(p);
}
}
@@ -863,13 +865,14 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt)
RemoteClient *client = getClient(pkt->getPeerId());
- for (u16 i = 0; i < count; i++) {
- if ((s16)pkt->getSize() < 1 + (i + 1) * 6)
- throw con::InvalidIncomingDataException
+ if ((s16)pkt->getSize() < 1 + (int)count * 6) {
+ throw con::InvalidIncomingDataException
("DELETEDBLOCKS length is too short");
+ }
+
+ for (u16 i = 0; i < count; i++) {
v3s16 p;
*pkt >> p;
-
client->SetBlockNotSent(p);
}
}
@@ -1057,69 +1060,15 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
return;
}
- // 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());
-
- // Run script hook
- bool ate = m_script->on_chat_message(player->getName(),
- wide_to_narrow(message));
- // If script ate the message, don't proceed
- if (ate)
- return;
-
- // Line to send to players
- std::wstring line;
- // Whether to send to the player that sent the line
- bool send_to_sender_only = false;
-
- // Commands are implemented in Lua, so only catch invalid
- // commands that were not "eaten" and send an error back
- if (message[0] == L'/') {
- message = message.substr(1);
- send_to_sender_only = true;
- if (message.length() == 0)
- line += L"-!- Empty command";
- else
- line += L"-!- Invalid command: " + str_split(message, L' ')[0];
- }
- else {
- if (checkPriv(player->getName(), "shout")) {
- line += L"<";
- line += name;
- line += L"> ";
- line += message;
- } else {
- line += L"-!- You don't have permission to shout.";
- send_to_sender_only = true;
- }
- }
+ std::string name = player->getName();
+ std::wstring wname = narrow_to_wide(name);
- if (line != L"")
- {
- /*
- Send the message to sender
- */
- if (send_to_sender_only) {
- SendChatMessage(pkt->getPeerId(), line);
- }
- /*
- Send the message to others
- */
- else {
- actionstream << "CHAT: " << wide_to_narrow(line)<<std::endl;
-
- std::vector<u16> clients = m_clients.getClientIDs();
-
- for (std::vector<u16>::iterator i = clients.begin();
- i != clients.end(); ++i) {
- if (*i != pkt->getPeerId())
- SendChatMessage(*i, line);
- }
- }
+ std::wstring answer_to_sender = handleChat(name, wname, message,
+ true, pkt->getPeerId());
+ if (!answer_to_sender.empty()) {
+ // Send the answer to sender
+ SendChatMessage(pkt->getPeerId(), answer_to_sender);
}
}
@@ -1410,7 +1359,9 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
Check that target is reasonably close
(only when digging or placing things)
*/
- if (action == 0 || action == 2 || action == 3) {
+ static const bool enable_anticheat = !g_settings->getBool("disable_anticheat");
+ if ((action == 0 || action == 2 || action == 3) &&
+ (enable_anticheat && !isSingleplayer())) {
float d = player_pos.getDistanceFrom(pointed_pos_under);
float max_d = BS * 14; // Just some large enough value
if (d > max_d) {
@@ -1467,21 +1418,22 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
NOTE: This can be used in the future to check if
somebody is cheating, by checking the timing.
*/
+
MapNode n(CONTENT_IGNORE);
bool pos_ok;
- n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
- if (pos_ok)
- n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
+ n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
if (!pos_ok) {
infostream << "Server: Not punching: Node not found."
<< " Adding block to emerge queue."
<< std::endl;
- m_emerge->enqueueBlockEmerge(pkt->getPeerId(), getNodeBlockPos(p_above), false);
+ m_emerge->enqueueBlockEmerge(pkt->getPeerId(),
+ getNodeBlockPos(p_above), false);
}
if (n.getContent() != CONTENT_IGNORE)
m_script->node_on_punch(p_under, n, playersao, pointed);
+
// Cheat prevention
playersao->noCheatDigStart(p_under);
}
@@ -1538,14 +1490,15 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
MapNode n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
if (!pos_ok) {
infostream << "Server: Not finishing digging: Node not found."
- << " Adding block to emerge queue."
- << std::endl;
- m_emerge->enqueueBlockEmerge(pkt->getPeerId(), getNodeBlockPos(p_above), false);
+ << " Adding block to emerge queue."
+ << std::endl;
+ m_emerge->enqueueBlockEmerge(pkt->getPeerId(),
+ getNodeBlockPos(p_above), false);
}
/* Cheat prevention */
bool is_valid_dig = true;
- if (!isSingleplayer() && !g_settings->getBool("disable_anticheat")) {
+ if (enable_anticheat && !isSingleplayer()) {
v3s16 nocheat_p = playersao->getNoCheatDigPos();
float nocheat_t = playersao->getNoCheatDigTime();
playersao->noCheatDigEnd();
@@ -1703,13 +1656,30 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
}
} // action == 4
+
+ /*
+ 5: rightclick air
+ */
+ else if (action == 5) {
+ ItemStack item = playersao->getWieldedItem();
+
+ actionstream << player->getName() << " activates "
+ << item.name << std::endl;
+
+ if (m_script->item_OnSecondaryUse(
+ item, playersao)) {
+ if( playersao->setWieldedItem(item)) {
+ SendInventory(playersao);
+ }
+ }
+ }
/*
Catch invalid actions
*/
else {
- infostream << "WARNING: Server: Invalid action "
+ warningstream << "Server: Invalid action "
<< action << std::endl;
}
}
@@ -1838,7 +1808,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
*pkt >> salt >> verification_key >> is_empty;
verbosestream << "Server: Got TOSERVER_FIRST_SRP from " << addr_s
- << ", with is_empty= " << is_empty << std::endl;
+ << ", with is_empty=" << (is_empty == 1) << std::endl;
// Either this packet is sent because the user is new or to change the password
if (cstate == CS_HelloSent) {
@@ -1861,7 +1831,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
std::string initial_ver_key;
- initial_ver_key = encodeSRPVerifier(verification_key, salt);
+ initial_ver_key = encode_srp_verifier(verification_key, salt);
m_script->createAuth(playername, initial_ver_key);
acceptAuth(pkt->getPeerId(), false);
@@ -1873,7 +1843,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
return;
}
m_clients.event(pkt->getPeerId(), CSE_SudoLeave);
- std::string pw_db_field = encodeSRPVerifier(verification_key, salt);
+ std::string pw_db_field = encode_srp_verifier(verification_key, salt);
bool success = m_script->setPassword(playername, pw_db_field);
if (success) {
actionstream << playername << " changes password" << std::endl;
@@ -1947,22 +1917,14 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
client->chosen_mech = chosen;
- std::string bytes_s;
- std::string bytes_v;
+ std::string salt;
+ std::string verifier;
if (based_on == 0) {
- char *p_bytes_s = 0;
- size_t len_s = 0;
- char *p_bytes_v = 0;
- size_t len_v = 0;
- getSRPVerifier(client->getName(), client->enc_pwd,
- &p_bytes_s, &len_s,
- &p_bytes_v, &len_v);
- bytes_s = std::string(p_bytes_s, len_s);
- bytes_v = std::string(p_bytes_v, len_v);
- free(p_bytes_s);
- free(p_bytes_v);
- } else if (!decodeSRPVerifier(client->enc_pwd, &bytes_s, &bytes_v)) {
+
+ generate_srp_verifier_and_salt(client->getName(), client->enc_pwd,
+ &verifier, &salt);
+ } else if (!decode_srp_verifier_and_salt(client->enc_pwd, &verifier, &salt)) {
// Non-base64 errors should have been catched in the init handler
actionstream << "Server: User " << client->getName()
<< " tried to log in, but srp verifier field"
@@ -1976,8 +1938,8 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
client->auth_data = srp_verifier_new(SRP_SHA256, SRP_NG_2048,
client->getName().c_str(),
- (const unsigned char *) bytes_s.c_str(), bytes_s.size(),
- (const unsigned char *) bytes_v.c_str(), bytes_v.size(),
+ (const unsigned char *) salt.c_str(), salt.size(),
+ (const unsigned char *) verifier.c_str(), verifier.size(),
(const unsigned char *) bytes_A.c_str(), bytes_A.size(),
NULL, 0,
(unsigned char **) &bytes_B, &len_B, NULL, NULL);
@@ -1996,7 +1958,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
}
NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, pkt->getPeerId());
- resp_pkt << bytes_s << std::string(bytes_B, len_B);
+ resp_pkt << salt << std::string(bytes_B, len_B);
Send(&resp_pkt);
}
@@ -2060,9 +2022,8 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
} else {
actionstream << "Server: User " << client->getName()
<< " at " << getPeerAddress(pkt->getPeerId()).serializeString()
- << " supplied wrong (SRP) password from address "
- << getPeerAddress(pkt->getPeerId()).serializeString()
- << "." << std::endl;
+ << " supplied wrong password (auth mechanism: SRP)."
+ << std::endl;
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD);
return;
}