wc3fakeserver
Här kommer lite kod jag skrev ikväll för att fejka en massa wc3 servrar. Vad skall man ha det till? Tja, jävlas med polare kanske Ett av matricks små party-trick som gör dig till centrumet på LAN:et Enjoy.
/*******************************************************************************
wc3fakeserver
This will emulate a series of wc3 servers. Made for windows and compiles under
msvc++ 2003.
********************************************************************************
Copyright (c) 2003 Klas Magnus Auvinen
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*******************************************************************************/
//
// Includes
//
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "ws2_32.lib")
//
// Packets
//
unsigned char game_discover_packet[] = {0xf7,0x2f,0x10,0x00,0x50,0x58,0x33,0x57,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char game_response_packet[]={0xf7,
0x30,0x86,0x00,0x50,0x58,0x33,0x57,0x14,0x00,0x00,
0x00,0x01,0x00,0x00,0x00,0x04,0x74,0xe7,0x03,
// message bytes
0x4c,
0x6f,0x63,0x61,0x6c,0x20,0x47,0x61,0x6d,0x65,0x20,
0x28,0x6a,0x6f,0x69,0x6e,0x61,0x2d,0x69,0x6e,0x74,
0x65,0x29,
0x00,0x00,0x01,0x03,0x49,0x07,0x01,0x01,
0x55,0x01,0x81,0x55,0x01,0xff,0x37,0x7f,0x5d,0x4d,
0xcb,0x61,0x71,0x73,0x5d,0x45,0x6f,0x77,0x19,0x6f,
0x6d,0x6f,0x61,0x65,0x5d,0x55,0x6f,0x6f,0x77,0x65,
0x73,0x57,0x61,0x73,0xa7,0x73,0x5f,0x33,0x2f,0x31,
0x2f,0x77,0x63,0x33,0x79,0x01,0x6b,0x6f,0x69,0x6f,
0x4f,0x61,0x2d,0x69,0x6f,0x75,0x65,0x01,0x01,0x01,
0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,
0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x1d,0x16,0x00,
0x00,0xe0,0x17};
const int msglength = 23;
const int msgoffset = 20;
// sockets and message
const int numsockets = 10;
const char *messages[10] = {
"*********************",
"the message goes here",
"limited to 23 per row",
"this could be fixed",
"but i'm lazy and it's",
"late right now. take",
"care and don't abuse",
"this to ruin for",
"others.",
"/matricks : )"
};
//
//
//
int main()
{
SOCKET sockets[numsockets];
// Init winsock
WSADATA wsd;
WSAStartup(MAKEWORD(2,1), &wsd);
for(int i = 0; i < numsockets; i++)
{
// create socket
if((sockets[i] = socket(AF_INET, SOCK_DGRAM, 0)) == SOCKET_ERROR)
{
printf("ERR: socket() failed\n");
return 1;
}
// bind socket
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr));
addr.sin_addr.S_un.S_addr = ADDR_ANY;
addr.sin_port = htons(6112+i);
addr.sin_family = AF_INET;
if(bind(sockets[i], (sockaddr*)&addr, sizeof(addr)) != 0)
{
printf("ERR: bind() failed\n");
return 1;
}
// non-blocking and broadcast
unsigned long mode = 1;
ioctlsocket(sockets[i], FIONBIO, &mode);
setsockopt(sockets[i], SOL_SOCKET, SO_BROADCAST, (const char*)&mode, sizeof(mode));
}
//
while(1)
{
for(int i = 0; i < 100; i++)
{
Sleep(10);
// pump for packets
while(1)
{
// recvice data
char recvbuf[1024*4];
sockaddr_in from;
memset(&from, 0, sizeof(from));
int formsize = sizeof(from);
int numbytes = recvfrom(sockets[0], recvbuf, sizeof(recvbuf), 0, (sockaddr*)&from, &formsize);
//
if(numbytes <= 0)
break;
// check for discover packet
if(numbytes == sizeof(game_discover_packet) && memcmp(game_discover_packet, recvbuf, numbytes) == 0)
{
//
printf("INFO: %d.%d.%d.%d broadcasting for game, responding\n", from.sin_addr.S_un.S_un_b.s_b1,
from.sin_addr.S_un.S_un_b.s_b2, from.sin_addr.S_un.S_un_b.s_b3, from.sin_addr.S_un.S_un_b.s_b4);
// setup target address
sockaddr_in addr;
memset(&addr, 0, sizeof(sockaddr));
addr.sin_addr.S_un.S_addr = from.sin_addr.S_un.S_addr;
addr.sin_port = htons(6112);
addr.sin_family = AF_INET;
// send response
Sleep(20);
for(int i = 0; i < numsockets; i++)
{
memset(game_response_packet+msgoffset, 32, msglength);
memcpy(game_response_packet+msgoffset, messages[i], strlen(messages[i]));
sendto(sockets[i], (const char*)game_response_packet, sizeof(game_response_packet), 0, (sockaddr*)&addr, sizeof(addr));
Sleep(1);
}
}
}
}
}
}
Teeworlds - För dig som gillar gulliga saker med stora vapen.