Ejemplo n.º 1
0
Archivo: net.c Proyecto: davmlaw/xtux
/* Put a message onto the output buffer */
void net_put_message(netconnection_t *nc, netmsg msg)
{
    int type, size;

#if NET_DEBUG
    printf("net_put_message(%s)\n", net_message_name(msg.type));
#endif

    type = (int)msg.type;
    if( type >= NUM_NETMESSAGES ) {
	printf("Unknown message type %d\n", type);
	return;
    }

    size = netmsg_table[type].size;

    if( nc->output.size + size > NETBUFSIZ ) {
	printf("Output full. Auto-flushing.\n");
	net_output_flush(nc);

	if( nc->output.size + size > NETBUFSIZ ) {
	    printf("Could not write output to %s. Discarding buffer\n",
		   nc->remote_address);
	    nc->output.size = 0;
	    return;
	}
    }

    tonet(&msg); /* To network byte order */
    memcpy(nc->output.buf + nc->output.size, &msg, size);
    nc->output.size += size;

}
Ejemplo n.º 2
0
static int sv_netmsg_not_handled(client_t *cl, netmsg msg)
{

    printf("NOT HANDLING MESSAGE \"%s\" from \"%s\" (%s)\n",
	   net_message_name(msg.type), cl->name, cl->nc->remote_address);
    cl->bad++;

    return 0;

}
Ejemplo n.º 3
0
/* Handle message and return the message type */
int cl_net_handle_message(netmsg msg)
{

    if( client.debug )
	printf("cl_net_handle_message: type = %s\n",
	       net_message_name(msg.type));

    if( msg.type < NUM_NETMESSAGES ) {
	if( recv_message[msg.type] == NULL )
	    cl_netmsg_not_handled(msg);
	else
	    recv_message[msg.type](msg);
	return msg.type;
    } else {
	printf("cl_netmsg_recv: Unknown message type %d!\n", msg.type);
	return -1;
    }

}
Ejemplo n.º 4
0
Archivo: net.c Proyecto: davmlaw/xtux
/* Find and mark the first/last complete frame in input buffer,
   if there is only a partial frame, then set in->frames to -1 */
static void net_mark_full_frame(netbuf_t *in, nm_frame_t nm)
{
    int start_found;
    int p, type, size;

    start_found = -1;

    for( p = in->pos ; p < in->size ; p += size ) {
	type = (byte)in->buf[p];
	if( type >= NUM_NETMESSAGES ) {
	    printf("ERROR: Type (%d) out of range!\n", type);
	    printf("in->pos = %d, in->size = %d, p = %d\n",
		   in->pos, in->size, p);
	    in->size = 0;
	    return;
	}
	size = netmsg_table[type].size;

#if NET_DEBUG
	printf("%4d: (%3d), \"%s\" (s=%d)\n",
	       p, type, net_message_name(type), size);
#endif

	if( type == NETMSG_START_FRAME ) {
	    start_found = p;
	    if( in->frames == 0 )
		in->frames = -1; /* Partial frame */
	} else if( type == NETMSG_END_FRAME && start_found >= 0 ) {
	    /* Ok, we now have a full frame */
	    in->start = start_found;
	    in->end = p + size;
	    in->frames++;
	    if( nm == NM_FIRST_FRAME )
		return;
	}
    }

}
Ejemplo n.º 5
0
/*
  Function pointer table for handling incoming messages.
  All of the below functions are in "cl_netmsg_recv.c"
  We shouldn't get the messages that are NOTHANDLED, because
  the server shouldn't send them. In theory anyway.
*/
static void cl_netmsg_not_handled(netmsg msg)
{
    printf("NOT HANDLING MESSAGE \"%s\"\n", net_message_name(msg.type));
}