nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
version.cc
Go to the documentation of this file.
1#include "protocol/version.h"
2
3#include <array>
4#include <optional>
5#include <string_view>
6#include <vector>
7
8#include "absl/strings/numbers.h"
9#include "absl/strings/str_split.h"
10
11namespace nanommo {
12
13namespace {
14
15// MAJOR.MINOR.PATCH as three numbers, or nothing if it isn't that.
16std::optional<std::array<int, 3>> Parse(std::string_view version) {
17 const std::vector<std::string_view> parts = absl::StrSplit(version, '.');
18 if (parts.size() != 3) {
19 return std::nullopt;
20 }
21 std::array<int, 3> numbers;
22 for (int i = 0; i < 3; ++i) {
23 if (!absl::SimpleAtoi(parts[i], &numbers[i]) || numbers[i] < 0) {
24 return std::nullopt;
25 }
26 }
27 return numbers;
28}
29
30} // namespace
31
32bool Compatible(std::string_view client, std::string_view server) {
33 const std::optional<std::array<int, 3>> a = Parse(client);
34 const std::optional<std::array<int, 3>> b = Parse(server);
35 return a && b && (*a)[0] == (*b)[0] && (*a)[1] == (*b)[1];
36}
37
38} // namespace nanommo
Definition chat.cc:9
bool Compatible(std::string_view client, std::string_view server)
Definition version.cc:32