Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Client/game_sa/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
#include <string>
#include <vector>

// SDK includes
#include <ijsify.h>

// Game includes
#include "HookSystem.h"
#include "gamesa_init.h"
1 change: 0 additions & 1 deletion Client/multiplayer_sa/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

// SDK includes
#include <core/CCoreInterface.h>
#include <net/CNet.h>
#include <game/CGame.h>
#include <CMatrix_Pad.h>
#include <version.h>
Expand Down
5 changes: 2 additions & 3 deletions Server/mods/deathmatch/logic/packets/CConsoleEchoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
bool CConsoleEchoPacket::Write(NetBitStreamInterface& BitStream) const
{
// Not too short?
size_t sizeMessage = m_strMessage.length();
if (sizeMessage >= MIN_CONSOLEECHO_LENGTH)
if (m_strMessage.length() >= MIN_CONSOLEECHO_LENGTH)
{
// Write the string
BitStream.WriteStringCharacters(m_strMessage, sizeMessage);
BitStream.WriteStringCharacters(m_strMessage);
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions Server/mods/deathmatch/logic/packets/CDebugEchoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ bool CDebugEchoPacket::Write(NetBitStreamInterface& BitStream) const
}

// Too short?
size_t sizeMessage = m_strMessage.length();
if (sizeMessage >= MIN_DEBUGECHO_LENGTH)
if (m_strMessage.length() >= MIN_DEBUGECHO_LENGTH)
{
// Write the string
BitStream.WriteStringCharacters(m_strMessage, sizeMessage);
BitStream.WriteStringCharacters(m_strMessage);
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions Server/mods/deathmatch/logic/packets/CLuaEventPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ bool CLuaEventPacket::Read(NetBitStreamInterface& BitStream)

bool CLuaEventPacket::Write(NetBitStreamInterface& BitStream) const
{
unsigned short usNameLength = static_cast<unsigned short>(m_strName.length());
BitStream.WriteCompressed(usNameLength);
BitStream.WriteStringCharacters(m_strName, usNameLength);
BitStream.WriteCompressed(static_cast<unsigned short>(m_strName.length()));
BitStream.WriteStringCharacters(m_strName);
BitStream.Write(m_ElementID);
m_pArguments->WriteToBitStream(BitStream);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool CPlayerChangeNickPacket::Write(NetBitStreamInterface& BitStream) const
BitStream.Write(ID);

// Write the nick
BitStream.WriteStringCharacters(m_strNewNick, m_strNewNick.length());
BitStream.WriteStringCharacters(m_strNewNick);
return true;
}

Expand Down
63 changes: 38 additions & 25 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <alloca.h>
#endif

#ifdef __cpp_lib_string_view
#include <string_view>
#endif

struct ISyncStructure;
class NetBitStreamInterface;

Expand Down Expand Up @@ -196,15 +200,43 @@ class NetBitStreamInterfaceNoVersion : public CRefCountable
// Return true if enough bytes left in the bitstream
bool CanReadNumberOfBytes(int iLength) const { return iLength >= 0 && iLength <= (GetNumberOfUnreadBits() + 7) / 8; }

// Write characters from a std::string
void WriteStringCharacters(const std::string& value, uint uiLength)
// For whatever stupid reason sdk/net gets included in Multiplayer SA and Game SA
// And since those projects are c++14 we need this stuff.
// TODO: Rip sdk/net out of these projects...
#ifdef __cpp_lib_string_view
// Write characters in `value`
void WriteStringCharacters(std::string_view value)
{
dassert(uiLength <= value.length());
// Send the data
if (uiLength)
Write(&value.at(0), uiLength);
if (!value.empty())
Write(value.data(), (int)value.length());
}
// Write `n` characters from `value`
void WriteStringCharacters(std::string_view value, size_t n)
{
dassert(n <= value.length());
if (n)
Write(value.data(), (int)n);
}

// Write all characters in `value` (incl. length as `SizeType`)
template<typename SizeType = unsigned short>
void WriteString(std::string_view value)
{
// Write the length
Write(static_cast<SizeType>(value.length()));

// Write the characters
return WriteStringCharacters(value);
}

// Write a string (incl. variable size header)
void WriteStr(std::string_view value)
{
WriteLength(value.length());
return WriteStringCharacters(value, value.length());
}
#endif

// Read characters into a std::string
bool ReadStringCharacters(std::string& result, uint uiLength)
{
Expand All @@ -224,18 +256,6 @@ class NetBitStreamInterfaceNoVersion : public CRefCountable
return true;
}

// Write a string (incl. ushort size header)
template <typename SizeType = unsigned short>
void WriteString(const std::string& value)
{
// Write the length
auto length = static_cast<SizeType>(value.length());
Write(length);

// Write the characters
return WriteStringCharacters(value, length);
}

// Read a string (incl. ushort size header)
template <typename SizeType = unsigned short>
bool ReadString(std::string& result)
Expand Down Expand Up @@ -296,13 +316,6 @@ class NetBitStreamInterfaceNoVersion : public CRefCountable
return true;
}

// Write a string (incl. variable size header)
void WriteStr(const std::string& value)
{
WriteLength(value.length());
return WriteStringCharacters(value, value.length());
}

// Read a string (incl. variable size header)
bool ReadStr(std::string& result)
{
Expand Down