ch_dst = ch_itr;
list_add_tail(&ch_dst->link_node, &ch_src->channel_links);
- Log_info("Adding channel link %s -> %s", ch_src->name, ch_dst->name);
+ Log_info("Adding channel link '%s' -> '%s'", ch_src->name, ch_dst->name);
}
}
list_iterate_safe(itr, save, &channels) {
ch = list_get_entry(itr, channel_t, flatlist_node);
- Log_debug("Free channel %s", ch->name);
+ Log_debug("Free channel '%s'", ch->name);
free(ch->name);
if (ch->desc)
free(ch->desc);
if (Timer_isElapsed(&c->lastActivity, 1000000LL * INACTICITY_TIMEOUT)) {
/* No activity from client - assume it is lost and close. */
- Log_info("Timeout, closing session %d - %s@%s:%d",
- c->sessionId,
- c->playerName,
- inet_ntoa(c->remote_tcp.sin_addr),
- ntohs(c->remote_tcp.sin_port));
+ Log_info_client(c, "Timeout, closing.");
Client_free(c);
}
}
memcpy(&newclient->remote_tcp, remote, sizeof(struct sockaddr_in));
newclient->ssl = SSL_newconnection(newclient->tcpfd, &newclient->SSLready);
if (newclient->ssl == NULL) {
- Log_warn("SSL negotiation failed");
+ Log_warn("SSL negotiation failed with %s:%d", inet_ntoa(remote->sin_addr),
+ ntohs(remote->sin_port));
free(newclient);
return -1;
}
struct dlist *itr, *save;
message_t *sendmsg;
- Log_info("Disconnect session %d - %s@%s:%d",
- client->sessionId,
- client->playerName,
- inet_ntoa(client->remote_tcp.sin_addr),
- ntohs(client->remote_tcp.sin_port));
-
if (client->authenticated) {
int leave_id;
leave_id = Chan_playerLeave(client);
client->msgsize = ntohl(msgLen);
}
if (client->msgsize > BUFSIZE - 6 && client->drainleft == 0) {
- Log_warn("Too big message received (%d). Discarding.", client->msgsize);
+ Log_info_client(client, "Too big message received (%d bytes). Discarding.", client->msgsize);
client->rxcount = client->msgsize = 0;
client->drainleft = client->msgsize;
}
return 0;
}
else if (SSL_get_error(client->ssl, rc) == SSL_ERROR_ZERO_RETURN) {
- Log_warn("Error: Zero return - closing");
+ Log_info_client(client, "Connection closed by peer");
if (!client->shutdown_wait)
Client_close(client);
}
/* Hmm. This is where we end up when the client closes its connection.
* Kind of strange...
*/
- Log_info("Connection closed by peer. Session %d - %s@%s:%d",
- client->sessionId,
- client->playerName,
- inet_ntoa(client->remote_tcp.sin_addr),
- ntohs(client->remote_tcp.sin_port));
+ Log_info_client(client, "Connection closed by peer");
}
else {
- Log_warn("SSL error: %d - Closing connection.", SSL_get_error(client->ssl, rc));
+ Log_info_client(client, "SSL error: %d - Closing connection", SSL_get_error(client->ssl, rc));
}
Client_free(client);
return -1;
Timer_restart(&client->cryptState.tLastRequest);
sendmsg = Msg_create(CryptSetup);
- Log_info("Requesting voice channel crypt resync. Session %d - %s@%s:%d",
- client->sessionId,
- client->playerName,
- inet_ntoa(client->remote_tcp.sin_addr),
- ntohs(client->remote_tcp.sin_port));
-
+ Log_info_client(client, "Requesting voice channel crypt resync");
Client_send_message(client, sendmsg);
}
}
if (itr->remote_tcp.sin_addr.s_addr == from.sin_addr.s_addr) {
if (checkDecrypt(itr, encrypted, buffer, len)) {
itr->key = key;
- Log_info("New UDP connection from session %d - %s@%s:%d",
- itr->sessionId,
- itr->playerName,
- inet_ntoa(from.sin_addr),
- ntohs(from.sin_port));
+ Log_info_client(itr, "New UDP connection port %d", ntohs(from.sin_port));
memcpy(&itr->remote_udp, &from, sizeof(struct sockaddr_in));
break;
}
#include "log.h"
-#define BUFSIZE 254
+#define STRSIZE 254
static bool_t termprint;
void logthis(const char *logstring, ...)
{
va_list argp;
- char buf[BUFSIZE + 2];
+ char buf[STRSIZE + 2];
va_start(argp, logstring);
- vsnprintf(&buf[0], BUFSIZE, logstring, argp);
+ vsnprintf(&buf[0], STRSIZE, logstring, argp);
va_end(argp);
strcat(buf, "\n");
if (termprint)
- fprintf(stderr, "%s", buf); /* XXX - other targets for logging */
+ fprintf(stderr, "%s", buf);
else
syslog(LOG_INFO, buf);
}
void Log_warn(const char *logstring, ...)
{
va_list argp;
- char buf[BUFSIZE + 2];
+ char buf[STRSIZE + 2];
int offset = 0;
va_start(argp, logstring);
offset = sprintf(buf, "WARN: ");
- vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp);
+ vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
va_end(argp);
strcat(buf, "\n");
if (termprint)
- fprintf(stderr, "%s", buf); /* XXX - other targets for logging */
+ fprintf(stderr, "%s", buf);
else
syslog(LOG_WARNING, buf);
}
void Log_info(const char *logstring, ...)
{
va_list argp;
- char buf[BUFSIZE + 2];
+ char buf[STRSIZE + 2];
int offset = 0;
va_start(argp, logstring);
offset = sprintf(buf, "INFO: ");
- vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp);
+ vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
va_end(argp);
strcat(buf, "\n");
if (termprint)
- fprintf(stderr, "%s", buf); /* XXX - other targets for logging */
+ fprintf(stderr, "%s", buf);
else
syslog(LOG_INFO, buf);
}
+void Log_info_client(client_t *client, const char *logstring, ...)
+{
+ va_list argp;
+ char buf[STRSIZE + 2];
+ int offset = 0;
+
+ va_start(argp, logstring);
+ offset = sprintf(buf, "INFO: ");
+ offset += vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
+ va_end(argp);
+ offset += snprintf(&buf[offset], STRSIZE - offset, " - [%d] %s@%s:%d",
+ client->sessionId,
+ client->playerName,
+ inet_ntoa(client->remote_tcp.sin_addr),
+ ntohs(client->remote_tcp.sin_port));
+ strcat(buf, "\n");
+ if (termprint)
+ fprintf(stderr, "%s", buf);
+ else
+ syslog(LOG_INFO, buf);
+
+}
#ifdef DEBUG
void Log_debug(const char *logstring, ...)
{
va_list argp;
- char buf[BUFSIZE + 2];
+ char buf[STRSIZE + 2];
int offset = 0;
va_start(argp, logstring);
offset = sprintf(buf, "DEBUG: ");
- vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp);
+ vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
va_end(argp);
strcat(buf, "\n");
if (termprint)
- fprintf(stderr, "%s", buf); /* XXX - other targets for logging */
+ fprintf(stderr, "%s", buf);
else
syslog(LOG_DEBUG, buf);
}
void Log_fatal(const char *logstring, ...)
{
va_list argp;
- char buf[BUFSIZE + 2];
+ char buf[STRSIZE + 2];
int offset = 0;
va_start(argp, logstring);
offset = sprintf(buf, "FATAL: ");
- vsnprintf(&buf[offset], BUFSIZE - offset, logstring, argp);
+ vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
va_end(argp);
strcat(buf, "\n");
if (termprint)
- fprintf(stderr, "%s", buf); /* XXX - other targets for logging */
+ fprintf(stderr, "%s", buf);
else
syslog(LOG_CRIT, buf);
exit(1);
#define LOG_H_2435642356
#include "types.h"
+#include "client.h"
#define doAssert(_cond_) do { \
if (!(_cond_)) { \
void Log_warn(const char *logstring, ...);
void Log_info(const char *logstring, ...);
+void Log_info_client(client_t *client, const char *logstring, ...);
void Log_fatal(const char *logstring, ...);
void Log_init(bool_t terminal);
msg->payload.reject->has_type = true;
Client_send_message(client, msg);
- Log_info("Server reject reason: %s. Disconnecting session %d - %s@%s:%d",
- reason,
- client->sessionId,
- client->playerName,
- inet_ntoa(client->remote_tcp.sin_addr),
- ntohs(client->remote_tcp.sin_port));
-
+ Log_info_client(client, "Server reject reason: %s", reason);
}
static void sendPermissionDenied(client_t *client, const char *reason)
sendmsg->payload.serverSync->allow_html = true; /* Support this? */
Client_send_message(client, sendmsg);
- Log_info("User %s authenticated", client->playerName);
+ Log_info_client(client, "User %s authenticated", client->playerName);
break;
case Ping:
do {
Chan_iterate(&ch_itr);
} while (ch_itr != NULL && ch_itr->id != msg->payload.textMessage->channel_id[i]);
- if (ch_itr == NULL)
- Log_warn("Channel id %d not found - ignoring.", msg->payload.textMessage->channel_id[i]);
- else {
+ if (ch_itr != NULL) {
struct dlist *itr;
list_iterate(itr, &ch_itr->clients) {
client_t *c;