Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "../NetworkIdentifier.h"
- struct BinaryStream;
- struct NetEventCallback;
- struct Packet {
- int unk_4 = 2, unk_8 = 1;
- unsigned char playerSubIndex = 0;
- Packet(unsigned char playerSubIndex) : playerSubIndex(playerSubIndex) {}
- virtual ~Packet() = 0;
- virtual void *getId() const = 0;
- virtual void *getName() const = 0;
- virtual void *write(BinaryStream &) const = 0;
- virtual void *read(BinaryStream &) = 0;
- virtual void *handle(NetworkIdentifier const &, NetEventCallback &) const = 0;
- virtual bool disallowBatching() const = 0;
- };
- //-------------------------------------------------------------------------------------
- #pragma once
- #include "Packet.h"
- #include <string>
- /*
- * Server -> Client
- */
- class ModalFormRequestPacket : public Packet {
- public:
- int formId;
- std::string formData;
- ModalFormRequestPacket(unsigned char playerSubIndex) : Packet(playerSubIndex) {}
- virtual void *getId() const;
- virtual void *getName() const;
- virtual void *write(BinaryStream &) const;
- virtual void *read(BinaryStream &);
- virtual void *handle(NetworkIdentifier const &, NetEventCallback &) const;
- virtual bool disallowBatching() const;
- };
- //-------------------------------------------------------------------------------------
- #pragma once
- #include "rapidjson/document.h"
- #include "rapidjson/writer.h"
- #include "rapidjson/reader.h"
- #include "rapidjson/stringbuffer.h"
- #include "rapidjson/prettywriter.h"
- using namespace rapidjson;
- typedef PrettyWriter<StringBuffer> JsonWriter;
- //-------------------------------------------------------------------------------------
- //Element.h, Element.cpp:
- #pragma once
- #include "../Json.h"
- class Element {
- protected:
- const char *text;
- public:
- explicit Element(const char *text) {
- this->text = text;
- }
- const char *getText() const {
- return text;
- };
- virtual const char *getType() {
- return nullptr;
- };
- void jsonSerialize(JsonWriter &writer);
- virtual void serializeElementData(JsonWriter &writer) {};
- };
- #include "Element.h"
- void Element::jsonSerialize(JsonWriter &writer) {
- writer.StartObject();
- writer.Key("text");
- writer.String(getText());
- auto type = getType();
- if (type != nullptr) {
- writer.Key("type");
- writer.String(type);
- }
- serializeElementData(writer);
- writer.EndObject();
- }
- //-------------------------------------------------------------------------------------
- //Button.h:
- #pragma once
- #include "Element.h"
- class Button : public Element {
- public:
- explicit Button(const char *text) : Element(text) {};
- };
- //-------------------------------------------------------------------------------------
- //Form.h, Form.cpp:
- #pragma once
- #include <vector>
- #include "../elements/Element.h"
- using namespace std;
- class Form {
- protected:
- const char *title;
- public:
- explicit Form(const char *title) {
- this->title = title;
- }
- virtual const char *getType() const = 0;
- const char *getTitle() const {
- return title;
- }
- string jsonSerialize();
- virtual void serializeFormData(JsonWriter &writer) {}
- };
- #include "Form.h"
- string Form::jsonSerialize() {
- StringBuffer buffer;
- JsonWriter writer(buffer);
- writer.StartObject();
- writer.Key("type");
- writer.String(getType());
- writer.Key("title");
- writer.String(getTitle());
- serializeFormData(writer);
- writer.EndObject();
- return string(buffer.GetString());
- }
- //-------------------------------------------------------------------------------------
- //MenuForm.h, MenuForm.cpp:
- #include <utility>
- #pragma once
- #include "Form.h"
- #include "../elements/Button.h"
- class MenuForm : public Form {
- protected:
- const char *text;
- const vector<Button *> buttons;
- public:
- explicit MenuForm(const char *title, const char *text, vector<Button *> buttons) : Form(title), text(text), buttons(std::move(buttons)) {}
- const char *getType() const override {
- return "form";
- }
- void serializeFormData(JsonWriter &writer) override;
- };
- #include "MenuForm.h"
- void MenuForm::serializeFormData(JsonWriter &writer) {
- writer.Key("content");
- writer.String(text);
- writer.Key("buttons");
- writer.StartArray();
- for (auto *button : buttons) {
- button->jsonSerialize(writer);
- }
- writer.EndArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement