Completed client/server communications encoding
This commit is contained in:
parent
32e892d5b6
commit
2304c874a0
10
lib/client.c
10
lib/client.c
@ -51,7 +51,7 @@ int socket_connect(char *user, char *prg, char *city)
|
||||
{
|
||||
int s;
|
||||
static char buf[SS_BUFSIZE], tty[18];
|
||||
char *tmp;
|
||||
char *tmp, *u, *p, *c;
|
||||
|
||||
myname = prg;
|
||||
|
||||
@ -117,7 +117,13 @@ int socket_connect(char *user, char *prg, char *city)
|
||||
/*
|
||||
* 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) {
|
||||
sock = -1;
|
||||
return -1;
|
||||
|
@ -547,15 +547,20 @@ void Chat(int sysop)
|
||||
{
|
||||
int curpos = 0, stop = FALSE, data, rc;
|
||||
unsigned char ch = 0;
|
||||
char sbuf[81], resp[128];
|
||||
char sbuf[81], resp[128], *sysop_name, *name;
|
||||
static char buf[200];
|
||||
|
||||
clr_index();
|
||||
rsize = rows - 7;
|
||||
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);
|
||||
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('-', "< %s", buf);
|
||||
@ -611,8 +616,7 @@ void Chat(int sysop)
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -657,7 +661,7 @@ void Chat(int sysop)
|
||||
putchar(7);
|
||||
}
|
||||
} 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);
|
||||
if (socket_send(buf) == 0) {
|
||||
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); /* 1= fatal error, end chat */
|
||||
rc = atoi(resp);
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -701,8 +704,7 @@ void Chat(int sysop)
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -722,8 +724,6 @@ void Chat(int sysop)
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('-', "< %s", buf);
|
||||
if (strncmp(buf, "100:1,", 6)) {
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -419,8 +419,7 @@ void show_date(int fg, int bg, int y, int x)
|
||||
pid = strtok(buf, ",");
|
||||
pid = strtok(NULL, ",");
|
||||
page = strtok(NULL, ",");
|
||||
reason = strtok(NULL, "\0");
|
||||
reason[strlen(reason)-1] = '\0';
|
||||
reason = xstrcpy(cldecode(strtok(NULL, ";")));
|
||||
if (strlen(reason) > 60)
|
||||
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);
|
||||
putchar(7); /* Each second */
|
||||
}
|
||||
free(reason);
|
||||
}
|
||||
|
||||
if (y && x)
|
||||
|
@ -167,7 +167,7 @@ void Chat(char *username, char *channel)
|
||||
{
|
||||
int curpos = 0, stop = FALSE, data, rc;
|
||||
unsigned char ch;
|
||||
char sbuf[81], resp[128];
|
||||
char sbuf[81], resp[128], *name, *mname;
|
||||
static char buf[200];
|
||||
|
||||
WhosDoingWhat(SYSOPCHAT, NULL);
|
||||
@ -213,7 +213,11 @@ void Chat(char *username, char *channel)
|
||||
snprintf(buf, 200, "%-*s", cols -1, " MBSE BBS Chat Server");
|
||||
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);
|
||||
if (socket_send(buf) == 0) {
|
||||
strncpy(buf, socket_receive(), sizeof(buf)-1);
|
||||
@ -245,10 +249,10 @@ void Chat(char *username, char *channel)
|
||||
* commands to the chatserver.
|
||||
*/
|
||||
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)
|
||||
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)
|
||||
strcpy(buf, socket_receive());
|
||||
}
|
||||
@ -274,8 +278,7 @@ void Chat(char *username, char *channel)
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal, chat ended */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -317,8 +320,8 @@ void Chat(char *username, char *channel)
|
||||
}
|
||||
} else if ((ch == '\r') && curpos) {
|
||||
alarm_on();
|
||||
snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, sbuf);
|
||||
Syslog('c', "> %s", buf);
|
||||
snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, clencode(sbuf));
|
||||
Syslog('c', "> %s", clencode(buf));
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
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); /* 1= fatal, chat ended */
|
||||
rc = atoi(resp);
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -361,8 +363,7 @@ void Chat(char *username, char *channel)
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* 1= fatal error */
|
||||
rc = atoi(resp);
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, ";")), 80); /* The message */
|
||||
DispMsg(resp);
|
||||
if (rc == 1) {
|
||||
Syslog('+', "Chat server error: %s", resp);
|
||||
@ -396,8 +397,6 @@ void Chat(char *username, char *channel)
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('c', "< %s", buf);
|
||||
if (strncmp(buf, "100:1,", 6)) {
|
||||
}
|
||||
}
|
||||
sleep(2);
|
||||
clear();
|
||||
|
@ -68,9 +68,9 @@ int CheckStatus()
|
||||
buf[strlen(buf) -1] = '\0';
|
||||
Enter(2);
|
||||
PUTCHAR('\007');
|
||||
snprintf(msg, 81, "*** %s ***", buf+8);
|
||||
snprintf(msg, 81, "*** %s ***", cldecode(buf+8));
|
||||
PUTSTR(msg);
|
||||
Syslog('+', "Send user message \"%s\"", buf+8);
|
||||
Syslog('+', "Send user message \"%s\"", cldecode(buf+8));
|
||||
Enter(3);
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -146,7 +146,7 @@ void Page_Sysop(char *String)
|
||||
|
||||
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)) {
|
||||
Syslog('+', "Failed to send message to mbtask");
|
||||
free(Reason);
|
||||
|
@ -64,7 +64,7 @@ void Check_PM(void)
|
||||
|
||||
strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */
|
||||
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);
|
||||
PUTCHAR('\007');
|
||||
@ -72,8 +72,7 @@ void Check_PM(void)
|
||||
/* ** Message ** from */
|
||||
snprintf(msg, 81, "%s %s:", (char *)Language(434), resp);
|
||||
poutCR(CYAN, BLACK, msg);
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The real message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
strncpy(resp, cldecode(strtok(NULL, "\0")), 80); /* The real message */
|
||||
PUTSTR(resp);
|
||||
Enter(1);
|
||||
Pause();
|
||||
|
@ -282,7 +282,7 @@ void user(void)
|
||||
strtok(buf, ","); /* response */
|
||||
strtok(NULL, ","); /* pid */
|
||||
strtok(NULL, ","); /* tty */
|
||||
fullname = xstrcpy(strtok(NULL, ",")); /* username */
|
||||
fullname = xstrcpy(cldecode(strtok(NULL, ","))); /* username */
|
||||
if (strcmp(fullname, usrconfig.Name) == 0) {
|
||||
logins++;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ void WhosOn(char *OpData)
|
||||
cnt = strtok(buf, ",");
|
||||
strtok(NULL, ",");
|
||||
device = xstrcpy(strtok(NULL, ","));
|
||||
fullname = xstrcpy(strtok(NULL, ","));
|
||||
fullname = xstrcpy(cldecode(strtok(NULL, ",")));
|
||||
|
||||
if (((strcasecmp(OpData, "/H")) == 0) || (strlen(OpData) == 0)) {
|
||||
/*
|
||||
@ -136,8 +136,8 @@ void WhosOn(char *OpData)
|
||||
free(device);
|
||||
|
||||
strtok(NULL, ",");
|
||||
location = xstrcpy(strtok(NULL, ","));
|
||||
isdoing = xstrcpy(strtok(NULL, ","));
|
||||
location = xstrcpy(cldecode(strtok(NULL, ",")));
|
||||
isdoing = xstrcpy(cldecode(strtok(NULL, ",")));
|
||||
|
||||
if (strstr(isdoing, "Browsing"))
|
||||
/* Browseng */
|
||||
@ -267,7 +267,7 @@ void WhosDoingWhat(int iStatus, char *what)
|
||||
void SendOnlineMsg(char *OpData)
|
||||
{
|
||||
static char buf[128];
|
||||
char *User, *String, *temp;
|
||||
char *User, *String, *temp, *from, *too, *msg;
|
||||
FILE *fp;
|
||||
struct userhdr ushdr;
|
||||
struct userrec us;
|
||||
@ -320,11 +320,17 @@ void SendOnlineMsg(char *OpData)
|
||||
if ((strcmp(String, "")) != 0) {
|
||||
buf[0] = '\0';
|
||||
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)
|
||||
snprintf(buf, 128, "CSPM:3,%s,%s,%s;", exitinfo.Name, User, String);
|
||||
from = xstrcpy(clencode(exitinfo.Name));
|
||||
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) {
|
||||
strcpy(buf, socket_receive());
|
||||
|
@ -446,8 +446,7 @@ int reg_spm(char *data)
|
||||
from = xstrcpy(cldecode(strtok(NULL, ",")));
|
||||
too = xstrcpy(cldecode(strtok(NULL, ",")));
|
||||
txt = xstrcpy(cldecode(strtok(NULL, ";")));
|
||||
|
||||
Syslog('-', "SIPM:%s,%s,%s,%s;", cnt, from, too, txt);
|
||||
Syslog('+', "PM from \"%s\" to \"%s\": \"%s\"", from, too, txt);
|
||||
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) {
|
||||
|
Reference in New Issue
Block a user