• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ how to simulate high ping

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
I am logged in to my server 127.0.0.1, so the ping is 0 ms. Is there a function where I can test the ping that players will have? 100, 150 ms. I use tfs 1.2 8.6 and otcv8.
I'm testing the 'onWalking' functions, and I want to simulate a 100-150ms ping to mimic real-world gameplay.
 
Diff:
diff --git a/src/connection.cpp b/src/connection.cpp
index d911b237..07927461 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -253,7 +253,9 @@ void Connection::send(const OutputMessage_ptr& msg)
 void Connection::internalSend(const OutputMessage_ptr& msg)
 {
     protocol->onSendMessage(msg);
+    std::thread([this, msg]() {
     try {
+        std::this_thread::sleep_for(std::chrono::milliseconds(normal_random(100, 150)));
         writeTimer.expires_from_now(boost::posix_time::seconds((int)Connection::write_timeout));
         writeTimer.async_wait(std::bind(&Connection::handleTimeout, std::weak_ptr<Connection>(shared_from_this()),
                                              std::placeholders::_1));
@@ -265,6 +267,7 @@ void Connection::internalSend(const OutputMessage_ptr& msg)
         std::cout << "[Network error - Connection::internalSend] " << e.what() << std::endl;
         close(FORCE_CLOSE);
     }
+    }).detach();
 }
 
 uint32_t Connection::getIP()
 

Similar threads

Back
Top