Skip to content

Commit

Permalink
Implemented point entities: point_clientcommand, point_servercommand
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Apr 7, 2019
1 parent 45fbb04 commit eed7b19
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
90 changes: 90 additions & 0 deletions regamedll/dlls/addons/point_command.cpp
@@ -0,0 +1,90 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#include "precompiled.h"

void CPointBaseCommand::KeyValue(KeyValueData *pkvd)
{
// add this field to the command list
if (m_uiCommandsCount < MAX_POINT_CMDS)
{
char command[128];
if (pkvd->szValue[0] != '\0' && Q_strcmp(pkvd->szValue, "-") != 0)
{
Q_snprintf(command, sizeof(command), "%s \"%s\"", pkvd->szKeyName, pkvd->szValue);
}
else
{
Q_strlcpy(command, pkvd->szKeyName);
}

m_iszCommands[m_uiCommandsCount++] = ALLOC_STRING(command);
pkvd->fHandled = TRUE;
return;
}

CPointEntity::KeyValue(pkvd);
}

LINK_ENTITY_TO_CLASS(point_clientcommand, CPointClientCommand, CCSPointClientCommand)

void CPointClientCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
edict_t *pClient = nullptr;
if (gpGlobals->maxClients == 1)
{
pClient = INDEXENT(1);
}
else if (pActivator &&
pActivator->IsPlayer() &&
pActivator->IsNetClient() &&
!pActivator->IsDormant())
{
// In multiplayer, send it back to the activator
pClient = pActivator->edict();
}

if (pClient)
{
for (size_t cmd = 0; cmd < m_uiCommandsCount; cmd++) {
CLIENT_COMMAND(pClient, UTIL_VarArgs("%s\n", m_iszCommands[cmd].str()));
}
}
}

LINK_ENTITY_TO_CLASS(point_servercommand, CPointServerCommand, CCSPointServerCommand)

void CPointServerCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
for (size_t cmd = 0; cmd < m_uiCommandsCount; cmd++) {
Execute(m_iszCommands[cmd]);
}
}

void CPointServerCommand::Execute(const char *command)
{
if (!IS_DEDICATED_SERVER())
{
// potentially dangerous for untrusted maps
// so try to use it for passing through filtered svc_stufftext
CLIENT_COMMAND(INDEXENT(1), UTIL_VarArgs("%s\n", command));
return;
}

SERVER_COMMAND(UTIL_VarArgs("%s\n", command));
}
49 changes: 49 additions & 0 deletions regamedll/dlls/addons/point_command.h
@@ -0,0 +1,49 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#pragma once

const int MAX_POINT_CMDS = 16; // maximum number of commands a single point_[server/client]command entity may be assigned

class CPointBaseCommand: public CPointEntity {
public:
virtual void KeyValue(KeyValueData *pkvd);
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0;

protected:
size_t m_uiCommandsCount;
string_t m_iszCommands[MAX_POINT_CMDS];
};

// It issues commands to the client console
class CPointClientCommand: public CPointBaseCommand {
public:
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);

private:
void Execute(edict_t *pEdict, const char *command);
};

// It issues commands to the server console
class CPointServerCommand: public CPointBaseCommand {
public:
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);

private:
void Execute(const char *command);
};
12 changes: 12 additions & 0 deletions regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
Expand Up @@ -3026,3 +3026,15 @@
sprite_scale(string) : "Sprite scale" : "1.0"
sprite_framerate(string) : "Sprite framerate" : "10"
]

@BaseClass base(Targetname) = BaseCommand
[
]

@PointClass base(BaseCommand) size(-8 -8 -8, 8 8 8) = point_servercommand : "It issues commands to the server console"
[
]

@PointClass base(BaseCommand) size(-8 -8 -8, 8 8 8) = point_clientcommand : "It issues commands to the client console"
[
]
2 changes: 2 additions & 0 deletions regamedll/msvc/ReGameDLL.vcxproj
Expand Up @@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\dlls\addons\item_airbox.cpp" />
<ClCompile Include="..\dlls\addons\point_command.cpp" />
<ClCompile Include="..\dlls\addons\trigger_random.cpp" />
<ClCompile Include="..\dlls\addons\trigger_setorigin.cpp" />
<ClCompile Include="..\dlls\airtank.cpp" />
Expand Down Expand Up @@ -602,6 +603,7 @@
<ClInclude Include="..\common\winsani_out.h" />
<ClInclude Include="..\dlls\activity.h" />
<ClInclude Include="..\dlls\addons\item_airbox.h" />
<ClInclude Include="..\dlls\addons\point_command.h" />
<ClInclude Include="..\dlls\addons\trigger_random.h" />
<ClInclude Include="..\dlls\addons\trigger_setorigin.h" />
<ClInclude Include="..\dlls\airtank.h" />
Expand Down
6 changes: 6 additions & 0 deletions regamedll/msvc/ReGameDLL.vcxproj.filters
Expand Up @@ -553,6 +553,9 @@
<ClCompile Include="..\dlls\addons\trigger_random.cpp">
<Filter>dlls\addons</Filter>
</ClCompile>
<ClCompile Include="..\dlls\addons\point_command.cpp">
<Filter>dlls\addons</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\version\version.h">
Expand Down Expand Up @@ -1047,6 +1050,9 @@
<ClInclude Include="..\dlls\addons\trigger_random.h">
<Filter>dlls\addons</Filter>
</ClInclude>
<ClInclude Include="..\dlls\addons\point_command.h">
<Filter>dlls\addons</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\linux\appversion.sh">
Expand Down
3 changes: 3 additions & 0 deletions regamedll/public/regamedll/API/CSInterfaces.h
Expand Up @@ -228,3 +228,6 @@ class CCSClientFog: public CCSEntity {};
class CCSTriggerSetOrigin: public CCSDelay {};
class CCSTriggerRandom: public CCSDelay {};
class CCSItemAirBox: public CCSArmoury {};
class CCSPointBaseCommand: public CCSPointEntity {};
class CCSPointClientCommand: public CCSPointBaseCommand {};
class CCSPointServerCommand: public CCSPointBaseCommand {};
1 change: 1 addition & 0 deletions regamedll/regamedll/dlls.h
Expand Up @@ -133,6 +133,7 @@ using FloatRef = float;
#include "addons/item_airbox.h"
#include "addons/trigger_setorigin.h"
#include "addons/trigger_random.h"
#include "addons/point_command.h"

// Tutor
#include "tutor.h"
Expand Down

1 comment on commit eed7b19

@afwn90cj93201nixr2e1re
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain ;)

Please sign in to comment.