UserCmd strings: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 4: Line 4:
==Changes==
==Changes==
===UserCmd.cpp===
===UserCmd.cpp===
Note how WriteUsercmd only writes data if there is a non-standard delta (change). They can be called non-standard because of tick_count integer should have a standard incrementation of one, so it is a standard delta. Notice how the count is tested, the data is then sent, and all of the saved data is then purged. This means only delta data will be sent.
====WriteUsercmd====
====WriteUsercmd====
At the end:
At the end:
  byte count = g_pLocalPlayer->GetUserDataCount();
  byte count = g_pLocalPlayer->GetUserDataCount();
  if(g_pLocalPlayer&&count)
  if(count)
  {
  {
  buf->WriteOneBit( 1 );
  buf->WriteOneBit( 1 );

Revision as of 19:27, 21 June 2006

Warning.pngWarning:These changes are only theoretical and haven't been tested whatsoever.

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

Note how WriteUsercmd only writes data if there is a non-standard delta (change). They can be called non-standard because of tick_count integer should have a standard incrementation of one, so it is a standard delta. Notice how the count is tested, the data is then sent, and all of the saved data is then purged. This means only delta data will be sent.

WriteUsercmd

At the end:

	byte count = g_pLocalPlayer->GetUserDataCount();
	if(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_pUserData stores all of the data to send (The player should never have to send over 255 strings for 1 usercmd).
  • void AddUserData(const char *pNewData) adds data to send.
  • byte GetUserDataCount(void) returns m_pUserData.Count().
  • const char *GetUserData(byte index) returns m_pUserData.Element(index).
  • void ClearUserData(void) calls m_pUserData.PurgeAndDeleteElements(). See strdup 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.