Skip to content

Commit 9edb91d

Browse files
sapiersapier
sapier
authored and
sapier
committedJan 10, 2014
Fixed minetest reliable udp implementation (compatible to old clients)
1 parent 8b0b857 commit 9edb91d

8 files changed

+2696
-1008
lines changed
 

‎minetest.conf.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@
345345
# Number of emerge threads to use. Make this field blank, or increase this number, to use multiple threads.
346346
# On multiprocessor systems, this will improve mapgen speed greatly, at the cost of slightly buggy caves.
347347
#num_emerge_threads = 1
348-
348+
# maximum number of packets sent per send step, if you have a slow connection
349+
# try reducing it, but don't reduce it to a number below double of targeted
350+
# client number
351+
#max_packets_per_iteration = 1024
349352
#
350353
# Physics stuff
351354
#

‎src/client.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ void Client::step(float dtime)
538538
writeU16(&data[53], CLIENT_PROTOCOL_VERSION_MAX);
539539

540540
// Send as unreliable
541-
Send(0, data, false);
541+
Send(1, data, false);
542542
}
543543

544544
// Not connected, return
@@ -597,7 +597,7 @@ void Client::step(float dtime)
597597
writeV3S16(&reply[2+1+6*k], *j);
598598
k++;
599599
}
600-
m_con.Send(PEER_ID_SERVER, 1, reply, true);
600+
m_con.Send(PEER_ID_SERVER, 2, reply, true);
601601

602602
if(i == deleted_blocks.end())
603603
break;
@@ -745,7 +745,7 @@ void Client::step(float dtime)
745745
reply[2] = 1;
746746
writeV3S16(&reply[3], r.p);
747747
// Send as reliable
748-
m_con.Send(PEER_ID_SERVER, 1, reply, true);
748+
m_con.Send(PEER_ID_SERVER, 2, reply, true);
749749
}
750750
}
751751
if(num_processed_meshes > 0)
@@ -840,7 +840,7 @@ void Client::step(float dtime)
840840
std::string s = os.str();
841841
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
842842
// Send as reliable
843-
Send(0, data, true);
843+
Send(1, data, true);
844844
}
845845
}
846846
}
@@ -957,7 +957,7 @@ void Client::request_media(const std::list<std::string> &file_requests)
957957
std::string s = os.str();
958958
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
959959
// Send as reliable
960-
Send(0, data, true);
960+
Send(1, data, true);
961961
infostream<<"Client: Sending media request list to server ("
962962
<<file_requests.size()<<" files)"<<std::endl;
963963
}
@@ -970,7 +970,7 @@ void Client::received_media()
970970
std::string s = os.str();
971971
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
972972
// Send as reliable
973-
Send(0, data, true);
973+
Send(1, data, true);
974974
infostream<<"Client: Notifying server that we received all media"
975975
<<std::endl;
976976
}

‎src/connection.cpp

+2,069-810
Large diffs are not rendered by default.

‎src/connection.h

+600-180
Large diffs are not rendered by default.

‎src/defaultsettings.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ void set_default_settings(Settings *settings)
172172

173173
// Server stuff
174174
// "map-dir" doesn't exist by default.
175+
settings->setDefault("workaround_window_size","5");
176+
settings->setDefault("max_packets_per_iteration","1024");
175177
settings->setDefault("port", "30000");
176178
settings->setDefault("default_game", "minetest");
177179
settings->setDefault("motd", "");

‎src/log.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static std::string get_lev_string(enum LogMessageLevel lev)
9393

9494
void log_printline(enum LogMessageLevel lev, const std::string &text)
9595
{
96+
log_threadnamemutex.Lock();
9697
std::string threadname = "(unknown thread)";
9798
std::map<threadid_t, std::string>::const_iterator i;
9899
i = log_threadnames.find(get_current_thread_id());
@@ -108,6 +109,7 @@ void log_printline(enum LogMessageLevel lev, const std::string &text)
108109
out->printLog(os.str(), lev);
109110
out->printLog(lev, text);
110111
}
112+
log_threadnamemutex.Unlock();
111113
}
112114

113115
class Logbuf : public std::streambuf

‎src/server.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,15 @@ class ServerThread : public JThread
9090

9191
void * ServerThread::Thread()
9292
{
93-
ThreadStarted();
94-
9593
log_register_thread("ServerThread");
9694

9795
DSTACK(__FUNCTION_NAME);
98-
9996
BEGIN_DEBUG_EXCEPTION_HANDLER
10097

98+
m_server->AsyncRunStep(true);
99+
100+
ThreadStarted();
101+
101102
while(!StopRequested())
102103
{
103104
try{
@@ -1018,7 +1019,7 @@ void Server::step(float dtime)
10181019
}
10191020
}
10201021

1021-
void Server::AsyncRunStep()
1022+
void Server::AsyncRunStep(bool initial_step)
10221023
{
10231024
DSTACK(__FUNCTION_NAME);
10241025

@@ -1035,7 +1036,7 @@ void Server::AsyncRunStep()
10351036
SendBlocks(dtime);
10361037
}
10371038

1038-
if(dtime < 0.001)
1039+
if((dtime < 0.001) && (initial_step == false))
10391040
return;
10401041

10411042
g_profiler->add("Server::AsyncRunStep with dtime (num)", 1);
@@ -1528,7 +1529,7 @@ void Server::AsyncRunStep()
15281529
memcpy((char*)&reply[2], unreliable_data.c_str(),
15291530
unreliable_data.size());
15301531
// Send as unreliable
1531-
m_con.Send(client->peer_id, 0, reply, false);
1532+
m_con.Send(client->peer_id, 1, reply, false);
15321533
}
15331534

15341535
/*if(reliable_data.size() > 0 || unreliable_data.size() > 0)
@@ -3721,7 +3722,7 @@ void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form)
37213722
std::string s = os.str();
37223723
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
37233724
// Send as reliable
3724-
m_con.Send(peer_id, 0, data, true);
3725+
m_con.Send(peer_id, 1, data, true);
37253726
}
37263727

37273728
void Server::SendHUDRemove(u16 peer_id, u32 id)
@@ -3736,7 +3737,8 @@ void Server::SendHUDRemove(u16 peer_id, u32 id)
37363737
std::string s = os.str();
37373738
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
37383739
// Send as reliable
3739-
m_con.Send(peer_id, 0, data, true);
3740+
3741+
m_con.Send(peer_id, 1, data, true);
37403742
}
37413743

37423744
void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value)
@@ -4204,7 +4206,7 @@ void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto
42044206
/*
42054207
Send packet
42064208
*/
4207-
m_con.Send(peer_id, 1, reply, true);
4209+
m_con.Send(peer_id, 2, reply, true);
42084210
}
42094211

42104212
void Server::SendBlocks(float dtime)
@@ -4566,7 +4568,7 @@ void Server::sendRequestedMedia(u16 peer_id,
45664568
<<" size=" <<s.size()<<std::endl;
45674569
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
45684570
// Send as reliable
4569-
m_con.Send(peer_id, 0, data, true);
4571+
m_con.Send(peer_id, 2, data, true);
45704572
}
45714573
}
45724574

‎src/server.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
330330
// Actual processing is done in an another thread.
331331
void step(float dtime);
332332
// This is run by ServerThread and does the actual processing
333-
void AsyncRunStep();
333+
void AsyncRunStep(bool initial_step=false);
334334
void Receive();
335335
void ProcessData(u8 *data, u32 datasize, u16 peer_id);
336336

0 commit comments

Comments
 (0)
Please sign in to comment.