change folder name

This commit is contained in:
Julian Nießner
2019-06-02 17:54:50 +02:00
parent 84beaf7fd6
commit 473432d9bb
7 changed files with 2 additions and 2 deletions

37
src/commands/Command.cpp Normal file
View 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
View 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;
};

View 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;
}

View File

@@ -0,0 +1,6 @@
#include "Command.h"
void StopCommandInternal::execute(GameServer *server)
{
server->m_running = false;
}

View 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;
}

View File

@@ -0,0 +1,8 @@
#include "Command.h"
#include <iostream>
void TestCommandInternal::execute(GameServer *server)
{
std::cout << "Internal testcommand launched!" << std::endl;
}