diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index e0120ce..cf7ff86 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -9,11 +9,11 @@ Command *Command::create(int clientIndex, yojimbo::Message *message) switch (message->GetType()) { case (int)GameMessageType::TEST: - return new TestCommand(clientIndex, message); + return new TestCommand(clientIndex, ((TestMessage *)message)->m_data); case (int)GameMessageType::SETNAME: - return new SetNameCommand(clientIndex, message); + return new SetNameCommand(clientIndex, std::string(((SetNameMessage *)message)->buffer)); default: - std::cout << "Unknown message type received!" << std::endl; + std::cout << "Unknown message type received over network!" << std::endl; return nullptr; } } @@ -22,16 +22,16 @@ Command *Command::create(std::string command) { std::stringstream ss(command); std::string token; - ss >> + ss >> token; if (token == "stop") { - return new StopCommandInternal(); + return new StopCommand(); } else if (token == "test") { - return new TestCommandInternal(); + return new TestCommand(-1, 100); } - std::cout << "Internal commando don't exists: " << command << std::endl; + std::cout << "Local command don't exists: " << command << std::endl; return nullptr; } \ No newline at end of file diff --git a/src/commands/Command.h b/src/commands/Command.h index 4863aa5..84c62cd 100644 --- a/src/commands/Command.h +++ b/src/commands/Command.h @@ -24,9 +24,9 @@ public: class TestCommand : public Command { public: - TestCommand(int clientIndex, yojimbo::Message *message) + TestCommand(int clientIndex, int data) : m_clientIndex(clientIndex), - m_data(((TestMessage *)message)->m_data) + m_data(data) {} virtual void execute(GameServer *server) override; @@ -39,9 +39,9 @@ private: class SetNameCommand : public Command { public: - SetNameCommand(int clientIndex, yojimbo::Message *message) + SetNameCommand(int clientIndex, std::string name) : m_clientIndex(clientIndex), - m_name(std::string(((SetNameMessage *)message)->buffer)) + m_name(name) {} virtual void execute(GameServer *server) override; @@ -51,15 +51,9 @@ private: std::string m_name; }; -// --- Classes Internal: +// --- Classes local: -class TestCommandInternal : public Command -{ -public: - virtual void execute(GameServer *server) override; -}; - -class StopCommandInternal : public Command +class StopCommand : public Command { public: virtual void execute(GameServer *server) override; diff --git a/src/commands/StopCommandInternal.cpp b/src/commands/StopCommand.cpp similarity index 50% rename from src/commands/StopCommandInternal.cpp rename to src/commands/StopCommand.cpp index 5225d7e..02b6145 100644 --- a/src/commands/StopCommandInternal.cpp +++ b/src/commands/StopCommand.cpp @@ -1,6 +1,6 @@ #include "Command.h" -void StopCommandInternal::execute(GameServer *server) +void StopCommand::execute(GameServer *server) { server->m_running = false; } diff --git a/src/commands/TestCommand.cpp b/src/commands/TestCommand.cpp index 7969f54..1360672 100644 --- a/src/commands/TestCommand.cpp +++ b/src/commands/TestCommand.cpp @@ -4,9 +4,14 @@ void TestCommand::execute(GameServer *server) { - // ... process test message ... - entityx::Entity entity = server->serverToEntityX.at(m_clientIndex); - entityx::ComponentHandle playerproperties = entity.component(); - - std::cout << "Test message received from client " << playerproperties->name << ":" << m_clientIndex << " with data: " << m_data << std::endl; + if (m_clientIndex == -1) + { + std::cout << "Test message received from server cmd :" << m_clientIndex << " with data: " << m_data << std::endl; + } + else + { + entityx::Entity entity = server->serverToEntityX.at(m_clientIndex); + entityx::ComponentHandle playerproperties = entity.component(); + std::cout << "Test message received from client " << playerproperties->name << ":" << m_clientIndex << " with data: " << m_data << std::endl; + } } diff --git a/src/commands/TestCommandInternal.cpp b/src/commands/TestCommandInternal.cpp deleted file mode 100644 index c8d00a0..0000000 --- a/src/commands/TestCommandInternal.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Command.h" - -#include - -void TestCommandInternal::execute(GameServer *server) -{ - std::cout << "Internal testcommand launched!" << std::endl; -} \ No newline at end of file