Пример #1
0
void CNewsHubDlg::OnBnClickedSend()
{
  CListBox* pRunningClients = (CListBox*)GetDlgItem(IDC_RUNNING_CLIENTS);

  int row = pRunningClients->GetCurSel();
  if (row == LB_ERR)
  {
    MessageBox(_T("Please select one of running clients to send message through"), _T("No client selected"), MB_OK);
    return;
  }

  CEdit* pMessage = (CEdit*)GetDlgItem(IDC_MESSAGE);
  CString message;
  pMessage->GetWindowText(message);

  ClientLoop* clientLoop = (ClientLoop*)pRunningClients->GetItemDataPtr(row);
  unsigned int messageId = clientLoop->nextMessageId();
  clientLoop->Queue()->AddMessage(messageId, std::string(CT2CA(message)));

  CListBox* pSentMessages = (CListBox*)GetDlgItem(IDC_SENT_MESSAGES);
  NewsHub::TcpClient* tcpClient = (NewsHub::TcpClient*)clientLoop->Client();
  CString str;
  str.Format(_T("(To: %s:%d msgId:%d): %s"), 
    CString(tcpClient->Host().c_str()), tcpClient->Port(), messageId, message);

  row = pSentMessages->AddString(str);

  MessageInfo* messageInfo = new MessageInfo;
  messageInfo->queue = clientLoop->Queue();
  messageInfo->messageId = messageId;
  pSentMessages->SetItemDataPtr(row, messageInfo);

  pSentMessages->SetCurSel(row);
}
Пример #2
0
void CNewsHubDlg::OnBnClickedServerStart()
{
  CEdit* pPort = (CEdit*)GetDlgItem(IDC_SERVER_PORT);
  CString strPort;
  pPort->GetWindowText(strPort);
  int port = atoi(CT2CA(strPort));

  CButton* pServerTcp = (CButton*)GetDlgItem(IDC_SERVER_TCP);
  bool bTcp = (pServerTcp->GetCheck() == BST_CHECKED);

  ServerLoop* serverLoop;
  try
  {
    NewsHub::Server* server;
    if (bTcp)
      server = new NewsHub::TcpServer(port);
    else
      server = new NewsHub::UdpServer(port);
    serverLoop = new ServerLoop(server, new NewsHub::ServerThreadLoop(*server, *this, bTcp));
  }
  catch (std::exception & e)
  {
    MessageBox(CString(e.what()), _T("Exception"), MB_OK);
    return;
  }

  CString serverDescription = CString(bTcp?"TCP":"UDP") + CString(" server is listening on port ") + strPort; 

  CListBox* pRunningServers = (CListBox*)GetDlgItem(IDC_RUNNING_SERVERS);
  int row = pRunningServers->AddString(serverDescription);
  pRunningServers->SetItemDataPtr(row, serverLoop);
}
Пример #3
0
void CNewsHubDlg::MessageDelivered(NewsHub::ClientQueueThreadLoop* queue, const NewsHub::Socket & socket, const unsigned int messageId, const std::string & message)
{
  CListBox* pSentMessages = (CListBox*)GetDlgItem(IDC_SENT_MESSAGES);
  for (int i = 0; i < pSentMessages->GetCount(); ++i)
  {
    MessageInfo* messageInfo = (MessageInfo*)pSentMessages->GetItemDataPtr(i);
    if ((messageInfo->queue == queue) && (messageInfo->messageId == messageId))
    {
      CString str;
      pSentMessages->GetText(i, str);
      pSentMessages->DeleteString(i);
      pSentMessages->InsertString(i, str + _T(": Delivered"));
      pSentMessages->SetItemDataPtr(i, messageInfo);
      pSentMessages->SetCurSel(i);
      break;
    }
  }
}
Пример #4
0
void CNewsHubDlg::OnBnClickedClientStart()
{
  CEdit* pPort = (CEdit*)GetDlgItem(IDC_PORT);
  CEdit* pHost = (CEdit*)GetDlgItem(IDC_HOST);
  CEdit* pTimeout = (CEdit*)GetDlgItem(IDC_TIMEOUT);

  CString host, strPort, strTimeout;
  pHost->GetWindowText(host);
  pPort->GetWindowText(strPort);
  pTimeout->GetWindowText(strTimeout);
  int port = atoi(CT2CA(strPort));
  int timeout = atoi(CT2CA(strTimeout));

  CButton* pClientTcp = (CButton*)GetDlgItem(IDC_CLIENT_TCP);
  bool bTcp = (pClientTcp->GetCheck() == BST_CHECKED);

  ClientLoop* clientLoop;
  try
  {
    NewsHub::Client* client;
    if (bTcp)
      client = new NewsHub::TcpClient(std::string(CT2CA(host)), port);
    else
      client = new NewsHub::UdpClient(std::string(CT2CA(host)), port);

    clientLoop = new ClientLoop(client, new NewsHub::ClientQueueThreadLoop(*client, *this, timeout * 1000));
  }
  catch (std::exception & e)
  {
    MessageBox(CString(e.what()), _T("Exception"), MB_OK);
    return;
  }

  CString clientDescription = CString(bTcp?"TCP":"UDP") + CString(" client to host ") + host + CString(" on port ") + strPort; 

  CListBox* pRunningClients = (CListBox*)GetDlgItem(IDC_RUNNING_CLIENTS);
  int row = pRunningClients->AddString(clientDescription);
  pRunningClients->SetItemDataPtr(row, clientLoop);
}
Пример #5
0
//-----------------------------------------------------------------------
// EVENTS: Connect/Disconnect implementation
//-----------------------------------------------------------------------
void CFanmotorDlg::AddBridgeEvent(BSTR BridgeID)
{
	VARIANT version;
	CString dummyStr = L""; //Need this var in order to VariantClear() ->
	BSTR emptyStr = dummyStr.AllocSysString(); // works in case of empty Version string

	for (int i=0; i<5; i++)
	{	
		VariantInit(&version);
	    VARIANT r = Bridge->GetBridgeVersion(BridgeID, &version);
		Bridge->AbortTransfer(); // Deactivate Bridge (optionally) after "GetBridgeVersion" operation
		if (r.bVal == 34) break;// operation finished successfully
		else version.bstrVal = emptyStr;
	}
	CBridgeInfo* bridgeInfo = new CBridgeInfo(BridgeID,version.bstrVal);
	CString strInfo;
	bridgeInfo->GetBridgeInfo(strInfo);
	
	CListBox* listBoxBridges = (CListBox*)GetDlgItem(IDC_BRIDGE_LISTBOX);
	int index = listBoxBridges->AddString(strInfo);
	listBoxBridges->SetItemDataPtr(index, bridgeInfo);
	
	VariantClear(&version);
}
Пример #6
0
BOOL WeaponEditorDlg::OnInitDialog() 
{
	int i, z, big = 1, end1, end2, inst, flag = 0;
	object *ptr;
	model_subsystem *psub;
	ship_subsys *ssl, *pss;
	CComboBox *box;
	CListBox *list;

	CDialog::OnInitDialog();
	m_ship = cur_ship;
	if (m_ship == -1)
		m_ship = Objects[cur_object_index].instance;

	end1 = First_secondary_index;
	end2 = Num_weapon_types;

	list = (CListBox *) GetDlgItem(IDC_LIST);

	z = list->AddString("Pilot");
	if (m_multi_edit) {
		list->SetItemDataPtr(z, &pilot);
		ptr = GET_FIRST(&obj_used_list);
		while (ptr != END_OF_LIST(&obj_used_list)) {
			if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags[Object::Object_Flags::Marked])) {
				inst = ptr->instance;
                if (!(Ship_info[Ships[inst].ship_info_index].is_big_or_huge()))
					big = 0;

				if (!flag) {
					pilot = Ships[inst].weapons;
					m_ship_class = Ships[inst].ship_info_index;
					flag = 1;

				} else {
					Assert(Ships[inst].ship_info_index == m_ship_class);
					if (pilot.ai_class != Ships[inst].weapons.ai_class)
						pilot.ai_class = BLANK_FIELD;

					for (i=0; i<MAX_SHIP_PRIMARY_BANKS; i++)
						if (pilot.primary_bank_weapons[i] != Ships[inst].weapons.primary_bank_weapons[i])
							pilot.primary_bank_weapons[i] = BLANK_FIELD;

					for (i=0; i<MAX_SHIP_SECONDARY_BANKS; i++) {
						if (pilot.secondary_bank_weapons[i] != Ships[inst].weapons.secondary_bank_weapons[i])
							pilot.secondary_bank_weapons[i] = BLANK_FIELD;
						if (pilot.secondary_bank_ammo[i] != Ships[inst].weapons.secondary_bank_ammo[i])
							pilot.secondary_bank_ammo[i] = BLANK_FIELD;
					}
				}
			}

			ptr = GET_NEXT(ptr);
		}

	} else {
        if (!(Ship_info[Ships[m_ship].ship_info_index].is_big_or_huge()))
			big = 0;

		m_ship_class = Ships[m_ship].ship_info_index;
		list->SetItemDataPtr(z, &Ships[m_ship].weapons);
		ssl = &Ships[m_ship].subsys_list;
		for (pss = GET_FIRST(ssl); pss != END_OF_LIST(ssl); pss = GET_NEXT(pss)) {
			psub = pss->system_info;
			if (psub->type == SUBSYSTEM_TURRET) {
				z = list->AddString(psub->subobj_name);
				list->SetItemDataPtr(z, &pss->weapons);
			}
		}
	}

	box = (CComboBox *) GetDlgItem(IDC_AI_CLASS);
	for (i=0; i<Num_ai_classes; i++){
		box->AddString(Ai_class_names[i]);
	}

	for (i=0; i<end1; i++){
		if ((Weapon_info[i].wi_flags & WIF_CHILD) || (!big && (Weapon_info[i].wi_flags & WIF_BIG_ONLY))){
			end1 = i;
		}
	}

	box = (CComboBox *) GetDlgItem(IDC_GUN1);
	box->AddString("None");
	for (i=0; i<end1; i++){
		box->AddString(Weapon_info[i].name);
	}

	box = (CComboBox *) GetDlgItem(IDC_GUN2);
	box->AddString("None");
	for (i=0; i<end1; i++){
		box->AddString(Weapon_info[i].name);
	}

	box = (CComboBox *) GetDlgItem(IDC_GUN3);
	box->AddString("None");
	for (i=0; i<end1; i++){
		box->AddString(Weapon_info[i].name);
	}

	for (i=First_secondary_index; i<end2; i++){
		if ((Weapon_info[i].wi_flags & WIF_CHILD) || (!big && (Weapon_info[i].wi_flags & WIF_BIG_ONLY))){
			end2 = i;
		}
	}

	box = (CComboBox *) GetDlgItem(IDC_MISSILE1);
	box->AddString("None");
	for (i=First_secondary_index; i<end2; i++){
		box->AddString(Weapon_info[i].name);
	}

	box = (CComboBox *) GetDlgItem(IDC_MISSILE2);
	box->AddString("None");
	for (i=First_secondary_index; i<end2; i++){
		box->AddString(Weapon_info[i].name);
	}

	box = (CComboBox *) GetDlgItem(IDC_MISSILE3);
	box->AddString("None");
	for (i=First_secondary_index; i<end2; i++){
		box->AddString(Weapon_info[i].name);
	}

	box = (CComboBox *) GetDlgItem(IDC_MISSILE4);
	box->AddString("None");
	for (i=First_secondary_index; i<end2; i++){
		box->AddString(Weapon_info[i].name);
	}

	m_cur_item = 0;
	UpdateData(FALSE);
	change_selection();
	UpdateData(TRUE);
	return TRUE;
}