NetworkConnectionMenu::NetworkConnectionMenu(network_menu_action_t action) : Menu("menu/bg_network", vOkCancel) { Profile *res = GetResourceManager().LoadXMLProfile("graphism.xml",false); uint max_width = 0.95f*GetMainWindow().GetWidth(); uint offset = (GetMainWindow().GetWidth() - max_width)/2; uint width = max_width - 10; /* Tabs */ tabs = new MultiTabs(Point2i(max_width, GetMainWindow().GetHeight()-140)); tabs->SetPosition(offset, offset); // ############################# /* client connection related widgets */ Box * cl_connection_box = new VBox(W_UNDEF, false, false, false); cl_connection_box->SetNoBorder(); tabs->AddNewTab(TAB_CLIENT_ID, _("Connect to game"), cl_connection_box); // Public battles Box * cl_tmp_box = new HBox(W_UNDEF, false, false, false); cl_tmp_box->SetMargin(0); cl_tmp_box->SetNoBorder(); cl_refresh_net_games = new Button(res, "menu/refresh_small", false); cl_tmp_box->AddWidget(cl_refresh_net_games); refresh_net_games_label = new Label(_("Public battles"), width - cl_refresh_net_games->GetSizeX(), Font::FONT_MEDIUM, Font::FONT_BOLD, c_red, Text::ALIGN_LEFT_TOP, true); cl_tmp_box->AddWidget(refresh_net_games_label); cl_connection_box->AddWidget(cl_tmp_box); cl_net_games_lst = new GameListBox(Point2i(width, 30)); cl_connection_box->AddWidget(cl_net_games_lst); // Server password cl_tmp_box = new HBox(W_UNDEF, false, false, false); cl_tmp_box->SetMargin(0); cl_tmp_box->SetNoBorder(); cl_tmp_box->AddWidget(new Label(_("Password:"******"", (3*width)/4); cl_tmp_box->AddWidget(cl_net_server_pwd); cl_connection_box->AddWidget(cl_tmp_box); // ############################# // Manual connection Box *manual_connection_box; if (GetMainWindow().GetHeight() < 480) { manual_connection_box = new VBox(W_UNDEF, false, false, false); manual_connection_box->SetNoBorder(); tabs->AddNewTab(TAB_MANUAL_ID, _("Manual connection"), manual_connection_box); } else { cl_connection_box->AddWidget(new Label(_("Manual connection"), width, Font::FONT_MEDIUM, Font::FONT_BOLD, c_red, Text::ALIGN_LEFT_TOP, true)); manual_connection_box = cl_connection_box; } // Server address cl_tmp_box = new HBox(W_UNDEF, false, false, false); cl_tmp_box->SetMargin(0); cl_tmp_box->SetNoBorder(); cl_tmp_box->AddWidget(new Label(_("Server address:"), width/4)); cl_server_address = new TextBox(Config::GetInstance()->GetNetworkClientHost(), (3*width)/4); cl_tmp_box->AddWidget(cl_server_address); manual_connection_box->AddWidget(cl_tmp_box); // Server port cl_tmp_box = new HBox(W_UNDEF, false, false, false); cl_tmp_box->SetMargin(0); cl_tmp_box->SetNoBorder(); cl_tmp_box->AddWidget(new Label(_("Port:"), width/4)); cl_port_number = new TextBox(Config::GetInstance()->GetNetworkClientPort(), (3*width)/4); cl_tmp_box->AddWidget(cl_port_number); manual_connection_box->AddWidget(cl_tmp_box); // Server password cl_tmp_box = new HBox(W_UNDEF, false, false, false); cl_tmp_box->SetMargin(0); cl_tmp_box->SetNoBorder(); cl_tmp_box->AddWidget(new Label(_("Password:"******"", (3*width)/4); cl_tmp_box->AddWidget(cl_server_pwd); manual_connection_box->AddWidget(cl_tmp_box); // ############################# /* server connection related widgets */ Box * srv_connection_box = new VBox(W_UNDEF, false, false, false); srv_connection_box->SetNoBorder(); // Server port Box * srv_tmp_box = new HBox(W_UNDEF, false, false, false); srv_tmp_box->SetMargin(0); srv_tmp_box->SetNoBorder(); srv_tmp_box->AddWidget(new Label(_("Port:"), width/4)); srv_port_number = new TextBox(Config::GetInstance()->GetNetworkServerPort(), (3*width)/4); srv_tmp_box->AddWidget(srv_port_number); srv_connection_box->AddWidget(srv_tmp_box); // Game name srv_tmp_box = new HBox(W_UNDEF, false, false, false); srv_tmp_box->SetMargin(0); srv_tmp_box->SetNoBorder(); srv_tmp_box->AddWidget(new Label(_("Game name:"), width/4)); srv_game_name = new TextBox(Config::GetInstance()->GetNetworkServerGameName(), (3*width)/4); srv_game_name->SetMaxNbChars(15); srv_tmp_box->AddWidget(srv_game_name); srv_connection_box->AddWidget(srv_tmp_box); // Server password srv_tmp_box = new HBox(W_UNDEF, false, false, false); srv_tmp_box->SetMargin(0); srv_tmp_box->SetNoBorder(); srv_tmp_box->AddWidget(new Label(_("Password:"******"", (3*width)/4); srv_game_pwd->SetMaxNbChars(15); srv_tmp_box->AddWidget(srv_game_pwd); srv_connection_box->AddWidget(srv_tmp_box); // Available on internet ? srv_internet_server = new CheckBox(_("Server available on Internet"), width, Config::GetInstance()->GetNetworkServerPublic()); srv_connection_box->AddWidget(srv_internet_server); tabs->AddNewTab(TAB_SERVER_ID, _("Host a game"), srv_connection_box); // ############################# widgets.AddWidget(tabs); widgets.Pack(); // Optimize height of public net games table uint net_games_lst_width = tabs->GetSizeX() - 2*(cl_connection_box->GetPositionX()-tabs->GetPositionX()); uint net_games_lst_height = cl_net_games_lst->GetSizeY() + (tabs->GetPositionY() + tabs->GetSizeY()) - (cl_connection_box->GetPositionY() + cl_connection_box->GetSizeY()) - 10; cl_net_games_lst->SetSize(net_games_lst_width, net_games_lst_height); // Warning about experimental networking Point2i msg_box_pos(offset, tabs->GetPositionY() + tabs->GetSizeY() + 10); Point2i msg_box_size(max_width, GetMainWindow().GetHeight() - 50 - msg_box_pos.y); msg_box = new MsgBox(msg_box_size, Font::FONT_SMALL, Font::FONT_BOLD); msg_box->SetPosition(msg_box_pos); widgets.AddWidget(msg_box); widgets.Pack(); msg_box->NewMessage(_("Have a good game!")); msg_box->NewMessage(""); // Skip a line //Double click m_last_click_on_games_lst = 0; m_Double_click_interval = 400; // ************************************************************************ InitNetInfo(); switch (action) { case NET_HOST: tabs->SelectTab(1); break; case NET_CONNECT: tabs->SelectTab(0); break; default: ThreadRefreshList(); break; } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { uint16 i; RCC_Configuration(); // Configure the system clocks NVIC_Configuration(); // NVIC Configuration GPIO_Configuration(); USART1_Init(115200); Timer_Configuration(); printf("============================================\r\n"); printf(" HTTP client for W5200 \r\n"); printf("============================================\r\n"); WIZ_SPI_Init(); Reset_W5200(); wizInit(); InitNetInfo(); DisplayNetInfo(); // LED3 and LED4 On! LED3_onoff(ON); LED4_onoff(ON); uint8 url[MAX_URL_SIZE]; //full url uint8 url_dn[MAX_URL_SIZE]; //domain name url uint8 url_path[MAX_URL_SIZE]; //local path in html server char * split; //string split pointer uint16 done_http = 0; uint16 start_idx = 0 ; uint16 end_idx = 0; uint16 tmp_start; uint16 tmp_end; uint8 BR [4]= "<BR>"; uint8 rBR [4]= "\r\n"; uint8 TITLE [7]= "<TITLE>"; uint8 bTITLE [8]= "</TITLE>"; uint16 tmp_idx; uint8 no_pr = 0; uint8 str[17]; while (1) { sprintf((char*)str,"%.3d.%.3d.%.3d.%.3d ", IINCHIP_READ (SIPR0+0), IINCHIP_READ (SIPR0+1), IINCHIP_READ (SIPR0+2), IINCHIP_READ (SIPR0+3)); /* Get Http Address */ printf("\r\n Please enter a HTTP Address without 'http://' \n\r"); printf("http://"); memset(url,0,sizeof(url)); //Modified by Gang 2011-10-04 zScanf_s(1, url); printf("\r\n Your HTTP address is: %s \r\n",url); /* Parse URL Path */ split = strchr((char const*)url,'/'); strcpy((char*)url_path,split); printf("Domain path: %s \r\n",url_path); /* Parse URL Domain */ split = strtok((char*)url,"/"); strcpy((char*)url_dn,split); printf("Domain name: %s \r\n",url_dn); /* Do DNS Client */ memset(httpclient_NetInfo.HTTPs_IP,0,sizeof(httpclient_NetInfo.HTTPs_IP)); //Delay_ms(10); done_dns = dns_query(DNS_SOCK, url_dn, httpclient_NetInfo.HTTPs_IP); printf("\r\n HTTPs_IP= %d.%d.%d.%d",httpclient_NetInfo.HTTPs_IP[0],httpclient_NetInfo.HTTPs_IP[1],httpclient_NetInfo.HTTPs_IP[2],httpclient_NetInfo.HTTPs_IP[3]); while(done_dns) { /* Do HTTP Client */ done_http = http_client(HTTPC_SOCK, httpclient_NetInfo.HTTPs_IP, url_path, url_dn,data_buf); if(done_http) { // on success, done_dns is not '0' #define Recieved_DATA #ifdef Recieved_DATA printf("\r\n<< Recieved Data -- START>> \r\n"); for(i=0; i<done_http; i++){ printf("%c",(uint8)data_buf[i]); } printf("\r\n"); printf("<< Recieved Data -- END>> \r\n"); #endif /* parsed index */ //All other HTML elements are nested between the opening <html> and </html> tags. start_idx = pased_idx((uint8 *)str_start , sizeof(str_start), done_http ); end_idx = pased_idx((uint8 *)str_end , sizeof(str_end), done_http ); /* printf get <html> ...</html> */ for(i=start_idx; i<(end_idx+7); i++){ /* remove header */ data_buf[i-start_idx] = data_buf[i]; } printf("\r\n"); /* replace <br> tag to \r\n */ //The br tag is used for specifying a line break. do{ tmp_idx = pased_idx((uint8*)BR, sizeof(BR) , end_idx-start_idx) ; if(tmp_idx == 0 ) break; memcpy((uint8 *)data_buf+tmp_idx, (uint8*)rBR, sizeof(rBR)) ; }while(tmp_idx!=end_idx-start_idx); #define Parsed_DATA #ifdef Parsed_DATA /* parsed DATA */ printf("\r\n<< Parsed Data -- START >>"); printf("\r\nTITLE : \r\n"); /* parse <TITLE> and </TITLE> tags */ tmp_start = pased_idx((uint8 *)TITLE , sizeof(TITLE),(end_idx-start_idx) ) + sizeof(TITLE); tmp_end = pased_idx((uint8 *)bTITLE , sizeof(bTITLE),(end_idx-start_idx) ); for(i=tmp_start; i<tmp_end; i++){ printf("%c",(uint8)data_buf[i]); // printf title } printf("\r\n BODY : \r\n"); /*DO NOT PRINT TAG COMMAND: between '<' with '>' */ for(i=tmp_end; i<(end_idx-start_idx); i++){ //Tag command - ex.)<PRE> //'<' is a start point of tag command. if((uint8)data_buf[i]=='<'){ no_pr = 0; } //'>' is a end point of Tag command. //To avoid in row tags -> ex.) <PRE><H1> if((uint8)data_buf[i]=='>' && (uint8)data_buf[i+1] !='<' ) { no_pr = 1; i++; } if(no_pr){ Delay_ms(1); printf("%c",(uint8)data_buf[i]); } } printf("\r\n<< Parsed Data -- END >>\r\n"); #endif /* Init. parameter */ start_idx= 0; end_idx= 0; done_dns = 0; break; } //done_http //done_dns=0; }//while : done_dns == 1 } }