UserCmd strings: Difference between revisions
Jump to navigation
Jump to search
Warning:These changes are only theoretical and haven't been tested whatsoever.
m (→UserCmd.cpp) |
m (char*ful) |
||
Line 9: | Line 9: | ||
{ | { | ||
buf->WriteOneBit( 1 ); | buf->WriteOneBit( 1 ); | ||
int count = g_pLocalPlayer->GetUserDataCount(); | |||
const char *pData; | |||
buf->WriteByte(count); | |||
int | for(int x=0;x<count;x++) | ||
buf-> | { | ||
buf->WriteString(g_pLocalPlayer->GetUserData(x)); | |||
} | |||
g_pLocalPlayer->ClearUserData(); | g_pLocalPlayer->ClearUserData(); | ||
} | } | ||
Line 26: | Line 27: | ||
if( buf->ReadOneBit() ) | if( buf->ReadOneBit() ) | ||
{ | { | ||
int count = buf-> | int count = buf->ReadByte(); | ||
for(int x=0;x<count;x++) | |||
buf-> | { | ||
char *cmd = buf->ReadAndAllocateString(); | |||
#ifndef CLIENT_DLL | #ifndef CLIENT_DLL | ||
pPlayer->EvaluateUserData(cmd); | |||
#endif | #endif | ||
delete cmd; | |||
} | |||
} | } | ||
====UserCmd.h==== | ====UserCmd.h==== | ||
Line 44: | Line 48: | ||
==Implementation== | ==Implementation== | ||
===Client=== | ===Client=== | ||
*<code> | *<code>int GetUserDataCount(void)</code> returns the number of data strings stored in a char array stored on the player. | ||
*<code>void ClearUserData(void)</code> clears the client-side | *<code>const char *GetUserData(int index)</code> returns the data stored in the array of user data stored on the player. | ||
*<code>void ClearUserData(void)</code> clears the client-side char*[] and sets the boolean so they don't get sent twice. | |||
*<code>bool UserDataChanged(void)</code> returns the boolean modified by ClearUserData. | *<code>bool UserDataChanged(void)</code> returns the boolean modified by ClearUserData. | ||
===Server=== | ===Server=== | ||
*<code>void EvaluateUserData(const char *pData)</code> | *<code>void EvaluateUserData(const char *pData)</code> evaluates what to do with the commands stored in pData. | ||
[[Category:Programming]][[Category:Tutorials]] | [[Category:Programming]][[Category:Tutorials]] |
Revision as of 17:07, 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:
if(g_pLocalPlayer&&g_pLocalPlayer->UserDataChanged()) { buf->WriteOneBit( 1 ); int count = g_pLocalPlayer->GetUserDataCount(); const char *pData; buf->WriteByte(count); for(int 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 )
At the end:
if( buf->ReadOneBit() ) { int count = buf->ReadByte(); for(int x=0;x<count;x++) { char *cmd = buf->ReadAndAllocateString(); #ifndef CLIENT_DLL pPlayer->EvaluateUserData(cmd); #endif delete cmd; } }
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
int GetUserDataCount(void)
returns the number of data strings stored in a char array stored on the player.const char *GetUserData(int index)
returns the data stored in the array of user data stored on the player.void ClearUserData(void)
clears the client-side char*[] 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)
evaluates what to do with the commands stored in pData.