/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/handle_file.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/bnetd/handle_file.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 sysadm 1.1 /*
2     * Copyright (C) 1999,2000 Ross Combs (rocombs@cs.nmsu.edu)
3     * Copyright (C) 1999,2000 Rob Crittenden (rcrit@greyoak.com)
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19     #include "common/setup_before.h"
20     #ifdef HAVE_STDDEF_H
21     # include <stddef.h>
22     #else
23     # ifndef NULL
24     # define NULL ((void *)0)
25     # endif
26     #endif
27     #include <compat/socket.h>
28     #include "common/packet.h"
29     #include "common/file_protocol.h"
30     #include "common/eventlog.h"
31     #include "connection.h"
32     #include "common/queue.h"
33     #include "file.h"
34     #include "common/bn_type.h"
35     #include "common/field_sizes.h"
36     #include "handle_file.h"
37     /* ADDED BY UNDYING SOULZZ 4/3/02 */
38     #ifdef HAVE_SYS_TYPES_H
39     # include <sys/types.h>
40     #endif
41     #ifdef HAVE_SYS_SOCKET_H
42     # include <sys/socket.h>
43     #endif
44     #include "compat/psock.h"
45     #include "common/setup_after.h"
46    
47    
48     extern int handle_file_packet(t_connection * c, t_packet const * const packet)
49     {
50     if (!c)
51     {
52     eventlog(eventlog_level_error,__FUNCTION__,"[%d] got NULL connection",conn_get_socket(c));
53     return -1;
54     }
55     if (!packet)
56     {
57     eventlog(eventlog_level_error,__FUNCTION__,"[%d] got NULL packet",conn_get_socket(c));
58     return -1;
59     }
60     /* REMOVED BY UNDYING SOULZZ 4/3/02 */
61     /*
62     if (packet_get_class(packet)!=packet_class_file)
63     {
64     eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad packet (class %d)",conn_get_socket(c),(int)packet_get_class(packet));
65     return -1;
66     }
67     */
68     switch (conn_get_state(c))
69     {
70     case conn_state_connected:
71     switch (packet_get_type(packet))
72     {
73     case CLIENT_FILE_REQ:
74     {
75     char const * rawname;
76    
77     if (!(rawname = packet_get_str_const(packet,sizeof(t_client_file_req),MAX_FILENAME_STR)))
78     {
79     eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad FILE_REQ (missing or too long filename)",conn_get_socket(c));
80    
81     return -1;
82     }
83    
84     file_send(c,rawname,
85     bn_int_get(packet->u.client_file_req.adid),
86     bn_int_get(packet->u.client_file_req.extensiontag),
87     bn_int_get(packet->u.client_file_req.startoffset),
88     1);
89     }
90     break;
91    
92     case CLIENT_FILE_REQ2:
93     {
94     t_packet * rpacket = NULL;
95     if((rpacket = packet_create(packet_class_raw))) {
96     packet_set_size(rpacket,sizeof(t_server_file_unknown1));
97     bn_int_set( &rpacket->u.server_file_unknown1.unknown, 0xdeadbeef );
98     conn_push_outqueue(c, rpacket );
99     packet_del_ref( rpacket );
100     }
101     conn_set_state(c, conn_state_pending_raw);
102     break;
103     }
104    
105     default:
106     eventlog(eventlog_level_error,__FUNCTION__,"[%d] unknown file packet type 0x%04x, len %u",conn_get_socket(c),packet_get_type(packet),packet_get_size(packet));
107    
108     break;
109     }
110     break;
111    
112     case conn_state_pending_raw:
113     switch (packet_get_type(packet))
114     {
115     case CLIENT_FILE_REQ3:
116     {
117     char rawname[MAX_FILENAME_STR];
118    
119     psock_recv( conn_get_socket(c), rawname, MAX_FILENAME_STR, 0 );
120     file_send(c, rawname, 0, 0, 0, 1);
121     }
122     break;
123    
124     default:
125     eventlog(eventlog_level_error, __FUNCTION__, "[%d] unknown file packet type 0x%04x, len %u",conn_get_socket(c),packet_get_type(packet),packet_get_size(packet));
126    
127     break;
128     }
129     break;
130    
131     default:
132     eventlog(eventlog_level_error,__FUNCTION__,"[%d] unknown file connection state %d",conn_get_socket(c),(int)conn_get_state(c));
133     }
134    
135     return 0;
136     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1