Changeset View
Changeset View
Standalone View
Standalone View
source/network/NetMessage.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2024 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
public: | public: | ||||
/** | /** | ||||
* Factory method which creates a message object based on the given data | * Factory method which creates a message object based on the given data | ||||
* | * | ||||
* @param pData Data buffer | * @param pData Data buffer | ||||
* @param dataSize Size of data buffer | * @param dataSize Size of data buffer | ||||
* @param scriptInterface Script instance to use when constructing scripted messages | |||||
* @return The new message created | * @return The new message created | ||||
*/ | */ | ||||
static CNetMessage* CreateMessage(const void* pData, size_t dataSize, const ScriptInterface& scriptInterface); | static CNetMessage* CreateMessage(const void* pData, size_t dataSize); | ||||
}; | |||||
/** | |||||
* Special message type for simulation commands. | |||||
* These commands are exposed as arbitrary JS objects, associated with a specific player. | |||||
*/ | |||||
class CSimulationMessage : public CNetMessage | |||||
{ | |||||
public: | |||||
CSimulationMessage(const ScriptInterface& scriptInterface); | |||||
CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data); | |||||
/** The compiler can't create a copy constructor because of the PersistentRooted member, | |||||
* so we have to write it manually. | |||||
* NOTE: It doesn't clone the m_Data member and the copy will reference the same JS::Value! | |||||
*/ | |||||
CSimulationMessage(const CSimulationMessage& orig); | |||||
virtual u8* Serialize(u8* pBuffer) const; | |||||
virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); | |||||
virtual size_t GetSerializedLength() const; | |||||
virtual CStr ToString() const; | |||||
u32 m_Client; | |||||
i32 m_Player; | |||||
u32 m_Turn; | |||||
JS::PersistentRooted<JS::Value> m_Data; | |||||
private: | |||||
const ScriptInterface& m_ScriptInterface; | |||||
}; | |||||
/** | |||||
* Special message type for updated to game startup settings. | |||||
*/ | |||||
class CGameSetupMessage : public CNetMessage | |||||
{ | |||||
NONCOPYABLE(CGameSetupMessage); | |||||
public: | |||||
CGameSetupMessage(const ScriptInterface& scriptInterface); | |||||
CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data); | |||||
virtual u8* Serialize(u8* pBuffer) const; | |||||
virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); | |||||
virtual size_t GetSerializedLength() const; | |||||
virtual CStr ToString() const; | |||||
JS::PersistentRootedValue m_Data; | |||||
private: | |||||
const ScriptInterface& m_ScriptInterface; | |||||
}; | }; | ||||
// This time, the classes are created | // This time, the classes are created | ||||
#include "NetMessages.h" | #include "NetMessages.h" | ||||
#endif // NETMESSAGE_H | #endif // NETMESSAGE_H |
Wildfire Games · Phabricator