change folder name
This commit is contained in:
37
src/commands/Command.cpp
Normal file
37
src/commands/Command.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "Command.h"
|
||||
#include "../Shared.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
Command *Command::create(int clientIndex, yojimbo::Message *message)
|
||||
{
|
||||
switch (message->GetType())
|
||||
{
|
||||
case (int)GameMessageType::TEST:
|
||||
return new TestCommand(clientIndex, message);
|
||||
case (int)GameMessageType::SETNAME:
|
||||
return new SetNameCommand(clientIndex, message);
|
||||
default:
|
||||
std::cout << "Unknown message type received!" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Command *Command::create(std::string command)
|
||||
{
|
||||
std::stringstream ss(command);
|
||||
std::string token;
|
||||
ss >>
|
||||
token;
|
||||
if (token == "stop")
|
||||
{
|
||||
return new StopCommandInternal();
|
||||
}
|
||||
else if (token == "test")
|
||||
{
|
||||
return new TestCommandInternal();
|
||||
}
|
||||
std::cout << "Internal commando don't exists: " << command << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
66
src/commands/Command.h
Normal file
66
src/commands/Command.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
//Vendor
|
||||
#include <yojimbo.h>
|
||||
|
||||
class Command;
|
||||
#include "../GameServer.h"
|
||||
|
||||
// ---- Interface:
|
||||
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
// Create Commands from Network messages (Limited list)
|
||||
static Command *create(int clientIndex, yojimbo::Message *message);
|
||||
// Create Commands from Strings internal (Limited list)
|
||||
static Command *create(std::string);
|
||||
|
||||
virtual void execute(GameServer *server) = 0;
|
||||
};
|
||||
|
||||
// --- Classes Network:
|
||||
|
||||
class TestCommand : public Command
|
||||
{
|
||||
public:
|
||||
TestCommand(int clientIndex, yojimbo::Message *message)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_data(((TestMessage *)message)->m_data)
|
||||
{}
|
||||
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
private:
|
||||
int m_clientIndex;
|
||||
int m_data;
|
||||
};
|
||||
|
||||
class SetNameCommand : public Command
|
||||
{
|
||||
public:
|
||||
SetNameCommand(int clientIndex, yojimbo::Message *message)
|
||||
: m_clientIndex(clientIndex),
|
||||
m_name(std::string(((SetNameMessage *)message)->buffer))
|
||||
{}
|
||||
|
||||
virtual void execute(GameServer *server) override;
|
||||
|
||||
private:
|
||||
int m_clientIndex;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
// --- Classes Internal:
|
||||
|
||||
class TestCommandInternal : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(GameServer *server) override;
|
||||
};
|
||||
|
||||
class StopCommandInternal : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(GameServer *server) override;
|
||||
};
|
||||
14
src/commands/SetNameCommand.cpp
Normal file
14
src/commands/SetNameCommand.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "Command.h"
|
||||
|
||||
#include "../core/Components.h"
|
||||
|
||||
void SetNameCommand::execute(GameServer *server)
|
||||
{
|
||||
entityx::Entity entity = server->serverToEntityX.at(m_clientIndex);
|
||||
entityx::ComponentHandle<NetworkPlayerProperties> playerproperties = entity.component<NetworkPlayerProperties>();
|
||||
if (playerproperties)
|
||||
{
|
||||
playerproperties->name = m_name;
|
||||
}
|
||||
std::cout << "Entity name changed to " << playerproperties->name << " Buffer content: " << m_name << std::endl;
|
||||
}
|
||||
6
src/commands/StopCommandInternal.cpp
Normal file
6
src/commands/StopCommandInternal.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "Command.h"
|
||||
|
||||
void StopCommandInternal::execute(GameServer *server)
|
||||
{
|
||||
server->m_running = false;
|
||||
}
|
||||
12
src/commands/TestCommand.cpp
Normal file
12
src/commands/TestCommand.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Command.h"
|
||||
|
||||
#include "../core/Components.h"
|
||||
|
||||
void TestCommand::execute(GameServer *server)
|
||||
{
|
||||
// ... process test message ...
|
||||
entityx::Entity entity = server->serverToEntityX.at(m_clientIndex);
|
||||
entityx::ComponentHandle<NetworkPlayerProperties> playerproperties = entity.component<NetworkPlayerProperties>();
|
||||
|
||||
std::cout << "Test message received from client " << playerproperties->name << ":" << m_clientIndex << " with data: " << m_data << std::endl;
|
||||
}
|
||||
8
src/commands/TestCommandInternal.cpp
Normal file
8
src/commands/TestCommandInternal.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "Command.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void TestCommandInternal::execute(GameServer *server)
|
||||
{
|
||||
std::cout << "Internal testcommand launched!" << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user