From: H.G. Muller Date: Thu, 29 Nov 2012 21:14:05 +0000 (+0100) Subject: Implement auto-creation of ICS logon file X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=8baea05c6e9e63f8b1b57891b67b5ac0e1961b81;p=xboard.git Implement auto-creation of ICS logon file Under control of the new option -autoCreateLogon (which can be set from the ICS Options dialog) the first two lines in response to the ICS "login:" pompt will be saved on a newly created logon file (if logon from such an existing file failed). --- diff --git a/args.h b/args.h index acfb8f7..91270dd 100644 --- a/args.h +++ b/args.h @@ -354,6 +354,7 @@ ArgDescriptor argDescriptors[] = { { "autocomm", ArgTrue, (void *) &appData.autoComment, FALSE, INVALID }, { "xautocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID }, { "-autocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID }, + { "autoCreateLogon", ArgBoolean, (void *) &appData.autoCreateLogon, TRUE, (ArgIniType) FALSE }, { "autoObserve", ArgBoolean, (void *) &appData.autoObserve, TRUE, (ArgIniType) FALSE }, { "autobs", ArgTrue, (void *) &appData.autoObserve, FALSE, INVALID }, { "xautobs", ArgFalse, (void *) &appData.autoObserve, FALSE, INVALID }, diff --git a/backend.c b/backend.c index 71923d7..13afbc5 100644 --- a/backend.c +++ b/backend.c @@ -1845,6 +1845,7 @@ read_from_player (InputSourceRef isr, VOIDSTAR closure, char *message, int count { int outError, outCount; static int gotEof = 0; + static FILE *ini; /* Pass data read from player on to ICS */ if (count > 0) { @@ -1853,6 +1854,17 @@ read_from_player (InputSourceRef isr, VOIDSTAR closure, char *message, int count if (outCount < count) { DisplayFatalError(_("Error writing to ICS"), outError, 1); } + if(have_sent_ICS_logon == 2) { + if(ini = fopen(appData.icsLogon, "w")) { // save first two lines (presumably username & password) on init script file + fprintf(ini, "%s", message); + have_sent_ICS_logon = 3; + } else + have_sent_ICS_logon = 1; + } else if(have_sent_ICS_logon == 3) { + fprintf(ini, "%s", message); + fclose(ini); + have_sent_ICS_logon = 1; + } } else if (count < 0) { RemoveInputSource(isr); DisplayFatalError(_("Error reading from keyboard"), error, 1); @@ -3438,9 +3450,15 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int continue; } - if (!have_sent_ICS_logon && looking_at(buf, &i, "login:")) { - ICSInitScript(); - have_sent_ICS_logon = 1; + if (looking_at(buf, &i, "login:")) { + if (!have_sent_ICS_logon) { + if(ICSInitScript()) + have_sent_ICS_logon = 1; + else // no init script was found + have_sent_ICS_logon = (appData.autoCreateLogon ? 2 : 1); // flag that we should capture username + password + } else { // we have sent (or created) the InitScript, but apparently the ICS rejected it + have_sent_ICS_logon = (appData.autoCreateLogon ? 2 : 1); // request creation of a new script + } continue; } diff --git a/common.h b/common.h index 0a6a163..90428b4 100644 --- a/common.h +++ b/common.h @@ -483,6 +483,7 @@ typedef struct { Boolean ponderNextMove; Boolean periodicUpdates; Boolean autoObserve; + Boolean autoCreateLogon; Boolean autoComment; Boolean getMoveList; Boolean testLegality; diff --git a/dialogs.c b/dialogs.c index d7ab360..877d88c 100644 --- a/dialogs.c +++ b/dialogs.c @@ -569,6 +569,7 @@ Option icsOptions[] = { { 0, 0, 0, NULL, (void*) &appData.autoComment, "", NULL, CheckBox, N_("Auto-Comment") }, { 0, 0, 0, NULL, (void*) &appData.autoObserve, "", NULL, CheckBox, N_("Auto-Observe") }, { 0, 0, 0, NULL, (void*) &appData.autoRaiseBoard, "", NULL, CheckBox, N_("Auto-Raise Board") }, +{ 0, 0, 0, NULL, (void*) &appData.autoCreateLogon, "", NULL, CheckBox, N_("Auto-Create Logon Script") }, { 0, 0, 0, NULL, (void*) &appData.bgObserve, "", NULL, CheckBox, N_("Background Observe while Playing") }, { 0, 0, 0, NULL, (void*) &appData.dualBoard, "", NULL, CheckBox, N_("Dual Board for Background-Observed Game") }, { 0, 0, 0, NULL, (void*) &appData.getMoveList, "", NULL, CheckBox, N_("Get Move List") }, diff --git a/frontend.h b/frontend.h index 64cd79f..1f0bb1d 100644 --- a/frontend.h +++ b/frontend.h @@ -185,7 +185,7 @@ void TagsPopUp P((char *tags, char *msg)); void TagsPopDown P((void)); void ParseIcsTextColors P((void)); -void ICSInitScript P((void)); +int ICSInitScript P((void)); void StartAnalysisClock P((void)); void EngineOutputPopUp P((void)); void EgineOutputPopDown P((void)); diff --git a/gtk/xboard.c b/gtk/xboard.c index a3add4a..c5f81e8 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -199,7 +199,6 @@ void MoveTypeInProc P((GdkEventKey *eventkey)); gboolean KeyPressProc P((GtkWindow *window, GdkEventKey *eventkey, gpointer data)); Boolean TempBackwardActive = False; void DisplayMove P((int moveNumber)); -void ICSInitScript P((void)); void update_ics_width P(()); int CopyMemoProc P(()); static gboolean EventProc P((GtkWidget *widget, GdkEvent *event, gpointer g)); diff --git a/usystem.c b/usystem.c index d2571df..bab1303 100644 --- a/usystem.c +++ b/usystem.c @@ -712,7 +712,7 @@ OutputToProcessDelayed (ProcRef pr, char *message, int count, int *outError, lon return outCount; } -void +int ICSInitScript () { /* try to open the icsLogon script, either in the location given @@ -736,12 +736,13 @@ ICSInitScript () } } - if (f != NULL) + if (f != NULL) { ProcessICSInitScript(f); - else + return TRUE; + } else printf("Warning: Couldn't open icsLogon file (checked %s and %s).\n", appData.icsLogon, buf); - return; + return FALSE; } void diff --git a/winboard/resource.h b/winboard/resource.h index e571c68..7b07764 100644 --- a/winboard/resource.h +++ b/winboard/resource.h @@ -338,6 +338,7 @@ #define CBO_Sounds 1350 #define OPT_DefaultSounds 1351 #define OPT_AlwaysOnTop 1352 +#define OPT_AutoCreate 1352 #define OPT_AutoFlag 1353 #define OPT_AlwaysQueen 1354 #define OPT_AutoComment 1354 diff --git a/winboard/winboard.c b/winboard/winboard.c index 1651947..8420e3b 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -9764,7 +9764,7 @@ CmailSigHandlerCallBack(InputSourceRef isr, VOIDSTAR closure, /* see wedittags.c for Edit Tags functions */ -VOID +int ICSInitScript() { FILE *f; @@ -9776,8 +9776,10 @@ ICSInitScript() if (f != NULL) { ProcessICSInitScript(f); fclose(f); + return TRUE; } } + return FALSE; } diff --git a/winboard/winboard.h b/winboard/winboard.h index f3b1439..c1a846e 100644 --- a/winboard/winboard.h +++ b/winboard/winboard.h @@ -106,7 +106,7 @@ VOID InitAppData(LPSTR); VOID InitDrawingColors(VOID); VOID InitDrawingSizes(BoardSize boardSize, int flags); VOID InitMenuChecks(VOID); -VOID ICSInitScript(VOID); +int ICSInitScript(VOID); BOOL CenterWindow(HWND hwndChild, HWND hwndParent); VOID ResizeEditPlusButtons(HWND hDlg, HWND hText, int sizeX, int sizeY, int newSizeX, int newSizeY); VOID PromotionPopup(HWND hwnd); diff --git a/winboard/winboard.rc b/winboard/winboard.rc index 1457af1..ee32188 100644 --- a/winboard/winboard.rc +++ b/winboard/winboard.rc @@ -513,7 +513,9 @@ BEGIN CONTROL "&Auto Kibitz",OPT_AutoKibitz,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,94,12,73,8 CONTROL "Auto &Observe",OPT_AutoObserve,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,10,25,150,8 + WS_TABSTOP,10,25,73,8 + CONTROL "Auto &Create Logon",OPT_AutoCreate,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,94,25,73,8 CONTROL "&Get Move List",OPT_GetMoveList,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,10,38,150,8 CONTROL "&Local Line Editing",OPT_LocalLineEditing,"Button", diff --git a/winboard/woptions.c b/winboard/woptions.c index e548360..cfd5cdb 100644 --- a/winboard/woptions.c +++ b/winboard/woptions.c @@ -1188,6 +1188,7 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) CHECK_BOX(OPT_AutoKibitz, appData.autoKibitz); CHECK_BOX(OPT_AutoComment, appData.autoComment); CHECK_BOX(OPT_AutoObserve, appData.autoObserve); + CHECK_BOX(OPT_AutoCreate, appData.autoCreateLogon); CHECK_BOX(OPT_GetMoveList, appData.getMoveList); CHECK_BOX(OPT_LocalLineEditing, appData.localLineEditing); CHECK_BOX(OPT_QuietPlay, appData.quietPlay); @@ -1273,6 +1274,7 @@ IcsOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) appData.autoKibitz = IS_CHECKED(OPT_AutoKibitz); appData.autoComment = IS_CHECKED(OPT_AutoComment); appData.autoObserve = IS_CHECKED(OPT_AutoObserve); + appData.autoCreateLogon = IS_CHECKED(OPT_AutoCreate); appData.getMoveList = IS_CHECKED(OPT_GetMoveList); appData.localLineEditing = IS_CHECKED(OPT_LocalLineEditing); appData.quietPlay = IS_CHECKED(OPT_QuietPlay); diff --git a/xaw/xboard.c b/xaw/xboard.c index 5bf3b0c..d8f3df2 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -260,7 +260,6 @@ void TempForwardProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) Boolean TempBackwardActive = False; void ManInner P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DisplayMove P((int moveNumber)); -void ICSInitScript P((void)); void update_ics_width P(()); int CopyMemoProc P(());