aboutsummaryrefslogtreecommitdiff
path: root/client/src/main.cpp
diff options
context:
space:
mode:
authoralpine <[email protected]>2020-06-24 13:05:48 +0200
committeralpine <[email protected]>2020-06-24 13:05:48 +0200
commit8f0130c8f74482a7d54f9bfb8763f4c6d705765c (patch)
treee9090817a498da9ae18a58adee92f4f8ba2db03b /client/src/main.cpp
parentChanged clang format style. (diff)
downloadloader-8f0130c8f74482a7d54f9bfb8763f4c6d705765c.tar.xz
loader-8f0130c8f74482a7d54f9bfb8763f4c6d705765c.zip
Added client version control.
Reverted back to google formatting.
Diffstat (limited to 'client/src/main.cpp')
-rw-r--r--client/src/main.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/client/src/main.cpp b/client/src/main.cpp
index 3cc3c77..fef9fca 100644
--- a/client/src/main.cpp
+++ b/client/src/main.cpp
@@ -2,40 +2,42 @@
#include "util/io.h"
#include "client/client.h"
-int main(int argc, char* argv[])
-{
- io::init();
+int main(int argc, char* argv[]) {
+ io::init();
- tcp::client client;
+ tcp::client client;
- std::thread t{ tcp::client::monitor, std::ref(client) };
- t.detach();
+ std::thread t{tcp::client::monitor, std::ref(client)};
+ t.detach();
- if(client.start("127.0.0.1", 6666)) {
- io::logger->info("connected.");
- client.set_state(tcp::client_state::active);
- }
+ client.start("127.0.0.1", 6666);
- client.receive_event.add([&](tcp::packet_t& packet) {
- if(!packet)
- return;
+ client.receive_event.add([&](tcp::packet_t& packet) {
+ if (!packet) return;
- // first packet is the session id and current version
- if(packet.id == 1) {
- client.session_id = packet.session_id;
- }
+ // first packet is the session id and current version
+ if (packet.id == 1) {
+ client.session_id = packet.session_id;
+ tcp::version_t v;
+ auto version = fmt::format("{}.{}.{}", v.major, v.minor, v.patch);
+ if(version != packet.message) {
+ io::logger->error("please update your client");
+ client.shutdown();
+ return;
+ }
+ }
- io::logger->info("{}:{}->{}", packet.id, packet.session_id, packet.message);
- });
+ io::logger->info("{}:{}->{}", packet.id, packet.session_id, packet.message);
+ });
- while(client) {
- std::string p;
- getline(std::cin, p);
+ while (client) {
+ std::string p;
+ getline(std::cin, p);
- int ret =
- client.write(tcp::packet_t(p, tcp::packet_type::write, client.session_id));
- if(ret <= 0) {
- break;
- }
+ int ret = client.write(
+ tcp::packet_t(p, tcp::packet_type::write, client.session_id));
+ if (ret <= 0) {
+ break;
}
+ }
}