1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 2005 Simon Howard
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 // Network packet I/O. Base layer for sending/receiving packets,
23 // through the network module system
25 //-----------------------------------------------------------------------------
32 #define MAX_MODULES 16
36 net_module_t
*modules
[MAX_MODULES
];
40 net_addr_t net_broadcast_addr
;
42 net_context_t
*NET_NewContext(void)
44 net_context_t
*context
;
46 context
= Z_Malloc(sizeof(net_context_t
), PU_STATIC
, 0);
47 context
->num_modules
= 0;
52 void NET_AddModule(net_context_t
*context
, net_module_t
*module
)
54 if (context
->num_modules
>= MAX_MODULES
)
56 I_Error("NET_AddModule: No more modules for context");
59 context
->modules
[context
->num_modules
] = module
;
60 ++context
->num_modules
;
63 net_addr_t
*NET_ResolveAddress(net_context_t
*context
, char *addr
)
70 for (i
=0; i
<context
->num_modules
; ++i
)
72 result
= context
->modules
[i
]->ResolveAddress(addr
);
83 void NET_SendPacket(net_addr_t
*addr
, net_packet_t
*packet
)
85 addr
->module
->SendPacket(addr
, packet
);
88 void NET_SendBroadcast(net_context_t
*context
, net_packet_t
*packet
)
92 for (i
=0; i
<context
->num_modules
; ++i
)
94 context
->modules
[i
]->SendPacket(&net_broadcast_addr
, packet
);
98 boolean
NET_RecvPacket(net_context_t
*context
,
100 net_packet_t
**packet
)
104 // check all modules for new packets
106 for (i
=0; i
<context
->num_modules
; ++i
)
108 if (context
->modules
[i
]->RecvPacket(addr
, packet
))
117 // Note: this prints into a static buffer, calling again overwrites
120 char *NET_AddrToString(net_addr_t
*addr
)
122 static char buf
[128];
124 addr
->module
->AddrToString(addr
, buf
, sizeof(buf
) - 1);
129 void NET_FreeAddress(net_addr_t
*addr
)
131 addr
->module
->FreeAddress(addr
);