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 <stdint.h>
- #include <time.h>
- #include <sys/stat.h>
- #include <winsock.h>
- #include <windows.h>
- #include <stdlib.h>
- #include <process.h>
- #ifdef WIN32
- #include <winsock.h>
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <process.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 myrecvfrom recvfrom
- static ssize_t (*old_recvfrom)(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) = NULL;
- #endif
- typedef uint8_t u8;
- typedef uint16_t u16;
- typedef uint32_t u32;
- /*
- DEKLARACIJA VARIJABLI
- */
- #define MAXIPS 256 // Maksimalan broj IP adresa u tabelama
- #define GETSTATUS "\xFF\xFF\xFF\xFFgetstatus"
- #define GETSTATUS_LEN 13
- //****************************************************************************************************
- // TABELA ZA GETSTATUS
- typedef struct {
- u32 ip;
- DWORD zadnjigetstatus,
- brojac;
- } getstatust_t;
- // TABELA ZA BANOVE
- typedef struct {
- u32 ip;
- DWORD banirando;
- } banovit_t;
- //****************************************************************************************************
- static getstatust_t getstatust[MAXIPS] = {{0,0,0}};
- static banovit_t banovit[MAXIPS] = {{0,0}};
- //****************************************************************************************************
- // PRIMLJENI PAKETI
- ssize_t myrecvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) {
- DWORD sada;
- u32 ip;
- int i,
- stari;
- #ifndef WIN32
- if(!old_recvfrom) old_recvfrom = dlsym(RTLD_NEXT, "recvfrom");
- len = old_recvfrom(s, buf, len, flags, from, fromlen);
- #endif
- if(!from) return(len);
- if((int)len <= 0) return(len);
- if((int)len > 0)
- {
- ip = ((struct sockaddr_in *)from)->sin_addr.s_addr;
- //****************************************************************************************************
- // GETSTATUS
- if(!strncasecmp(GETSTATUS,buf,GETSTATUS_LEN)) {
- for(i = 0; i < MAXIPS; i++) { // Provjeri je li IP u tabeli
- if(ip != getstatust[i].ip) continue; // Ako to nije IP iz tabele prijedi na sljedeci
- if(GetTickCount() < (getstatust[i].zadnjigetstatus + 250)) { // provjeri je li prošlo 250 ms od zadnjeg getstatusa
- //len = 0; // postavi paket na nulu za disconnect
- getstatust[i].brojac++; // povecaj brojac
- }
- if(getstatust[i].brojac > 10){ // ako je više od 10 zahtjeva, dodaj IP u ban listu
- banovit[i].ip = getstatust[i].ip; // dodaj IP u bazu banova
- banovit[i].banirando = GetTickCount() + 10000; // dodaj 10 sekundi na vrijeme za ban
- getstatust[i].brojac = 0; // resetiraj brojac da se nanovo provjeri nastavak flooda
- }
- getstatust[i].zadnjigetstatus = GetTickCount(); // postavi vrijeme zadnjeg upcita na trenutno
- return(len); // vrati paket
- }
- stari = 0;
- for(i = 0; i < MAXIPS; i++) { // dodaj ili obnovi IP
- if(!getstatust[i].ip) { // prazno mjesto
- stari = i;
- break;
- }
- if(getstatust[i].zadnjigetstatus < getstatust[stari].zadnjigetstatus) {
- stari = i; // nadi najstariji IP
- }
- }
- getstatust[stari].ip = ip;
- getstatust[stari].zadnjigetstatus = GetTickCount();
- getstatust[stari].brojac = 0;
- }
- return(len);
- }
- }
- // POSLANI PAKETI
- int __cdecl mysendto(SOCKET s, u_char **retbuf, int len, int flags, const struct sockaddr *to, int tolen) {
- u_char *buf = *retbuf;
- DWORD sada;
- u32 ip;
- int i;
- ip = ((struct sockaddr_in *)to)->sin_addr.s_addr;
- for(i = 0; i < MAXIPS; i++) { // provjeri da li je IP u tabeli baniranih
- if(ip != banovit[i].ip) continue; // ako IP nije u polju baniranih, nastavi pretragu
- if(GetTickCount() < banovit[i].banirando) { // ne vracaj ništa dok ne prode vrijeme hladenja
- return(-0x77777777); // vrati ništa i izbaci petlju
- }
- }
- *retbuf = buf;
- return(len);
- }
- #ifdef WIN32
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
- switch(fdwReason) {
- case DLL_PROCESS_ATTACH: {
- DisableThreadLibraryCalls(hinstDLL);
- break;
- }
- case DLL_PROCESS_DETACH: {
- break;
- }
- default: break;
- }
- return(TRUE);
- }
- #endif
- /*
- example of fake number of players on the own server
- by Luigi Auriemma
- e-mail: aluigi@autistici.org
- web: aluigi.org
- this plugin for Proxocket (http://aluigi.org/mytoolz.htm#proxocket) shows
- how to send a false number of players to the clients that query the server
- on which is running this plugin.
- how to use:
- - copy ws2_32.dll of Proxocket in the folder of your server
- - copy THIS myproxocket.dll in the same folder (you must compile it if the
- file not available)
- - start your server
- - query the server with a client to know if it's working, in which case
- it will appear non-empty
- oh and yes, this example looks simple and basic (or even "lame") because...
- it's just an example!!!
- */
- // win: gcc -o myproxocket.dll myproxocket.c -shared
- // linux can NOT be implemented because mysendto uses a different prototype (**buf)!
- #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