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

Contents of /pvpgn-1.7.4/src/bnetd/handle_udp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: pvpgn_1-7-4-0_MIL, arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 /*
2 * Copyright (C) 1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "common/setup_before.h"
19 #include "common/packet.h"
20 #include "common/udp_protocol.h"
21 #include "common/eventlog.h"
22 #include "connection.h"
23 #include "common/queue.h"
24 #include "common/bn_type.h"
25 #include "common/addr.h"
26 #include "udptest_send.h"
27 #include "handle_udp.h"
28 #include "common/setup_after.h"
29
30
31 extern int handle_udp_packet(int usock, unsigned int src_addr, unsigned short src_port, t_packet const * const packet)
32 {
33 if (!packet)
34 {
35 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got NULL packet",usock);
36 return -1;
37 }
38 if (packet_get_class(packet)!=packet_class_udp)
39 {
40 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad packet (class %d)",usock,(int)packet_get_class(packet));
41 return -1;
42 }
43
44 switch (packet_get_type(packet))
45 {
46 case SERVER_UDPTEST: /* we might get these if a client is running on the same machine as us */
47 if (packet_get_size(packet)<sizeof(t_server_udptest))
48 {
49 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad UDPTEST packet (expected %u bytes, got %u)",usock,sizeof(t_server_udptest),packet_get_size(packet));
50 return -1;
51 }
52 eventlog(eventlog_level_debug,__FUNCTION__,"[%d] got UDPTEST packet from %s (myself?)",usock,addr_num_to_addr_str(src_addr,src_port));
53 return 0;
54
55 case CLIENT_UDPPING:
56 if (packet_get_size(packet)<sizeof(t_client_udpping))
57 {
58 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad UDPPING packet (expected %u bytes, got %u)",usock,sizeof(t_client_udpping),packet_get_size(packet));
59 return -1;
60 }
61 eventlog(eventlog_level_debug,__FUNCTION__,"[%d] got udpping unknown1=%u",usock,bn_int_get(packet->u.client_udpping.unknown1));
62 return 0;
63
64 case CLIENT_SESSIONADDR1:
65 if (packet_get_size(packet)<sizeof(t_client_sessionaddr1))
66 {
67 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad SESSIONADDR1 packet (expected %u bytes, got %u)",usock,sizeof(t_client_sessionaddr1),packet_get_size(packet));
68 return -1;
69 }
70
71 {
72 t_connection * c;
73
74 if (!(c = connlist_find_connection_by_sessionkey(bn_int_get(packet->u.client_sessionaddr1.sessionkey))))
75 {
76 eventlog(eventlog_level_error,__FUNCTION__,"[%d] address not set (no connection with session key 0x%08x)",usock,bn_int_get(packet->u.client_sessionaddr1.sessionkey));
77 return -1;
78 }
79
80 if (conn_get_game_addr(c)!=src_addr || conn_get_game_port(c)!=src_port)
81 eventlog(eventlog_level_info,__FUNCTION__,"[%d][%d] SESSIONADDR1 set new UDP address to %s",conn_get_socket(c),usock,addr_num_to_addr_str(src_addr,src_port));
82
83 conn_set_game_socket(c,usock);
84 conn_set_game_addr(c,src_addr);
85 conn_set_game_port(c,src_port);
86
87 udptest_send(c);
88 }
89 return 0;
90
91 case CLIENT_SESSIONADDR2:
92 if (packet_get_size(packet)<sizeof(t_client_sessionaddr2))
93 {
94 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad SESSIONADDR2 packet (expected %u bytes, got %u)",usock,sizeof(t_client_sessionaddr2),packet_get_size(packet));
95 return -1;
96 }
97
98 {
99 t_connection * c;
100
101 if (!(c = connlist_find_connection_by_sessionnum(bn_int_get(packet->u.client_sessionaddr2.sessionnum))))
102 {
103 eventlog(eventlog_level_error,__FUNCTION__,"[%d] address not set (no connection with session number %u)",usock,bn_int_get(packet->u.client_sessionaddr2.sessionnum));
104 return -1;
105 }
106 if (conn_get_sessionkey(c)!=bn_int_get(packet->u.client_sessionaddr2.sessionkey))
107 {
108 eventlog(eventlog_level_error,__FUNCTION__,"[%d][%d] address not set (expected session key 0x%08x, got 0x%08x)",conn_get_socket(c),usock,conn_get_sessionkey(c),bn_int_get(packet->u.client_sessionaddr2.sessionkey));
109 return -1;
110 }
111
112 if (conn_get_game_addr(c)!=src_addr || conn_get_game_port(c)!=src_port)
113 eventlog(eventlog_level_info,__FUNCTION__,"[%d][%d] SESSIONADDR2 set new UDP address to %s",conn_get_socket(c),usock,addr_num_to_addr_str(src_addr,src_port));
114
115 conn_set_game_socket(c,usock);
116 conn_set_game_addr(c,src_addr);
117 conn_set_game_port(c,src_port);
118
119 udptest_send(c);
120 }
121 return 0;
122
123 case CLIENT_SEARCH_LAN_GAMES: //added by Spider
124 {
125 eventlog(eventlog_level_debug,__FUNCTION__,"[%d] got SEARCH_LAN_GAMES packet from %s",usock,addr_num_to_addr_str(src_addr,src_port));
126 return 0;
127 }
128
129 default:
130 eventlog(eventlog_level_error,__FUNCTION__,"[%d] got unknown udp packet type 0x%04x, len %u from %s",usock,(unsigned int)packet_get_type(packet),packet_get_size(packet),addr_num_to_addr_str(src_addr,src_port));
131 }
132
133 return 0;
134 }

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