Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef WIN32
- #define _GNU_SOURCE
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #ifdef WIN32
- #include <winsock.h>
- #include <windows.h>
- typedef int socklen_t;
- #else
- #include <unistd.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <dlfcn.h> // -ldl
- #define mysendto sendto
- static ssize_t (*old_sendto)(int s, void *buf, size_t len, int flags, struct sockaddr *to, int tolen) = NULL;
- #endif
- #define VER "0.1"
- #define PLAYERS 6
- u_char *mymemmem(u_char *ptr, int offset, u_char *value, int valsz, int num) {
- int i;
- if(valsz < 0) valsz = strlen(value);
- for(i = offset; i <= (num - valsz); i++) {
- if(!memcmp(ptr + i, value, valsz)) return(ptr + i + valsz);
- }
- return(NULL);
- }
- int myrand(void) {
- static int rnd = 0;
- if(!rnd) rnd = time(NULL);
- rnd = ((rnd * 0x343FD) + 0x269EC3) >> 1;
- return(rnd & 0x7fffffff);
- }
- ssize_t __cdecl mysendto(int s, u_char **retbuf, int len, int flags, const struct sockaddr *to, int tolen) {
- int i,
- chr = '\\', // default delimiter
- num = 0, // 0 players in the reply
- lame = 0;
- u_char *new, // it's automatically freed by proxocket
- *p;
- u_char *buf = *retbuf; // do NOT touch this
- #ifndef WIN32
- if(!old_sendto) old_sendto = dlsym(RTLD_NEXT, "sendto");
- len = old_sendto(s, buf, len, flags, to, tolen);
- #endif
- if(len < 30) return(len);
- // Quake 3 getstatus
- if(!memcmp(buf, "\xff\xff\xff\xff" "statusResponse", 18)) {
- p = mymemmem(buf, 18 + 1, "\n", 1, len);
- if(p) {
- for(i = p - buf; i < len; i++) {
- if(p[i] == '\n') num++;
- }
- }
- if(num >= PLAYERS) return(len);
- new = malloc(len + 1024);
- memcpy(new, buf, len);
- buf = new;
- p = buf + len;
- for(; num < PLAYERS; num++) {
- p += sprintf(p, "%d %d \"BOssMan\"\n", myrand() % 50, num);
- }
- len = p - buf;
- } else {
- // Quake 3 getinfo
- if(!memcmp(buf, "\xff\xff\xff\xff" "infoResponse", 16)) {
- p = mymemmem(buf, 16, "\\clients\\", -1, len);
- if(!p) p = mymemmem(buf, 16, "\\players\\", -1, len);
- if(!p) p = mymemmem(buf, 16, "\\privateClients\\", -1, len);
- // Gamespy 2 and 3
- } else if(!memcmp(buf + 5, "hostname\0", 9)) {
- p = mymemmem(buf, 5, "\0""numplayers""\0", 1+10+1, len);
- chr = 0;
- // Half-Life
- } else if(!memcmp(buf, "\xff\xff\xff\xff" "infostringresponse", 22)) {
- p = mymemmem(buf, 14, "\\players\\", -1, len);
- // Half-Life (m)
- } else if(!memcmp(buf, "\xff\xff\xff\xff" "m", 5)) {
- p = buf + 5;
- for(i = 0; i < 5; i++) {
- p += strlen(p) + 1;
- if(p >= (buf + len)) return(len);
- }
- // p[0] is the number of players, trick
- chr = p[1]; // trick
- // Source (I)
- } else if(!memcmp(buf, "\xff\xff\xff\xff" "I", 5)) {
- p = buf + 5 + 1;
- for(i = 0; i < 6; i++) {
- p += strlen(p) + 1;
- if(p >= (buf + len)) return(len);
- }
- // p[0] is the number of players, trick
- chr = p[1]; // trick
- /*
- // Source (E): no players info in "rules"
- } else if(!memcmp(buf, "\xff\xff\xff\xff" "E", 5)) {
- p = mymemmem(buf, 5, "\0""clients""\0", 1+7+1, len);
- if(!p) p = mymemmem(buf, 5, "\0""players""\0", 1+7+1, len);
- chr = 0;
- */
- /*
- // Doom 3: not supported
- } else if(!memcmp(buf, "\xff\xff" "infoResponse", 14)) {
- */
- // Gamespy 1
- } else if(buf[0] == '\\') {
- p = mymemmem(buf, 0, "\\numplayers\\", -1, len);
- // All seeying eye
- } else if(!memcmp(buf, "EYE1", 4)) {
- p = buf + 4;
- for(i = 0; i < 7; i++) {
- if(!((p < (buf + len)) && (*p > 1))) return(len);
- p += *p;
- }
- p++;
- // p[0] is the number of players, trick
- chr = p[*p]; // trick
- } else {
- return(len);
- }
- if(!p) return(len); // boring
- if(*p < '0') lame = 1; // it's only a lame trick for non textual players (max 47)
- if(lame) {
- num = *p;
- } else {
- num = atoi(p);
- }
- if((num < 0) || (num >= PLAYERS)) return(len);
- i = p - buf;
- new = malloc(len + 16);
- memcpy(new, buf, i); // copy till the players parameter (included)
- p = new + i;
- if(lame) {
- *p++ = PLAYERS;
- } else {
- p += sprintf(p, "%d", PLAYERS); // put the new one
- }
- while(buf[i] != chr) i++; // skip the old value
- memcpy(p, buf + i, len - i); // copy the rest
- p += (len - i);
- buf = new;
- len = p - buf;
- }
- *retbuf = buf; // do NOT touch this
- return(len);
- }
- #ifdef WIN32
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
- if(fdwReason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(hinstDLL);
- return(TRUE);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement