Need some C++ Programming Help

Joined
Oct 25, 2010
Messages
2
Reaction score
0
Okay, this code is supposed to block the ability to flood a game server by querying it massive amounts of times. The two query packets are \info\ and \status\

What's happening right now is that as soon as it is queried, the game server will freeze until it is queried again. I've spent numerous hours trying to figure out why it keeps doing that but it's apparent that this is the code that causes it to freeze as when i comment it out, it functions as normal. Can you please tell me what's wrong and possibly fix the code up for me? The errors the compiler tell me are:

Code:
wsock32.c(304) : warning C4047: 'function' : 'int' differs in levels of indirection from 'int *'
wsock32.c(304) : warning C4024: 'orig_sendto' : different types for formal and actual parameter 6
wsock32.c(319) : warning C4047: 'function' : 'int' differs in levels of indirection from 'int *'
wsock32.c(319) : warning C4024: 'orig_sendto' : different types for formal and actual parameter 6


This is the code below:
Code:
// Query Optimization
 int last_i=0;
 int last_s=0;
 char l_info[1400];
 char l_status[1400];
 int len_info=0;
 int len_status=0;
 int last_p=0;

 char l_ip[14];
 int l_c=0;
// Query Optimization
typedef int(FAR PASCAL*lpfn_sendto)(IN SOCKET s, IN const char *buf, IN int len, IN int flags, IN const struct sockaddr *to, IN int tolen);
lpfn_sendto orig_sendto; 

typedef int (FAR PASCAL*lpfn_recvfrom)(IN SOCKET s, OUT char FAR * buf, IN int len, IN int flags, OUT struct sockaddr FAR *from, IN OUT int FAR * fromlen);
lpfn_recvfrom orig_recvfrom;

int FAR PASCAL sys_recvfrom(IN SOCKET s, OUT char FAR * buf, IN int len, IN int flags, OUT struct sockaddr FAR *from, IN OUT int FAR * fromlen)
{
   int splitnumber;
   int splittotal;
   int TokenLength;
   const char * token;
   const char * ptr;

int returnCode=0;
   int counter=0;
   int tick=0; // Query Optimization
   int max_q=3; //max queries per frame
   // Query Optimization
   begin: 
   returnCode = (*orig_recvfrom)(s, buf, len, flags, from, fromlen);
   // Start of Query Optimization
   if(returnCode < 9){
          if((unsigned char)buf[0] == 0x5C){
			    if(returnCode == 6){
							 tick = GetTickCount() - last_i;
							 if((tick - last_i) < 1000){
								 if(max_q > 0){
[COLOR="Magenta"]//This is line 304[/COLOR]									(*orig_sendto)(s, l_info, len_info, flags, from, fromlen);
									max_q--;
									goto begin;
								 }
								 return(0);
								  }
							 else{
								  last_p=1;
								  return(returnCode);
								  }
							 }
			    else if(returnCode == 8) {
					   tick = GetTickCount() - last_s;
					 if(tick < 1000){
						  if(max_q > 0){      
[COLOR="Magenta"]//This is line 319[/COLOR]						  (*orig_sendto)(s, l_status, len_status, flags, from, fromlen);
						  max_q--;
								goto begin;
						  }
						  return(0);
								}
					  else {
						   last_p=2;
						   return(returnCode);
						   }
					  }
			    }																	
          }
	
	// End of Query Optimization







// Query Optimization
int FAR PASCAL sys_sendto(IN SOCKET s, IN const char *buf, IN int len, IN int flags, IN const struct sockaddr *to, IN int tolen)
{
    if(last_p==1) {
               memcpy(l_info, buf, len);
               len_info = len;
               last_i = GetTickCount();
			   last_p=0;
               }
    else if(last_p==2) {
               memcpy(l_status, buf, len);
               len_status = len;
               last_s = GetTickCount();
			   last_p=0;
			}
	//query anything flood fix
	if(len < 25){
		if( (unsigned char)buf[1] == 102 ){return(0);}
		}
               return((*orig_sendto)(s, buf, len, flags, to, tolen));
}
 
Last edited:
Joined
Oct 25, 2010
Messages
2
Reaction score
0
Okay I finally found out that moving begin: one line below fixed it from freezing every other frame, and when i attempt flooding the server with \status\ or \info\ it is no longer DDOSing the connection, but no one can query the server at all while it is being spammed. Any help on that? Thanks. I've tried increasing the max queries per frame and the more i increase it, the higher the overall latency gets but still it's unqueryable during a flood. Increasing the ticks from 1000 doesn't seem to make any difference either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top