aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2022-04-25 18:14:36 -0500
committerMatt Strapp <matt@mattstrapp.net>2022-04-25 18:14:36 -0500
commit647ce51556f9c04d7847b0a9ab5d8533a79e4bc9 (patch)
treef9d49cabae24f92c5d2da9677ce420efdd0048e6
parentmore (diff)
downloadcsci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar.gz
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar.bz2
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar.lz
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar.xz
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.tar.zst
csci4211-647ce51556f9c04d7847b0a9ab5d8533a79e4bc9.zip
e
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to '')
-rw-r--r--Makefile1
-rw-r--r--src/client.cpp4
-rw-r--r--src/server.cpp25
3 files changed, 15 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 8820f85..9cb5221 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-
.DELETE_ON_ERROR:
CXX = g++
diff --git a/src/client.cpp b/src/client.cpp
index baf2215..d2b7562 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -486,10 +486,10 @@ void doClientCommand(int i) {
// Open new S2C connection with server for file transfer
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd == -1)
- Log("[%s] Warning: Cannot create file transfer socket.", NAME);
+ Log("[%s] WARN: Cannot create file transfer socket.", NAME);
else if (connect(fd, (const struct sockaddr *)&serverAddr,
sizeof(serverAddr)) != 0)
- Log("[%s] Warning: File transfer cannot connect to server", NAME);
+ Log("[%s] WARN: File transfer cannot connect to server", NAME);
else {
// Usual setup
SetNonBlockIO(fd);
diff --git a/src/server.cpp b/src/server.cpp
index b5e5757..745b215 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -138,8 +138,8 @@ void DoServer(int port) {
if (!((header.m_command == CONNECT) | (header.m_command == SENDF) |
(header.m_command == SENDF2) | (header.m_command == GETF))) {
- Log("[%s] WARNING: Unexpected initial connection command %s",
- NAME, com2str(header.m_command));
+ Log("[%s] WARN: Unexpected initial connection command %s", NAME,
+ com2str(header.m_command));
}
connStat[i].recInitHeader = true;
@@ -377,8 +377,7 @@ void doServerCommand(int i) {
sendMessageToId(connStat[i].id, true, outHeader, message);
}
} else {
- Log("[---- : %s] Login failed: %s",
- com2str(header.m_command), username);
+ Log("[---- : %s] Login failed: %s", com2str(header.m_command), username);
outHeader.setFlags(S2C, FAIL, PUB, SIGN);
outHeader.m_command = LOGIN;
memcpy(outHeader.m_name, NAME, strlen(NAME));
@@ -515,11 +514,14 @@ void doServerCommand(int i) {
offset += filenameLen;
buf2i(&buf[i][offset], fileLen);
offset += 4;
- // Log("[%s : %s] Saving file: %s", server_filename);
fp = fopen(FILE_DATABASE, "a");
- fputs(server_filename, fp);
- fputs("\n", fp);
- fclose(fp);
+ if (fp == NULL) {
+ Log("Failed to open %s for writing.", FILE_DATABASE);
+ } else {
+ fputs(server_filename, fp);
+ fputs("\n", fp);
+ fclose(fp);
+ }
buf2file(&buf[i][offset], fileLen, server_filename);
// Send SENDF/SENDF2 message to interested parties
@@ -630,15 +632,14 @@ void doServerCommand(int i) {
if ((connStat[x].direction == C2S) &&
(connStat[x].linkType == MESSAGE_LINK) && (connStat[x].isLoggedIn)) {
strcat(message, "\n\t");
- strcat(message, connStat[x].name);
+ strncat(message, connStat[x].name, MAX_USERNAME_LEN);
}
}
outHeader.m_size = strlen(message);
sendMessageToId(connStat[i].id, false, outHeader, message);
break;
case PING:
- // Log("Ping from %s", header.m_name);
- asm("nop"); // do nothing
+ // PONG
break;
default:
Log("No doServerCommand() for command %s", com2str(header.m_command));
@@ -713,7 +714,7 @@ void prepareMessage(int i, Header header, char *message) {
peers[i].events |= POLLWRNORM;
} else {
- Log("[%s] WARNING: attempted to write to C2S connection %d", NAME, i);
+ Log("[%s] WARN: attempted to write to C2S connection %d", NAME, i);
}
}