summaryrefslogtreecommitdiff
path: root/Cmd.c
diff options
context:
space:
mode:
authorg8bpq <john.wiseman@cantab.net>2022-11-23 10:56:20 +0000
committerg8bpq <john.wiseman@cantab.net>2022-11-23 10:56:20 +0000
commitbe0f2b85761c40cbdc7339bbe722fad2d5e1eca4 (patch)
tree540662950bf06baabe89479a73adede3b484c392 /Cmd.c
parent6c6848bdcbedcee989fefdd8d39105e7022aeae3 (diff)
6.0.23.2923.30
Diffstat (limited to 'Cmd.c')
-rw-r--r--Cmd.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/Cmd.c b/Cmd.c
index 71fbd11..31dd130 100644
--- a/Cmd.c
+++ b/Cmd.c
@@ -169,6 +169,9 @@ VOID FLMSG(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * Us
void ListExcludedCalls(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID APRSCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
VOID RECONFIGTELNET (TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
+VOID HELPCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD);
+
+
char * __cdecl Cmdprintf(TRANSPORTENTRY * Session, char * Bufferptr, const char * format, ...)
{
@@ -4205,6 +4208,7 @@ CMDX COMMANDS[] =
"BYE ",1,BYECMD,0,
"QUIT ",1,BYECMD,0,
"INFO ",1,CMDI00,0,
+ "HELP ",1,HELPCMD,0,
"VERSION ",1,CMDV00,0,
"NODES ",1,CMDN00,0,
"LINKS ",1,CMDL00,0,
@@ -5496,6 +5500,93 @@ BOOL isSYSOP(TRANSPORTENTRY * Session, char * Bufferptr)
return TRUE;
}
+VOID HELPCMD(TRANSPORTENTRY * Session, char * Bufferptr, char * CmdTail, CMDX * CMD)
+{
+ int FileSize;
+ char MsgFile[MAX_PATH];
+ FILE * hFile;
+ char * MsgBytes;
+ struct stat STAT;
+ char * ptr1, * ptr, * ptr2;
+
+ sprintf_s(MsgFile, sizeof(MsgFile), "%s/%s", BPQDirectory, "NodeHelp.txt");
+
+ if (stat(MsgFile, &STAT) == -1)
+ {
+ Bufferptr = Cmdprintf(Session, Bufferptr, "Help file not found\r");
+ SendCommandReply(Session, REPLYBUFFER, (int)(Bufferptr - (char *)REPLYBUFFER));
+ return;
+ }
+
+ FileSize = STAT.st_size;
+
+ hFile = fopen(MsgFile, "rb");
+
+ if (hFile == NULL)
+ {
+ Bufferptr = Cmdprintf(Session, Bufferptr, "Help file not found\r");
+ SendCommandReply(Session, REPLYBUFFER, (int)(Bufferptr - (char *)REPLYBUFFER));
+ return;
+ }
+
+ MsgBytes = malloc(FileSize+1);
+
+ fread(MsgBytes, 1, FileSize, hFile);
+
+ fclose(hFile);
+
+ MsgBytes[FileSize] = 0;
+
+ ptr1 = MsgBytes;
+
+ // Replace LF or CRLF with CR
+
+ // First remove cr from crlf
+
+ while(ptr2 = strstr(ptr1, "\r\n"))
+ {
+ memmove(ptr2, ptr2 + 1, strlen(ptr2));
+ }
+
+ // Now replace lf with cr
+
+ ptr1 = MsgBytes;
+
+ while (*ptr1)
+ {
+ if (*ptr1 == '\n')
+ *(ptr1) = '\r';
+
+ ptr1++;
+ }
+
+ ptr = ptr1 = MsgBytes;
+
+ Bufferptr = Cmdprintf(Session, Bufferptr, "\r");
+
+ // Read and send a line at a time, converting any line endings into CR
+
+ while (*ptr1)
+ {
+ if (*ptr1 == '\r')
+ {
+ *(ptr1++) = 0;
+
+ Bufferptr = Cmdprintf(Session, Bufferptr, "%s\r", ptr);
+
+ ptr = ptr1;
+ }
+ else
+ ptr1++;
+ }
+
+ free(MsgBytes);
+ SendCommandReply(Session, REPLYBUFFER, (int)(Bufferptr - (char *)REPLYBUFFER));
+}
+
+
+
+