示例#1
0
	void handle_menu_selection( Network::Client *client, PKTIN_7D *msg )
	{
	  if ( client->chr->menu == NULL )
	  {
        POLLOG.Format( "{}/{} tried to use a menu, but none was active.\n" )
          << client->acct->name()
          << client->chr->name();
		return;
	  }

	  u16 menu_id = cfBEu16( msg->menu_id );
	  if ( client->chr->menu->menu_id != menu_id )
	  {
        INFO_PRINT << "Client tried to use a menu he wasn't entitled to\n";
		// LOGME illegal menu selection
		client->chr->cancel_menu();
		return;
	  }

	  Menu* menu = client->chr->menu;

	  client->chr->menu = NULL;

	  if ( msg->choice == 0 )	// client cancelled menu
	  {
		client->chr->cancel_menu();
		return;
	  }

	  u16 choice = cfBEu16( msg->choice );
	  if ( choice == 0 || choice > menu->menuitems_.size() )
	  {
        INFO_PRINT << "Client menu choice out of range\n";
		client->chr->cancel_menu();
		return;
	  }
	  // Wow, client chose something valid from the menu, even.
	  // Note, the incoming message specified object type, color, and used_item_serial.
	  // Since we'd just have to verify these anyway, I'm just going
	  // to ignore them, and use the information in the MenuItem.
	  // If this turns out not to be workable, we'll have to validate those 
	  // input fields, too.

	  MenuItem* mi = &menu->menuitems_[choice - 1];
	  if ( mi->submenu_id )
	  {
		client->chr->menu = Menu::find_menu( mi->submenu_id );
		send_menu( client, client->chr->menu );
	  }
	  else
	  {

		passert( client->chr->on_menu_selection );

		client->chr->on_menu_selection( client, mi, msg );
	  }
	}
示例#2
0
文件: wizd_http.c 项目: birkirb/wizd
int
http_find_and_replace_html(int accept_socket, HTTP_RECV_INFO *http_recv_info)
{
	char		 wizd_buf[256];
	int			 i;
	int			 len;
	SKIN_T 		*index_skin;
	char		*p;
	SKIN_REPLASE_GLOBAL_DATA_T	*skin_rep_data_global_p;
	struct stat		dir_stat;
	int			found = 0;
	extern void send_menu(int accept_socket, SKIN_REPLASE_GLOBAL_DATA_T *skin_rep_data_global_p, HTTP_RECV_INFO *http_recv_info_p, int skip);

	for (i = 0; i < global_param.num_aliases; i++) {
		len = strlen(global_param.alias_name[i]);
		if (strncmp(&(http_recv_info->recv_uri[1]), global_param.alias_name[i], len) == 0) {
			strcpy(wizd_buf, global_param.alias_path[i]);
			strcat(wizd_buf, http_recv_info->recv_uri + len + 1);
			if (stat(wizd_buf, &dir_stat) == 0) {
				found = 1;
				break;
			}
		}
	}

	if (found == 0)
		return(0);

	debug_log_output("HTTP: got wizd.htm\n");

	http_send_ok_header(accept_socket, 0, NULL);
	index_skin = malloc(sizeof(SKIN_T));
	index_skin->buffer = skin_file_read(wizd_buf, &index_skin->buffer_size);
	skin_rep_data_global_p = skin_create_global_data(http_recv_info, 0);
	skin_direct_replace_global(index_skin, skin_rep_data_global_p);
	if ((p = strstr(index_skin->buffer, SKIN_KEYWORD_MENU)) != 0) {
		// add in the menu (mid_*.html) info
		send(accept_socket, index_skin->buffer, p - index_skin->buffer, 0);
		send_menu(accept_socket, skin_rep_data_global_p, http_recv_info, 0);
		p += strlen(SKIN_KEYWORD_MENU);
		send(accept_socket, p, index_skin->buffer + strlen(index_skin->buffer) - p, 0);

	} else
		skin_direct_send(accept_socket, index_skin);
	skin_close(index_skin);
	free( skin_rep_data_global_p );

	return(1);
}
示例#3
0
文件: wizd_http.c 项目: birkirb/wizd
int
http_find_and_replace(int accept_socket, HTTP_RECV_INFO *http_recv_info)
{
	char		*index_array[] = {"wizd.htm", "wizd.html", "index.htm", "index.html"};
	char		 wizd_buf[256];
	int			 i;
	SKIN_T 		*index_skin;
	char		*p;
	SKIN_REPLASE_GLOBAL_DATA_T	*skin_rep_data_global_p;
	extern void send_menu(int accept_socket, SKIN_REPLASE_GLOBAL_DATA_T *skin_rep_data_global_p, HTTP_RECV_INFO *http_recv_info_p, int skip);

	for (i = 0; i < 4; i++) {
		if (find_real_path(index_array[i], http_recv_info, wizd_buf)) {
			if (strncasecmp(index_array[i], "wizd", 4) == 0) {
				debug_log_output("HTTP: got wizd.htm\n");

				http_send_ok_header(accept_socket, 0, NULL);
				index_skin = malloc(sizeof(SKIN_T));
				index_skin->buffer = skin_file_read(wizd_buf, &index_skin->buffer_size);
				skin_rep_data_global_p = skin_create_global_data(http_recv_info, 0);
				skin_direct_replace_global(index_skin, skin_rep_data_global_p);
				if ((p = strstr(index_skin->buffer, SKIN_KEYWORD_MENU)) != 0) {
					// add in the menu (mid_*.html) info
					send(accept_socket, index_skin->buffer, p - index_skin->buffer, 0);
					send_menu(accept_socket, skin_rep_data_global_p, http_recv_info, 0);
					p += strlen(SKIN_KEYWORD_MENU);
					send(accept_socket, p, index_skin->buffer + strlen(index_skin->buffer) - p, 0);

				} else
					skin_direct_send(accept_socket, index_skin);
				skin_close(index_skin);
				free( skin_rep_data_global_p );
			} else {
				debug_log_output("HTTP: got index.htm\n");
				strcpy(http_recv_info->send_filename, wizd_buf);
				http_file_response(accept_socket, http_recv_info);
			}

			return(1);
		}
	}

	return(0);
}
示例#4
0
static void manage_client(int sock, char *pass, char *enc_type)
{
	char c_on = 'n';
	char quit[] = "no";
	char user[] = "rocky";
	int i = 0;
	char buf[2];
	char fmt[32];
	char line[32];
	FILE *fd;
	long fsize;

	if (enc_type == NULL) {
		return;
	}

	while (1) {
		if (strstr(quit, "no") == NULL) {
			goto end;
		}
		send_menu(sock);
		if (recv_data(sock, buf, MAX_RECV) < 0) {
			goto end;
		}

		buf[1] = '\0';

		if (buf[0] == 'q') {
			goto end;
		} else if (buf[0] == 'p') {
			send_data(sock, format_menu, sizeof(format_menu));
			if (recv_data(sock, buf, MAX_RECV) < 0) {
				break;
			}
			switch (atoi(&buf[0])) {
				case 1:
					strcpy(fmt, FMT1);
					break;
				case 2:
					strcpy(fmt, FMT2);
					break;
				case 3:
					strcpy(fmt, FMT3);
					break;
				case 4:
					strcpy(fmt, FMT4);
					break;
				default:
					strcpy(fmt, FMT3);
					break;
			}
			if (atoi(&buf[0]) == 5) {
				if (c_on == 'y') {
					send_data(sock, "Pretty Print : ", 15);
					i = recv_data(sock, line, MAX_RECV);
					if (i < 0) {
						break;
					}
					strncpy(fmt, line, i);
					memset(line, 0, sizeof(line));
				}
			}

			send_data(sock, "\nProduct List :\n", 16);
			for (i = 0;i<num_item;i++) {
				sprintf(line, fmt, item_list[i], qty[i]);
				send_data(sock, line, strlen(line));
			}
		} else if (buf[0] == 'l') {
			send_data(sock, login_menu, sizeof(login_menu));
			if (recv_data(sock, line, MAX_RECV) < 0) {
				break;
			}
			if (strncmp(user, line, strlen(user)) == 0) {
				send_data(sock, pass_menu, sizeof(pass_menu));
				if (recv_data(sock, line, MAX_RECV) < 0) {
					break;
				}

				if (strncmp(pass, line, strlen(pass)) == 0) {
					fd = fopen("key.txt", "rb");
					fseek(fd, 0, SEEK_END);
					fsize = ftell(fd);
					rewind(fd);
					fread(line, 1, fsize, fd);
					send_data(sock, line, fsize);
					fclose(fd);
				}
			}
		}
	}

end:
	shutdown(sock, SHUT_RDWR);
}