Jump to content

Question

9 answers to this question

Recommended Posts

Posted

Saw this one in eAthena, I do not know if this is compatible with rAthena. I suggest you to use Harmony, but here's the code.

trunk/src/common/socket.c

Index: socket.c
===================================================================
--- socket.c	(revision 13725)
+++ socket.c	(working copy)
@@ -16,6 +16,7 @@
 
 #ifdef WIN32
 	#include <winsock2.h>
+	#include <time.h>
 	#include <io.h>
 #else
 	#include <errno.h>
@@ -112,7 +113,54 @@
 		sock_arr_len = fd+1;
 	return fd;
 }
+ 
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
+#else
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
+#endif
 
+struct timezone 
+{
+  int  tz_minuteswest; /* minutes W of Greenwich */
+  int  tz_dsttime;     /* type of dst correction */
+};
+ 
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+  FILETIME ft;
+  unsigned __int64 tmpres = 0;
+  static int tzflag;
+ 
+  if (NULL != tv)
+  {
+    GetSystemTimeAsFileTime(&ft);
+ 
+    tmpres |= ft.dwHighDateTime;
+    tmpres <<= 32;
+    tmpres |= ft.dwLowDateTime;
+ 
+    /*converting file time to unix epoch*/
+    tmpres /= 10;  /*convert into microseconds*/
+    tmpres -= DELTA_EPOCH_IN_MICROSECS; 
+    tv->tv_sec = (long)(tmpres / 1000000UL);
+    tv->tv_usec = (long)(tmpres % 1000000UL);
+  }
+ 
+  if (NULL != tz)
+  {
+    if (!tzflag)
+    {
+      _tzset();
+      tzflag++;
+    }
+    tz->tz_minuteswest = _timezone / 60;
+    tz->tz_dsttime = _daylight;
+  }
+ 
+  return 0;
+}
+
 int sAccept(int fd, struct sockaddr* addr, int* addrlen)
 {
 	SOCKET s;
@@ -196,6 +244,9 @@
 time_t last_tick;
 time_t stall_time = 60;
 
+uint32 max_frequency_warning = 12; //Max number of packets user can have that are within a certain interval of each other before the program kicks
+int diff_tolerance = 7000; //In microseconds
+
 uint32 addr_[16];   // ip addresses of local host (host byte order)
 int naddr_ = 0;   // # of ip addresses
 
@@ -317,9 +368,37 @@
 		set_eof(fd);
 		return 0;
 	}
-
 	session[fd]->rdata_size += len;
 	session[fd]->rdata_tick = last_tick;
+	
+	// Anti-WPE script by Zohan
+    if(!session[fd]->flag.server && (RFIFOW(fd,0) == 0x0438 || RFIFOW(fd,0) == 0x0116))
+    {
+       session[fd]->lastDiff = session[fd]->thisDiff;
+       session[fd]->lastPacket.tv_sec = session[fd]->thisPacket.tv_sec;
+       session[fd]->lastPacket.tv_usec = session[fd]->thisPacket.tv_usec;
+       gettimeofday(&session[fd]->thisPacket, NULL);
+       session[fd]->thisDiff = (((session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec) * 1000000) + session[fd]->thisPacket.tv_usec) - session[fd]->lastPacket.tv_usec;
+       if(abs(session[fd]->thisDiff - session[fd]->lastDiff) < diff_tolerance)
+       {
+          session[fd]->warning_number++;
+          if(session[fd]->warning_number > max_frequency_warning)
+          {
+            set_eof(fd);
+          }
+       }
+       else if(session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec > 10)
+       {
+            session[fd]->warning_number = 0;
+       }
+       else
+       {
+           if(session[fd]->warning_number > 0)
+           {
+             session[fd]->warning_number--;
+           }
+       }
+    }
 	return 0;
 }

 

trunk/src/common/socket.h

Index: socket.h
===================================================================
--- socket.h	(revision 13725)
+++ socket.h	(working copy)
@@ -83,6 +83,13 @@
 	size_t rdata_pos;
 	time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
 
+    //Anti-WPE
+    struct timeval thisPacket;
+    struct timeval lastPacket;
+    int thisDiff;
+    int lastDiff;
+    uint32 warning_number; 
+    
 	RecvFunc func_recv;
 	SendFunc func_send;
 	ParseFunc func_parse;
Posted · Hidden by Capuche, August 31, 2013 - No reason given
Hidden by Capuche, August 31, 2013 - No reason given
-	script	AntiWPEandRPE	-1,{
OnPCLoginEvent:
	dispbottom "Do not use WPE/RPE.";
	end;
}

Sadly, you can't do it with script.

LOL trolling wkkwkw

Posted (edited)

Saw this one in eAthena, I do not know if this is compatible with rAthena. I suggest you to use Harmony, but here's the code.

trunk/src/common/socket.c

Index: socket.c
===================================================================
--- socket.c	(revision 13725)
+++ socket.c	(working copy)
@@ -16,6 +16,7 @@
 
 #ifdef WIN32
 	#include <winsock2.h>
+	#include <time.h>
 	#include <io.h>
 #else
 	#include <errno.h>
@@ -112,7 +113,54 @@
 		sock_arr_len = fd+1;
 	return fd;
 }
+ 
+#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
+#else
+  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
+#endif
 
+struct timezone 
+{
+  int  tz_minuteswest; /* minutes W of Greenwich */
+  int  tz_dsttime;     /* type of dst correction */
+};
+ 
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+  FILETIME ft;
+  unsigned __int64 tmpres = 0;
+  static int tzflag;
+ 
+  if (NULL != tv)
+  {
+    GetSystemTimeAsFileTime(&ft);
+ 
+    tmpres |= ft.dwHighDateTime;
+    tmpres <<= 32;
+    tmpres |= ft.dwLowDateTime;
+ 
+    /*converting file time to unix epoch*/
+    tmpres /= 10;  /*convert into microseconds*/
+    tmpres -= DELTA_EPOCH_IN_MICROSECS; 
+    tv->tv_sec = (long)(tmpres / 1000000UL);
+    tv->tv_usec = (long)(tmpres % 1000000UL);
+  }
+ 
+  if (NULL != tz)
+  {
+    if (!tzflag)
+    {
+      _tzset();
+      tzflag++;
+    }
+    tz->tz_minuteswest = _timezone / 60;
+    tz->tz_dsttime = _daylight;
+  }
+ 
+  return 0;
+}
+
 int sAccept(int fd, struct sockaddr* addr, int* addrlen)
 {
 	SOCKET s;
@@ -196,6 +244,9 @@
 time_t last_tick;
 time_t stall_time = 60;
 
+uint32 max_frequency_warning = 12; //Max number of packets user can have that are within a certain interval of each other before the program kicks
+int diff_tolerance = 7000; //In microseconds
+
 uint32 addr_[16];   // ip addresses of local host (host byte order)
 int naddr_ = 0;   // # of ip addresses
 
@@ -317,9 +368,37 @@
 		set_eof(fd);
 		return 0;
 	}
-
 	session[fd]->rdata_size += len;
 	session[fd]->rdata_tick = last_tick;
+	
+	// Anti-WPE script by Zohan
+    if(!session[fd]->flag.server && (RFIFOW(fd,0) == 0x0438 || RFIFOW(fd,0) == 0x0116))
+    {
+       session[fd]->lastDiff = session[fd]->thisDiff;
+       session[fd]->lastPacket.tv_sec = session[fd]->thisPacket.tv_sec;
+       session[fd]->lastPacket.tv_usec = session[fd]->thisPacket.tv_usec;
+       gettimeofday(&session[fd]->thisPacket, NULL);
+       session[fd]->thisDiff = (((session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec) * 1000000) + session[fd]->thisPacket.tv_usec) - session[fd]->lastPacket.tv_usec;
+       if(abs(session[fd]->thisDiff - session[fd]->lastDiff) < diff_tolerance)
+       {
+          session[fd]->warning_number++;
+          if(session[fd]->warning_number > max_frequency_warning)
+          {
+            set_eof(fd);
+          }
+       }
+       else if(session[fd]->thisPacket.tv_sec - session[fd]->lastPacket.tv_sec > 10)
+       {
+            session[fd]->warning_number = 0;
+       }
+       else
+       {
+           if(session[fd]->warning_number > 0)
+           {
+             session[fd]->warning_number--;
+           }
+       }
+    }
 	return 0;
 }

 

trunk/src/common/socket.h

Index: socket.h
===================================================================
--- socket.h	(revision 13725)
+++ socket.h	(working copy)
@@ -83,6 +83,13 @@
 	size_t rdata_pos;
 	time_t rdata_tick; // time of last recv (for detecting timeouts); zero when timeout is disabled
 
+    //Anti-WPE
+    struct timeval thisPacket;
+    struct timeval lastPacket;
+    int thisDiff;
+    int lastDiff;
+    uint32 warning_number; 
+    
 	RecvFunc func_recv;
 	SendFunc func_send;
 	ParseFunc func_parse;

 

Anyone had tried this at rAthena?

 

-	script	AntiWPEandRPE	-1,{
OnPCLoginEvent:
	dispbottom "Do not use WPE/RPE.";
	end;
}

Sadly, you can't do it with script.

 

Haha. Very sad! /wah

 

 

 

                    Posted 30 August 2013 - 05:59 PM

                              

 I hope we could have something like this from Hercules http://hercules.ws/b...une-14th-patch/

 

 

Posted 15 June 2013 - 05:33 PM

either request at rAthena to convert it, or change to using Hercules

 

Hercules devs will not create this for rAthena o_O

 

Dem~

Edited by uDe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...