forked from gurotopia/Gurotopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (65 loc) · 2.9 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (65 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
@copyright gurotopia (c) 2024-05-25
@version perent SHA: 14db88c41229c6cbcd20d47ad1bd55e1ff999977 2026-2-16
*/
#include "include/pch.hpp"
#include "include/event_type/__event_type.hpp"
#include "include/database/shouhin.hpp" // @note init_shouhin_tachi()
#include "include/https/https.hpp" // @note https::listener()
#include "include/https/server_data.hpp" // @note g_server_data
#include "include/automate/holiday.hpp" // @note holiday
#include <filesystem>
#include <csignal>
int main()
{
/* !! please press Ctrl + C when restarting or stopping server !! */
std::signal(SIGINT, safe_disconnect_peers);
#ifdef SIGHUP // @note unix
std::signal(SIGHUP, safe_disconnect_peers); // @note PuTTY, SSH problems
#endif
/* libary version checker */
std::printf("ZTzTopia/enet %d.%d.%d\n", ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH);
std::printf("sqlite/sqlite3 %s\n", sqlite3_libversion());
std::printf("openssl/openssl %s\n", OpenSSL_version(OPENSSL_VERSION_STRING));
std::filesystem::create_directory("db");
init_shouhin_tachi();
g_server_data = init_server_data();
{
std::time_t now = std::time(nullptr);
std::tm time = *std::localtime(&now);
if (time.tm_mon == 1/*feb*/ && (time.tm_mday >= 13 && time.tm_mday <= 13+7)) holiday = H_VALENTINES; // @note Valentine's Week
} // @note delete now, time
enet_initialize();
{
ENetAddress address{
.type = ENET_ADDRESS_TYPE_IPV4,
.port = g_server_data.port
};
host = enet_host_create (ENET_ADDRESS_TYPE_IPV4, &address, 50zu/* max peer count */, 2zu, 0, 0);
std::thread(&https::listener).detach();
} // @note delete server_data, address
host->usingNewPacketForServer = true;
host->checksum = enet_crc32;
enet_host_compress_with_range_coder(host);
try // @note for people who don't use a debugger···
{
const int size = std::filesystem::file_size("items.dat");
im_data = compress_state(::state{
.type = 0x10,
.peer_state = 0x08,
.size = size
});
im_data.resize(im_data.size() + size); // @note resize to fit binary data
std::ifstream("items.dat", std::ios::binary)
.read(reinterpret_cast<char*>(&im_data[sizeof(::state)]), size); // @note the binary data···
cache_items();
} // @note delete size
catch (std::filesystem::filesystem_error error) { puts(error.what()); }
catch (...) { puts("unknown error occured during decoding items.dat"); } // @note if this appears, it's probably cache_items()···
ENetEvent event{};
while (true)
while (enet_host_service(host, &event, 1000/*ms*/) > 0)
if (const auto i = event_pool.find(event.type); i != event_pool.end())
i->second(event);
return 0;
}