Added a way to tell apart console-executed events from code-executed SendNetworkEvent

This commit is contained in:
ZZYZX 2017-03-06 11:25:30 +02:00 committed by Christoph Oelckers
parent f4b0435e66
commit 21ecd714ec
4 changed files with 24 additions and 12 deletions

View file

@ -2676,7 +2676,8 @@ void Net_DoCommand (int type, BYTE **stream, int player)
int arg[3] = { 0, 0, 0 }; int arg[3] = { 0, 0, 0 };
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
arg[i] = ReadLong(stream); arg[i] = ReadLong(stream);
E_Console(player, s, arg[0], arg[1], arg[2]); bool manual = ReadByte(stream);
E_Console(player, s, arg[0], arg[1], arg[2], manual);
} }
break; break;
@ -2727,7 +2728,7 @@ void Net_SkipCommand (int type, BYTE **stream)
break; break;
case DEM_NETEVENT: case DEM_NETEVENT:
skip = strlen((char *)(*stream)) + 14; skip = strlen((char *)(*stream)) + 15;
break; break;
case DEM_SUMMON2: case DEM_SUMMON2:

View file

@ -117,7 +117,7 @@ bool E_UnregisterHandler(DStaticEventHandler* handler)
return true; return true;
} }
bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3) bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual)
{ {
if (gamestate != GS_LEVEL) if (gamestate != GS_LEVEL)
return false; return false;
@ -128,6 +128,7 @@ bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3)
Net_WriteLong(arg1); Net_WriteLong(arg1);
Net_WriteLong(arg2); Net_WriteLong(arg2);
Net_WriteLong(arg3); Net_WriteLong(arg3);
Net_WriteByte(manual);
return true; return true;
} }
@ -433,10 +434,10 @@ bool E_Responder(event_t* ev)
return false; return false;
} }
void E_Console(int player, FString name, int arg1, int arg2, int arg3) void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manual)
{ {
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
handler->ConsoleProcess(player, name, arg1, arg2, arg3); handler->ConsoleProcess(player, name, arg1, arg2, arg3, manual);
} }
bool E_CheckUiProcessors() bool E_CheckUiProcessors()
@ -523,6 +524,7 @@ DEFINE_FIELD_X(InputEvent, DInputEvent, MouseY);
DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Player) DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Player)
DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Name) DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Name)
DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Args) DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, Args)
DEFINE_FIELD_X(ConsoleEvent, DConsoleEvent, IsManual)
DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder) DEFINE_ACTION_FUNCTION(DStaticEventHandler, SetOrder)
{ {
@ -545,7 +547,7 @@ DEFINE_ACTION_FUNCTION(DEventHandler, SendNetworkEvent)
PARAM_INT(arg3); PARAM_INT(arg3);
// //
ACTION_RETURN_BOOL(E_SendNetworkEvent(name, arg1, arg2, arg3)); ACTION_RETURN_BOOL(E_SendNetworkEvent(name, arg1, arg2, arg3, false));
} }
DEFINE_ACTION_FUNCTION(DEventHandler, Create) DEFINE_ACTION_FUNCTION(DEventHandler, Create)
@ -1091,10 +1093,11 @@ static DConsoleEvent* E_SetupConsoleEvent()
e->Name = ""; e->Name = "";
for (size_t i = 0; i < countof(e->Args); i++) for (size_t i = 0; i < countof(e->Args); i++)
e->Args[i] = 0; e->Args[i] = 0;
e->IsManual = false;
return e; return e;
} }
void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3) void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual)
{ {
if (player < 0) if (player < 0)
{ {
@ -1111,6 +1114,7 @@ void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int
e->Args[0] = arg1; e->Args[0] = arg1;
e->Args[1] = arg2; e->Args[1] = arg2;
e->Args[2] = arg3; e->Args[2] = arg3;
e->IsManual = manual;
VMValue params[2] = { (DStaticEventHandler*)this, e }; VMValue params[2] = { (DStaticEventHandler*)this, e };
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr); GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
@ -1131,6 +1135,7 @@ void DStaticEventHandler::ConsoleProcess(int player, FString name, int arg1, int
e->Args[0] = arg1; e->Args[0] = arg1;
e->Args[1] = arg2; e->Args[1] = arg2;
e->Args[2] = arg3; e->Args[2] = arg3;
e->IsManual = manual;
VMValue params[2] = { (DStaticEventHandler*)this, e }; VMValue params[2] = { (DStaticEventHandler*)this, e };
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr); GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
@ -1162,7 +1167,7 @@ CCMD(event)
for (int i = 0; i < argn; i++) for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]); arg[i] = atoi(argv[2 + i]);
// call locally // call locally
E_Console(-1, argv[1], arg[0], arg[1], arg[2]); E_Console(-1, argv[1], arg[0], arg[1], arg[2], true);
} }
} }
@ -1187,6 +1192,6 @@ CCMD(netevent)
for (int i = 0; i < argn; i++) for (int i = 0; i < argn; i++)
arg[i] = atoi(argv[2 + i]); arg[i] = atoi(argv[2 + i]);
// call networked // call networked
E_SendNetworkEvent(argv[1], arg[0], arg[1], arg[2]); E_SendNetworkEvent(argv[1], arg[0], arg[1], arg[2], true);
} }
} }

View file

@ -58,10 +58,10 @@ void E_PlayerDisconnected(int num);
// this executes on events. // this executes on events.
bool E_Responder(event_t* ev); // splits events into InputProcess and UiProcess bool E_Responder(event_t* ev); // splits events into InputProcess and UiProcess
// this executes on console/net events. // this executes on console/net events.
void E_Console(int player, FString name, int arg1, int arg2, int arg3); void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manual);
// send networked event. unified function. // send networked event. unified function.
bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3); bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual);
// check if there is anything that should receive GUI events // check if there is anything that should receive GUI events
bool E_CheckUiProcessors(); bool E_CheckUiProcessors();
@ -152,7 +152,7 @@ public:
bool UiProcess(event_t* ev); bool UiProcess(event_t* ev);
// //
void ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3); void ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual);
}; };
class DEventHandler : public DStaticEventHandler class DEventHandler : public DStaticEventHandler
{ {
@ -300,10 +300,13 @@ public:
// //
FString Name; FString Name;
int Args[3]; int Args[3];
//
bool IsManual;
DConsoleEvent() DConsoleEvent()
{ {
Player = -1; Player = -1;
IsManual = false;
} }
}; };

View file

@ -275,8 +275,11 @@ class ConsoleEvent : BaseEvent native version("2.4")
// for net events, this will be the activator. // for net events, this will be the activator.
// for UI events, this is always -1, and you need to check if level is loaded and use players[consoleplayer]. // for UI events, this is always -1, and you need to check if level is loaded and use players[consoleplayer].
native readonly int Player; native readonly int Player;
// this is the name and args as specified in SendNetworkEvent or event/netevent CCMDs
native readonly String Name; native readonly String Name;
native readonly int Args[3]; native readonly int Args[3];
// this will be true if the event is fired from the console by event/netevent CCMD
native readonly bool IsManual;
} }
class StaticEventHandler : Object native play version("2.4") class StaticEventHandler : Object native play version("2.4")