Added time offset sync, added web version multiplayer
This commit is contained in:
1 parent
a59bcc0c4b
commit
2c1c077611
13 files changed
+534
-324
No files matched your search
+6
-3
@@ -180,7 +180,9 @@ public:
|
||||
timer->expires_after(std::chrono::milliseconds(100));
|
||||
timer->async_wait([self = shared_from_this(), timer](const boost::system::error_code& ec) {
|
||||
if (!ec) {
|
||||
self->send_message("ID:" + std::to_string(self->id_));
|
||||
int64_t serverNow = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
self->send_message("ID:" + std::to_string(self->id_) + ":" + std::to_string(serverNow));
|
||||
self->do_read();
|
||||
}
|
||||
});
|
||||
@@ -297,6 +299,7 @@ private:
|
||||
}
|
||||
|
||||
void process_message(const std::string& msg) {
|
||||
std::cout << "Received from player " << id_ << ": " << msg << std::endl;
|
||||
auto parts = split(msg, ':');
|
||||
|
||||
if (parts.empty()) return;
|
||||
@@ -754,11 +757,11 @@ int main() {
|
||||
std::cout << "Generated " << g_serverBoxes.size() << " boxes on server\n";
|
||||
}
|
||||
net::io_context ioc;
|
||||
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8080} };
|
||||
tcp::acceptor acceptor{ ioc, {tcp::v4(), 8081} };
|
||||
|
||||
int next_id = 1000;
|
||||
|
||||
std::cout << "Server started on port 8080...\n";
|
||||
std::cout << "Server started on port 8081...\n";
|
||||
|
||||
auto do_accept = [&](auto& self_fn) -> void {
|
||||
acceptor.async_accept([&, self_fn](beast::error_code ec, tcp::socket socket) {
|
||||
|
||||
Reference in new issue
Block a user