예제 #1
0
/*
 * Setup and initialize a network socket.
 */
static
int
open_socket(THREAD_DATA::net_t *n) 
{
	struct addrinfo ai_hints, *ai;
	bzero(&ai_hints, sizeof(ai_hints));
	ai_hints.ai_socktype = SOCK_DGRAM;
	ai_hints.ai_family = AF_INET;
	ai_hints.ai_flags = AI_CANONNAME;

#ifdef LOCK_GETADDRINFO
	pthread_mutex_lock(&g_getaddrinfo_mutex);
#endif

	/* resolve the host name */
	int getaddrret = getaddrinfo(n->servername,
	    n->serverport, &ai_hints, &ai);

#ifdef LOCK_GETADDRINFO
	pthread_mutex_unlock(&g_getaddrinfo_mutex);
#endif

	if (getaddrret != 0) {
		StopBot("error resolving hostname");
		return -1;
	}
	
	/* copy resolved sockaddr_in struct to the bot's data and free it */
	memcpy(&n->serv_sin, ai->ai_addr, sizeof(struct sockaddr_in));
	/* ai->ai_canonname can be null on macs if the ip doesnt have rdns */
	strlcpy(n->servername, ai->ai_canonname ? ai->ai_canonname : n->servername, 128);
	snprintf(n->serverport, 8, "%hu", ntohs(n->serv_sin.sin_port)); 
	freeaddrinfo(ai);

	/* resolve the ip and store it for future reference */
	if (inet_ntop(n->serv_sin.sin_family, &n->serv_sin.sin_addr, 
	    n->serverip, INET_ADDRSTRLEN) == NULL)
		strlcpy(n->serverip, "unknown", INET_ADDRSTRLEN);

	/* create a udp socket */
	if ((n->fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		StopBot("error creating network socket");
		return -1;
	}
	
	if (connect(n->fd, (struct sockaddr*)&n->serv_sin,
	    sizeof(struct sockaddr_in)) == -1) {
		StopBot("error connecting to network socket");
		return -1;
	}

	n->pfd[0].fd = n->fd;
	n->pfd[0].events = POLLRDNORM;

	return 0;
}
예제 #2
0
파일: Form.cpp 프로젝트: GodLesZ/svn-dump
BOOL CALLBACK Dlgproc3(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDC_BUTTON1:
					IsBotting = !IsBotting;				
					if (IsBotting)
						StartBot();
					else
						StopBot();		
					break;

				case IDC_CHECK1:
					PickItems = !PickItems;
					if (PickItems)
						EnableWindow(GetDlgItem(hWnd, IDC_CHECK2), true);
					else
						EnableWindow(GetDlgItem(hWnd, IDC_CHECK2), false);
					break;

				case IDC_CHECK2:
					DoSellItems = !DoSellItems;
					break;

				case IDC_CHECK3:
					DoRepairEquipment = !DoRepairEquipment;
					break;

				case IDC_CHECK4:
					UseOnlySkills = !UseOnlySkills;
					break;

				case IDC_BUTTON4:
					ClearListBox(GetDlgItem(hWnd, IDC_LIST2));
					char c[100];
					DWORD Count = SendMessage(GetDlgItem(hWnd, IDC_LIST1), LB_GETCOUNT, 0, 0);
					if ((Count != 0) && (Count != LB_ERR))
					{		
						for (BYTE i = 0; i < Count; i++)
						{
							if (SendMessage(GetDlgItem(hWnd, IDC_LIST1), LB_GETSEL, i, 0) > 0)
							{
								SendMessage(GetDlgItem(hWnd, IDC_LIST1), LB_GETTEXT, i, (LPARAM)c);
								SendMessage(GetDlgItem(hWnd, IDC_LIST2), LB_ADDSTRING, i, (LPARAM)c);
								IsUsingSkill(i, true);
							}
							else
								IsUsingSkill(i, false);
						}
					}
					break;

			}
	}
	return FALSE;
}
예제 #3
0
void
StopBotFmt(char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	
	char buf[256];
	vsnprintf(buf, 256, fmt, ap);

	StopBot(buf);

	va_end(ap);
}
예제 #4
0
파일: Form.cpp 프로젝트: GodLesZ/svn-dump
void CatchKeystrokes(HWND hWnd)
{
	bool KeyIsPressed = false;
	bool Key2IsPressed = false;
	while (true)
	{
		if (GetAsyncKeyState(VK_F5) < 0)
		{
			if (!KeyIsPressed)
			{
				KeyIsPressed = true;

				if (IsDialogVisible)
					ShowWindow(FormHandle, SW_HIDE);
				else
					ShowWindow(FormHandle, SW_SHOW);
				IsDialogVisible = !IsDialogVisible;
			}
		}
		else
			KeyIsPressed = false;

		if (GetAsyncKeyState(VK_F6) < 0)
		{
			if ((!Key2IsPressed) && (BotReady))
			{
				Key2IsPressed = true;

				IsBotting = !IsBotting;				
				if (IsBotting)
					StartBot();
				else
					StopBot();
			}
		}
		else
			Key2IsPressed = false;

		Sleep(1);
	}
}
예제 #5
0
파일: main.c 프로젝트: DerekTitus/Lab6
/*
 * main.c
 */
int main(void) {

	WDTCTL = WDTPW|WDTHOLD;                 // stop the watchdog timer

	initMotors();
	
	while(1)
	{
		TurnLeft();
		ShortDelay();
		StopBot();
		Delay();
		TurnRight();
		ShortDelay();
		StopBot();
		Delay();
		MoveForward();
		Delay();
		StopBot();
		Delay();
		MoveBack();
		Delay();
		StopBot();
		Delay();
		TurnRight();
		Delay();
		StopBot();
		Delay();
		TurnLeft();
		Delay();
		StopBot();
		Delay();
		Delay();
		Delay();

	}

}