Skip to content

Commit

Permalink
Implement auto-creation of ICS logon file
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
HGMuller committed Dec 7, 2012
1 parent 50ffaff commit 8baea05
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
24 changes: 21 additions & 3 deletions backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ typedef struct {
Boolean ponderNextMove;
Boolean periodicUpdates;
Boolean autoObserve;
Boolean autoCreateLogon;
Boolean autoComment;
Boolean getMoveList;
Boolean testLegality;
Expand Down
1 change: 1 addition & 0 deletions dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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") },
Expand Down
2 changes: 1 addition & 1 deletion frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion gtk/xboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
9 changes: 5 additions & 4 deletions usystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions winboard/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion winboard/winboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -9764,7 +9764,7 @@ CmailSigHandlerCallBack(InputSourceRef isr, VOIDSTAR closure,
/* see wedittags.c for Edit Tags functions */


VOID
int
ICSInitScript()
{
FILE *f;
Expand All @@ -9776,8 +9776,10 @@ ICSInitScript()
if (f != NULL) {
ProcessICSInitScript(f);
fclose(f);
return TRUE;
}
}
return FALSE;
}


Expand Down
2 changes: 1 addition & 1 deletion winboard/winboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion winboard/winboard.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions winboard/woptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion xaw/xboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(());

Expand Down

0 comments on commit 8baea05

Please sign in to comment.