Removed unnecessary unnecessary if in Client::OnInputCommand.
Change name from Server::parseEvent to Server::parseOnInputCommand
This commit is contained in:
@@ -81,8 +81,9 @@ private:
|
|||||||
bool hasMappedEntity(EntityID entityID);
|
bool hasMappedEntity(EntityID entityID);
|
||||||
// Events
|
// Events
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
|
|
||||||
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
EventRelay<Client, Events::InputCommand> m_EInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand &e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ enum class MessageType
|
|||||||
Message,
|
Message,
|
||||||
Snapshot,
|
Snapshot,
|
||||||
Event,
|
Event,
|
||||||
|
OnInputCommand
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ private:
|
|||||||
void checkForTimeOuts();
|
void checkForTimeOuts();
|
||||||
void disconnect(int i);
|
void disconnect(int i);
|
||||||
void parseMessageType(Packet& packet);
|
void parseMessageType(Packet& packet);
|
||||||
void parseEvent(Packet& packet);
|
void parseOnInputCommand(Packet& packet);
|
||||||
void parseConnect(Packet& packet);
|
void parseConnect(Packet& packet);
|
||||||
void parseDisconnect();
|
void parseDisconnect();
|
||||||
void parseClientPing();
|
void parseClientPing();
|
||||||
|
|||||||
@@ -254,7 +254,6 @@ int Client::receive(char* data, size_t length)
|
|||||||
if (error) {
|
if (error) {
|
||||||
LOG_ERROR("receive: %s", error.message().c_str());
|
LOG_ERROR("receive: %s", error.message().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytesReceived;
|
return bytesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,18 +296,18 @@ void Client::moveMessageHead(char*& data, size_t& length, size_t stepSize)
|
|||||||
|
|
||||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||||
{
|
{
|
||||||
if (e.Command == "Forward" || e.Command == "Right") {
|
if (e.Command == "ConnectToServer") { // Connect for now
|
||||||
Packet packet(MessageType::Event, m_SendPacketID);
|
connect();
|
||||||
|
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Packet packet(MessageType::OnInputCommand, m_SendPacketID);
|
||||||
packet.WriteString(e.Command);
|
packet.WriteString(e.Command);
|
||||||
packet.WritePrimitive(e.PlayerID);
|
packet.WritePrimitive(e.PlayerID);
|
||||||
packet.WritePrimitive(e.Value);
|
packet.WritePrimitive(e.Value);
|
||||||
send(packet);
|
send(packet);
|
||||||
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
||||||
return true;
|
return true;
|
||||||
} else if (e.Command == "ConnectToServer") { // Connect for now
|
|
||||||
connect();
|
|
||||||
LOG_INFO("Client::OnInputCommand: Command is %s. Value is %f. PlayerID is %i.", e.Command.c_str(), e.Value, e.PlayerID);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,8 +81,10 @@ void Server::parseMessageType(Packet& packet)
|
|||||||
parseDisconnect();
|
parseDisconnect();
|
||||||
break;
|
break;
|
||||||
case MessageType::Event:
|
case MessageType::Event:
|
||||||
parseEvent(packet);
|
|
||||||
break;
|
break;
|
||||||
|
case MessageType::OnInputCommand:
|
||||||
|
parseOnInputCommand(packet);
|
||||||
|
break;;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -218,7 +220,7 @@ void Server::disconnect(int i)
|
|||||||
m_PlayerDefinitions[i].Name = "";
|
m_PlayerDefinitions[i].Name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::parseEvent(Packet& packet)
|
void Server::parseOnInputCommand(Packet& packet)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < MAXCONNECTIONS; i++) {
|
for (i = 0; i < MAXCONNECTIONS; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user