mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 19:45:23 -04:00
Merge pull request #908 from SpiralP/add-cpe-plugin-message
Add new CPE type PluginMessage
This commit is contained in:
commit
b2b6273aa7
32
src/Event.c
32
src/Event.c
@ -1,18 +1,19 @@
|
||||
#include "Event.h"
|
||||
#include "Logger.h"
|
||||
|
||||
struct _EntityEventsList EntityEvents;
|
||||
struct _TabListEventsList TabListEvents;
|
||||
struct _TextureEventsList TextureEvents;
|
||||
struct _GfxEventsList GfxEvents;
|
||||
struct _UserEventsList UserEvents;
|
||||
struct _BlockEventsList BlockEvents;
|
||||
struct _WorldEventsList WorldEvents;
|
||||
struct _ChatEventsList ChatEvents;
|
||||
struct _WindowEventsList WindowEvents;
|
||||
struct _InputEventsList InputEvents;
|
||||
struct _PointerEventsList PointerEvents;
|
||||
struct _NetEventsList NetEvents;
|
||||
struct _EntityEventsList EntityEvents;
|
||||
struct _TabListEventsList TabListEvents;
|
||||
struct _TextureEventsList TextureEvents;
|
||||
struct _GfxEventsList GfxEvents;
|
||||
struct _UserEventsList UserEvents;
|
||||
struct _BlockEventsList BlockEvents;
|
||||
struct _WorldEventsList WorldEvents;
|
||||
struct _ChatEventsList ChatEvents;
|
||||
struct _WindowEventsList WindowEvents;
|
||||
struct _InputEventsList InputEvents;
|
||||
struct _PointerEventsList PointerEvents;
|
||||
struct _NetEventsList NetEvents;
|
||||
struct _PluginMessageEventsList PluginMessageEvents;
|
||||
|
||||
void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
|
||||
int i;
|
||||
@ -170,3 +171,10 @@ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDel
|
||||
handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta);
|
||||
}
|
||||
}
|
||||
|
||||
void Event_RaisePluginMessage(struct Event_PluginMessage* handlers, cc_uint8 channel, cc_uint8* data) {
|
||||
int i;
|
||||
for (i = 0; i < handlers->Count; i++) {
|
||||
handlers->Handlers[i](handlers->Objs[i], channel, data);
|
||||
}
|
||||
}
|
||||
|
13
src/Event.h
13
src/Event.h
@ -63,6 +63,13 @@ struct Event_RawMove {
|
||||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||
};
|
||||
|
||||
/* "data" will be 64 bytes in length. */
|
||||
typedef void (*Event_PluginMessage_Callback)(void* obj, cc_uint8 channel, cc_uint8* data);
|
||||
struct Event_PluginMessage {
|
||||
Event_PluginMessage_Callback Handlers[EVENT_MAX_CALLBACKS];
|
||||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||
};
|
||||
|
||||
/* Registers a callback function for the given event. */
|
||||
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
||||
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||
@ -94,6 +101,8 @@ void Event_RaiseInput(struct Event_Input* handlers, int key, cc_bool repeating);
|
||||
void Event_RaiseString(struct Event_String* handlers, const cc_string* str);
|
||||
/* Calls all registered callbacks for an event which has raw pointer movement arguments. */
|
||||
void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDelta);
|
||||
/* Calls all registered callbacks for an event which has a channel and a 64 byte data argument. */
|
||||
void Event_RaisePluginMessage(struct Event_PluginMessage* handlers, cc_uint8 channel, cc_uint8* data);
|
||||
|
||||
void Event_UnregisterAll(void);
|
||||
/* NOTE: Event_UnregisterAll must be updated if events lists are changed */
|
||||
@ -177,4 +186,8 @@ CC_VAR extern struct _NetEventsList {
|
||||
struct Event_Void Connected; /* Connection to a server was established. */
|
||||
struct Event_Void Disconnected; /* Connection to the server was lost. */
|
||||
} NetEvents;
|
||||
|
||||
CC_VAR extern struct _PluginMessageEventsList {
|
||||
struct Event_PluginMessage Received; /* Received a PluginMessage from the server. */
|
||||
} PluginMessageEvents;
|
||||
#endif
|
||||
|
@ -63,7 +63,7 @@ cc_bool cpe_needD3Fix;
|
||||
static int cpe_serverExtensionsCount, cpe_pingTicks;
|
||||
static int cpe_envMapVer = 2, cpe_blockDefsExtVer = 2, cpe_customModelsVer = 2;
|
||||
static cc_bool cpe_sendHeldBlock, cpe_useMessageTypes, cpe_extEntityPos, cpe_blockPerms, cpe_fastMap;
|
||||
static cc_bool cpe_twoWayPing, cpe_extTextures, cpe_extBlocks;
|
||||
static cc_bool cpe_twoWayPing, cpe_pluginMessages, cpe_extTextures, cpe_extBlocks;
|
||||
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------Common handlers-----------------------------------------------------*
|
||||
@ -758,7 +758,7 @@ static const char* cpe_clientExtensions[] = {
|
||||
"EnvWeatherType", "MessageTypes", "HackControl", "PlayerClick", "FullCP437", "LongerMessages",
|
||||
"BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors", "EnvMapAspect",
|
||||
"EntityProperty", "ExtEntityPositions", "TwoWayPing", "InventoryOrder", "InstantMOTD", "FastMap", "SetHotbar",
|
||||
"SetSpawnpoint", "VelocityControl", "CustomParticles", "CustomModels",
|
||||
"SetSpawnpoint", "VelocityControl", "CustomParticles", "CustomModels", "PluginMessages",
|
||||
/* NOTE: These must be placed last for when EXTENDED_TEXTURES or EXTENDED_BLOCKS are not defined */
|
||||
"ExtendedTextures", "ExtendedBlocks"
|
||||
};
|
||||
@ -795,6 +795,19 @@ void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct
|
||||
Server.SendData(data, 15);
|
||||
}
|
||||
|
||||
void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data) {
|
||||
cc_uint8 buffer[66];
|
||||
|
||||
if (!cpe_pluginMessages) return;
|
||||
|
||||
buffer[0] = OPCODE_PLUGIN_MESSAGE;
|
||||
{
|
||||
buffer[1] = channel;
|
||||
Mem_Copy(buffer + 2, data, 64);
|
||||
}
|
||||
Server.SendData(buffer, 66);
|
||||
}
|
||||
|
||||
static void CPE_SendExtInfo(int extsCount) {
|
||||
cc_uint8 data[67];
|
||||
data[0] = OPCODE_EXT_INFO;
|
||||
@ -932,6 +945,8 @@ static void CPE_ExtEntry(cc_uint8* data) {
|
||||
if (version == 2) {
|
||||
Protocol.Sizes[OPCODE_DEFINE_MODEL_PART] = 167;
|
||||
}
|
||||
} else if (String_CaselessEqualsConst(&ext, "PluginMessages")) {
|
||||
cpe_pluginMessages = true;
|
||||
}
|
||||
#ifdef EXTENDED_TEXTURES
|
||||
else if (String_CaselessEqualsConst(&ext, "ExtendedTextures")) {
|
||||
@ -1530,13 +1545,18 @@ static void CPE_UndefineModel(cc_uint8* data) {
|
||||
if (id < MAX_CUSTOM_MODELS) CustomModel_Undefine(&custom_models[id]);
|
||||
}
|
||||
|
||||
static void CPE_PluginMessage(cc_uint8* data) {
|
||||
cc_uint8 channel = data[0];
|
||||
Event_RaisePluginMessage(&PluginMessageEvents.Received, channel, data + 1);
|
||||
}
|
||||
|
||||
static void CPE_Reset(void) {
|
||||
cpe_serverExtensionsCount = 0; cpe_pingTicks = 0;
|
||||
cpe_sendHeldBlock = false; cpe_useMessageTypes = false;
|
||||
cpe_envMapVer = 2; cpe_blockDefsExtVer = 2; cpe_customModelsVer = 2;
|
||||
cpe_needD3Fix = false; cpe_extEntityPos = false; cpe_twoWayPing = false;
|
||||
cpe_extTextures = false; cpe_fastMap = false; cpe_extBlocks = false;
|
||||
Game_UseCPEBlocks = false; cpe_blockPerms = false;
|
||||
cpe_pluginMessages = false; cpe_extTextures = false; cpe_fastMap = false;
|
||||
cpe_extBlocks = false; Game_UseCPEBlocks = false; cpe_blockPerms = false;
|
||||
if (!Game_UseCPE) return;
|
||||
|
||||
Net_Set(OPCODE_EXT_INFO, CPE_ExtInfo, 67);
|
||||
@ -1575,6 +1595,7 @@ static void CPE_Reset(void) {
|
||||
Net_Set(OPCODE_DEFINE_MODEL, CPE_DefineModel, 116);
|
||||
Net_Set(OPCODE_DEFINE_MODEL_PART, CPE_DefineModelPart, 104);
|
||||
Net_Set(OPCODE_UNDEFINE_MODEL, CPE_UndefineModel, 2);
|
||||
Net_Set(OPCODE_PLUGIN_MESSAGE, CPE_PluginMessage, 66);
|
||||
}
|
||||
|
||||
static void CPE_Tick(void) {
|
||||
|
@ -35,6 +35,7 @@ enum OPCODE_ {
|
||||
OPCODE_SET_SPAWNPOINT, OPCODE_VELOCITY_CONTROL,
|
||||
OPCODE_DEFINE_EFFECT, OPCODE_SPAWN_EFFECT,
|
||||
OPCODE_DEFINE_MODEL, OPCODE_DEFINE_MODEL_PART, OPCODE_UNDEFINE_MODEL,
|
||||
OPCODE_PLUGIN_MESSAGE,
|
||||
|
||||
OPCODE_COUNT
|
||||
};
|
||||
@ -63,4 +64,7 @@ void Classic_WritePosition(Vec3 pos, float yaw, float pitch);
|
||||
void Classic_WriteSetBlock(int x, int y, int z, cc_bool place, BlockID block);
|
||||
void Classic_SendLogin(void);
|
||||
void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct RayTracer* t);
|
||||
|
||||
/* Send a PluginMessage to the server; data must contain 64 bytes. */
|
||||
CC_API void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user