mirror of
https://github.com/ENSL/NS.git
synced 2024-11-30 16:30:57 +00:00
b918c731aa
Rewrote WeaponsResource code so that uninitialized slots are no longer returned as valid weapons Removed upp_* from command constants and console commands Removed commented out entry from hl_baseentity.cpp Shift in map data position is now performed by the network layer instead of at the time of creation Deleted obsolete Util.vcproj Replaced calls to fmax with calls to max in AvHEntities.cpp (Win32 compiler wasn't finding fmax command without explicit include) Began implementation of client-to-server tunnel for Nexus git-svn-id: https://unknownworlds.svn.cloudforge.com/ns1@94 67975925-1194-0748-b3d5-c16f83f1a3a1
119 lines
No EOL
3.6 KiB
C++
119 lines
No EOL
3.6 KiB
C++
#include <NexusClientInterface.h>
|
|
#include "AvHNexusClient.h"
|
|
#include "AvHNexusTunnelToServer.h"
|
|
#include "cl_dll/hud.h"
|
|
#include "cl_dll/cl_util.h"
|
|
|
|
string BASE64Encode(const byte_string& input);
|
|
int __MsgFunc_NexusData(const char *pszName, int iSize, void *pbuf);
|
|
|
|
bool AvHNexus::send(const unsigned char* data, const size_t length)
|
|
{
|
|
byte_string raw_data(data,length);
|
|
|
|
string cmdline("NexusData ");
|
|
cmdline += BASE64Encode(raw_data);
|
|
cmdline += "\n";
|
|
|
|
//ugliness due to pfnClientCmd wanting a non-const ptr
|
|
char* ptr = new char[cmdline.length()+1];
|
|
strncpy(ptr,cmdline.c_str(),cmdline.length());
|
|
ptr[cmdline.length()] = '\0';
|
|
gEngfuncs.pfnClientCmd(ptr);
|
|
delete[] ptr;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool AvHNexus::recv(const unsigned char* data, const size_t length)
|
|
{
|
|
byte_string raw_data(data,length);
|
|
AvHNexus::TunnelToServer::getInstance()->insertMessage(raw_data);
|
|
return true;
|
|
}
|
|
|
|
void AvHNexus::startup(void)
|
|
{
|
|
gEngfuncs.pfnHookUserMsg("NexusBytes", __MsgFunc_NexusData);
|
|
// Nexus::setTunnelToServer(AvHNexus::TunnelToServer::getInstance());
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Incominng message handler
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
int __MsgFunc_NexusData(const char *pszName, int iSize, void *pbuf)
|
|
{
|
|
AvHNexus::recv((unsigned char*)pbuf, iSize);
|
|
return iSize;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// Base 64 encoder
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
char Base64EncodeTable[65] = {
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0- 7
|
|
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8-15
|
|
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', //16-23
|
|
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', //24-31
|
|
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', //32-39
|
|
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', //40-47
|
|
'w', 'x', 'y', 'z', '0', '1', '2', '3', //48-55
|
|
'4', '5', '6', '7', '8', '9', '+', '/', //56-63
|
|
'=' }; //64 = padding
|
|
|
|
//debugged and working properly... do not disturb.
|
|
string BASE64Encode(const byte_string& input)
|
|
{
|
|
string output;
|
|
const byte* data = input.c_str();
|
|
size_t length = input.length();
|
|
int value, value2;
|
|
|
|
//handle input in 3 byte blocks
|
|
while( length > 2 )
|
|
{
|
|
value = data[0]; value >>= 2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[0]; value2 = data[1];
|
|
value &= 0x03; value <<= 4;
|
|
value2 &= 0xF0; value2 >>= 4; value |= value2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[1]; value2 = data[2];
|
|
value &= 0x0F; value <<= 2;
|
|
value2 &= 0xC0; value2 >>= 6; value |= value2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[2]; value &= 0x3F;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
data += 3; length -= 3;
|
|
}
|
|
|
|
//handle remainder
|
|
switch(length)
|
|
{
|
|
case 0: //no remainder to process
|
|
break;
|
|
case 1: //process and pad with two =
|
|
value = data[0]; value >>= 2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[0]; value &= 0x03; value <<= 4;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
output.push_back(Base64EncodeTable[64]);
|
|
output.push_back(Base64EncodeTable[64]);
|
|
break;
|
|
case 2: //process and pad with one =
|
|
value = data[0]; value >>= 2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[0]; value2 = data[1];
|
|
value &= 0x03; value <<= 4;
|
|
value2 &= 0xF0; value2 >>= 4; value |= value2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
value = data[1]; value &= 0x0F; value <<= 2;
|
|
output.push_back(Base64EncodeTable[value]);
|
|
output.push_back(Base64EncodeTable[64]);
|
|
break;
|
|
}
|
|
|
|
return output;
|
|
} |