UserCmd strings: Difference between revisions
Jump to navigation
Jump to search
Warning:These changes are only theoretical and haven't been tested whatsoever.
mNo edit summary |
mNo edit summary |
||
| Line 25: | Line 25: | ||
} | } | ||
====ReadUsercmd==== | ====ReadUsercmd==== | ||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from<font color="green">, CBasePlayer *pPlayer</font> ) | void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from<font color="green">, CBasePlayer *pPlayer /*= NULL*/</font> ) | ||
At the end: | At the end: | ||
if( buf->ReadOneBit() ) | if( buf->ReadOneBit() ) | ||
| Line 38: | Line 38: | ||
Assert(!bOverflow); | Assert(!bOverflow); | ||
#ifndef CLIENT_DLL | #ifndef CLIENT_DLL | ||
Assert(pPlayer); | |||
pPlayer->EvaluateUserData(cmd); | pPlayer->EvaluateUserData(cmd); | ||
#endif | #endif | ||
| Line 46: | Line 47: | ||
#include "baseplayer_shared.h" | #include "baseplayer_shared.h" | ||
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from<font color="green">, CBasePlayer *pPlayer | void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from<font color="green">, CBasePlayer *pPlayer = NULL</font> ); | ||
= | |||
====Changes to gameinterface.cpp==== | ====Changes to gameinterface.cpp==== | ||
ReadUsercmd( buf, to, from<font color="green">, pPlayer</font> ); | ReadUsercmd( buf, to, from<font color="green">, pPlayer</font> ); | ||
Revision as of 18:13, 17 June 2006
Introduction
This modification allows a mod to send messages from the client to the server without using commands. This allows for a more secure method of communication from the client to the server. A possible implementation would be with VGUI Screens.
Changes
UserCmd.cpp
WriteUsercmd
At the end:
byte count = g_pLocalPlayer->GetUserDataCount();
if(g_pLocalPlayer&&count)
{
buf->WriteOneBit( 1 );
buf->WriteByte(count);
for(byte x=0;x<count;x++)
{
buf->WriteString(g_pLocalPlayer->GetUserData(x));
}
g_pLocalPlayer->ClearUserData();
}
else
{
buf->WriteOneBit( 0 );
}
ReadUsercmd
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBasePlayer *pPlayer /*= NULL*/ )
At the end:
if( buf->ReadOneBit() )
{
int count = buf->ReadByte();
for(int x=0;x<count;x++)
{
#ifdef DEBUG
bool bOverflow = false;
#endif
char *cmd = buf->ReadAndAllocateString(&bOverflow);
Assert(!bOverflow);
#ifndef CLIENT_DLL
Assert(pPlayer);
pPlayer->EvaluateUserData(cmd);
#endif
delete cmd;
}
}
UserCmd.h
#include "baseplayer_shared.h"
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBasePlayer *pPlayer = NULL );
Changes to gameinterface.cpp
ReadUsercmd( buf, to, from, pPlayer );
Implementation
C_BasePlayer
CUtlLinkedList<const char *, byte> m_pUserDatastores all of the data to send.void AddUserData(const char *pNewData)adds data to send.byte GetUserDataCount(void)returnsm_pUserData.Count().const char *GetUserData(byte index)returnsm_pUserData.Element(index).void ClearUserData(void)callsm_pUserData.PurgeAndDeleteElements(). See CloneString to make sure you don't accidentally get any null pointers.
CBasePlayer
void EvaluateUserData(const char *pData)evaluates what to do with the command stored in pData.