-/* $Id: packets.c,v 1.5 2014/06/25 15:14:33 mmondor Exp $ */
+/* $Id: packets.c,v 1.6 2014/07/05 18:15:18 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <stdlib.h>
#include <string.h>
+#include <conf.h>
+#include <screen.h>
#include <packets_common.h>
#include <packets.h>
#include <tms-endian.h>
#include <debug.h>
#include <hmac.h>
#include <enc.h>
-#include <conf.h>
uint8_t *data;
size_t size, off, len;
- if (amsg->size == -1) {
- (void) fprintf(stderr, "Error reading from server socket\n");
- exit(EXIT_FAILURE);
- }
+ if (amsg->size == -1)
+ screen_error(
+ "spackets_handle() - Error reading from server socket");
data = (uint8_t *)amsg->data;
size = amsg->size;
/* Kill client on packet processing error */
ASSERT(spacket_index[id].handler != NULL);
- if (spacket_index[id].handler((uint16_t *)&data[off]) == -1) {
- (void) fprintf(stderr,
- "Error processing server packet 0x%02x\n", id);
- exit(EXIT_FAILURE);
- }
+ if (spacket_index[id].handler((uint16_t *)&data[off]) == -1)
+ screen_error("spackets_handle() - "
+ "Error processing server packet 0x%02x", id);
}
}
{
struct spacket_auth *p = (struct spacket_auth *)ptr;
- if (p->protocol_version != CLIENT_VERSION) {
- (void) fprintf(stderr,
- "Client and server versions do not match\n");
- exit(EXIT_FAILURE);
- }
+ if (p->protocol_version != CLIENT_VERSION)
+ screen_error("Client and server versions do not match");
return cpacket_auth_send(CLIENT_LOGIN, CLIENT_PASSWD,
p->noncerand1, p->noncerand2);
{
thread_amsg_t *amsg;
- if ((amsg = thread_amsg_create()) == NULL) {
- (void) fprintf(stderr,
- "cpacket_send() - thread_amsg_create()\n");
- exit(EXIT_FAILURE);
- }
+ if ((amsg = thread_amsg_create()) == NULL)
+ screen_error("cpacket_send() - thread_amsg_create()");
(void) memcpy(amsg->data, buf, size);
amsg->size = size;
{
thread_amsg_t *amsg;
- if ((amsg = thread_amsg_create()) == NULL) {
- (void) fprintf(stderr,
- "cpacket_send() - thread_amsg_create()\n");
- exit(EXIT_FAILURE);
- }
+ if ((amsg = thread_amsg_create()) == NULL)
+ screen_error("cpacket_send() - thread_amsg_create()");
thread_amsg_setcallback(amsg, callback, callback_arg);
(void) memcpy(amsg->data, buf, size);
-/* $Id: recvq.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
+/* $Id: recvq.c,v 1.3 2014/07/05 18:15:18 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <SDL_net.h>
#include <conf.h>
+#include <screen.h>
#ifdef USE_COMPRESSION
#include <zlib.h>
if ((s = SDLNet_TCP_Recv(q->sock, rbuffer, RBUFFER_SIZE)) == -1 ||
s == 0) {
(void) fprintf(stderr,
- "SDLNet_TCP_Recv() == %d - %d - %s\n",
+ "recvq_read() - SDLNet_TCP_Recv() == %d - %d - %s\n",
s, errno, SDLNet_GetError());
return -1;
}
q->zin.avail_out = IBUFFER_SIZE;
if ((ret = inflate(&q->zin, Z_SYNC_FLUSH)) != Z_OK &&
ret != Z_STREAM_END) {
- (void) fprintf(stderr,
- "inflate() error\n");
+ (void) fprintf(stderr, "recvq_read() - inflate() error");
return -1;
}
buf = (int8_t *)ibuffer;
-/* $Id: thread_net_recv.c,v 1.2 2014/06/25 15:33:48 mmondor Exp $ */
+/* $Id: thread_net_recv.c,v 1.3 2014/07/05 18:15:18 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <stdlib.h>
#include <string.h>
+#include <conf.h>
#include <main.h>
#include <thread_net_recv.h>
#include <recvq.h>
#include <screen.h>
-#include <conf.h>
{
/* Initialize reply port and ring */
- if (thread_ring_init(&recv_ring) == -1) {
- (void) fprintf(stderr,
- "thread_net_recv() - thread_ring_init(recv_port) - %s\n",
+ if (thread_ring_init(&recv_ring) == -1)
+ screen_error(
+ "thread_net_recv() - thread_ring_init(recv_port) - %s",
SDL_GetError());
- exit(EXIT_FAILURE);
- }
- if (thread_port_init(&recv_port) == -1) {
- (void) fprintf(stderr,
- "thread_net_recv() - thread_port_init(recv_port) - %s\n",
+ if (thread_port_init(&recv_port) == -1)
+ screen_error(
+ "thread_net_recv() - thread_port_init(recv_port) - %s",
SDL_GetError());
- exit(EXIT_FAILURE);
- }
thread_port_set_ring(&recv_port, &recv_ring);
if (state_connect() == 0)
* it's fatal since the receiving main thread will never be
* notified.
*/
- if ((amsg = thread_amsg_create()) == NULL) {
- (void) fprintf(stderr,
- "state_recv() - thread_amsg_create()\n");
- exit(EXIT_FAILURE);
- }
+ if ((amsg = thread_amsg_create()) == NULL)
+ screen_error("state_recv() - thread_amsg_create()");
/*
* Call recvq_read() until we either have 1, in which case
* we'll send an async message, or -1 for error.
*/
while ((res = recvq_read(&recvq)) == 0) ;
-
if (res == -1)
screen_error("Lost server connection");
* it asynchroneously.
*/
recvq_content(&recvq, &buf, &size);
- if (size > AMSG_MAXSIZE) {
- (void) fprintf(stderr,
- "state_recv() - increase AMSG_MAXSIZE!\n");
- exit(EXIT_FAILURE);
- }
+ if (size > AMSG_MAXSIZE)
+ screen_error("state_recv() - increase AMSG_MAXSIZE!");
(void) memcpy(amsg->data, buf, size);
amsg->size = size;
recvq_content_reset(&recvq);
-/* $Id: thread_net_send.c,v 1.1 2006/12/31 08:32:39 mmondor Exp $ */
+/* $Id: thread_net_send.c,v 1.2 2014/07/05 18:15:18 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <stdlib.h>
#include <conf.h>
+#include <screen.h>
#ifdef USE_COMPRESSION
#include <zlib.h>
zout.zalloc = NULL;
zout.zfree = NULL;
zout.opaque = NULL;
- if (deflateInit(&zout, Z_DEFAULT_COMPRESSION) != Z_OK) {
- (void) fprintf(stderr, "thread_net_recv() - deflateInit()\n");
- exit(EXIT_FAILURE);
- }
+ if (deflateInit(&zout, Z_DEFAULT_COMPRESSION) != Z_OK)
+ screen_error("thread_net_recv() - deflateInit()");
#endif
/* Initialize reply port and ring */
- if (thread_ring_init(&send_ring) == -1) {
- (void) fprintf(stderr,
- "thread_net_recv() - thread_ring_init(send_port) - %s\n",
+ if (thread_ring_init(&send_ring) == -1)
+ screen_error(
+ "thread_net_recv() - thread_ring_init(send_port) - %s",
SDL_GetError());
- exit(EXIT_FAILURE);
- }
- if (thread_port_init(&send_port) == -1) {
- (void) fprintf(stderr,
- "thread_net_send() - thread_port_init(send_port) - %s\n",
+ if (thread_port_init(&send_port) == -1)
+ screen_error(
+ "thread_net_send() - thread_port_init(send_port) - %s",
SDL_GetError());
- exit(EXIT_FAILURE);
- }
thread_port_set_ring(&send_port, &send_ring);
/*
zout.avail_in = amsg->size;
zout.next_out = (Bytef *)dbuffer;
zout.avail_out = DBUFFER_SIZE;
- if (deflate(&zout, Z_SYNC_FLUSH) != Z_OK) {
- (void) fprintf(stderr,
- "thread_net_send() - deflate()\n");
- exit(EXIT_FAILURE);
- }
+ if (deflate(&zout, Z_SYNC_FLUSH) != Z_OK)
+ screen_error("thread_net_send() - deflate()");
buf = (uint8_t *)dbuffer;
s = DBUFFER_SIZE - zout.avail_out;
#else
#endif
if (SDLNet_TCP_Send(server_socket, buf, s)
!= s)
- (void) fprintf(stderr,
- "Error writing to server socket\n");
+ screen_error("thread_net_send() - "
+ "SDLNet_TCP_Send() - %s",
+ SDL_GetError());
}
thread_amsg_callback(amsg);
thread_amsg_destroy(amsg);