Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented point entities: point_clientcommand, point_servercommand
- Loading branch information
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eed7b19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain ;)