5 Commits

Author SHA1 Message Date
582a66d4eb Merge branch 'main' into gestionnaireajoutkick
Some checks are pending
Linux arm64 / Build (push) Waiting to run
2024-04-11 17:18:39 +02:00
9a6642b1ad Update BlitzConfig.h and LeaderBoardGui.cpp, and fix kick button size in ServerGui.cpp
All checks were successful
Linux arm64 / Build (push) Successful in 22m42s
2024-04-11 11:56:11 +02:00
d823dfa9d7 Squashed commit of the following:
Some checks are pending
Linux arm64 / Build (push) Waiting to run
commit 98fcb30f68
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Apr 9 19:19:51 2024 +0200

    update color interface
2024-04-11 11:41:33 +02:00
028715d3b5 interface fonctionnelle
All checks were successful
Linux arm64 / Build (push) Successful in 23m29s
2024-04-11 09:20:00 +02:00
d4902214ae Gestionnaire d'ajout de joueurs et de kick
All checks were successful
Linux arm64 / Build (push) Successful in 23m16s
2024-04-10 10:03:25 +02:00
9 changed files with 104 additions and 24 deletions

View File

@@ -19,7 +19,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;
@@ -30,7 +30,7 @@ class BlitzConfig {
BlitzConfig();
~BlitzConfig();
std::array<char, 256>& GetPseudo() {
std::array<char, 20>& GetPseudo() {
return m_Pseudo;
}

View File

@@ -38,6 +38,8 @@ class Server {
void AddBot();
void KickPlayer(game::PlayerID player);
void RemoveConnexion(std::uint8_t connexionID);
void BroadcastPacket(const protocol::Packet* packet);

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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 =

View File

@@ -2,6 +2,7 @@
#include "client/Client.h"
#include "client/display/InputManager.h"
#include "client/game/ClientGame.h"
#include "server/Server.h"
#include "server/game/ServerGame.h"
#include <imgui.h>
@@ -23,8 +24,8 @@ void ServerGui::Render() {
ImGuiWindowFlags servergui_flags =
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar;
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
static float servergui_width = 640.0f;
static float servergui_height = 640.0f;
static float servergui_width = 1500.0f;
static float servergui_height = 800.0f;
const static ImVec2 buttonSize = {300, 60};
@@ -33,14 +34,48 @@ void ServerGui::Render() {
if (ImGui::BeginPopupModal("FENETRE D'ADMIN", nullptr, servergui_flags)) {
InputManager::GrabMouse(false);
ImGui::BeginChild("Mutateurs PARTIE", ImVec2(servergui_width * (5.0f / 10.0f), 0.0f), true);
ImGui::Text("PARTIE");
ImGui::BeginChild("Mutateurs JOUEURS", ImVec2(servergui_width * (1.0f / 3.0f), 0.0f), true);
{
ImGui::Text("JOUEURS");
ImGui::NewLine();
ImGui::Text("AJOUTER JOUEUR");
if (ImGui::Button("Ajouter Bot", buttonSize)) {
m_Client->GetServer()->AddBot();
}
ImGui::NewLine();
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
}
hasOtherPlayers = true;
ImGui::Text("%s", player->GetName().c_str());
ImGui::SameLine();
ImGui::PushID(player->GetID());
if (ImGui::Button("Kick", {kickButtonSizex, kickButtonSizey})) {
m_Client->GetServer()->KickPlayer(player->GetID());
}
ImGui::PopID();
}
if (!hasOtherPlayers) {
ImGui::Text("Aucun autre joueur");
}
}
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("Mutateurs PARTIE", ImVec2(servergui_width * (1.0f / 3.0f), 0.0f), true);
ImGui::Text("PARTIE");
ImGui::NewLine();
ImGui::Text("GRAVITE");
float gravity[] = {20.0f, 7.0f, 40.0f};
@@ -86,7 +121,7 @@ void ServerGui::Render() {
ImGui::SameLine();
ImGui::BeginChild("MUTATEUR TEMPS", ImVec2(servergui_width * (4.5f / 10.0f), 0.0f), true);
ImGui::BeginChild("MUTATEUR TEMPS", ImVec2(servergui_width * (0.9f / 3.0f), 0.0f), true);
static int gameDurMin = static_cast<int>(m_Client->GetServer()->GetGame().GetServerDuration().m_GameDuration / 1000) / 60;
static int gameDurSec = static_cast<int>(m_Client->GetServer()->GetGame().GetServerDuration().m_GameDuration / 1000) % 60;

View File

@@ -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

View File

@@ -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

View File

@@ -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();
}
}