UserCmd strings: Difference between revisions
Jump to navigation
Jump to search
Warning:These changes are only theoretical and haven't been tested whatsoever.
No edit summary |
m (→UserCmd.cpp) |
||
| Line 5: | Line 5: | ||
===UserCmd.cpp=== | ===UserCmd.cpp=== | ||
====WriteUsercmd==== | ====WriteUsercmd==== | ||
At the end: | |||
if(g_pLocalPlayer&&g_pLocalPlayer->UserDataChanged()) | if(g_pLocalPlayer&&g_pLocalPlayer->UserDataChanged()) | ||
{ | { | ||
| Line 22: | Line 23: | ||
====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</font> ) | ||
At the end: | |||
if( buf->ReadOneBit() ) | if( buf->ReadOneBit() ) | ||
{ | { | ||
| Line 40: | Line 41: | ||
====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> ); | ||
==Implementation== | ==Implementation== | ||
===Client=== | ===Client=== | ||
Revision as of 22:37, 16 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:
if(g_pLocalPlayer&&g_pLocalPlayer->UserDataChanged())
{
buf->WriteOneBit( 1 );
KeyValues *data = g_pLocalPlayer->GetUserData();
CUtlBuffer databuf;
data->WriteAsBinary(databuf);
int len = strlen(static_cast<char*>(databuf.Base()));
buf->WriteShort(len);
buf->WriteBits(databuf, len);
g_pLocalPlayer->ClearUserData();
}
else
{
buf->WriteOneBit( 0 );
}
ReadUsercmd
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBasePlayer *pPlayer )
At the end:
if( buf->ReadOneBit() )
{
int count = buf->ReadShort();
char data[count+1];
buf->ReadBytes(data,count);
#ifndef CLIENT_DLL
pPlayer->EvaluateUserData(data);
#endif
}
UserCmd.h
#include "baseplayer_shared.h"
void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from, CBasePlayer *pPlayer );
in_main.cpp
ReadUsercmd( buf, to, from, NULL );
Changes to gameinterface.cpp
ReadUsercmd( buf, to, from, pPlayer );
Implementation
Client
KeyValues *GetUserData(void)returns the KeyValues data stored on the player.void ClearUserData(void)clears the client-side KeyValues and sets the boolean so they don't get sent twice.bool UserDataChanged(void)returns the boolean modified by ClearUserData.
Server
void EvaluateUserData(const char *pData)reads pData to a KeyValues and evaluates what to do with the commands stored within them.