Skip to content

Commit 725e177

Browse files
committed
new status server. more reactive ping time
1 parent 3ebff34 commit 725e177

4 files changed

Lines changed: 23 additions & 28 deletions

File tree

discord.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222

2323
void discordLobbyJoined(Game gameId, const std::string& username, const std::vector<std::string>& playerList);
2424
void discordGameCreated(Game gameId, const std::string& username, const std::string& gameName, const std::vector<std::string>& playerList);
25+
const char *getDCNetGameId(Game game);

kageserver.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern "C" {
3636
#define DATADIR "."
3737
#endif
3838

39+
using namespace std::chrono_literals;
40+
3941
static std::map<std::string, std::string> Config;
4042
std::string DataDir;
4143

@@ -183,21 +185,11 @@ void BootstrapServer::onUpdateTimer(const std::error_code& ec)
183185
{
184186
if (ec)
185187
return;
186-
int playerCount;
187-
int gameCount;
188-
bombermanServer.getStatus(playerCount, gameCount);
189-
statusUpdate("bomberman", playerCount, gameCount);
190-
outtriggerServer.getStatus(playerCount, gameCount);
191-
statusUpdate("outtrigger", playerCount, gameCount);
192-
propellerServer.getStatus(playerCount, gameCount);
193-
statusUpdate("propeller", playerCount, gameCount);
194-
try {
195-
statusCommit("kage");
196-
} catch (const std::exception& e) {
197-
ERROR_LOG(Game::None, "statusCommit failed: %s", e.what());
198-
}
199-
200-
statusTimer.expires_after(asio::chrono::seconds(statusGetInterval()));
188+
if (statusTimer.expiry().time_since_epoch() == 0ms)
189+
status::reset("kage");
190+
else
191+
status::ping("kage");
192+
statusTimer.expires_after(asio::chrono::seconds(status::pingInterval()));
201193
statusTimer.async_wait(std::bind(&BootstrapServer::onUpdateTimer, this, asio::placeholders::error));
202194
}
203195

model.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "model.h"
2020
#include "discord.h"
2121
#include "log.h"
22+
#include <dcserver/status.hpp>
2223
#include <algorithm>
2324
#include <cctype>
2425

@@ -126,7 +127,7 @@ void Player::ackRUdp(uint32_t seq)
126127
ackedRelSeq = seq;
127128
std::error_code ec;
128129
timer.cancel(ec);
129-
ping = ping * 0.7f + (Clock::now() - lastRUdpSend) / 1.0ms * 0.3f;
130+
ping = ping * 0.5f + (Clock::now() - lastRUdpSend) / 1.0ms * 0.5f;
130131
if (!relQueue.empty()) {
131132
sendRel(relQueue.front().second, relQueue.front().first);
132133
relQueue.pop_front();
@@ -252,6 +253,8 @@ void LobbyServer::addPlayer(Player *player)
252253
player->getName().c_str(), player->getId(),
253254
player->getEndpoint().address().to_string().c_str(), player->getEndpoint().port());
254255
players[player->getEndpoint()] = player;
256+
status::join(getDCNetGameId(game), player->getEndpoint().address().to_string(),
257+
player->getEndpoint().port(), player->getName());
255258
}
256259

257260
void LobbyServer::removePlayer(Player *player)
@@ -260,14 +263,18 @@ void LobbyServer::removePlayer(Player *player)
260263
player->getLobby()->removePlayer(player);
261264
players.erase(player->getEndpoint());
262265
INFO_LOG(game, "Player %s [%x] left lobby server", player->getName().c_str(), player->getId());
266+
status::leave(getDCNetGameId(game), player->getEndpoint().address().to_string(),
267+
player->getEndpoint().port(), player->getName());
263268
delete player;
264269
}
265270

266271
void LobbyServer::send(Packet& packet, const asio::ip::udp::endpoint& endpoint)
267272
{
268273
size_t pktsize = packet.finalize();
269-
std::error_code ec2;
270-
socket.send_to(asio::buffer(packet.data, pktsize), endpoint, 0, ec2);
274+
std::error_code ec;
275+
socket.send_to(asio::buffer(packet.data, pktsize), endpoint, 0, ec);
276+
if (ec)
277+
WARN_LOG(game, "send to %s:%d failed: %s", endpoint.address().to_string().c_str(), endpoint.port(), ec.message().c_str());
271278
}
272279

273280
static inline void strtolower(std::string& str) {
@@ -937,14 +944,6 @@ Room *LobbyServer::addRoom(const std::string& name, uint32_t attributes, Player
937944
return room;
938945
}
939946

940-
void LobbyServer::getStatus(int& playerCount, int& gameCount)
941-
{
942-
playerCount = players.size();
943-
gameCount = 0;
944-
for (const Lobby& lobby : lobbies)
945-
gameCount += lobby.getRooms().size();
946-
}
947-
948947
bool Room::DumpNetData = false;
949948

950949
Room::Room(Lobby& lobby, uint32_t id, const std::string& name, uint32_t attributes, Player *owner, asio::io_context& io_context)
@@ -1139,9 +1138,13 @@ void Lobby::addRoom(Room *room)
11391138
if (pl != owner)
11401139
lobbyUsers.push_back(pl->getName());
11411140
discordGameCreated(server.game, owner->getName(), room->getName(), lobbyUsers);
1141+
status::createGame(getDCNetGameId(server.game));
1142+
11421143
}
11431144

1144-
void Lobby::removeRoom(Room *room) {
1145+
void Lobby::removeRoom(Room *room)
1146+
{
1147+
status::deleteGame(getDCNetGameId(server.game));
11451148
rooms.erase(room->getId());
11461149
delete room;
11471150
}

model.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ class LobbyServer : public Server
335335
void removePlayer(Player *player);
336336
void send(Packet& packet, const asio::ip::udp::endpoint& endpoint);
337337
virtual Room *addRoom(const std::string& name, uint32_t attributes, Player *owner);
338-
void getStatus(int& playerCount, int& gameCount);
339338

340339
const Game game;
341340

0 commit comments

Comments
 (0)