mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-26 18:21:04 +00:00
Code modernization: subfolders (#6283)
* Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo
This commit is contained in:
parent
7528986e44
commit
88b436e6a9
49 changed files with 398 additions and 518 deletions
|
@ -221,7 +221,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
|
|||
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
|
||||
denyCode == SERVER_ACCESSDENIED_CRASH) {
|
||||
*pkt >> m_access_denied_reason;
|
||||
if (m_access_denied_reason == "") {
|
||||
if (m_access_denied_reason.empty()) {
|
||||
m_access_denied_reason = accessDeniedStrings[denyCode];
|
||||
}
|
||||
u8 reconnect;
|
||||
|
@ -237,7 +237,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
|
|||
// Until then (which may be never), this is outside
|
||||
// of the defined protocol.
|
||||
*pkt >> m_access_denied_reason;
|
||||
if (m_access_denied_reason == "") {
|
||||
if (m_access_denied_reason.empty()) {
|
||||
m_access_denied_reason = "Unknown";
|
||||
}
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
|
|||
Strfnd sf(str);
|
||||
while(!sf.at_end()) {
|
||||
std::string baseurl = trim(sf.next(","));
|
||||
if (baseurl != "")
|
||||
if (!baseurl.empty())
|
||||
m_media_downloader->addRemoteServer(baseurl);
|
||||
}
|
||||
}
|
||||
|
@ -1213,7 +1213,7 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
|
|||
}
|
||||
else if (param == HUD_PARAM_HOTBAR_IMAGE) {
|
||||
// If value not empty verify image exists in texture source
|
||||
if (value != "" && !getTextureSource()->isKnownSourceImage(value)) {
|
||||
if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
|
||||
errorstream << "Server sent wrong Hud hotbar image (sent value: '"
|
||||
<< value << "')" << std::endl;
|
||||
return;
|
||||
|
@ -1222,7 +1222,7 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
|
|||
}
|
||||
else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
|
||||
// If value not empty verify image exists in texture source
|
||||
if (value != "" && !getTextureSource()->isKnownSourceImage(value)) {
|
||||
if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
|
||||
errorstream << "Server sent wrong Hud hotbar selected image (sent value: '"
|
||||
<< value << "')" << std::endl;
|
||||
return;
|
||||
|
|
|
@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include <iomanip>
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
#include "connection.h"
|
||||
#include "serialization.h"
|
||||
#include "log.h"
|
||||
|
@ -151,11 +151,9 @@ std::list<SharedBuffer<u8> > makeSplitPacket(
|
|||
}
|
||||
while(end != data.getSize() - 1);
|
||||
|
||||
for(std::list<SharedBuffer<u8> >::iterator i = chunks.begin();
|
||||
i != chunks.end(); ++i)
|
||||
{
|
||||
for (SharedBuffer<u8> &chunk : chunks) {
|
||||
// Write chunk_count
|
||||
writeU16(&((*i)[3]), chunk_count);
|
||||
writeU16(&(chunk[3]), chunk_count);
|
||||
}
|
||||
|
||||
return chunks;
|
||||
|
@ -174,15 +172,13 @@ std::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
|||
split_seqnum++;
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
list.push_back(makeOriginalPacket(data));
|
||||
}
|
||||
|
||||
list.push_back(makeOriginalPacket(data));
|
||||
return list;
|
||||
}
|
||||
|
||||
SharedBuffer<u8> makeReliablePacket(
|
||||
SharedBuffer<u8> data,
|
||||
const SharedBuffer<u8> &data,
|
||||
u16 seqnum)
|
||||
{
|
||||
u32 header_size = 3;
|
||||
|
@ -206,11 +202,8 @@ void ReliablePacketBuffer::print()
|
|||
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();
|
||||
i != m_list.end();
|
||||
++i)
|
||||
{
|
||||
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
||||
for (BufferedPacket &bufferedPacket : m_list) {
|
||||
u16 s = readU16(&(bufferedPacket.data[BASE_HEADER_SIZE+1]));
|
||||
LOG(dout_con<<index<< ":" << s << std::endl);
|
||||
index++;
|
||||
}
|
||||
|
@ -406,11 +399,9 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected)
|
|||
void ReliablePacketBuffer::incrementTimeouts(float dtime)
|
||||
{
|
||||
MutexAutoLock listlock(m_list_mutex);
|
||||
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||
i != m_list.end(); ++i)
|
||||
{
|
||||
i->time += dtime;
|
||||
i->totaltime += dtime;
|
||||
for (BufferedPacket &bufferedPacket : m_list) {
|
||||
bufferedPacket.time += dtime;
|
||||
bufferedPacket.totaltime += dtime;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,14 +410,12 @@ std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout,
|
|||
{
|
||||
MutexAutoLock listlock(m_list_mutex);
|
||||
std::list<BufferedPacket> timed_outs;
|
||||
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||
i != m_list.end(); ++i)
|
||||
{
|
||||
if (i->time >= timeout) {
|
||||
timed_outs.push_back(*i);
|
||||
for (BufferedPacket &bufferedPacket : m_list) {
|
||||
if (bufferedPacket.time >= timeout) {
|
||||
timed_outs.push_back(bufferedPacket);
|
||||
|
||||
//this packet will be sent right afterwards reset timeout here
|
||||
i->time = 0.0;
|
||||
bufferedPacket.time = 0.0f;
|
||||
if (timed_outs.size() >= max_packets)
|
||||
break;
|
||||
}
|
||||
|
@ -441,10 +430,8 @@ std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout,
|
|||
IncomingSplitBuffer::~IncomingSplitBuffer()
|
||||
{
|
||||
MutexAutoLock listlock(m_map_mutex);
|
||||
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
|
||||
i != m_buf.end(); ++i)
|
||||
{
|
||||
delete i->second;
|
||||
for (auto &i : m_buf) {
|
||||
delete i.second;
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -506,15 +493,13 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
|
|||
sp->chunks[chunk_num] = chunkdata;
|
||||
|
||||
// If not all chunks are received, return empty buffer
|
||||
if (sp->allReceived() == false)
|
||||
if (!sp->allReceived())
|
||||
return SharedBuffer<u8>();
|
||||
|
||||
// Calculate total size
|
||||
u32 totalsize = 0;
|
||||
for(std::map<u16, SharedBuffer<u8> >::iterator i = sp->chunks.begin();
|
||||
i != sp->chunks.end(); ++i)
|
||||
{
|
||||
totalsize += i->second.getSize();
|
||||
for (const auto &chunk : sp->chunks) {
|
||||
totalsize += chunk.second.getSize();
|
||||
}
|
||||
|
||||
SharedBuffer<u8> fulldata(totalsize);
|
||||
|
@ -541,25 +526,21 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
|
|||
std::list<u16> remove_queue;
|
||||
{
|
||||
MutexAutoLock listlock(m_map_mutex);
|
||||
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
|
||||
i != m_buf.end(); ++i)
|
||||
{
|
||||
IncomingSplitPacket *p = i->second;
|
||||
for (auto &i : m_buf) {
|
||||
IncomingSplitPacket *p = i.second;
|
||||
// Reliable ones are not removed by timeout
|
||||
if (p->reliable == true)
|
||||
if (p->reliable)
|
||||
continue;
|
||||
p->time += dtime;
|
||||
if (p->time >= timeout)
|
||||
remove_queue.push_back(i->first);
|
||||
remove_queue.push_back(i.first);
|
||||
}
|
||||
}
|
||||
for(std::list<u16>::iterator j = remove_queue.begin();
|
||||
j != remove_queue.end(); ++j)
|
||||
{
|
||||
for (u16 j : remove_queue) {
|
||||
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);
|
||||
delete m_buf[j];
|
||||
m_buf.erase(j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -929,7 +910,7 @@ void Peer::RTTStatistics(float rtt, const std::string &profiler_id,
|
|||
m_rtt.jitter_avg = m_rtt.jitter_avg * (num_samples/(num_samples-1)) +
|
||||
jitter * (1/num_samples);
|
||||
|
||||
if (profiler_id != "") {
|
||||
if (!profiler_id.empty()) {
|
||||
g_profiler->graphAdd(profiler_id + "_rtt", rtt);
|
||||
g_profiler->graphAdd(profiler_id + "_jitter", jitter);
|
||||
}
|
||||
|
@ -1071,7 +1052,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||
|
||||
if (c.raw)
|
||||
{
|
||||
originals.push_back(c.data);
|
||||
originals.emplace_back(c.data);
|
||||
}
|
||||
else {
|
||||
originals = makeAutoSplitPacket(c.data, chunksize_max,split_sequence_number);
|
||||
|
@ -1083,9 +1064,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||
std::queue<BufferedPacket> toadd;
|
||||
volatile u16 initial_sequence_number = 0;
|
||||
|
||||
for(std::list<SharedBuffer<u8> >::iterator i = originals.begin();
|
||||
i != originals.end(); ++i)
|
||||
{
|
||||
for (SharedBuffer<u8> &original : originals) {
|
||||
u16 seqnum = channels[c.channelnum].getOutgoingSequenceNumber(have_sequence_number);
|
||||
|
||||
/* oops, we don't have enough sequence numbers to send this packet */
|
||||
|
@ -1098,7 +1077,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||
have_initial_sequence_number = true;
|
||||
}
|
||||
|
||||
SharedBuffer<u8> reliable = makeReliablePacket(*i, seqnum);
|
||||
SharedBuffer<u8> reliable = makeReliablePacket(original, seqnum);
|
||||
|
||||
// Add base headers and make a packet
|
||||
BufferedPacket p = con::makePacket(address, reliable,
|
||||
|
@ -1110,7 +1089,7 @@ bool UDPPeer::processReliableSendCommand(
|
|||
|
||||
if (have_sequence_number) {
|
||||
volatile u16 pcount = 0;
|
||||
while(toadd.size() > 0) {
|
||||
while (!toadd.empty()) {
|
||||
BufferedPacket p = toadd.front();
|
||||
toadd.pop();
|
||||
// LOG(dout_con<<connection->getDesc()
|
||||
|
@ -1124,35 +1103,36 @@ bool UDPPeer::processReliableSendCommand(
|
|||
sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
volatile u16 packets_available = toadd.size();
|
||||
/* we didn't get a single sequence number no need to fill queue */
|
||||
if (!have_initial_sequence_number)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while(toadd.size() > 0) {
|
||||
/* remove packet */
|
||||
toadd.pop();
|
||||
|
||||
bool successfully_put_back_sequence_number
|
||||
= channels[c.channelnum].putBackSequenceNumber(
|
||||
(initial_sequence_number+toadd.size() % (SEQNUM_MAX+1)));
|
||||
|
||||
FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error");
|
||||
}
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<< " Windowsize exceeded on reliable sending "
|
||||
<< c.data.getSize() << " bytes"
|
||||
<< std::endl << "\t\tinitial_sequence_number: "
|
||||
<< initial_sequence_number
|
||||
<< std::endl << "\t\tgot at most : "
|
||||
<< packets_available << " packets"
|
||||
<< std::endl << "\t\tpackets queued : "
|
||||
<< channels[c.channelnum].outgoing_reliables_sent.size()
|
||||
<< std::endl);
|
||||
volatile u16 packets_available = toadd.size();
|
||||
/* we didn't get a single sequence number no need to fill queue */
|
||||
if (!have_initial_sequence_number) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (!toadd.empty()) {
|
||||
/* remove packet */
|
||||
toadd.pop();
|
||||
|
||||
bool successfully_put_back_sequence_number
|
||||
= channels[c.channelnum].putBackSequenceNumber(
|
||||
(initial_sequence_number+toadd.size() % (SEQNUM_MAX+1)));
|
||||
|
||||
FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error");
|
||||
}
|
||||
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<< " Windowsize exceeded on reliable sending "
|
||||
<< c.data.getSize() << " bytes"
|
||||
<< std::endl << "\t\tinitial_sequence_number: "
|
||||
<< initial_sequence_number
|
||||
<< std::endl << "\t\tgot at most : "
|
||||
<< packets_available << " packets"
|
||||
<< std::endl << "\t\tpackets queued : "
|
||||
<< channels[c.channelnum].outgoing_reliables_sent.size()
|
||||
<< std::endl);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UDPPeer::RunCommandQueues(
|
||||
|
@ -1161,21 +1141,21 @@ void UDPPeer::RunCommandQueues(
|
|||
unsigned int maxtransfer)
|
||||
{
|
||||
|
||||
for (unsigned int i = 0; i < CHANNEL_COUNT; i++) {
|
||||
for (Channel &channel : channels) {
|
||||
unsigned int commands_processed = 0;
|
||||
|
||||
if ((channels[i].queued_commands.size() > 0) &&
|
||||
(channels[i].queued_reliables.size() < maxtransfer) &&
|
||||
if ((!channel.queued_commands.empty()) &&
|
||||
(channel.queued_reliables.size() < maxtransfer) &&
|
||||
(commands_processed < maxcommands)) {
|
||||
try {
|
||||
ConnectionCommand c = channels[i].queued_commands.front();
|
||||
ConnectionCommand c = channel.queued_commands.front();
|
||||
|
||||
LOG(dout_con << m_connection->getDesc()
|
||||
<< " processing queued reliable command " << std::endl);
|
||||
|
||||
// Packet is processed, remove it from queue
|
||||
if (processReliableSendCommand(c,max_packet_size)) {
|
||||
channels[i].queued_commands.pop_front();
|
||||
channel.queued_commands.pop_front();
|
||||
} else {
|
||||
LOG(dout_con << m_connection->getDesc()
|
||||
<< " Failed to queue packets for peer_id: " << c.peer_id
|
||||
|
@ -1291,10 +1271,8 @@ bool ConnectionSendThread::packetsQueued()
|
|||
if (!m_outgoing_queue.empty() && !peerIds.empty())
|
||||
return true;
|
||||
|
||||
for(std::list<u16>::iterator j = peerIds.begin();
|
||||
j != peerIds.end(); ++j)
|
||||
{
|
||||
PeerHelper peer = m_connection->getPeerNoEx(*j);
|
||||
for (u16 peerId : peerIds) {
|
||||
PeerHelper peer = m_connection->getPeerNoEx(peerId);
|
||||
|
||||
if (!peer)
|
||||
continue;
|
||||
|
@ -1302,10 +1280,8 @@ bool ConnectionSendThread::packetsQueued()
|
|||
if (dynamic_cast<UDPPeer*>(&peer) == 0)
|
||||
continue;
|
||||
|
||||
for(u16 i=0; i < CHANNEL_COUNT; i++) {
|
||||
Channel *channel = &(dynamic_cast<UDPPeer*>(&peer))->channels[i];
|
||||
|
||||
if (channel->queued_commands.size() > 0) {
|
||||
for (Channel &channel : (dynamic_cast<UDPPeer *>(&peer))->channels) {
|
||||
if (channel.queued_commands.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1320,10 +1296,8 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
std::list<u16> timeouted_peers;
|
||||
std::list<u16> peerIds = m_connection->getPeerIDs();
|
||||
|
||||
for(std::list<u16>::iterator j = peerIds.begin();
|
||||
j != peerIds.end(); ++j)
|
||||
{
|
||||
PeerHelper peer = m_connection->getPeerNoEx(*j);
|
||||
for (u16 &peerId : peerIds) {
|
||||
PeerHelper peer = m_connection->getPeerNoEx(peerId);
|
||||
|
||||
if (!peer)
|
||||
continue;
|
||||
|
@ -1333,7 +1307,7 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
|
||||
PROFILE(std::stringstream peerIdentifier);
|
||||
PROFILE(peerIdentifier << "runTimeouts[" << m_connection->getDesc()
|
||||
<< ";" << *j << ";RELIABLE]");
|
||||
<< ";" << peerId << ";RELIABLE]");
|
||||
PROFILE(ScopeProfiler peerprofiler(g_profiler, peerIdentifier.str(), SPT_AVG));
|
||||
|
||||
SharedBuffer<u8> data(2); // data for sending ping, required here because of goto
|
||||
|
@ -1356,19 +1330,17 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
|
||||
float resend_timeout = dynamic_cast<UDPPeer*>(&peer)->getResendTimeout();
|
||||
bool retry_count_exceeded = false;
|
||||
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
||||
{
|
||||
for (Channel &channel : (dynamic_cast<UDPPeer *>(&peer))->channels) {
|
||||
std::list<BufferedPacket> timed_outs;
|
||||
Channel *channel = &(dynamic_cast<UDPPeer*>(&peer))->channels[i];
|
||||
|
||||
if (dynamic_cast<UDPPeer*>(&peer)->getLegacyPeer())
|
||||
channel->setWindowSize(g_settings->getU16("workaround_window_size"));
|
||||
channel.setWindowSize(g_settings->getU16("workaround_window_size"));
|
||||
|
||||
// Remove timed out incomplete unreliable split packets
|
||||
channel->incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout);
|
||||
channel.incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout);
|
||||
|
||||
// Increment reliable packet times
|
||||
channel->outgoing_reliables_sent.incrementTimeouts(dtime);
|
||||
channel.outgoing_reliables_sent.incrementTimeouts(dtime);
|
||||
|
||||
unsigned int numpeers = m_connection->m_peers.size();
|
||||
|
||||
|
@ -1376,11 +1348,10 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
return;
|
||||
|
||||
// Re-send timed out outgoing reliables
|
||||
timed_outs = channel->
|
||||
outgoing_reliables_sent.getTimedOuts(resend_timeout,
|
||||
(m_max_data_packets_per_iteration/numpeers));
|
||||
timed_outs = channel.outgoing_reliables_sent.getTimedOuts(resend_timeout,
|
||||
(m_max_data_packets_per_iteration/numpeers));
|
||||
|
||||
channel->UpdatePacketLossCounter(timed_outs.size());
|
||||
channel.UpdatePacketLossCounter(timed_outs.size());
|
||||
g_profiler->graphAdd("packets_lost", timed_outs.size());
|
||||
|
||||
m_iteration_packets_avaialble -= timed_outs.size();
|
||||
|
@ -1392,7 +1363,7 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
u8 channelnum = readChannel(*(k->data));
|
||||
u16 seqnum = readU16(&(k->data[BASE_HEADER_SIZE+1]));
|
||||
|
||||
channel->UpdateBytesLost(k->data.getSize());
|
||||
channel.UpdateBytesLost(k->data.getSize());
|
||||
k->resend_count++;
|
||||
|
||||
if (k-> resend_count > MAX_RELIABLE_RETRY) {
|
||||
|
@ -1421,7 +1392,7 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
break; /* no need to check other channels if we already did timeout */
|
||||
}
|
||||
|
||||
channel->UpdateTimers(dtime,dynamic_cast<UDPPeer*>(&peer)->getLegacyPeer());
|
||||
channel.UpdateTimers(dtime,dynamic_cast<UDPPeer*>(&peer)->getLegacyPeer());
|
||||
}
|
||||
|
||||
/* skip to next peer if we did timeout */
|
||||
|
@ -1447,12 +1418,10 @@ void ConnectionSendThread::runTimeouts(float dtime)
|
|||
}
|
||||
|
||||
// Remove timed out peers
|
||||
for(std::list<u16>::iterator i = timeouted_peers.begin();
|
||||
i != timeouted_peers.end(); ++i)
|
||||
{
|
||||
LOG(derr_con<<m_connection->getDesc()
|
||||
<<"RunTimeouts(): Removing peer "<<(*i)<<std::endl);
|
||||
m_connection->deletePeer(*i, true);
|
||||
for (u16 timeouted_peer : timeouted_peers) {
|
||||
LOG(derr_con << m_connection->getDesc()
|
||||
<< "RunTimeouts(): Removing peer "<< timeouted_peer <<std::endl);
|
||||
m_connection->deletePeer(timeouted_peer, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1532,39 +1501,30 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum,
|
|||
sendAsPacketReliable(p,channel);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<<" INFO: queueing reliable packet for peer_id: " << peer_id
|
||||
<<" channel: " << channelnum
|
||||
<<" seqnum: " << seqnum << std::endl);
|
||||
channel->queued_reliables.push(p);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Address peer_address;
|
||||
|
||||
if (peer->getAddress(MTP_UDP, peer_address))
|
||||
{
|
||||
// Add base headers and make a packet
|
||||
BufferedPacket p = con::makePacket(peer_address, data,
|
||||
m_connection->GetProtocolID(), m_connection->GetPeerID(),
|
||||
channelnum);
|
||||
|
||||
// Send the packet
|
||||
rawSend(p);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<<" INFO: dropped unreliable packet for peer_id: " << peer_id
|
||||
<<" because of (yet) missing udp address" << std::endl);
|
||||
return false;
|
||||
}
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<<" INFO: queueing reliable packet for peer_id: " << peer_id
|
||||
<<" channel: " << channelnum
|
||||
<<" seqnum: " << seqnum << std::endl);
|
||||
channel->queued_reliables.push(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
//never reached
|
||||
Address peer_address;
|
||||
if (peer->getAddress(MTP_UDP, peer_address)) {
|
||||
// Add base headers and make a packet
|
||||
BufferedPacket p = con::makePacket(peer_address, data,
|
||||
m_connection->GetProtocolID(), m_connection->GetPeerID(),
|
||||
channelnum);
|
||||
|
||||
// Send the packet
|
||||
rawSend(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG(dout_con << m_connection->getDesc()
|
||||
<< " INFO: dropped unreliable packet for peer_id: " << peer_id
|
||||
<< " because of (yet) missing udp address" << std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1731,11 +1691,8 @@ void ConnectionSendThread::disconnect()
|
|||
// Send to all
|
||||
std::list<u16> peerids = m_connection->getPeerIDs();
|
||||
|
||||
for (std::list<u16>::iterator i = peerids.begin();
|
||||
i != peerids.end();
|
||||
++i)
|
||||
{
|
||||
sendAsPacket(*i, 0,data,false);
|
||||
for (u16 peerid : peerids) {
|
||||
sendAsPacket(peerid, 0,data,false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1790,10 +1747,7 @@ void ConnectionSendThread::send(u16 peer_id, u8 channelnum,
|
|||
|
||||
peer->setNextSplitSequenceNumber(channelnum,split_sequence_number);
|
||||
|
||||
for(std::list<SharedBuffer<u8> >::iterator i = originals.begin();
|
||||
i != originals.end(); ++i)
|
||||
{
|
||||
SharedBuffer<u8> original = *i;
|
||||
for (const SharedBuffer<u8> &original : originals) {
|
||||
sendAsPacket(peer_id, channelnum, original);
|
||||
}
|
||||
}
|
||||
|
@ -1811,11 +1765,8 @@ void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer<u8> data)
|
|||
{
|
||||
std::list<u16> peerids = m_connection->getPeerIDs();
|
||||
|
||||
for (std::list<u16>::iterator i = peerids.begin();
|
||||
i != peerids.end();
|
||||
++i)
|
||||
{
|
||||
send(*i, channelnum, data);
|
||||
for (u16 peerid : peerids) {
|
||||
send(peerid, channelnum, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1823,11 +1774,8 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
|
|||
{
|
||||
std::list<u16> peerids = m_connection->getPeerIDs();
|
||||
|
||||
for (std::list<u16>::iterator i = peerids.begin();
|
||||
i != peerids.end();
|
||||
++i)
|
||||
{
|
||||
PeerHelper peer = m_connection->getPeerNoEx(*i);
|
||||
for (u16 peerid : peerids) {
|
||||
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
||||
|
||||
if (!peer)
|
||||
continue;
|
||||
|
@ -1842,85 +1790,84 @@ void ConnectionSendThread::sendPackets(float dtime)
|
|||
std::list<u16> pendingDisconnect;
|
||||
std::map<u16,bool> pending_unreliable;
|
||||
|
||||
for(std::list<u16>::iterator
|
||||
j = peerIds.begin();
|
||||
j != peerIds.end(); ++j)
|
||||
{
|
||||
PeerHelper peer = m_connection->getPeerNoEx(*j);
|
||||
for (u16 peerId : peerIds) {
|
||||
PeerHelper peer = m_connection->getPeerNoEx(peerId);
|
||||
//peer may have been removed
|
||||
if (!peer) {
|
||||
LOG(dout_con<<m_connection->getDesc()<< " Peer not found: peer_id=" << *j << std::endl);
|
||||
LOG(dout_con<<m_connection->getDesc()<< " Peer not found: peer_id=" << peerId
|
||||
<< std::endl);
|
||||
continue;
|
||||
}
|
||||
peer->m_increment_packets_remaining = m_iteration_packets_avaialble/m_connection->m_peers.size();
|
||||
|
||||
if (dynamic_cast<UDPPeer*>(&peer) == 0)
|
||||
{
|
||||
UDPPeer *udpPeer = dynamic_cast<UDPPeer*>(&peer);
|
||||
|
||||
if (!udpPeer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dynamic_cast<UDPPeer*>(&peer)->m_pending_disconnect)
|
||||
{
|
||||
pendingDisconnect.push_back(*j);
|
||||
if (udpPeer->m_pending_disconnect) {
|
||||
pendingDisconnect.push_back(peerId);
|
||||
}
|
||||
|
||||
PROFILE(std::stringstream peerIdentifier);
|
||||
PROFILE(peerIdentifier << "sendPackets[" << m_connection->getDesc() << ";" << *j << ";RELIABLE]");
|
||||
PROFILE(peerIdentifier << "sendPackets[" << m_connection->getDesc() << ";" << peerId
|
||||
<< ";RELIABLE]");
|
||||
PROFILE(ScopeProfiler peerprofiler(g_profiler, peerIdentifier.str(), SPT_AVG));
|
||||
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<< " Handle per peer queues: peer_id=" << *j
|
||||
<< " packet quota: " << peer->m_increment_packets_remaining << std::endl);
|
||||
<< " Handle per peer queues: peer_id=" << peerId
|
||||
<< " packet quota: " << peer->m_increment_packets_remaining << std::endl);
|
||||
|
||||
// first send queued reliable packets for all peers (if possible)
|
||||
for (unsigned int i=0; i < CHANNEL_COUNT; i++)
|
||||
{
|
||||
for (unsigned int i=0; i < CHANNEL_COUNT; i++) {
|
||||
Channel &channel = udpPeer->channels[i];
|
||||
u16 next_to_ack = 0;
|
||||
dynamic_cast<UDPPeer*>(&peer)->channels[i].outgoing_reliables_sent.getFirstSeqnum(next_to_ack);
|
||||
|
||||
channel.outgoing_reliables_sent.getFirstSeqnum(next_to_ack);
|
||||
u16 next_to_receive = 0;
|
||||
dynamic_cast<UDPPeer*>(&peer)->channels[i].incoming_reliables.getFirstSeqnum(next_to_receive);
|
||||
channel.incoming_reliables.getFirstSeqnum(next_to_receive);
|
||||
|
||||
LOG(dout_con<<m_connection->getDesc()<< "\t channel: "
|
||||
<< i << ", peer quota:"
|
||||
<< peer->m_increment_packets_remaining
|
||||
<< std::endl
|
||||
<< "\t\t\treliables on wire: "
|
||||
<< dynamic_cast<UDPPeer*>(&peer)->channels[i].outgoing_reliables_sent.size()
|
||||
<< channel.outgoing_reliables_sent.size()
|
||||
<< ", waiting for ack for " << next_to_ack
|
||||
<< std::endl
|
||||
<< "\t\t\tincoming_reliables: "
|
||||
<< dynamic_cast<UDPPeer*>(&peer)->channels[i].incoming_reliables.size()
|
||||
<< channel.incoming_reliables.size()
|
||||
<< ", next reliable packet: "
|
||||
<< dynamic_cast<UDPPeer*>(&peer)->channels[i].readNextIncomingSeqNum()
|
||||
<< channel.readNextIncomingSeqNum()
|
||||
<< ", next queued: " << next_to_receive
|
||||
<< std::endl
|
||||
<< "\t\t\treliables queued : "
|
||||
<< dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.size()
|
||||
<< channel.queued_reliables.size()
|
||||
<< std::endl
|
||||
<< "\t\t\tqueued commands : "
|
||||
<< dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_commands.size()
|
||||
<< channel.queued_commands.size()
|
||||
<< std::endl);
|
||||
|
||||
while ((dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.size() > 0) &&
|
||||
(dynamic_cast<UDPPeer*>(&peer)->channels[i].outgoing_reliables_sent.size()
|
||||
< dynamic_cast<UDPPeer*>(&peer)->channels[i].getWindowSize())&&
|
||||
while ((!channel.queued_reliables.empty()) &&
|
||||
(channel.outgoing_reliables_sent.size()
|
||||
< channel.getWindowSize())&&
|
||||
(peer->m_increment_packets_remaining > 0))
|
||||
{
|
||||
BufferedPacket p = dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.front();
|
||||
dynamic_cast<UDPPeer*>(&peer)->channels[i].queued_reliables.pop();
|
||||
Channel* channel = &(dynamic_cast<UDPPeer*>(&peer)->channels[i]);
|
||||
BufferedPacket p = channel.queued_reliables.front();
|
||||
channel.queued_reliables.pop();
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<<" INFO: sending a queued reliable packet "
|
||||
<<" channel: " << i
|
||||
<<", seqnum: " << readU16(&p.data[BASE_HEADER_SIZE+1])
|
||||
<< std::endl);
|
||||
sendAsPacketReliable(p,channel);
|
||||
sendAsPacketReliable(p, &channel);
|
||||
peer->m_increment_packets_remaining--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_outgoing_queue.size())
|
||||
{
|
||||
if (!m_outgoing_queue.empty()) {
|
||||
LOG(dout_con<<m_connection->getDesc()
|
||||
<< " Handle non reliable queue ("
|
||||
<< m_outgoing_queue.size() << " pkts)" << std::endl);
|
||||
|
@ -1944,9 +1891,9 @@ void ConnectionSendThread::sendPackets(float dtime)
|
|||
<< ", size: " << packet.data.getSize() <<std::endl);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* send acks immediately */
|
||||
else if (packet.ack)
|
||||
{
|
||||
if (packet.ack) {
|
||||
rawSendAsPacket(packet.peer_id, packet.channelnum,
|
||||
packet.data, packet.reliable);
|
||||
peer->m_increment_packets_remaining =
|
||||
|
@ -1965,13 +1912,10 @@ void ConnectionSendThread::sendPackets(float dtime)
|
|||
}
|
||||
}
|
||||
|
||||
for(std::list<u16>::iterator
|
||||
k = pendingDisconnect.begin();
|
||||
k != pendingDisconnect.end(); ++k)
|
||||
{
|
||||
if (!pending_unreliable[*k])
|
||||
for (u16 peerId : pendingDisconnect) {
|
||||
if (!pending_unreliable[peerId])
|
||||
{
|
||||
m_connection->deletePeer(*k,false);
|
||||
m_connection->deletePeer(peerId,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2237,21 +2181,16 @@ bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst
|
|||
{
|
||||
std::list<u16> peerids = m_connection->getPeerIDs();
|
||||
|
||||
for(std::list<u16>::iterator j = peerids.begin();
|
||||
j != peerids.end(); ++j)
|
||||
{
|
||||
PeerHelper peer = m_connection->getPeerNoEx(*j);
|
||||
for (u16 peerid : peerids) {
|
||||
PeerHelper peer = m_connection->getPeerNoEx(peerid);
|
||||
if (!peer)
|
||||
continue;
|
||||
|
||||
if (dynamic_cast<UDPPeer*>(&peer) == 0)
|
||||
continue;
|
||||
|
||||
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
||||
{
|
||||
Channel *channel = &(dynamic_cast<UDPPeer*>(&peer))->channels[i];
|
||||
|
||||
if (checkIncomingBuffers(channel, peer_id, dst)) {
|
||||
for (Channel &channel : (dynamic_cast<UDPPeer *>(&peer))->channels) {
|
||||
if (checkIncomingBuffers(&channel, peer_id, dst)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2425,8 +2364,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel,
|
|||
LOG(dout_con<<m_connection->getDesc()
|
||||
<<"DISCO: Removing peer "<<(peer_id)<<std::endl);
|
||||
|
||||
if (m_connection->deletePeer(peer_id, false) == false)
|
||||
{
|
||||
if (!m_connection->deletePeer(peer_id, false)) {
|
||||
derr_con<<m_connection->getDesc()
|
||||
<<"DISCO: Peer not found"<<std::endl;
|
||||
}
|
||||
|
@ -2662,11 +2600,8 @@ Connection::~Connection()
|
|||
m_receiveThread.wait();
|
||||
|
||||
// Delete peers
|
||||
for(std::map<u16, Peer*>::iterator
|
||||
j = m_peers.begin();
|
||||
j != m_peers.end(); ++j)
|
||||
{
|
||||
delete j->second;
|
||||
for (auto &peer : m_peers) {
|
||||
delete peer.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2734,10 +2669,8 @@ u16 Connection::lookupPeer(Address& sender)
|
|||
std::list<Peer*> Connection::getPeers()
|
||||
{
|
||||
std::list<Peer*> list;
|
||||
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||
j != m_peers.end(); ++j)
|
||||
{
|
||||
Peer *peer = j->second;
|
||||
for (auto &p : m_peers) {
|
||||
Peer *peer = p.second;
|
||||
list.push_back(peer);
|
||||
}
|
||||
return list;
|
||||
|
@ -2904,25 +2837,25 @@ float Connection::getLocalStat(rate_stat_type type)
|
|||
|
||||
float retval = 0.0;
|
||||
|
||||
for (u16 j=0; j<CHANNEL_COUNT; j++) {
|
||||
for (Channel &channel : dynamic_cast<UDPPeer *>(&peer)->channels) {
|
||||
switch(type) {
|
||||
case CUR_DL_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getCurrentDownloadRateKB();
|
||||
retval += channel.getCurrentDownloadRateKB();
|
||||
break;
|
||||
case AVG_DL_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getAvgDownloadRateKB();
|
||||
retval += channel.getAvgDownloadRateKB();
|
||||
break;
|
||||
case CUR_INC_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getCurrentIncomingRateKB();
|
||||
retval += channel.getCurrentIncomingRateKB();
|
||||
break;
|
||||
case AVG_INC_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getAvgIncomingRateKB();
|
||||
retval += channel.getAvgIncomingRateKB();
|
||||
break;
|
||||
case AVG_LOSS_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getAvgLossRateKB();
|
||||
retval += channel.getAvgLossRateKB();
|
||||
break;
|
||||
case CUR_LOSS_RATE:
|
||||
retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getCurrentLossRateKB();
|
||||
retval += channel.getCurrentLossRateKB();
|
||||
break;
|
||||
default:
|
||||
FATAL_ERROR("Connection::getLocalStat Invalid stat type");
|
||||
|
|
|
@ -133,16 +133,14 @@ inline bool seqnum_higher(u16 totest, u16 base)
|
|||
{
|
||||
if ((totest - base) > (SEQNUM_MAX/2))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((base - totest) > (SEQNUM_MAX/2))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((base - totest) > (SEQNUM_MAX/2))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size)
|
||||
|
@ -150,14 +148,12 @@ inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size)
|
|||
u16 window_start = next;
|
||||
u16 window_end = ( next + window_size ) % (SEQNUM_MAX+1);
|
||||
|
||||
if (window_start < window_end)
|
||||
{
|
||||
if (window_start < window_end) {
|
||||
return ((seqnum >= window_start) && (seqnum < window_end));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((seqnum < window_end) || (seqnum >= window_start));
|
||||
}
|
||||
|
||||
|
||||
return ((seqnum < window_end) || (seqnum >= window_start));
|
||||
}
|
||||
|
||||
struct BufferedPacket
|
||||
|
@ -166,8 +162,7 @@ struct BufferedPacket
|
|||
data(a_data, a_size)
|
||||
{}
|
||||
BufferedPacket(u32 a_size):
|
||||
data(a_size), time(0.0), totaltime(0.0), absolute_send_time(-1),
|
||||
resend_count(0)
|
||||
data(a_size)
|
||||
{}
|
||||
Buffer<u8> data; // Data of the packet, including headers
|
||||
float time = 0.0f; // Seconds from buffering the packet or re-sending
|
||||
|
@ -202,12 +197,13 @@ std::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
|||
|
||||
// Add the TYPE_RELIABLE header to the data
|
||||
SharedBuffer<u8> makeReliablePacket(
|
||||
SharedBuffer<u8> data,
|
||||
const SharedBuffer<u8> &data,
|
||||
u16 seqnum);
|
||||
|
||||
struct IncomingSplitPacket
|
||||
{
|
||||
IncomingSplitPacket() {}
|
||||
IncomingSplitPacket() = default;
|
||||
|
||||
// Key is chunk number, value is data without headers
|
||||
std::map<u16, SharedBuffer<u8> > chunks;
|
||||
u32 chunk_count;
|
||||
|
@ -315,7 +311,7 @@ typedef std::list<BufferedPacket>::iterator RPBSearchResult;
|
|||
class ReliablePacketBuffer
|
||||
{
|
||||
public:
|
||||
ReliablePacketBuffer() {};
|
||||
ReliablePacketBuffer() = default;
|
||||
|
||||
bool getFirstSeqnum(u16& result);
|
||||
|
||||
|
@ -410,7 +406,7 @@ struct ConnectionCommand
|
|||
bool reliable = false;
|
||||
bool raw = false;
|
||||
|
||||
ConnectionCommand() {}
|
||||
ConnectionCommand() = default;
|
||||
|
||||
void serve(Address address_)
|
||||
{
|
||||
|
@ -501,8 +497,8 @@ public:
|
|||
|
||||
IncomingSplitBuffer incoming_splits;
|
||||
|
||||
Channel() {};
|
||||
~Channel() {};
|
||||
Channel() = default;
|
||||
~Channel() = default;
|
||||
|
||||
void UpdatePacketLossCounter(unsigned int count);
|
||||
void UpdatePacketTooLateCounter();
|
||||
|
@ -590,12 +586,8 @@ class PeerHandler
|
|||
{
|
||||
public:
|
||||
|
||||
PeerHandler()
|
||||
{
|
||||
}
|
||||
virtual ~PeerHandler()
|
||||
{
|
||||
}
|
||||
PeerHandler() = default;
|
||||
virtual ~PeerHandler() = default;
|
||||
|
||||
/*
|
||||
This is called after the Peer has been inserted into the
|
||||
|
@ -612,7 +604,7 @@ public:
|
|||
class PeerHelper
|
||||
{
|
||||
public:
|
||||
PeerHelper() {};
|
||||
PeerHelper() = default;;
|
||||
PeerHelper(Peer* peer);
|
||||
~PeerHelper();
|
||||
|
||||
|
@ -744,7 +736,7 @@ class Peer {
|
|||
float max_rtt = 0.0f;
|
||||
float avg_rtt = -1.0f;
|
||||
|
||||
rttstats() {};
|
||||
rttstats() = default;
|
||||
};
|
||||
|
||||
rttstats m_rtt;
|
||||
|
@ -769,7 +761,7 @@ public:
|
|||
friend class Connection;
|
||||
|
||||
UDPPeer(u16 a_id, Address a_address, Connection* connection);
|
||||
virtual ~UDPPeer() {};
|
||||
virtual ~UDPPeer() = default;
|
||||
|
||||
void PutReliableSendCommand(ConnectionCommand &c,
|
||||
unsigned int max_packet_size);
|
||||
|
@ -841,7 +833,7 @@ struct ConnectionEvent
|
|||
bool timeout = false;
|
||||
Address address;
|
||||
|
||||
ConnectionEvent() {}
|
||||
ConnectionEvent() = default;
|
||||
|
||||
std::string describe()
|
||||
{
|
||||
|
|
|
@ -30,7 +30,8 @@ class NetworkPacket
|
|||
public:
|
||||
NetworkPacket(u16 command, u32 datasize, u16 peer_id);
|
||||
NetworkPacket(u16 command, u32 datasize);
|
||||
NetworkPacket() {}
|
||||
NetworkPacket() = default;
|
||||
|
||||
~NetworkPacket();
|
||||
|
||||
void putRawPacket(u8 *data, u32 datasize, u16 peer_id);
|
||||
|
|
|
@ -173,7 +173,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
|
|||
return;
|
||||
}
|
||||
|
||||
if (string_allowed(playerName, PLAYERNAME_ALLOWED_CHARS) == false) {
|
||||
if (!string_allowed(playerName, PLAYERNAME_ALLOWED_CHARS)) {
|
||||
actionstream << "Server: Player with an invalid name "
|
||||
<< "tried to connect from " << addr_s << std::endl;
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_CHARS_IN_NAME);
|
||||
|
@ -199,8 +199,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
|
|||
<< "tried to connect from " << addr_s << " "
|
||||
<< "but it was disallowed for the following reason: "
|
||||
<< reason << std::endl;
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_CUSTOM_STRING,
|
||||
reason.c_str());
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_CUSTOM_STRING, reason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +467,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
|
|||
return;
|
||||
}
|
||||
|
||||
if (string_allowed(playername, PLAYERNAME_ALLOWED_CHARS) == false) {
|
||||
if (!string_allowed(playername, PLAYERNAME_ALLOWED_CHARS)) {
|
||||
actionstream << "Server: Player with an invalid name "
|
||||
<< "tried to connect from " << addr_s << std::endl;
|
||||
DenyAccess_Legacy(pkt->getPeerId(), L"Name contains unallowed characters");
|
||||
|
@ -489,7 +488,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
|
|||
<< "tried to connect from " << addr_s << " "
|
||||
<< "but it was disallowed for the following reason: "
|
||||
<< reason << std::endl;
|
||||
DenyAccess_Legacy(pkt->getPeerId(), utf8_to_wide(reason.c_str()));
|
||||
DenyAccess_Legacy(pkt->getPeerId(), utf8_to_wide(reason));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -539,7 +538,7 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
|
|||
if (!has_auth) {
|
||||
if (!isSingleplayer() &&
|
||||
g_settings->getBool("disallow_empty_password") &&
|
||||
std::string(given_password) == "") {
|
||||
std::string(given_password).empty()) {
|
||||
actionstream << "Server: " << playername
|
||||
<< " supplied empty password" << std::endl;
|
||||
DenyAccess_Legacy(pkt->getPeerId(), L"Empty passwords are "
|
||||
|
@ -1637,7 +1636,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
|
|||
RemoteClient *client = getClient(pkt->getPeerId());
|
||||
v3s16 blockpos = getNodeBlockPos(floatToInt(pointed_pos_above, BS));
|
||||
v3s16 blockpos2 = getNodeBlockPos(floatToInt(pointed_pos_under, BS));
|
||||
if (item.getDefinition(m_itemdef).node_placement_prediction != "") {
|
||||
if (!item.getDefinition(m_itemdef).node_placement_prediction.empty()) {
|
||||
client->SetBlockNotSent(blockpos);
|
||||
if (blockpos2 != blockpos) {
|
||||
client->SetBlockNotSent(blockpos2);
|
||||
|
@ -1895,10 +1894,10 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
|
|||
if (wantSudo) {
|
||||
DenySudoAccess(pkt->getPeerId());
|
||||
return;
|
||||
} else {
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string bytes_A;
|
||||
|
@ -1967,10 +1966,10 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
|
|||
if (wantSudo) {
|
||||
DenySudoAccess(pkt->getPeerId());
|
||||
return;
|
||||
} else {
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkPacket resp_pkt(TOCLIENT_SRP_BYTES_S_B, 0, pkt->getPeerId());
|
||||
|
@ -2004,10 +2003,10 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
|
|||
if (wantSudo) {
|
||||
DenySudoAccess(pkt->getPeerId());
|
||||
return;
|
||||
} else {
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_UNEXPECTED_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string bytes_M;
|
||||
|
@ -2035,14 +2034,14 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
|
|||
<< " (SRP) password for authentication." << std::endl;
|
||||
DenySudoAccess(pkt->getPeerId());
|
||||
return;
|
||||
} else {
|
||||
actionstream << "Server: User " << client->getName()
|
||||
<< " at " << getPeerAddress(pkt->getPeerId()).serializeString()
|
||||
<< " supplied wrong password (auth mechanism: SRP)."
|
||||
<< std::endl;
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
actionstream << "Server: User " << client->getName()
|
||||
<< " at " << getPeerAddress(pkt->getPeerId()).serializeString()
|
||||
<< " supplied wrong password (auth mechanism: SRP)."
|
||||
<< std::endl;
|
||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_WRONG_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if (client->create_player_on_auth_success) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue