示例#1
0
/*
 * CommLoadSettings:  Load comm parameters from INI file.
 *  If use_defaults is False, try to load fonts from INI file.
 *  Otherwise use default comm settings.
 */
void CommLoadSettings(void)
{
   config.comm.timeout = GetConfigInt(comm_section, INIRedialDelay, DefaultRedialDelay, ini_file);

   GetPrivateProfileString(comm_section, INIHostname, DefaultHostname, 
			   inihost, MAXHOST, ini_file);
   GetPrivateProfileString(comm_section, INIDomainFormat, DefaultDomainFormat, 
			   config.comm.domainformat, MAXHOST, ini_file);
   if (!strstr(config.comm.domainformat, "%d"))
      strcpy(config.comm.domainformat, DefaultDomainFormat);
   config.comm.server_num = GetConfigInt(comm_section, INIServerNum, DefaultServerNum, ini_file);

   // We read the DomainFormat INI value (which we don't write into the INI)
   // and we set the hostname from that and the specified server number.
   //
   // A Meridian Service Provider other than NDS can supply another
   // value for DomainFormat in either the code (DefaultDomainFormat)
   // or by setting Domain=msp%d.foobar.co.sw in the INI.
   // We require there to be one %d in the format somewhere.
   //
   ConfigSetServerNameByNumber(config.comm.server_num);

   // What's the default port number we should connect to?  This varies by server number.
   config.comm.sockport = GetConfigInt(comm_section, INISockPort, -1, ini_file);

   if (config.comm.sockport == -1)
   {
      // We have no socket number set in the .ini file.
      config.comm.constant_port = False;
      ConfigSetSocketPortByNumber(config.comm.server_num);
   }
   else
   {
      config.comm.constant_port = True;
   }

}
示例#2
0
/*
 * LoginDialogProc:  Get login information.
 */
BOOL CALLBACK LoginDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   static HWND hUser, hPasswd, hServer;        /* Edit boxes in dialog */
   static HWND hGroupBox, hTryPreviewButton;
   int value;
   BOOL success;

   switch (message)
   {
   case WM_INITDIALOG:
      CenterWindow(hDlg, GetParent(hDlg));
      hUser = GetDlgItem(hDlg, IDC_USERNAME);
      hPasswd = GetDlgItem(hDlg, IDC_PASSWORD);
      hServer = GetDlgItem(hDlg, IDC_SERVERNUM);
      hGroupBox = GetDlgItem(hDlg, IDC_NEW_TO_MERIDIAN_59);

      Edit_LimitText(hUser, MAXUSERNAME);
      Edit_LimitText(hPasswd, MAXPASSWORD);
      Edit_LimitText(hServer, MAXSERVERNUM);

      SetWindowFont(hUser, GetFont(FONT_INPUT), FALSE);
      SetWindowFont(hPasswd, GetFont(FONT_INPUT), FALSE);
      SetWindowFont(hServer, GetFont(FONT_INPUT), FALSE);

      // Set server number, if it's valid
      if (config.comm.server_num != -1)
      {
         SetDlgItemInt(hDlg, IDC_SERVERNUM, config.comm.server_num, FALSE);
	 
	 // If already logged in, can't change server number
	 if (connection != CON_NONE)
	    EnableWindow(hServer, FALSE);
      }

      /* If we have a default name, go to password edit box */
      Edit_SetText(hUser, config.username);
      Edit_SetSel(hUser, 0, -1);
      if (config.guest)
      {
	 RECT rc;
	 int bottom;
	 Edit_SetText(hUser, "GUEST");
	 Edit_SetText(hPasswd, "GUEST");
	 EnableWindow(hUser, FALSE);
	 EnableWindow(hPasswd, FALSE);
	 EnableWindow(hServer, FALSE);	 
	 EnableWindow(GetDlgItem(hDlg,IDC_OK), FALSE);
	 GetWindowRect(hGroupBox, &rc);
	 bottom = rc.bottom + 5;
	 GetWindowRect(hDlg, &rc);
	 MoveWindow(hDlg, rc.left, rc.top, rc.right - rc.left, bottom - rc.top, TRUE);
      }
      else if (strlen(config.username) > 0)
      {
	 Edit_SetText(hPasswd, config.password);
	 Edit_SetSel(hPasswd, 0, -1);
	 SetFocus(hPasswd);
	 return 0;  /* We have already set focus */
      }
      return 1;     /* Set focus to default window */
      
   case BK_DIALOGDONE:
      EndDialog(hDlg, IDOK);
      return TRUE;

   case WM_COMMAND:
      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDC_GUEST:
	 strcpy(config.username, "GUEST");
	 strcpy(config.password, "GUEST");
	 ConfigSetServerNameByNumber(config.server_guest);
	 ConfigSetSocketPortByNumber(config.server_guest);
	 config.comm.server_num = config.server_guest;
	 EndDialog(hDlg, IDOK);
	 return TRUE;

      case IDC_HOMEPAGE:
	 {
	    char url[256];
	    LoadString(hInst,IDS_HOMEPAGEURL,url,sizeof(url));
	    if (*url)
	    {
	       WebLaunchBrowser(url);
	       EndDialog(hDlg, IDCANCEL);
	       PostMessage(hMain,WM_SYSCOMMAND,SC_CLOSE,0);
	    }
	 }
	 return TRUE;

      case IDOK:
	 /* User has pressed return on one of the edit boxes */
	 if (GetFocus() == hUser)
	 {
	    SetFocus(hPasswd);
	    return True;
	 }
	 
	 if (GetFocus() == hPasswd)
	 {
	    // Go to server edit box if it's empty
	    value = GetDlgItemInt(hDlg, IDC_SERVERNUM, &success, FALSE);
	    
	    if (success)
	       PostMessage(hDlg, WM_COMMAND, IDC_OK, 0);
	    else SetFocus(hServer);
	    return True;	    
	 }

	 if (GetFocus() == hServer)
	    PostMessage(hDlg, WM_COMMAND, IDC_OK, 0);
	 return TRUE;

      case IDC_OK:
	 /* Get username & password */
	 Edit_GetText(hUser, config.username, MAXUSERNAME + 1);
	 Edit_GetText(hPasswd, config.password, MAXPASSWORD + 1);

	 value = GetDlgItemInt(hDlg, IDC_SERVERNUM, &success, FALSE);
	 if (!success)
	 {
	    // If logging in as "guest", no server number required
	    if (!stricmp(config.username, GetString(hInst, IDS_GUEST)))
	       value = config.server_guest;
	    else
	    {
	       ClientError(hInst, hDlg, IDS_NOSERVERNUM);
	       return TRUE;
	    }
	 }
	 
	 // If value changed, set server name and socketport
	 if (value != config.comm.server_num)
	 {
	    ConfigSetServerNameByNumber(value);
	    ConfigSetSocketPortByNumber(value);
	    config.comm.server_num = value;
	 }

	 /* Kill off dialog */
	 EndDialog(hDlg, IDOK);
	 return TRUE;

      case IDC_HANGUP:
      case IDCANCEL:
	 EndDialog(hDlg, IDCANCEL);
	 return TRUE;
      }
      break;
   }

   return FALSE;
}