float yaw,
std::uint8_t actions,
std::uint8_t slot);
+ std::uint16_t SendMessage(
+ std::uint8_t type,
+ std::uint32_t ref,
+ const std::string &msg);
private:
void HandlePacket(const UDPpacket &);
#include "ChunkReceiver.hpp"
#include "NetworkedInput.hpp"
+#include "../app/ChatState.hpp"
#include "../app/IntervalTimer.hpp"
#include "../audio/SoundBank.hpp"
#include "../graphics/SkyBox.hpp"
class InteractiveState
: public State
-, public ClientController {
+, public ClientController
+, public ChatState::Responder {
public:
explicit InteractiveState(MasterState &, std::uint32_t player_id);
void Handle(const Packet::EntityUpdate &);
void Handle(const Packet::PlayerCorrection &);
void Handle(const Packet::BlockUpdate &);
+ void Handle(const Packet::Message &);
void SetAudio(bool) override;
void SetVideo(bool) override;
void SetDebug(bool) override;
void Exit() override;
+ void OnLineSubmit(const std::string &) override;
+
private:
/// flag entity as updated by given packet
/// returns false if the update should be ignored
};
std::map<std::uint32_t, UpdateStatus> update_status;
+ ChatState chat;
+
};
}
void On(const Packet::ChunkBegin &) override;
void On(const Packet::ChunkData &) override;
void On(const Packet::BlockUpdate &) override;
+ void On(const Packet::Message &) override;
private:
Environment &env;
, chunk_renderer(player.GetChunks())
, loop_timer(16)
, sky(master.GetEnv().loader.LoadCubeMap("skybox"))
-, update_status() {
+, update_status()
+, chat(master.GetEnv(), *this, *this) {
if (!save.Exists()) {
save.Write(master.GetWorldConf());
}
void InteractiveState::Handle(const SDL_Event &event) {
switch (event.type) {
case SDL_KEYDOWN:
- interface.HandlePress(event.key);
+ // TODO: move to interface
+ if (event.key.keysym.sym == SDLK_RETURN) {
+ master.GetEnv().state.Push(&chat);
+ hud.KeepMessages(true);
+ } else {
+ interface.HandlePress(event.key);
+ }
break;
case SDL_KEYUP:
interface.HandleRelease(event.key);
}
}
+void InteractiveState::Handle(const Packet::Message &pack) {
+ string msg;
+ pack.ReadMessage(msg);
+ hud.PostMessage(msg);
+}
+
void InteractiveState::SetAudio(bool b) {
master.GetConfig().audio.enabled = b;
if (b) {
master.Quit();
}
+void InteractiveState::OnLineSubmit(const string &line) {
+ master.GetClient().SendMessage(1, 0, line);
+}
+
MasterState::MasterState(
Environment &env,
state->Handle(pack);
}
+void MasterState::On(const Packet::Message &pack) {
+ if (state) {
+ state->Handle(pack);
+ } else {
+ string msg;
+ pack.ReadMessage(msg);
+ cout << "got message before interface was created: " << msg << endl;
+ }
+}
+
}
}
return conn.Send(client_pack, client_sock);
}
+uint16_t Client::SendMessage(
+ uint8_t type,
+ uint32_t ref,
+ const string &msg
+) {
+ auto pack = Packet::Make<Packet::Message>(client_pack);
+ pack.WriteType(type);
+ pack.WriteReferral(ref);
+ pack.WriteMessage(msg);
+ client_pack.len = sizeof(Packet::Header) + Packet::Message::GetSize(msg);
+ return conn.Send(client_pack, client_sock);
+}
NetworkedInput::NetworkedInput(World &world, Player &player, Client &client)
: PlayerController(world, player)
void MasterState::Handle(const SDL_Event &event) {
switch (event.type) {
case SDL_KEYDOWN:
- // TODO: move to interface?
+ // TODO: move to interface
if (event.key.keysym.sym == SDLK_RETURN) {
env.state.Push(&chat);
hud.KeepMessages(true);