Completed client/server communications encoding

This commit is contained in:
Michiel Broek 2005-10-17 18:02:00 +00:00
parent 32e892d5b6
commit 2304c874a0
10 changed files with 59 additions and 50 deletions

View File

@ -51,7 +51,7 @@ int socket_connect(char *user, char *prg, char *city)
{ {
int s; int s;
static char buf[SS_BUFSIZE], tty[18]; static char buf[SS_BUFSIZE], tty[18];
char *tmp; char *tmp, *u, *p, *c;
myname = prg; myname = prg;
@ -117,7 +117,13 @@ int socket_connect(char *user, char *prg, char *city)
/* /*
* Send the information to the server. * Send the information to the server.
*/ */
snprintf(buf, SS_BUFSIZE, "AINI:5,%d,%s,%s,%s,%s;", getpid(), tty, user, prg, city); u = xstrcpy(clencode(user));
p = xstrcpy(clencode(prg));
c = xstrcpy(clencode(city));
snprintf(buf, SS_BUFSIZE, "AINI:5,%d,%s,%s,%s,%s;", getpid(), tty, u, p, c);
free(c);
free(p);
free(u);
if (socket_send(buf) != 0) { if (socket_send(buf) != 0) {
sock = -1; sock = -1;
return -1; return -1;

View File

@ -547,15 +547,20 @@ void Chat(int sysop)
{ {
int curpos = 0, stop = FALSE, data, rc; int curpos = 0, stop = FALSE, data, rc;
unsigned char ch = 0; unsigned char ch = 0;
char sbuf[81], resp[128]; char sbuf[81], resp[128], *sysop_name, *name;
static char buf[200]; static char buf[200];
clr_index(); clr_index();
rsize = rows - 7; rsize = rows - 7;
rpointer = 0; rpointer = 0;
snprintf(buf, 200, "CCON,4,%d,%s,%s,%s;", mypid, CFG.sysop_name, CFG.sysop, sysop ? "1":"0"); sysop_name = xstrcpy(clencode(CFG.sysop_name));
name = xstrcpy(clencode(CFG.sysop));
snprintf(buf, 200, "CCON,4,%d,%s,%s,%s;", mypid, sysop_name, name, sysop ? "1":"0");
free(sysop_name);
free(name);
Syslog('-', "> %s", buf); Syslog('-', "> %s", buf);
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
Syslog('-', "< %s", buf); Syslog('-', "< %s", buf);
@ -611,8 +616,7 @@ void Chat(int sysop)
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
rc = atoi(resp); rc = atoi(resp);
memset(&resp, 0, sizeof(resp)); memset(&resp, 0, sizeof(resp));
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -657,7 +661,7 @@ void Chat(int sysop)
putchar(7); putchar(7);
} }
} else if ((ch == '\r') && curpos) { } else if ((ch == '\r') && curpos) {
snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, sbuf); snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, clencode(sbuf));
Syslog('-', "> %s", buf); Syslog('-', "> %s", buf);
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
@ -667,8 +671,7 @@ void Chat(int sysop)
strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */ strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error, end chat */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error, end chat */
rc = atoi(resp); rc = atoi(resp);
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -701,8 +704,7 @@ void Chat(int sysop)
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
rc = atoi(resp); rc = atoi(resp);
memset(&resp, 0, sizeof(resp)); memset(&resp, 0, sizeof(resp));
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -722,8 +724,6 @@ void Chat(int sysop)
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
Syslog('-', "< %s", buf); Syslog('-', "< %s", buf);
if (strncmp(buf, "100:1,", 6)) {
}
} }
sleep(1); sleep(1);
} }

View File

@ -419,8 +419,7 @@ void show_date(int fg, int bg, int y, int x)
pid = strtok(buf, ","); pid = strtok(buf, ",");
pid = strtok(NULL, ","); pid = strtok(NULL, ",");
page = strtok(NULL, ","); page = strtok(NULL, ",");
reason = strtok(NULL, "\0"); reason = xstrcpy(cldecode(strtok(NULL, ";")));
reason[strlen(reason)-1] = '\0';
if (strlen(reason) > 60) if (strlen(reason) > 60)
reason[60] = '\0'; reason[60] = '\0';
@ -435,6 +434,7 @@ void show_date(int fg, int bg, int y, int x)
mbse_mvprintw(3, 1, " Sysop page (%s) %-60s", pid, reason); mbse_mvprintw(3, 1, " Sysop page (%s) %-60s", pid, reason);
putchar(7); /* Each second */ putchar(7); /* Each second */
} }
free(reason);
} }
if (y && x) if (y && x)

View File

@ -167,7 +167,7 @@ void Chat(char *username, char *channel)
{ {
int curpos = 0, stop = FALSE, data, rc; int curpos = 0, stop = FALSE, data, rc;
unsigned char ch; unsigned char ch;
char sbuf[81], resp[128]; char sbuf[81], resp[128], *name, *mname;
static char buf[200]; static char buf[200];
WhosDoingWhat(SYSOPCHAT, NULL); WhosDoingWhat(SYSOPCHAT, NULL);
@ -213,7 +213,11 @@ void Chat(char *username, char *channel)
snprintf(buf, 200, "%-*s", cols -1, " MBSE BBS Chat Server"); snprintf(buf, 200, "%-*s", cols -1, " MBSE BBS Chat Server");
mvprintw(1, 1, buf); mvprintw(1, 1, buf);
snprintf(buf, 200, "CCON,4,%d,%s,%s,0;", mypid, exitinfo.sUserName, exitinfo.Name); mname = xstrcpy(clencode(exitinfo.sUserName));
name = xstrcpy(clencode(exitinfo.Name));
snprintf(buf, 200, "CCON,4,%d,%s,%s,0;", mypid, mname, name);
free(mname);
free(name);
Syslog('c', "> %s", buf); Syslog('c', "> %s", buf);
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strncpy(buf, socket_receive(), sizeof(buf)-1); strncpy(buf, socket_receive(), sizeof(buf)-1);
@ -245,10 +249,10 @@ void Chat(char *username, char *channel)
* commands to the chatserver. * commands to the chatserver.
*/ */
if (username && channel) { if (username && channel) {
snprintf(buf, 200, "CPUT:2,%d,/nick %s;", mypid, username); snprintf(buf, 200, "CPUT:2,%d,/nick %s;", mypid, clencode(username));
if (socket_send(buf) == 0) if (socket_send(buf) == 0)
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
snprintf(buf, 200, "CPUT:2,%d,/join %s;", mypid, channel); snprintf(buf, 200, "CPUT:2,%d,/join %s;", mypid, clencode(channel));
if (socket_send(buf) == 0) if (socket_send(buf) == 0)
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
} }
@ -274,8 +278,7 @@ void Chat(char *username, char *channel)
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal, chat ended */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal, chat ended */
rc = atoi(resp); rc = atoi(resp);
memset(&resp, 0, sizeof(resp)); memset(&resp, 0, sizeof(resp));
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -317,8 +320,8 @@ void Chat(char *username, char *channel)
} }
} else if ((ch == '\r') && curpos) { } else if ((ch == '\r') && curpos) {
alarm_on(); alarm_on();
snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, sbuf); snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, clencode(sbuf));
Syslog('c', "> %s", buf); Syslog('c', "> %s", clencode(buf));
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
Syslog('c', "< %s", buf); Syslog('c', "< %s", buf);
@ -327,8 +330,7 @@ void Chat(char *username, char *channel)
strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */ strncpy(resp, strtok(NULL, ","), 5); /* Should be 2 */
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal, chat ended */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal, chat ended */
rc = atoi(resp); rc = atoi(resp);
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -361,8 +363,7 @@ void Chat(char *username, char *channel)
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */ strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
rc = atoi(resp); rc = atoi(resp);
memset(&resp, 0, sizeof(resp)); memset(&resp, 0, sizeof(resp));
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
resp[strlen(resp)-1] = '\0';
DispMsg(resp); DispMsg(resp);
if (rc == 1) { if (rc == 1) {
Syslog('+', "Chat server error: %s", resp); Syslog('+', "Chat server error: %s", resp);
@ -396,8 +397,6 @@ void Chat(char *username, char *channel)
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
Syslog('c', "< %s", buf); Syslog('c', "< %s", buf);
if (strncmp(buf, "100:1,", 6)) {
}
} }
sleep(2); sleep(2);
clear(); clear();

View File

@ -68,9 +68,9 @@ int CheckStatus()
buf[strlen(buf) -1] = '\0'; buf[strlen(buf) -1] = '\0';
Enter(2); Enter(2);
PUTCHAR('\007'); PUTCHAR('\007');
snprintf(msg, 81, "*** %s ***", buf+8); snprintf(msg, 81, "*** %s ***", cldecode(buf+8));
PUTSTR(msg); PUTSTR(msg);
Syslog('+', "Send user message \"%s\"", buf+8); Syslog('+', "Send user message \"%s\"", cldecode(buf+8));
Enter(3); Enter(3);
} }
return FALSE; return FALSE;

View File

@ -146,7 +146,7 @@ void Page_Sysop(char *String)
locate(16, ((80 - CFG.iPageLength) / 2 - 2) + 1); locate(16, ((80 - CFG.iPageLength) / 2 - 2) + 1);
snprintf(buf, 128, "CPAG:2,%d,%s;", mypid, Reason); snprintf(buf, 128, "CPAG:2,%d,%s;", mypid, clencode(Reason));
if (socket_send(buf)) { if (socket_send(buf)) {
Syslog('+', "Failed to send message to mbtask"); Syslog('+', "Failed to send message to mbtask");
free(Reason); free(Reason);

View File

@ -62,9 +62,9 @@ void Check_PM(void)
if (strncmp(buf, "100:0;", 6) == 0) if (strncmp(buf, "100:0;", 6) == 0)
return; return;
strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */ strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */
strncpy(resp, strtok(NULL, ","), 3); /* Should be 2 */ strncpy(resp, strtok(NULL, ","), 3); /* Should be 2 */
strncpy(resp, strtok(NULL, ","), 36); /* From Name */ strncpy(resp, cldecode(strtok(NULL, ",")), 36); /* From Name */
Enter(2); Enter(2);
PUTCHAR('\007'); PUTCHAR('\007');
@ -72,8 +72,7 @@ void Check_PM(void)
/* ** Message ** from */ /* ** Message ** from */
snprintf(msg, 81, "%s %s:", (char *)Language(434), resp); snprintf(msg, 81, "%s %s:", (char *)Language(434), resp);
poutCR(CYAN, BLACK, msg); poutCR(CYAN, BLACK, msg);
strncpy(resp, strtok(NULL, "\0"), 80); /* The real message */ strncpy(resp, cldecode(strtok(NULL, "\0")), 80); /* The real message */
resp[strlen(resp)-1] = '\0';
PUTSTR(resp); PUTSTR(resp);
Enter(1); Enter(1);
Pause(); Pause();

View File

@ -279,10 +279,10 @@ void user(void)
/* /*
* Only mbsebbs is wanted * Only mbsebbs is wanted
*/ */
strtok(buf, ","); /* response */ strtok(buf, ","); /* response */
strtok(NULL, ","); /* pid */ strtok(NULL, ","); /* pid */
strtok(NULL, ","); /* tty */ strtok(NULL, ","); /* tty */
fullname = xstrcpy(strtok(NULL, ",")); /* username */ fullname = xstrcpy(cldecode(strtok(NULL, ","))); /* username */
if (strcmp(fullname, usrconfig.Name) == 0) { if (strcmp(fullname, usrconfig.Name) == 0) {
logins++; logins++;
} }

View File

@ -99,7 +99,7 @@ void WhosOn(char *OpData)
cnt = strtok(buf, ","); cnt = strtok(buf, ",");
strtok(NULL, ","); strtok(NULL, ",");
device = xstrcpy(strtok(NULL, ",")); device = xstrcpy(strtok(NULL, ","));
fullname = xstrcpy(strtok(NULL, ",")); fullname = xstrcpy(cldecode(strtok(NULL, ",")));
if (((strcasecmp(OpData, "/H")) == 0) || (strlen(OpData) == 0)) { if (((strcasecmp(OpData, "/H")) == 0) || (strlen(OpData) == 0)) {
/* /*
@ -136,8 +136,8 @@ void WhosOn(char *OpData)
free(device); free(device);
strtok(NULL, ","); strtok(NULL, ",");
location = xstrcpy(strtok(NULL, ",")); location = xstrcpy(cldecode(strtok(NULL, ",")));
isdoing = xstrcpy(strtok(NULL, ",")); isdoing = xstrcpy(cldecode(strtok(NULL, ",")));
if (strstr(isdoing, "Browsing")) if (strstr(isdoing, "Browsing"))
/* Browseng */ /* Browseng */
@ -267,7 +267,7 @@ void WhosDoingWhat(int iStatus, char *what)
void SendOnlineMsg(char *OpData) void SendOnlineMsg(char *OpData)
{ {
static char buf[128]; static char buf[128];
char *User, *String, *temp; char *User, *String, *temp, *from, *too, *msg;
FILE *fp; FILE *fp;
struct userhdr ushdr; struct userhdr ushdr;
struct userrec us; struct userrec us;
@ -320,11 +320,17 @@ void SendOnlineMsg(char *OpData)
if ((strcmp(String, "")) != 0) { if ((strcmp(String, "")) != 0) {
buf[0] = '\0'; buf[0] = '\0';
if ((strcasecmp(OpData, "/H") == 0) && strlen(exitinfo.sHandle)) if ((strcasecmp(OpData, "/H") == 0) && strlen(exitinfo.sHandle))
snprintf(buf, 128, "CSPM:3,%s,%s,%s;", exitinfo.sHandle, User, String); from = xstrcpy(clencode(exitinfo.sHandle));
else if (strcasecmp(OpData, "/U") == 0) else if (strcasecmp(OpData, "/U") == 0)
snprintf(buf, 128, "CSPM:3,%s,%s,%s;", exitinfo.Name, User, String); from = xstrcpy(clencode(exitinfo.Name));
else else
snprintf(buf, 128, "CSPM:3,%s,%s,%s;", exitinfo.sUserName, User, String); from = xstrcpy(clencode(exitinfo.sUserName));
too = xstrcpy(clencode(User));
msg = xstrcpy(clencode(String));
snprintf(buf, 128, "CSPM:3,%s,%s,%s;", from, too, msg);
free(from);
free(too);
free(msg);
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());

View File

@ -446,8 +446,7 @@ int reg_spm(char *data)
from = xstrcpy(cldecode(strtok(NULL, ","))); from = xstrcpy(cldecode(strtok(NULL, ",")));
too = xstrcpy(cldecode(strtok(NULL, ","))); too = xstrcpy(cldecode(strtok(NULL, ",")));
txt = xstrcpy(cldecode(strtok(NULL, ";"))); txt = xstrcpy(cldecode(strtok(NULL, ";")));
Syslog('+', "PM from \"%s\" to \"%s\": \"%s\"", from, too, txt);
Syslog('-', "SIPM:%s,%s,%s,%s;", cnt, from, too, txt);
for (i = 0; i < MAXCLIENT; i++) { for (i = 0; i < MAXCLIENT; i++) {
if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) { if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) {