Meilleur panel admin (#45)
All checks were successful
Linux arm64 / Build (push) Successful in 5m6s
All checks were successful
Linux arm64 / Build (push) Successful in 5m6s
Fix #34 Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com> Reviewed-on: #45 Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-committed-by: Persson-dev <sim16.prib@gmail.com>
This commit was merged in pull request #45.
This commit is contained in:
@@ -32,7 +32,7 @@ typedef std::array<int, kaMax> Keybinds;
|
||||
*/
|
||||
class BlitzConfig {
|
||||
private:
|
||||
std::array<char, 256> m_Pseudo;
|
||||
std::array<char, 20> m_Pseudo;
|
||||
game::GameConfig m_ServerConfig;
|
||||
bool m_VSync;
|
||||
bool m_DisplayFps;
|
||||
@@ -46,12 +46,7 @@ class BlitzConfig {
|
||||
BlitzConfig();
|
||||
~BlitzConfig();
|
||||
|
||||
/**
|
||||
* \brief Get the pseudo
|
||||
* \return The pseudo
|
||||
* \note The pseudo is a 256 characters array
|
||||
*/
|
||||
std::array<char, 256>& GetPseudo() {
|
||||
std::array<char, 20>& GetPseudo() {
|
||||
return m_Pseudo;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,12 @@ class Server {
|
||||
*/
|
||||
void AddBot();
|
||||
|
||||
/**
|
||||
* \brief Forcefully remove a player from the game
|
||||
* \param player the id of the player to remove
|
||||
*/
|
||||
void KickPlayer(game::PlayerID player);
|
||||
|
||||
/**
|
||||
* \brief Remove a connexion
|
||||
* \param connexionID The connexion ID
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "blitz/misc/PrettyLog.h"
|
||||
#include "blitz/protocol/packets/ChatPacket.h"
|
||||
#include "blitz/protocol/packets/ConnexionInfoPacket.h"
|
||||
#include "blitz/protocol/packets/DisconnectPacket.h"
|
||||
#include "blitz/protocol/packets/KeepAlivePacket.h"
|
||||
#include "blitz/protocol/packets/PlayerLoginPacket.h"
|
||||
#include "client/Client.h"
|
||||
@@ -52,7 +53,7 @@ void ClientConnexion::HandlePacket(const protocol::ChatPacket* packet) {
|
||||
}
|
||||
|
||||
void ClientConnexion::HandlePacket(const protocol::DisconnectPacket* packet) {
|
||||
utils::LOG("Disconnected !");
|
||||
utils::LOG("[ClientConnexion] Disconnected ! Reason : " + packet->GetReason());
|
||||
m_Client->NotifyListeners(&game::ClientListener::OnGameLeave);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ void BlitzGui::SetCustomTheme() {
|
||||
const static ImVec4 colorButtonHover = {0.56f, 0.02f, 0.02f, 1.0f};
|
||||
const static ImVec4 colorButtonActive = {0.36f, 0.03f, 0.03f, 1.0f};
|
||||
const static ImVec4 colorCheckMark = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
const static ImVec4 colorTab = {0.38f, 0.02f, 0.02f, 1.0f};
|
||||
const static ImVec4 colorTabHover = {0.74f, 0.0f, 0.0f, 0.73f};
|
||||
const static ImVec4 colorTabActive = {1.0f, 0.0f, 0.0f, 0.73f};
|
||||
|
||||
|
||||
ImGui::GetStyle().Colors[ImGuiCol_Button] = colorButton;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_ButtonActive] = colorButtonActive;
|
||||
@@ -39,6 +43,15 @@ void BlitzGui::SetCustomTheme() {
|
||||
ImGui::GetStyle().Colors[ImGuiCol_FrameBg] = colorButton;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_FrameBgActive] = colorButtonActive;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_FrameBgHovered] = colorButtonHover;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_Tab] = colorTab;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_TabHovered] = colorTabHover;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_TabActive] = colorTabActive;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_TitleBgActive] = colorTabActive;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_SliderGrab] = colorButton;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_SliderGrabActive] = colorButton;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_HeaderActive] = colorTab;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_HeaderHovered] = colorTabActive;
|
||||
ImGui::GetStyle().Colors[ImGuiCol_Header] = colorTabActive;
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -15,7 +15,7 @@ LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, Client* client) : GuiWidget(pa
|
||||
LeaderBoardGui::~LeaderBoardGui() {}
|
||||
|
||||
void LeaderBoardGui::Draw(const char* title, bool* p_open) {
|
||||
static float leaderboard_width = 640.0f;
|
||||
static float leaderboard_width = 800.0f;
|
||||
static float leaderboard_height = 450.0f;
|
||||
|
||||
ImGuiWindowFlags leaderboard_flags =
|
||||
|
||||
@@ -49,6 +49,8 @@ void ServerGui::Render() {
|
||||
ImGui::Text("KICK JOUEURS");
|
||||
bool hasOtherPlayers = false;
|
||||
auto& players = m_Client->GetGame()->GetLeaderBoard().GetPlayers();
|
||||
float kickButtonSizex = ImGui::CalcTextSize("Kick").x + 50.0f;
|
||||
float kickButtonSizey = ImGui::CalcTextSize("Kick").y + 20.0f;
|
||||
for (game::Player* player : players) {
|
||||
if (player->GetID() == m_Client->GetPlayerID()) {
|
||||
continue; // Skip the current player
|
||||
@@ -56,10 +58,11 @@ void ServerGui::Render() {
|
||||
hasOtherPlayers = true;
|
||||
ImGui::Text("%s", player->GetName().c_str());
|
||||
ImGui::SameLine();
|
||||
std::string idButton = "Kick ##" + std::to_string(player->GetID());
|
||||
if (ImGui::Button(idButton.c_str(), buttonSize) && (m_Client->GetServer()->GetGame().GetGameState() == game::gsGame)) {
|
||||
m_Client->GetGame()->RemovePlayer(player->GetID());
|
||||
ImGui::PushID(player->GetID());
|
||||
if (ImGui::Button("Kick", {kickButtonSizex, kickButtonSizey})) {
|
||||
m_Client->GetServer()->KickPlayer(player->GetID());
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (!hasOtherPlayers) {
|
||||
|
||||
@@ -153,9 +153,6 @@ void Server::BroadcastChatMessage(const std::string& msg) {
|
||||
|
||||
void Server::RemoveConnexion(std::uint8_t connexionID) {
|
||||
m_Connections.erase(connexionID);
|
||||
|
||||
protocol::PlayerLeavePacket packet(connexionID);
|
||||
BroadcastPacket(&packet);
|
||||
}
|
||||
|
||||
std::uint16_t Server::GetListeningPort() {
|
||||
@@ -173,5 +170,26 @@ void Server::AddBot() {
|
||||
botPlayer->SetBot();
|
||||
}
|
||||
|
||||
void Server::KickPlayer(game::PlayerID playerID) {
|
||||
auto it = m_Connections.find(playerID);
|
||||
|
||||
if (it != m_Connections.end()) {
|
||||
protocol::DisconnectPacket packet("Tu dois disparaître (in game) !");
|
||||
m_Connections.at(playerID)->SendPacket(&packet);
|
||||
}
|
||||
|
||||
game::Player* player = m_Game.GetPlayerById(playerID);
|
||||
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
m_Game.RemovePlayer(playerID);
|
||||
|
||||
if (player->IsBot()) {
|
||||
} else {
|
||||
RemoveConnexion(playerID);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
|
||||
@@ -179,12 +179,7 @@ ServerConnexion::~ServerConnexion() {
|
||||
|
||||
GetDispatcher()->UnregisterHandler(this);
|
||||
|
||||
if (m_Player) {
|
||||
std::string leaveMessage = utils::Format("%s a quitte la partie !", m_Player->GetName().c_str());
|
||||
|
||||
utils::LOG("[Server] " + leaveMessage);
|
||||
m_Server->BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + leaveMessage);
|
||||
}
|
||||
m_Server->GetGame().RemovePlayer(m_ID);
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "blitz/misc/Random.h"
|
||||
#include "blitz/protocol/packets/ChatPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerJoinPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerLeavePacket.h"
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
#include "blitz/protocol/packets/ServerConfigPacket.h"
|
||||
@@ -36,6 +37,7 @@ void ServerGame::Tick(std::uint64_t delta) {
|
||||
if (m_PositionTimer.Update(delta)) {
|
||||
SendPlayerPositions();
|
||||
}
|
||||
|
||||
if (m_GameState != game::gsWaiting && m_GameTimer.Update(delta)) {
|
||||
switch (m_GameState) {
|
||||
case game::gsPreparing:
|
||||
@@ -112,10 +114,24 @@ void ServerGame::AddPlayer(game::PlayerID player, const std::string& name) {
|
||||
}
|
||||
}
|
||||
|
||||
void ServerGame::RemovePlayer(game::PlayerID player) {
|
||||
Game::RemovePlayer(player);
|
||||
void ServerGame::RemovePlayer(game::PlayerID playerID) {
|
||||
|
||||
if (m_GameState == game::gsGame && m_Players.size() <= 1) {
|
||||
game::Player* player = GetPlayerById(playerID);
|
||||
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
protocol::PlayerLeavePacket packet(playerID);
|
||||
m_Server->BroadcastPacket(&packet);
|
||||
|
||||
std::string leaveMessage = utils::Format("%s a quitte la partie !", player->GetName().c_str());
|
||||
|
||||
utils::LOG("[Server] " + leaveMessage);
|
||||
m_Server->BroadcastChatMessage(protocol::ChatPacket::GetTextColor(protocol::YELLOW) + leaveMessage);
|
||||
|
||||
Game::RemovePlayer(playerID);
|
||||
|
||||
if ((m_GameState == game::gsGame || m_GameState == game::gsPreparing) && m_Players.size() <= 1) {
|
||||
CancelGame();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user