Skip to content

Commit 8db7196

Browse files
committed
ENetCallback & https thread revamp
- ranges:: on array rotation - downgrade from const char to bool for less memory
1 parent 4821abd commit 8db7196

File tree

6 files changed

+248
-245
lines changed

6 files changed

+248
-245
lines changed

include/action/join_request.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void join_request(ENetEvent event, const std::string& header)
8383
}
8484
if (std::find(_peer[event.peer]->recent_worlds.begin(), _peer[event.peer]->recent_worlds.end(), w->name) == _peer[event.peer]->recent_worlds.end())
8585
{
86-
std::rotate(_peer[event.peer]->recent_worlds.begin(), _peer[event.peer]->recent_worlds.begin() + 1, _peer[event.peer]->recent_worlds.end());
86+
std::ranges::rotate(_peer[event.peer]->recent_worlds, _peer[event.peer]->recent_worlds.begin() + 1);
8787
_peer[event.peer]->recent_worlds.back() = w->name;
8888
}
89-
_peer[event.peer]->ongoing_world = w->name.c_str();
89+
_peer[event.peer]->lobby = false;
9090
EmoticonDataChanged(event);
9191
_peer[event.peer]->netid = ++w->visitors;
9292
gt_packet(*event.peer, false, "OnSpawn", std::format("spawn|avatar\nnetID|{}\nuserID|{}\ncolrect|0|0|20|30\nposXY|{}|{}\nname|{}\ncountry|{}\ninvis|0\nmstate|0\nsmstate|0\nonlineID|\ntype|local\n",

include/action/quit_to_exit.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
void quit_to_exit(ENetEvent event, const std::string& header)
33
{
4-
if (_peer[event.peer]->ongoing_world == nullptr or _peer[event.peer]->ongoing_world[0] == '\0') return;
4+
if (_peer[event.peer]->lobby == true) return;
55
--worlds[_peer[event.peer]->recent_worlds.back()].visitors;
66
peers(ENET_PEER_STATE_CONNECTED, [&](ENetPeer& p)
77
{
@@ -14,7 +14,7 @@ void quit_to_exit(ENetEvent event, const std::string& header)
1414
if (worlds[_peer[event.peer]->recent_worlds.back()].visitors <= 0)
1515
worlds.erase(_peer[event.peer]->recent_worlds.back());
1616
_peer[event.peer]->post_enter.unlock();
17-
_peer[event.peer]->ongoing_world = "";
17+
_peer[event.peer]->lobby = true;
1818
_peer[event.peer]->netid = -1; // this will fix any packets being sent outside of world
1919
OnRequestWorldSelectMenu(event);
2020
}

include/database/peer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class peer {
3434
else slots.emplace_back(std::move(s)); // @note no such item in inventory, so we create a new entry.
3535
}
3636
std::array<std::string, 5> recent_worlds{}; // @note recent worlds, a list of 5 worlds, once it reaches 6 it'll be replaced by the oldest
37-
const char* ongoing_world{}; // @note the world the peer is inside.
37+
bool lobby{true}; // @note checks if peer is in EXIT or 'lobby'
3838

3939
std::array<steady_clock::time_point, 3> rate_limit{}; /* rate limit objects. for memory optimial reasons please manually increase array size. */
4040
std::deque<steady_clock::time_point> messages; /* last 5 que messages sent time, this is used to check for spamming */

include/https.o

-187 KB
Binary file not shown.

0 commit comments

Comments
 (0)