]> icculus.org git repositories - taylor/freespace2.git/blob - src/menuui/optionsmenumulti.cpp
const-char warning fixes
[taylor/freespace2.git] / src / menuui / optionsmenumulti.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/MenuUI/OptionsMenuMulti.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $Log$
16  * Revision 1.7  2005/03/29 02:18:47  taylor
17  * Various 64-bit platform fixes
18  * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
19  * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
20  * Streaming audio support (big thanks to Pierre Willenbrock!!)
21  * Removed dependance on strings.tbl for FS1 since we don't actually need it now
22  *
23  * Revision 1.6  2003/05/25 02:30:42  taylor
24  * Freespace 1 support
25  *
26  * Revision 1.5  2002/06/09 04:41:22  relnev
27  * added copyright header
28  *
29  * Revision 1.4  2002/06/05 08:05:29  relnev
30  * stub/warning removal.
31  *
32  * reworked the sound code.
33  *
34  * Revision 1.3  2002/06/02 06:02:59  relnev
35  * tcp.cfg namefix
36  *
37  * Revision 1.2  2002/05/07 03:16:46  theoddone33
38  * The Great Newline Fix
39  *
40  * Revision 1.1.1.1  2002/05/03 03:28:09  root
41  * Initial import.
42  *  
43  * 
44  * 21    10/25/99 5:47p Jefff
45  * reassigned some xstr ids
46  * 
47  * 20    8/02/99 2:44p Dave
48  * Disable IPX for demo build.
49  * 
50  * 19    7/15/99 7:15p Jefff
51  * Added various sound FX
52  * 
53  * 18    7/15/99 9:20a Andsager
54  * FS2_DEMO initial checkin
55  * 
56  * 17    6/25/99 11:59a Dave
57  * Multi options screen.
58  * 
59  * 16    6/22/99 7:03p Dave
60  * New detail options screen.
61  * 
62  * 15    4/25/99 3:02p Dave
63  * Build defines for the E3 build.
64  * 
65  * 14    2/25/99 4:19p Dave
66  * Added multiplayer_beta defines. Added cd_check define. Fixed a few
67  * release build warnings. Added more data to the squad war request and
68  * response packets.
69  * 
70  * 13    2/19/99 2:55p Dave
71  * Temporary checking to report the winner of a squad war match.
72  * 
73  * 12    2/17/99 2:10p Dave
74  * First full run of squad war. All freespace and tracker side stuff
75  * works.
76  * 
77  * 11    2/12/99 6:16p Dave
78  * Pre-mission Squad War code is 95% done.
79  * 
80  * 10    2/05/99 7:22p Neilk
81  * Fixed gamma bitmap and converted coordinates for multiple resolutions
82  * 
83  * 9     2/02/99 11:36a Dave
84  * Removed obsolete data reference.
85  * 
86  * 8     12/18/98 1:13a Dave
87  * Rough 1024x768 support for Direct3D. Proper detection and usage through
88  * the launcher.
89  * 
90  * 7     11/20/98 11:16a Dave
91  * Fixed up IPX support a bit. Making sure that switching modes and
92  * loading/saving pilot files maintains proper state.
93  * 
94  * 6     11/19/98 4:19p Dave
95  * Put IPX sockets back in psnet. Consolidated all multiplayer config
96  * files into one.
97  * 
98  * 5     11/05/98 5:55p Dave
99  * Big pass at reducing #includes
100  * 
101  * 4     10/13/98 9:28a Dave
102  * Started neatening up freespace.h. Many variables renamed and
103  * reorganized. Added AlphaColors.[h,cpp]
104  * 
105  * 3     10/09/98 2:57p Dave
106  * Starting splitting up OS stuff.
107  * 
108  * 2     10/07/98 10:53a Dave
109  * Initial checkin.
110  * 
111  * 1     10/07/98 10:49a Dave
112  * 
113  * 27    7/08/98 11:56a Dave
114  * Changed mic problem error message.
115  * 
116  * 26    6/12/98 7:13p Hoffoss
117  * Fixed options screen problem where it wasn't showing tooltips.
118  * 
119  * 25    6/09/98 10:31a Hoffoss
120  * Created index numbers for all xstr() references.  Any new xstr() stuff
121  * added from here on out should be added to the end if the list.  The
122  * current list count can be found in FreeSpace.cpp (search for
123  * XSTR_SIZE).
124  * 
125  * 24    6/01/98 11:43a John
126  * JAS & MK:  Classified all strings for localization.
127  * 
128  * 23    5/21/98 9:45p Dave
129  * Lengthened tracker polling times. Put in initial support for PXO
130  * servers with channel filters. Fixed several small UI bugs.
131  * 
132  * 22    5/20/98 2:24a Dave
133  * Fixed server side voice muting. Tweaked multi debrief/endgame
134  * sequencing a bit. Much friendlier for stats tossing/accepting now.
135  * 
136  * 21    5/19/98 1:35a Dave
137  * Tweaked pxo interface. Added rankings url to pxo.cfg. Make netplayer
138  * local options update dynamically in netgames.
139  * 
140  * 20    5/18/98 12:03p Frank
141  * Make sure network changes made in options screen are loaded into any
142  * current Net_player as well as the Player.
143  * 
144  * 19    5/11/98 11:39p Dave
145  * Stuff.
146  * 
147  * 18    5/10/98 7:05p Dave
148  * Fix endgame sequencing ESC key. Changed how host options warning popups
149  * are done. Fixed pause/message scrollback/options screen problems in mp.
150  * Make sure observer HUD doesn't try to lock weapons.
151  * 
152  * 17    5/08/98 7:08p Dave
153  * Lots of UI tweaking.
154  * 
155  * 16    5/08/98 5:04p Dave
156  * Go to the join game screen when quitting multiplayer. Fixed mission
157  * text chat bugs. Put mission type symbols on the create game list.
158  * Started updating standalone gui controls.
159  * 
160  * 15    5/07/98 12:57a Dave
161  * Fixed incorrect calls to free() from stats code. Put in new artwork for
162  * debrief and host options screens. Another modification to scoring
163  * system for secondary weapons.
164  * 
165  * 14    5/06/98 8:06p Dave
166  * Made standalone reset properly under weird conditions. Tweak
167  * optionsmulti screen. Upped MAX_WEAPONS to 350. Put in new launch
168  * countdown anim. Minro ui fixes/tweaks.
169  * 
170  * 13    5/02/98 5:38p Dave
171  * Put in new tracker API code. Put in ship information on mp team select
172  * screen. Make standalone server name permanent. Fixed standalone server
173  * text messages.
174  * 
175  * 12    4/30/98 5:24p Adam
176  * JAS: Made multi config specify path.
177  * 
178  * 11    4/28/98 5:13p Dave
179  * Remove references to old MT API
180  * 
181  * 10    4/25/98 2:00p Dave
182  * Installed a bunch of multiplayer context help screens. Reworked ingame
183  * join ship select screen. Fix places where network timestamps get hosed.
184  * 
185  * 9     4/22/98 4:09p John
186  * String externalization
187  * 
188  * 8     4/22/98 12:34a Dave
189  * Make sure hud config and control config buttons draw properly in all
190  * tab modes. Make small tab buttons light up correctly in multi options
191  * screen.
192  * 
193  * 7     4/21/98 4:44p Dave
194  * Implement Vasudan ships in multiplayer. Added a debug function to bash
195  * player rank. Fixed a few rtvoice buffer overrun problems. Fixed ui
196  * problem in options screen. 
197  * 
198  * 6     4/20/98 6:04p Dave
199  * Implement multidata cache flushing and xferring mission files to
200  * multidata. Make sure observers can't change hud config. Fix pilot image
201  * viewing in popup. Put in game status field. Tweaked multi options. 
202  * 
203  * 5     4/18/98 12:45p Dave
204  * Aesthetic changes to multi options screen. Put in missing exit button.
205  * oops.
206  * 
207  * 4     4/17/98 6:33p Dave
208  * Finished first run of the screen. About time.
209  * 
210  * 3     4/17/98 5:27p Dave
211  * More work on the multi options screen. Fixed many minor ui todo bugs.
212  * 
213  * 2     4/17/98 12:42a Dave
214  * Worked on voice tab. Need to implement mic testing and player muting
215  * list thingie.
216  * 
217  * 1     4/16/98 11:39p Dave
218  *  
219  * 
220  * $NoKeywords: $
221  */
222
223 #include "ui.h"
224 #include "bmpman.h"
225 #include "cfile.h"
226 #include "key.h"
227 #include "ds.h"
228 #include "font.h"
229 #include "gamesnd.h"
230 #include "freespace.h"
231 #include "player.h"
232 #include "multi.h"
233 #include "multi_voice.h"
234 #include "rtvoice.h"
235 #include "mouse.h"
236 #include "optionsmenu.h"
237 #include "optionsmenumulti.h"
238 #include "popup.h"
239 #include "osregistry.h"
240 #include "alphacolors.h"
241 #include "timer.h"
242 #include "gamesequence.h"  // needed for FS1
243
244 // general data section ------------------------------------------------
245 UI_WINDOW *Om_window = NULL;
246
247 #ifndef FS1_DEMO
248 static const char* Om_background_0_fname[GR_NUM_RESOLUTIONS] = {
249         "OptionsMultiGen",                      // GR_640
250         "2_OptionsMultiGen"                     // GR_1024
251 };
252
253 static const char* Om_background_0_mask_fname[GR_NUM_RESOLUTIONS] = {
254         "OptionsMultiGen-M",                    // GR_640
255         "2_OptionsMultiGen-M"           // GR_1024
256 };
257
258 static const char* Om_background_1_fname[GR_NUM_RESOLUTIONS] = {
259         "OptionsMultiVox",                      // GR_640
260         "2_OptionsMultiVox"                     // GR_1024
261 };
262
263 static const char* Om_background_1_mask_fname[GR_NUM_RESOLUTIONS] = {
264         "OptionsMultiVox-M",                    // GR_640
265         "2_OptionsMultiVox-M"           // GR_1024
266 };
267
268 int Om_background_0 = -1;
269 int Om_mask_0             = -1;
270
271 int Om_background_1 = -1;
272 int Om_mask_1       = -1;
273 #endif  // FS1_DEMO
274
275 // screen modes
276 #define OM_MODE_NONE                                                                    -1              // no mode (unintialized)
277 #define OM_MODE_GENERAL                                                         0               // general tab
278 #define OM_MODE_VOX                                                                     1               // voice tab
279 int Om_mode = OM_MODE_NONE;
280
281 // notification stuff
282 #define OM_NOTIFY_TIME                                                          8000
283 #define OM_NOTIFY_Y                                                                     430
284 #define OM_NOTIFY_Y2                                                                    440
285 int Om_notify_stamp = -1;
286 char Om_notify_string[255];
287
288 // load all background bitmaps
289 void options_multi_load_bmaps();
290
291 // unload all the background bitmaps
292 void options_multi_unload_bmaps();
293
294 // add a notification message
295 void options_multi_add_notify(const char *str);
296
297 // process and blit any notification messages
298 void options_multi_notify_process();
299
300
301 // protocol options section -------------------------------------------
302 #ifdef MAKE_FS1
303 #define OM_PRO_NUM_BUTTONS                                                      12
304
305 #define ABORT_GAME_BUTTON                                                       0
306 #define CONTROL_CONFIG_BUTTON                                           1
307 #define HUD_CONFIG_BUTTON                                                       2
308 #define OM_PRO_SCROLL_IP_UP                                                     3
309 #define OM_PRO_SCROLL_IP_DOWN                                           4
310 #define OM_PRO_ADD_IP                                                           5
311 #define OM_PRO_DELETE_IP                                                        6
312 #define OM_PRO_LOCAL_BROADCAST_YES                                      7
313 #define OM_PRO_LOCAL_BROADCAST_NO                                       8
314 #define OM_PRO_VMT                                                                      9
315 #define OM_PRO_VOX_TAB                                                          10
316 #define OM_PRO_GEN_TAB                                                          11
317 #else
318 #define OM_PRO_NUM_BUTTONS                                                              10
319
320 #define OM_PRO_TCP                                                                              0
321 #define OM_PRO_IPX                                                                              1
322 #define OM_PRO_SCROLL_IP_UP                                                     2
323 #define OM_PRO_SCROLL_IP_DOWN                                                   3
324 #define OM_PRO_ADD_IP                                                                   4
325 #define OM_PRO_DELETE_IP                                                                5
326 #define OM_PRO_LOCAL_BROADCAST                                          6
327 #define OM_PRO_VMT                                                                              7
328 #define OM_PRO_VOX_TAB                                                                  8
329 #define OM_PRO_GEN_TAB                                                                  9
330 #endif
331
332 ui_button_info Om_pro_buttons[GR_NUM_RESOLUTIONS][OM_PRO_NUM_BUTTONS] = {
333         { // GR_640
334 #ifdef MAKE_FS1
335                 ui_button_info("OPb_04",        6,              377,    -1,     -1,     4),             // Exit Game
336                 ui_button_info("OPb_05",        448,    335,    -1,     -1,     5),             // Control Config
337                 ui_button_info("OPb_06",        541,    335,    -1,     -1,     6),             // HUD Config
338
339                 ui_button_info("OPb_87",        252,    129,    -1,     -1,     87),    // Scroll IP Up
340                 ui_button_info("OPb_88",        252,    166,    -1,     -1,     88),    // Scroll IP Down
341                 ui_button_info("OPb_85",        26,             131,    -1,     -1,     85),    // Add IP
342                 ui_button_info("OPb_86",        26,             166,    -1,     -1,     86),    // Remove IP
343                 ui_button_info("OPb_89",        26,             221,    -1,     -1,     89),    // Local Broadcast Yes
344                 ui_button_info("OPb_90",        104,    221,    -1,     -1,     90),    // Local Broadcast No
345                 ui_button_info("OPb_91",        26,             243,    -1,     -1,     91),    // Parallax Online
346                 ui_button_info("OPb_92",        402,    72,     -1,     -1,     92),            // Voice Tab
347                 ui_button_info("OPb_93",        487,    72,     -1,     -1,     93),            // General Tab
348 #else
349                 ui_button_info("OMuB_07",       7,              66,     -1,     -1,     7),
350                 ui_button_info("OMuB_08",       7,              84,     -1,     -1,     8),
351                 ui_button_info("OMuB_09",       1,              124,    -1,     -1,     9),
352                 ui_button_info("OMuB_10",       1,              157,    -1,     -1,     10),
353                 ui_button_info("OMuB_11",       20,     207,    -1,     -1,     11),
354                 ui_button_info("OMuB_12",       64,     207,    -1,     -1,     12),
355                 ui_button_info("OMuB_13",       9,              251,    -1,     -1,     13),
356                 ui_button_info("OMuB_14",       9,              282,    -1,     -1,     14),
357                 ui_button_info("OMuB_15",       610,    53,     -1,     -1,     15),
358                 ui_button_info("OMuB_16",       610,    72,     -1,     -1,     16),
359 #endif
360         },
361         { // GR_1024
362                 ui_button_info("2_OMuB_07",     12,     105,    -1,     -1,     7),
363                 ui_button_info("2_OMuB_08",     12,     134,    -1,     -1,     8),
364                 ui_button_info("2_OMuB_09",     2,              198,    -1,     -1,     9),
365                 ui_button_info("2_OMuB_10",     2,              252,    -1,     -1,     10),
366                 ui_button_info("2_OMuB_11",     32,     332,    -1,     -1,     11),
367                 ui_button_info("2_OMuB_12",     103,    332,    -1,     -1,     12),
368                 ui_button_info("2_OMuB_13",     14,     402,    -1,     -1,     13),
369                 ui_button_info("2_OMuB_14",     14,     452,    -1,     -1,     14),
370                 ui_button_info("2_OMuB_15",     976,    85,     -1,     -1,     15),
371                 ui_button_info("2_OMuB_16",     976,    114,    -1,     -1,     16),
372 #ifdef MAKE_FS1
373                 // filler for extra FS1 buttons
374                 ui_button_info("none",          -1,     -1,     -1,     -1,     -1),
375                 ui_button_info("none",          -1,     -1,     -1,     -1,     -1),
376 #endif
377         }
378 };
379
380 UI_GADGET Om_pro_bogus;
381
382 // test
383 #ifndef MAKE_FS1
384 #define OM_PRO_NUM_TEXT         12
385
386 UI_XSTR Om_pro_text[GR_NUM_RESOLUTIONS][OM_PRO_NUM_TEXT] = {
387         { // GR_640
388                 { "TCP",                                1378,   38,     70,     UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_TCP].button },
389                 { "IPX",                                1379,   38,     88,     UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_IPX].button },
390                 { "IP Address", 1380,   30,     128,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
391                 { "add",                                1381,   22,     235,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_ADD_IP].button },
392                 { "rem.",                       1382,   68,     235,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_DELETE_IP].button },
393                 { "Broadcast Locally",  1397,   42,     260,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_LOCAL_BROADCAST].button },   
394                 { "PXO",                                1383,   42,     291,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_VMT].button },
395                 { "Login",                      1384,   14,     309,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
396                 { "Password",           1385,   14,     336,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
397                 { "Squadron",           1386,   14,     363,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
398                 { "Voice",                      1528,   557,    60,     UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_VOX_TAB].button },
399                 { "General",            1388,   542,    77,     UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[0][OM_PRO_GEN_TAB].button },   
400         },
401         { // GR_1024
402                 { "TCP",                                1378,   61,     113,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_TCP].button },
403                 { "IPX",                                1379,   61,     141,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_IPX].button },
404                 { "IP Address", 1380,   47,     206,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
405                 { "add",                                1381,   36,     375,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_ADD_IP].button },
406                 { "rem.",                       1382,   109,    375,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_DELETE_IP].button },
407                 { "Broadcast Locally",  1397,   68,     417,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_LOCAL_BROADCAST].button },   
408                 { "PXO",                                1383,   68,     467,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_VMT].button },
409                 { "Login",                      1384,   23,     495,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
410                 { "Password",           1385,   23,     538,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
411                 { "Squadron",           1386,   23,     582,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_bogus },
412                 { "Voice",                      1528,   921,    96,     UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_VOX_TAB].button },
413                 { "General",            1388,   902,    123,    UI_XSTR_COLOR_GREEN, -1, &Om_pro_buttons[1][OM_PRO_GEN_TAB].button },   
414         }
415 };
416 #endif
417
418 // defines for the tracker input boxes
419 int Om_tracker_login_coords[GR_NUM_RESOLUTIONS][4] = {
420         {
421 #ifdef MAKE_FS1
422                 62, 284, 175, -1
423 #else
424                 19, 322, 226, -1                // GR_640
425 #endif
426         },
427         {
428                 31, 518, 361, -1                // GR_1024
429         }
430 };
431 int Om_tracker_passwd_coords[GR_NUM_RESOLUTIONS][4] = {
432         {
433 #ifdef MAKE_FS1
434                 62, 328, 175, -1
435 #else
436                 19, 350, 226, -1                // GR_640
437 #endif
438         },
439         {
440                 31, 562, 361, -1                // GR_1024
441         }
442 };
443 int Om_tracker_squad_name_coords[GR_NUM_RESOLUTIONS][4] = {
444         {
445                 19, 378, 226, -1                // GR_640
446         },
447         {
448                 31, 607, 361, -1                // GR_1024
449         }
450 };
451
452 // protocol section tracker login input box
453 UI_INPUTBOX Om_tracker_login;
454
455 // protocol section tracker passwd input box
456 UI_INPUTBOX Om_tracker_passwd;
457
458 // pxo squad name/password
459 UI_INPUTBOX Om_tracker_squad_name;
460
461 #define TRACKER_FOCUS_NONE                      0
462 #define TRACKER_FOCUS_LOGIN             1
463 #define TRACKER_FOCUS_PASSWORD  2
464 #define TRACKER_FOCUS_SQUADRON  3
465 static int Om_tracker_focus = 0;
466
467 // ip address list vars
468 #define IP_STRING_LEN                                                           255
469 #define MAX_IP_ADDRS                                                                    100
470
471 #define IP_EMPTY_STRING                                                         ""
472
473 int Ip_list_coords[GR_NUM_RESOLUTIONS][4] = {
474         {
475 #ifdef MAKE_FS1
476                 106, 147, 141, 48
477 #else
478                 29, 137, 227, 67                // GR_640
479 #endif
480         },
481         {
482                 46, 220, 364, 106               // GR_1024
483         }
484 };
485
486
487 int Ip_list_max_display[GR_NUM_RESOLUTIONS] = {
488         5,
489         5
490 };
491
492 static int Ip_input_coords[GR_NUM_RESOLUTIONS][4] = {
493         {
494 #ifdef MAKE_FS1
495                 107, 138, 140, -1
496 #else
497                 109, 128, 140, -1               // GR_640
498 #endif
499         },
500         {
501                 132, 206, 261, -1               // GR_640
502         }
503 };
504
505 int Om_input_mode = 0;
506 int Om_ip_start;                                                                                                // index of the first element to be displayed in the list box
507 int Om_ip_selected;                                        // the selected default IP address
508 int Om_ip_disp_count;                              // how many items are currently being displayed
509 int Om_num_ips;                                                                                         // # of ip addresses we have
510 char Om_ip_addrs[MAX_IP_ADDRS][IP_STRING_LEN];          // the ip addresses themselves
511 UI_BUTTON Om_ip_button;                                                                         // button for detecting clicks on the ip address list
512 UI_INPUTBOX Om_ip_input;                                                                        // input box for adding new ip addresses
513
514 // setting vars
515 int Om_local_broadcast;                                                                         // whether the player has local broadcast selected or not
516 int Om_tracker_flag;                                                                                    // if the guy has the tracker selected
517 int Om_protocol;                                                                                                // protocol in use
518
519 // load all the controls for the protocol section
520 void options_multi_load_protocol_controls();
521
522 // disable/hide all the controls for the protocol section
523 void options_multi_disable_protocol_controls();
524
525 // enable/unhide all the controls for the protocol section
526 void options_multi_enable_protocol_controls();
527
528 // intialize the protocol section vars
529 void options_multi_init_protocol_vars();
530
531 // do frame for the protocol section
532 void options_multi_protocol_do(int key);
533
534 // if the accept button was hit
535 void options_multi_protocol_accept();
536
537 // check for button presses
538 void options_multi_protocol_check_buttons();
539
540 // if a button was pressed
541 void options_multi_protocol_button_pressed(int n);
542
543 // load the ip address file
544 void options_multi_protocol_load_ip_file();
545
546 // save the ip address file
547 void options_multi_protocol_save_ip_file();
548
549 // draw the list of ip addresses
550 void options_multi_protocol_display_ips();
551
552 // scroll the list of ip addresses down
553 void options_multi_protocol_scroll_ip_down();
554
555 // scroll the list of ip addresses up
556 void options_multi_protocol_scroll_ip_up();
557
558 // check the ip list to see if the user has selected a new item
559 void options_multi_protocol_check_ip_list();
560
561 // delete the currently selected ip if any
562 void options_multi_protocol_delete_ip();
563
564 // attempt to add the currently entered ip address
565 void options_multi_protocol_add_current_ip();
566
567
568 // general options tab section -------------------------------------------
569 #define OM_GEN_NUM_BUTTONS                                                              10
570
571 #define OM_GEN_OBJ_LOW                                                                  0
572 #define OM_GEN_OBJ_MED                                                                  1
573 #define OM_GEN_OBJ_HIGH                                                                 2
574 #define OM_GEN_OBJ_LAN                                                                  3
575 #define OM_GEN_PIX_YES                                                                  4
576 #define OM_GEN_PIX_NO                                                                   5
577 #define OM_GEN_XFER_MULTIDATA_YES                                       6
578 #define OM_GEN_XFER_MULTIDATA_NO                                                7
579 #define OM_GEN_FLUSH_NO                                                                 8
580 #define OM_GEN_FLUSH_YES                                                                9
581
582 ui_button_info Om_gen_buttons[GR_NUM_RESOLUTIONS][OM_GEN_NUM_BUTTONS] = {
583         { // GR_640
584 #ifdef MAKE_FS1
585                 ui_button_info("OPb_94",        410,    121,    -1,     -1,     94),
586                 ui_button_info("OPb_95",        410,    143,    -1,     -1,     95),
587                 ui_button_info("OPb_96",        410,    165,    -1,     -1,     96),
588                 ui_button_info("none",          -1,             -1,             -1,     -1,     -1),    // no LAN setting in FS1
589                 ui_button_info("OPb_97",        410,    199,    -1,     -1,     97),
590                 ui_button_info("OPb_98",        496,    199,    -1,     -1,     98),
591                 ui_button_info("OPb_99",        410,    233,    -1,     -1,     99),
592                 ui_button_info("OPb_100",       410,    256,    -1,     -1,     100),
593                 ui_button_info("OPb_101",       410,    290,    -1,     -1,     101),
594                 ui_button_info("OPb_102",       410,    313,    -1,     -1,     102),
595 #else
596                 ui_button_info("OGB_17",        598,    117,    -1,     -1,     17),
597                 ui_button_info("OGB_18",        598,    139,    -1,     -1,     18),
598                 ui_button_info("OGB_19",        598,    161,    -1,     -1,     19),
599                 ui_button_info("OGB_20",        598,    183,    -1,     -1,     20),
600                 ui_button_info("OGB_21",        549,    229,    -1,     -1,     21),
601                 ui_button_info("OGB_22",        598,    229,    -1,     -1,     22),
602                 ui_button_info("OGB_23",        598,    286,    -1,     -1,     23),
603                 ui_button_info("OGB_24",        598,    307,    -1,     -1,     24),
604                 ui_button_info("OGB_25",        598,    347,    -1,     -1,     25),
605                 ui_button_info("OGB_26",        598,    368,    -1,     -1,     26),
606 #endif
607         },
608         { // GR_1024
609                 ui_button_info("2_OGB_17",      957,    188,    -1,     -1,     17),
610                 ui_button_info("2_OGB_18",      957,    223,    -1,     -1,     18),
611                 ui_button_info("2_OGB_19",      957,    258,    -1,     -1,     19),
612                 ui_button_info("2_OGB_20",      957,    293,    -1,     -1,     20),
613                 ui_button_info("2_OGB_21",      879,    366,    -1,     -1,     21),
614                 ui_button_info("2_OGB_22",      957,    366,    -1,     -1,     22),
615                 ui_button_info("2_OGB_23",      957,    457,    -1,     -1,     23),
616                 ui_button_info("2_OGB_24",      957,    491,    -1,     -1,     24),
617                 ui_button_info("2_OGB_25",      957,    555,    -1,     -1,     25),
618                 ui_button_info("2_OGB_26",      957,    589,    -1,     -1,     26),
619         }
620 };
621
622 UI_GADGET Om_gen_bogus;
623
624 // text
625 #ifndef MAKE_FS1
626 #define OM_GEN_NUM_TEXT                                 14
627
628 UI_XSTR Om_gen_text[GR_NUM_RESOLUTIONS][OM_GEN_NUM_TEXT] = {
629         { // GR_640
630                 { "Object Update",      1391,           511,    104,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
631                 { "Low",                                        1160,           558,    127,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_OBJ_LOW].button },
632                 { "Medium",                             1161,           538,    149,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_OBJ_MED].button },            
633                 { "High",                               1162,           556,    171,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_OBJ_HIGH].button },           
634                 { "Lan",                                        1392,           561,    193,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_OBJ_LAN].button },            
635                 { "Pilot / Squad Images",       1393,           463,    214,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
636                 { "Yes",                                        1394,           555,    257,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_PIX_YES].button },            
637                 { "No",                                 1395,           604,    257,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_PIX_NO].button },             
638                 { "Transfer Missions",          1396,           478,    271,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
639                 { "/multidata",         1397,           519,    292,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_XFER_MULTIDATA_YES].button },         
640                 { "/missions",                  1398,           527,    314,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_XFER_MULTIDATA_NO].button },          
641                 { "Flush Cache",                1399,           529,    334,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
642                 { "Never",                              1400,           548,    355,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_FLUSH_NO].button },           
643                 { "Before Game",                1401,           502,    377,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[0][OM_GEN_FLUSH_YES].button },          
644         },
645         { // GR_1024
646                 { "Object Update",      1391,           818,    166,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
647                 { "Low",                                        1160,           913,    204,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_OBJ_LOW].button },
648                 { "Medium",                             1161,           892,    239,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_OBJ_MED].button },            
649                 { "High",                               1162,           909,    274,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_OBJ_HIGH].button },           
650                 { "Lan",                                        1392,           916,    310,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_OBJ_LAN].button },            
651                 { "Pilot / Squad Images",       1393,           821,    345,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
652                 { "Yes",                                        1394,           887,    411,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_PIX_YES].button },            
653                 { "No",                                 1395,           966,    411,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_PIX_NO].button },             
654                 { "Transfer Missions",          1396,           844,    435,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
655                 { "/multidata",         1397,           858,    468,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_XFER_MULTIDATA_YES].button },         
656                 { "/missions",                  1398,           870,    503,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_XFER_MULTIDATA_NO].button },          
657                 { "Flush Cache",                1399,           886,    533,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_bogus },                
658                 { "Never",                              1400,           897,    568,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_FLUSH_NO].button },           
659                 { "Before Game",                1401,           849,    603,    UI_XSTR_COLOR_GREEN,    -1,     &Om_gen_buttons[1][OM_GEN_FLUSH_YES].button },          
660         }
661 };
662 #endif
663
664 // setting vars
665 int Om_gen_obj_update;                                                          // object update level
666 int Om_gen_pix;                                                                         // accept pilot pix or not
667 int Om_gen_xfer_multidata;                                                      // xfer missions to multidata or not
668 int Om_gen_flush_cache;                                                         // flush multidata directory before every game
669
670 // load all the general tab controls
671 void options_multi_load_gen_controls();
672
673 // disable/hide all the general tab controls
674 void options_multi_disable_gen_controls();
675
676 // enable/unhide all the general tab controls
677 void options_multi_enable_gen_controls();
678
679 // initialize the general tab vars
680 void options_multi_init_gen_vars();
681
682 // accept function for the general tab
683 void options_multi_gen_accept();
684
685 // do frame for the general tab
686 void options_multi_gen_do();
687
688 // check for button presses
689 void options_multi_gen_check_buttons();
690
691 // a button was pressed
692 void options_multi_gen_button_pressed(int n);
693
694
695 // voice options tab section -------------------------------------------
696 #define OM_VOX_NUM_BUTTONS                                                              6
697
698 #define OM_VOX_VOICE_TEST                                                               0
699 #define OM_VOX_VOICE_YES                                                                1
700 #define OM_VOX_VOICE_NO                                                                 2
701 #define OM_VOX_PLIST_UP                                                                 3
702 #define OM_VOX_PLIST_DOWN                                                               4
703 #define OM_VOX_VOICE_MUTE                                                               5
704
705 UI_GADGET Om_vox_bogus;
706
707 ui_button_info Om_vox_buttons[GR_NUM_RESOLUTIONS][OM_VOX_NUM_BUTTONS] = {
708         { // GR_640
709 #ifdef MAKE_FS1
710                 ui_button_info("OPb_103",       413,    110,    -1,     -1,     103),
711                 ui_button_info("OPb_105",       413,    186,    -1,     -1,     105),
712                 ui_button_info("OPb_106",       491,    186,    -1,     -1,     106),
713                 ui_button_info("OPb_108",       413,    253,    -1,     -1,     108),
714                 ui_button_info("OPb_109",       413,    291,    -1,     -1,     109),
715                 ui_button_info("OPb_107",       413,    229,    -1,     -1,     107),
716 #else
717                 ui_button_info("OVB_17",        562,    118,    -1,     -1,     17),
718                 ui_button_info("OVB_19",        551,    208,    -1,     -1,     19),
719                 ui_button_info("OVB_20",        599,    208,    -1,     -1,     20),
720                 ui_button_info("OVB_21",        614,    256,    -1,     -1,     21),
721                 ui_button_info("OVB_22",        614,    290,    -1,     -1,     22),
722                 ui_button_info("OVB_23",        599,    354,    -1,     -1,     23),
723 #endif
724         },
725         { // GR_640
726                 ui_button_info("2_OVB_17",      900,    189,    -1,     -1,     17),
727                 ui_button_info("2_OVB_19",      882,    333,    -1,     -1,     19),
728                 ui_button_info("2_OVB_20",      959,    333,    -1,     -1,     20),
729                 ui_button_info("2_OVB_21",      983,    410,    -1,     -1,     21),
730                 ui_button_info("2_OVB_22",      983,    464,    -1,     -1,     22),
731                 ui_button_info("2_OVB_23",      959,    566,    -1,     -1,     23),
732         }
733 };
734
735 // text
736 #ifndef MAKE_FS1
737 #define OM_VOX_NUM_TEXT                                 6
738
739 UI_XSTR Om_vox_text[GR_NUM_RESOLUTIONS][OM_VOX_NUM_TEXT] = {
740         { // GR_640
741                 { "Mic test",                           1389,           567,    104,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[0][OM_VOX_VOICE_TEST].button },
742                 { "Voice Quality",              1531,           439,    149,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_bogus },
743                 { "Voice Transmission", 1530,           439,    193,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_bogus },
744                 { "On",                                         1285,           556,    233,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[0][OM_VOX_VOICE_YES].button },
745                 { "Off",                                                1286,           604,    233,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[0][OM_VOX_VOICE_NO].button },
746                 { "Mute",                                       1390,           594,    381,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[0][OM_VOX_VOICE_MUTE].button },
747         },
748         { // GR_1024
749                 { "mic test",                           1389,           908,    166,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[1][OM_VOX_VOICE_TEST].button },
750                 { "Voice Quality",              1531,           703,    239,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_bogus },
751                 { "Voice Transmission", 1530,           783,    310,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_bogus },
752                 { "On",                                         1285,           890,    373,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[1][OM_VOX_VOICE_YES].button },
753                 { "Off",                                                1286,           967,    373,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[1][OM_VOX_VOICE_NO].button },
754                 { "Mute",                                       1390,           950,    609,    UI_XSTR_COLOR_GREEN,    -1, &Om_vox_buttons[1][OM_VOX_VOICE_MUTE].button },
755         }
756 };
757 #endif
758
759 #define NUM_OM_VOX_SLIDERS                              1
760 #define OM_VOX_QOS_SLIDER                               0
761
762 op_sliders Om_vox_sliders[GR_NUM_RESOLUTIONS][NUM_OM_VOX_SLIDERS] = {
763         { // GR_640                             
764 #ifdef MAKE_FS1
765                 op_sliders("OPb_104",   413,    151,    -1,     -1,     104,    20,     10,     NULL, -1,       -1,     -1,     NULL,   -1,     -1,     -1),
766 #else
767                 op_sliders("OVB_18",    429,    162,    -1,     -1,     18,     20,     10, NULL, -1, -1, -1, NULL, -1, -1, -1),        // voice QOS
768 #endif
769         },      
770         { // GR_1024                            
771                 op_sliders("2_OVB_18",  686,    259,    -1,     -1,     18,     20,     10, NULL, -1, -1, -1, NULL, -1, -1, -1),        // voice QOS
772         }
773 };
774
775 // player list area
776 int Om_vox_plist_coords[GR_NUM_RESOLUTIONS][4] = {
777         {       // GR_640
778 #ifdef MAKE_FS1
779                 445, 260, 142, 61
780 #else
781                 377, 270, 232, 79
782 #endif
783         },
784         {       // GR_1024
785                 604, 432, 371, 127
786         }
787 };
788 int Om_vox_plist_max_display[GR_NUM_RESOLUTIONS] = {
789         6,
790         6
791 };
792
793 int Om_vox_plist_start;
794 UI_BUTTON Om_vox_plist_button;
795
796 // voice test buffer
797 #define OM_VOX_BUF_SIZE                         (1<<12)
798 #define OM_VOX_COMP_SIZE                        ((1<<15) + (1<<14))
799
800 #define OM_VOX_WAVE_Y                           240
801 #define OM_VOX_WAVE_WIDTH                       300
802
803 #define OM_VOX_DROP_ICON_X                      100
804 #define OM_VOX_DROP_ICON_Y                      100
805
806 #define OM_VOX_RECORD_INT                       175
807
808 unsigned char Om_vox_voice_buffer[OM_VOX_BUF_SIZE];
809 int Om_vox_voice_buffer_size = -1;
810
811 unsigned char Om_vox_comp_buffer[OM_VOX_COMP_SIZE];
812 int Om_vox_voice_comp_size = -1;
813
814 int Om_vox_playback_handle;
815
816 // status of any test voice recording
817 #define OM_VOX_TEST_NONE                                        -1
818 #define OM_VOX_TEST_RECORDING                           0
819 #define OM_VOX_TEST_PLAYBACK                            1
820 int Om_vox_test_status = OM_VOX_TEST_NONE;
821
822 // setting vars
823 int Om_vox_accept_voice;
824
825 // simple list of players we are looking through
826 net_player *Om_vox_players[MAX_PLAYERS];
827
828 // selected player
829 net_player *Om_vox_player_select;
830
831 // mute or don't mute for each player
832 int Om_vox_player_flags[MAX_PLAYERS];
833
834 // the # of players
835 int Om_vox_num_players;
836
837 // load all the voice tab controls
838 void options_multi_load_vox_controls();
839
840 // disable/hide all the voice tab controls
841 void options_multi_disable_vox_controls();
842
843 // enable/unhide all the voice tab controls
844 void options_multi_enable_vox_controls();
845
846 // initialize the voice tab vars
847 void options_multi_init_vox_vars();
848
849 // accept function for the voice tab
850 void options_multi_vox_accept();
851
852 // do frame for the voice tab
853 void options_multi_vox_do();
854
855 // check for button presses
856 void options_multi_vox_check_buttons();
857
858 // a button was pressed
859 void options_multi_vox_button_pressed(int n);
860
861 // process/display the player list
862 void options_multi_vox_process_player_list();
863
864 // scroll the player list down
865 void options_multi_vox_plist_scroll_down();
866
867 // scroll the player list up
868 void options_multi_vox_plist_scroll_up();
869
870 // get the index into the player list of the passed netplayer
871 int options_multi_vox_plist_get(net_player *pl);
872
873
874 // general data section ------------------------------------------------
875
876 // load all background bitmaps
877 void options_multi_load_bmaps()
878 {
879 #ifndef FS1_DEMO
880         // load both background bitmaps
881         Om_background_0 = bm_load(Om_background_0_fname[gr_screen.res]);
882         if(Om_background_0 == -1){
883                 nprintf(("Network","Error loading options background %s\n",Om_background_0_fname[gr_screen.res]));
884         }
885
886         Om_background_1 = bm_load(Om_background_1_fname[gr_screen.res]);
887         if(Om_background_1 == -1){
888                 nprintf(("Network","Error loading options background %s\n",Om_background_1_fname[gr_screen.res]));
889         }
890
891         // load in both mask bitmaps
892         Om_mask_0 = bm_load(Om_background_0_mask_fname[gr_screen.res]);
893         if(Om_mask_0 == -1){
894                 nprintf(("Network","Error loading options background mask %s\n",Om_background_0_mask_fname[gr_screen.res]));
895         }
896
897         Om_mask_1 = bm_load(Om_background_1_mask_fname[gr_screen.res]);
898         if(Om_mask_1 == -1){
899                 nprintf(("Network","Error loading options background mask %s\n",Om_background_1_mask_fname[gr_screen.res]));
900         }
901 #endif
902 }
903
904 // unload all the background bitmaps
905 void options_multi_unload_bmaps()
906 {
907 #ifndef FS1_DEMO
908         // unload all background bitmaps
909         if(Om_background_0 != -1){
910                 bm_release(Om_background_0);
911                 Om_background_0 = -1;
912         } 
913         if(Om_background_1 != -1){
914                 bm_release(Om_background_1);
915                 Om_background_1 = -1;
916         }
917
918         // unload all mask bitmaps
919         if(Om_mask_0 != -1){
920                 bm_release(Om_mask_0);
921                 Om_mask_0 = -1;
922         }
923         if(Om_mask_1 != -1){
924                 bm_release(Om_mask_1);
925                 Om_mask_1 = -1;
926         }
927 #endif
928 }
929
930 // add a notification message
931 void options_multi_add_notify(const char *str)
932 {
933         // copy the string
934         memset(Om_notify_string,0,255);
935         if(str != NULL){                
936                 strcpy(Om_notify_string,str);
937         }               
938
939         // set the timestamp
940         Om_notify_stamp = timestamp(OM_NOTIFY_TIME);
941 }
942
943 // process and blit any notification messages
944 void options_multi_notify_process()
945 {
946         int w;
947         char *p_str[3];
948         int n_chars[3];
949         char line[255];
950         int line_count;
951         int y_start;
952         int idx;
953         
954         // if there is no timestamp, do nothing
955         if(Om_notify_stamp == -1){
956                 return;
957         }
958
959         // otherwise, if it has elapsed, unset it
960         if(timestamp_elapsed(Om_notify_stamp)){
961                 Om_notify_stamp = -1;
962                 return;
963         }
964
965         // otherwise display the string
966         line_count = split_str(Om_notify_string, 600, n_chars, p_str, 3);       
967         y_start = OM_NOTIFY_Y;
968         gr_set_color_fast(&Color_bright);
969         for(idx=0;idx<line_count;idx++){
970                 memset(line, 0, 255);
971                 strncpy(line, p_str[idx], n_chars[idx]);
972                                 
973                 gr_get_string_size(&w,NULL,line);
974                 gr_string((600 - w)/2,y_start,line);
975
976                 y_start += 10;
977         }       
978 }
979
980
981 // protocol section --------------------------------------------------------
982
983 // load all the controls for the protocol section
984 void options_multi_load_protocol_controls()
985 {
986         int idx;
987         
988         Assert(Om_window != NULL);
989
990         // instantiate all the buttons
991         for(idx=0; idx<OM_PRO_NUM_BUTTONS; idx++){
992                 // create the object
993                 Om_pro_buttons[gr_screen.res][idx].button.create(Om_window, "", Om_pro_buttons[gr_screen.res][idx].x, Om_pro_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
994
995                 // set the sound to play when highlighted
996                 Om_pro_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
997
998                 // set the ani for the button
999                 Om_pro_buttons[gr_screen.res][idx].button.set_bmaps(Om_pro_buttons[gr_screen.res][idx].filename);
1000
1001                 // set the hotspot
1002                 Om_pro_buttons[gr_screen.res][idx].button.link_hotspot(Om_pro_buttons[gr_screen.res][idx].hotspot);
1003         }
1004
1005 #ifndef MAKE_FS1
1006         // text
1007         for(idx=0; idx<OM_PRO_NUM_TEXT; idx++){
1008                 Om_window->add_XSTR(&Om_pro_text[gr_screen.res][idx]);
1009         }
1010 #endif
1011
1012         // create the tracker input boxes       
1013         Om_tracker_login.create(Om_window, Om_tracker_login_coords[gr_screen.res][0], Om_tracker_login_coords[gr_screen.res][1], Om_tracker_login_coords[gr_screen.res][2], LOGIN_LEN - 1, Multi_tracker_login, UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_NO_BACK);
1014         Om_tracker_passwd.create(Om_window, Om_tracker_passwd_coords[gr_screen.res][0], Om_tracker_passwd_coords[gr_screen.res][1], Om_tracker_passwd_coords[gr_screen.res][2], 1, Multi_tracker_passwd, UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_PASSWD | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_NO_BACK);
1015         Om_tracker_squad_name.create(Om_window, Om_tracker_squad_name_coords[gr_screen.res][0], Om_tracker_squad_name_coords[gr_screen.res][1], Om_tracker_squad_name_coords[gr_screen.res][2], LOGIN_LEN - 1, Multi_tracker_squad_name, UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_KEYTHRU | UI_INPUTBOX_FLAG_NO_BACK);
1016
1017         // create the invisible button for checking for clicks on the ip address list
1018         Om_ip_button.create(Om_window, "", Ip_list_coords[gr_screen.res][0], Ip_list_coords[gr_screen.res][1], Ip_list_coords[gr_screen.res][2], Ip_list_coords[gr_screen.res][3], 0, 1);
1019         Om_ip_button.hide();
1020
1021         // create the new ip address input box  
1022         Om_ip_input.create(Om_window, Ip_input_coords[gr_screen.res][0], Ip_input_coords[gr_screen.res][1], Ip_input_coords[gr_screen.res][2], IP_STRING_LEN, IP_EMPTY_STRING, UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_CLR | UI_INPUTBOX_FLAG_KEYTHRU);
1023         Om_ip_input.hide();
1024         Om_ip_input.disable();
1025         
1026         // disable IPX button in demo
1027 #ifdef FS2_DEMO
1028         Om_pro_buttons[gr_screen.res][OM_PRO_IPX].button.disable();
1029         Om_pro_buttons[gr_screen.res][OM_PRO_IPX].button.hide();
1030 #endif
1031
1032         // bogus control
1033         Om_pro_bogus.base_create(Om_window, UI_KIND_ICON, 0, 0, 0, 0);
1034 }
1035
1036 // disable/hide all the controls for the protocol section
1037 void options_multi_disable_protocol_controls()
1038 {
1039         int idx;
1040         
1041         // hide and disable all the protocol buttons
1042         for(idx=0;idx<OM_PRO_NUM_BUTTONS;idx++){
1043                 // hide the button
1044                 Om_pro_buttons[gr_screen.res][idx].button.hide();
1045
1046                 // disable the button
1047                 Om_pro_buttons[gr_screen.res][idx].button.disable();
1048         }
1049
1050         // hide and disable the tracker input boxes
1051         Om_tracker_login.hide();
1052         Om_tracker_login.disable();
1053         Om_tracker_passwd.hide();
1054         Om_tracker_passwd.disable();
1055         Om_tracker_squad_name.hide();
1056         Om_tracker_squad_name.disable();
1057
1058         // disable the click detection button
1059         Om_ip_button.disable();
1060
1061         // disable and hide the ip address inputbox
1062         Om_ip_input.hide();
1063         Om_ip_input.disable();
1064
1065         // undo input mode if necessary
1066         Om_input_mode = 0;
1067
1068         // bogus control
1069         Om_pro_bogus.hide();
1070         Om_pro_bogus.disable();
1071 }
1072
1073 // enable/unhide all the controls for the protocol section
1074 void options_multi_enable_protocol_controls()
1075 {
1076         int idx;
1077         
1078         // unhide and enable all the protocol buttons
1079         for(idx=0;idx<OM_PRO_NUM_BUTTONS;idx++){
1080                 // enable the button
1081                 Om_pro_buttons[gr_screen.res][idx].button.enable();
1082                 
1083                 // unhide the button
1084                 Om_pro_buttons[gr_screen.res][idx].button.unhide();             
1085         }
1086
1087         // unhide and enable the tracker input boxes
1088         if(Om_tracker_flag){
1089                 Om_tracker_login.enable();      
1090                 Om_tracker_passwd.enable();
1091                 Om_tracker_squad_name.enable();
1092         }
1093         Om_tracker_login.unhide();
1094         Om_tracker_passwd.unhide();
1095         Om_tracker_squad_name.unhide();
1096
1097         // enable the click detection button
1098         Om_ip_button.enable();  
1099
1100         // bogus control
1101         Om_pro_bogus.enable();
1102         Om_pro_bogus.unhide();  
1103 }
1104
1105 // intialize the protocol section vars
1106 void options_multi_init_protocol_vars()
1107 {
1108         // current protocol
1109         Om_protocol = Multi_options_g.protocol;
1110
1111         // whether or not the user has the local broadcast button selected
1112         Om_local_broadcast = (Player->m_local_options.flags & MLO_FLAG_LOCAL_BROADCAST) ? 1 : 0;
1113
1114         // whether or not we're playing on the tracker
1115         Om_tracker_flag = 0; // (Multi_options_g.protocol == NET_TCP) && Multi_options_g.pxo ? 1 : 0;   
1116
1117         // load the ip address list     
1118         Om_ip_disp_count = 0;
1119         options_multi_protocol_load_ip_file();
1120         Om_ip_selected = Om_num_ips - 1;        
1121         Om_ip_start = Om_num_ips - 1;                   
1122 }
1123
1124 // do frame for the protocol section
1125 void options_multi_protocol_do(int key)
1126 {
1127         // check for button presses
1128         options_multi_protocol_check_buttons();
1129         
1130         // force draw the correct "local broadcast" button      
1131         if(Om_local_broadcast){
1132 #ifdef MAKE_FS1
1133                 Om_pro_buttons[gr_screen.res][OM_PRO_LOCAL_BROADCAST_YES].button.draw_forced(2);
1134         } else {
1135                 Om_pro_buttons[gr_screen.res][OM_PRO_LOCAL_BROADCAST_NO].button.draw_forced(2);
1136 #else
1137                 Om_pro_buttons[gr_screen.res][OM_PRO_LOCAL_BROADCAST].button.draw_forced(2);
1138 #endif
1139         }
1140
1141         // draw the "vmt" button if it is selected
1142         if(Om_tracker_flag){
1143                 Om_pro_buttons[gr_screen.res][OM_PRO_VMT].button.draw_forced(2);
1144         }
1145
1146         // see if he hit any interesting key presses
1147         switch(key){
1148         case KEY_ENTER:
1149                 // add a new ip string if we're in "input" mode
1150                 if(Om_input_mode){                      
1151                         options_multi_protocol_add_current_ip();
1152                         
1153                         // clear the text control and input mode
1154                         Om_ip_input.set_text("");
1155                         Om_ip_input.clear_focus();
1156                         Om_ip_input.disable();
1157                         Om_input_mode = 0;
1158                 }
1159
1160                 // if the tracker login inputbox has focus, lose it
1161                 if(Om_tracker_login.has_focus()){
1162                         Om_tracker_login.clear_focus();
1163                         gamesnd_play_iface(SND_COMMIT_PRESSED);
1164                 }
1165                 // if the tracker password inputbox has focus, lose it
1166                 if(Om_tracker_passwd.has_focus()){
1167                         Om_tracker_passwd.clear_focus();
1168                         gamesnd_play_iface(SND_COMMIT_PRESSED);
1169                 }
1170                 // if the tracker squad name inputbox has focus, lose it
1171                 if(Om_tracker_squad_name.has_focus()){
1172                         Om_tracker_squad_name.clear_focus();
1173                         gamesnd_play_iface(SND_COMMIT_PRESSED);
1174                 }
1175                 break;
1176
1177         case KEY_ESC:
1178                 // if we're in input mode, cancel out
1179                 if(Om_input_mode){
1180                         // clear the text control and input mode
1181                         Om_ip_input.set_text("");
1182                         Om_ip_input.clear_focus();
1183                         Om_ip_input.disable();
1184                         Om_input_mode = 0;
1185                 }
1186                 // otherwise quit the options screen altogether
1187                 else {
1188                         options_cancel_exit();
1189                 }
1190                 break;
1191
1192         case KEY_TAB:
1193                 // tab through the tracker input controls
1194                 if(Om_tracker_login.has_focus()){
1195                         Om_tracker_passwd.set_focus();
1196                 } else if(Om_tracker_passwd.has_focus()){
1197                         Om_tracker_squad_name.set_focus();
1198                 } else if(Om_tracker_squad_name.has_focus()){
1199                         Om_tracker_login.set_focus();
1200                 }
1201                 break;
1202         }
1203
1204         // force draw the proper protocol
1205 #ifndef MAKE_FS1        // not in FS1 menu
1206         if (Om_protocol == NET_IPX) {
1207                 Om_pro_buttons[gr_screen.res][OM_PRO_IPX].button.draw_forced(2);
1208         } else {
1209                 Om_pro_buttons[gr_screen.res][OM_PRO_TCP].button.draw_forced(2);
1210         }
1211 #endif
1212
1213         // force draw the proper tab button
1214         switch (Om_mode) {
1215         case OM_MODE_GENERAL:
1216                 Om_pro_buttons[gr_screen.res][OM_PRO_GEN_TAB].button.draw_forced(2);
1217                 break;
1218
1219         case OM_MODE_VOX:
1220                 Om_pro_buttons[gr_screen.res][OM_PRO_VOX_TAB].button.draw_forced(2);
1221                 break;
1222         }
1223
1224         // check to see if the user has clicked on the ip list and selected a new item
1225         options_multi_protocol_check_ip_list();
1226
1227         // draw the list of ip addresses
1228         options_multi_protocol_display_ips();   
1229
1230         // hack to play sound when input boxes gain focus
1231         if (Om_tracker_login.has_focus()) {
1232                 if (Om_tracker_focus != TRACKER_FOCUS_LOGIN) {
1233                         Om_tracker_focus = TRACKER_FOCUS_LOGIN;
1234                         gamesnd_play_iface(SND_USER_SELECT);
1235                 }
1236         } else if (Om_tracker_passwd.has_focus()) {
1237                 if (Om_tracker_focus != TRACKER_FOCUS_PASSWORD) {
1238                         Om_tracker_focus = TRACKER_FOCUS_PASSWORD;
1239                         gamesnd_play_iface(SND_USER_SELECT);
1240                 }
1241         } else if (Om_tracker_squad_name.has_focus()) {
1242                 if (Om_tracker_focus != TRACKER_FOCUS_SQUADRON) {
1243                         Om_tracker_focus = TRACKER_FOCUS_SQUADRON;
1244                         gamesnd_play_iface(SND_USER_SELECT);
1245                 }
1246         } else {
1247                 Om_tracker_focus = TRACKER_FOCUS_NONE;
1248         }
1249 }
1250
1251 // if the accept button was hit
1252 void options_multi_protocol_accept()
1253 {
1254         // if the user has selected local broadcast write it into his options struct
1255         Player->m_local_options.flags &= ~(MLO_FLAG_LOCAL_BROADCAST);
1256         if(Om_local_broadcast){
1257                 Player->m_local_options.flags |= MLO_FLAG_LOCAL_BROADCAST;
1258         }       
1259
1260         // active protocol
1261         Multi_options_g.protocol = Om_protocol;
1262
1263         // copy the VMT login and password data
1264         Om_tracker_login.get_text(Multi_tracker_login);
1265         Om_tracker_passwd.get_text(Multi_tracker_passwd);
1266         Om_tracker_squad_name.get_text(Multi_tracker_squad_name);
1267
1268         // write out the tracker login and passwd values to the registry
1269         os_config_write_string( "PXO", "Login", Multi_tracker_login );
1270         os_config_write_string( "PXO", "Password", Multi_tracker_passwd );
1271
1272         // write out the PXO squad name and passwd values to the registry
1273         os_config_write_string( "PXO", "SquadName", Multi_tracker_squad_name );
1274         
1275         // save the ip address list
1276         options_multi_protocol_save_ip_file();
1277 }
1278
1279 // check for button presses
1280 void options_multi_protocol_check_buttons()
1281 {
1282         int idx;
1283
1284         // go through each button
1285         for(idx=0;idx<OM_PRO_NUM_BUTTONS;idx++){
1286                 if(Om_pro_buttons[gr_screen.res][idx].button.pressed()){
1287                         options_multi_protocol_button_pressed(idx);
1288                         break;
1289                 }
1290         }
1291 }
1292
1293 // if a button was pressed
1294 void options_multi_protocol_button_pressed(int n)
1295 {
1296 #ifdef MAKE_FS1
1297         int choice;
1298 #endif
1299
1300         switch(n){
1301         // add an ip address
1302         case OM_PRO_ADD_IP:
1303                 // don't process if we're in input mode
1304                 if(Om_input_mode){
1305                         break;
1306                 }
1307
1308                 // setup the input mode
1309                 Om_input_mode = 1;
1310                 Om_ip_input.enable();
1311                 Om_ip_input.unhide();
1312                 Om_ip_input.set_text(IP_EMPTY_STRING);
1313                 Om_ip_input.set_focus();
1314                 gamesnd_play_iface(SND_USER_SELECT);
1315                 break;
1316
1317         // delete the currently selected ip
1318         case OM_PRO_DELETE_IP:
1319                 // don't process if we're in input mode
1320                 if(Om_input_mode){
1321                         break;
1322                 }
1323
1324                 options_multi_protocol_delete_ip();
1325                 gamesnd_play_iface(SND_USER_SELECT);
1326                 break;
1327
1328         // the "local" broadcast button - toggle
1329 #ifdef MAKE_FS1
1330         // Yes and No buttons in FS1
1331         case OM_PRO_LOCAL_BROADCAST_YES:
1332                 if(Om_input_mode){
1333                         break;
1334                 }
1335
1336                 Om_local_broadcast = 1;
1337
1338                 gamesnd_play_iface(SND_USER_SELECT);
1339                 break;
1340
1341         case OM_PRO_LOCAL_BROADCAST_NO:
1342                 if(Om_input_mode){
1343                         break;
1344                 }
1345
1346                 Om_local_broadcast = 0;
1347
1348                 gamesnd_play_iface(SND_USER_SELECT);
1349                 break;
1350 #else
1351         case OM_PRO_LOCAL_BROADCAST:
1352                 // don't process if we're in input mode
1353                 if(Om_input_mode){
1354                         break;
1355                 }
1356
1357                 if(!Om_local_broadcast){                        
1358                         Om_local_broadcast = 1;
1359                 } else {
1360                         Om_local_broadcast = 0;
1361                 }
1362
1363                 gamesnd_play_iface(SND_USER_SELECT);
1364                 break;
1365 #endif
1366
1367         // scroll ips down
1368         case OM_PRO_SCROLL_IP_DOWN:             
1369                 // don't process if we're in input mode
1370                 if(Om_input_mode){
1371                         break;
1372                 }
1373
1374                 options_multi_protocol_scroll_ip_down();
1375                 break;
1376
1377         // scroll ips up
1378         case OM_PRO_SCROLL_IP_UP:               
1379                 // don't process if we're in input mode
1380                 if(Om_input_mode){
1381                         break;
1382                 }
1383
1384                 options_multi_protocol_scroll_ip_up();
1385                 break;
1386
1387         // the vmt button
1388         case OM_PRO_VMT:
1389                 // for the multiplayer beta, always force tracker mode
1390 #ifdef MULTIPLAYER_BETA_BUILD // do we want this for FS2_DEMO
1391                 Om_tracker_flag = 1;
1392 #else
1393                 // don't process if we're in input mode
1394                 if(Om_input_mode){
1395                         break;
1396                 }
1397
1398                 // toggle the stupid thing
1399                 Om_tracker_flag = !Om_tracker_flag;
1400
1401                 // if the thing is toggled on - enable the inputbox controls, else diable them
1402                 if(Om_tracker_flag){
1403                         Om_tracker_login.enable();
1404                         Om_tracker_passwd.enable();
1405                         Om_tracker_squad_name.enable();
1406                 } else {
1407                         Om_tracker_login.disable();
1408                         Om_tracker_passwd.disable();
1409                         Om_tracker_squad_name.disable();
1410                 }
1411
1412                 // play a sound
1413                 gamesnd_play_iface(SND_USER_SELECT);
1414 #endif
1415                 break;
1416
1417         // general tab button 
1418 #ifndef FS1_DEMO
1419         case OM_PRO_GEN_TAB:    
1420                 if(Om_mode != OM_MODE_GENERAL){
1421                         // set the general tab
1422                         Om_mode = OM_MODE_GENERAL;              
1423
1424                         // disable the voice controls
1425                         options_multi_disable_vox_controls();
1426
1427                         // enable the general controls
1428                         options_multi_enable_gen_controls();
1429
1430                         // set the general screen mask  
1431                         Assert(Om_mask_0 >= 0);
1432                         Om_window->set_mask_bmap(Om_mask_0, Om_background_0_mask_fname[gr_screen.res]);
1433                 }
1434
1435                 // play a sound
1436                 gamesnd_play_iface(SND_USER_SELECT);
1437
1438                 break;
1439
1440         // voice tab button
1441         case OM_PRO_VOX_TAB:
1442                 if(Om_mode != OM_MODE_VOX){
1443                         // set the voice tab
1444                         Om_mode = OM_MODE_VOX;
1445
1446                         // disable the general controls
1447                         options_multi_disable_gen_controls();
1448
1449                         // enable the voice controls
1450                         options_multi_enable_vox_controls();
1451
1452                         // set the voice screen mask    
1453                         Assert(Om_mask_1 >= 0);
1454                         Om_window->set_mask_bmap(Om_mask_1, Om_background_1_mask_fname[gr_screen.res]);
1455                 }
1456                 // play a sound
1457                 gamesnd_play_iface(SND_USER_SELECT);
1458
1459                 break;
1460 #endif  // FS1_DEMO
1461
1462         // tcp mode
1463 #ifndef MAKE_FS1        // not in FS1 option menu
1464         case OM_PRO_TCP:
1465                 Om_protocol = NET_TCP;
1466                 gamesnd_play_iface(SND_USER_SELECT);
1467                 break;
1468
1469         // ipx mode
1470         case OM_PRO_IPX:
1471 #ifndef FS2_DEMO
1472                 Om_protocol = NET_IPX;
1473                 gamesnd_play_iface(SND_USER_SELECT);
1474 #endif
1475                 break;
1476 #endif
1477
1478 #ifdef MAKE_FS1
1479         case ABORT_GAME_BUTTON:
1480                 gamesnd_play_iface(SND_USER_SELECT);
1481                 choice = popup( PF_NO_NETWORKING | PF_BODY_BIG, 2, POPUP_NO, POPUP_YES, XSTR("Exit Game?", 374));
1482                 if ( choice == 1 )
1483                         gameseq_post_event(GS_EVENT_QUIT_GAME);
1484                 break;
1485 #endif
1486         }
1487 }
1488
1489 // load the ip address file
1490 void options_multi_protocol_load_ip_file()
1491 {
1492         char line[IP_STRING_LEN];
1493         CFILE *file = NULL;
1494
1495         // reset the ip address count
1496         Om_num_ips = 0;
1497
1498         // attempt to open the ip list file
1499         file = cfopen(IP_CONFIG_FNAME,"rt",CFILE_NORMAL,CF_TYPE_DATA);  
1500         if(file == NULL){
1501                 nprintf(("Network","Error loading tcp.cfg file!\n"));
1502                 return;
1503         }
1504
1505         // read in all the strings in the file
1506         while(!cfeof(file)){
1507                 line[0] = '\0';
1508                 cfgets(line,IP_STRING_LEN,file);
1509
1510                 // strip off any newline character
1511                 if(line[strlen(line) - 1] == '\n'){
1512                         line[strlen(line) - 1] = '\0';
1513                 }
1514
1515                 // 0 length lines don't get processed
1516                 if((line[0] == '\0') || (line[0] == '\n') )
1517                         continue;
1518
1519                 if ( !psnet_is_valid_ip_string(line) ) {
1520                         nprintf(("Network","Invalid ip string (%s)\n",line));
1521                 } else {
1522                         if(Om_num_ips < MAX_IP_ADDRS-1){
1523                                 strcpy(Om_ip_addrs[Om_num_ips++],line);
1524                         }
1525                 }
1526         }
1527
1528         cfclose(file);
1529 }
1530
1531 // save the ip address file
1532 void options_multi_protocol_save_ip_file()
1533 {
1534         int idx;
1535         CFILE *file = NULL;
1536
1537         // attempt to open the ip list file for writing
1538         file = cfopen(IP_CONFIG_FNAME,"wt",CFILE_NORMAL,CF_TYPE_DATA );
1539         if(file == NULL){
1540                 nprintf(("Network","Error loading tcp.cfg file\n"));
1541                 return;
1542         }
1543
1544         // write out all the string we have
1545         for(idx=0;idx<Om_num_ips;idx++){
1546                 // make _absolutely_ sure its a valid address
1547                 // MWA -- commented out next line because name resolution might fail when
1548                 // it was added.  We'll only grab games that we can actually get to.
1549                 //Assert(psnet_is_valid_ip_string(Multi_ip_addrs[idx]));
1550
1551                 cfputs(Om_ip_addrs[idx],file);
1552                                 
1553            // make sure to tack on a newline if necessary
1554                 if(Om_ip_addrs[idx][strlen(&Om_ip_addrs[idx][0]) - 1] != '\n'){
1555                         cfputs(NOX("\n"),file);
1556                 }
1557         }
1558
1559         cfclose(file);
1560 }
1561
1562 // draw the list of ip addresses
1563 void options_multi_protocol_display_ips()
1564 {
1565         int idx;
1566         int y_start = Ip_list_coords[gr_screen.res][1];
1567                 
1568         // get the # of items we should be displaying based upon the # of addresses and the starting display point
1569         if(Om_ip_start >= Ip_list_max_display[gr_screen.res]){
1570                 Om_ip_disp_count = Ip_list_max_display[gr_screen.res];
1571         } else {
1572                 Om_ip_disp_count = Om_ip_start + 1;
1573         }
1574         
1575         // display the addresses
1576         for(idx=Om_ip_start; idx >= Om_ip_start - Om_ip_disp_count + 1 ; idx--){        
1577                 if(idx == Om_ip_selected){
1578                         gr_set_color_fast(&Color_bright);
1579                 } else {
1580                         gr_set_color_fast(&Color_white);
1581                 }
1582
1583                 gr_printf(Ip_list_coords[gr_screen.res][0], y_start, Om_ip_addrs[idx]);
1584                 y_start += 10;
1585         }
1586 }
1587
1588 // scroll the list of ip addresses down
1589 void options_multi_protocol_scroll_ip_down()
1590 {
1591         if(Om_ip_start >= Ip_list_max_display[gr_screen.res]){
1592                 gamesnd_play_iface(SND_SCROLL);
1593                 Om_ip_start--;
1594         } else {
1595                 gamesnd_play_iface(SND_GENERAL_FAIL);
1596         }       
1597 }
1598
1599 // scroll the list of ip addresses up
1600 void options_multi_protocol_scroll_ip_up()
1601 {
1602         if(Om_ip_start < Om_num_ips-1){
1603                 gamesnd_play_iface(SND_SCROLL);
1604                 Om_ip_start++;
1605         } else {
1606                 gamesnd_play_iface(SND_GENERAL_FAIL);
1607         }
1608 }
1609
1610 // check the ip list to see if the user has selected a new item
1611 void options_multi_protocol_check_ip_list()
1612 {
1613         int click_y;    
1614         int item;
1615         
1616         if(Om_ip_button.pressed()){
1617                 // determine which item he clicked on   
1618                 Om_ip_button.get_mouse_pos(NULL, &click_y);
1619                 item = click_y / 10;
1620                         
1621                 // determine if there is an item in this location, and select it if so
1622                 if(item < Om_ip_disp_count){
1623                         Om_ip_selected = Om_ip_start - item;
1624                 }
1625         }
1626 }
1627
1628 // delete the currently selected ip if any
1629 void options_multi_protocol_delete_ip()
1630 {
1631         int idx;
1632         
1633         // attempt to delete the currently highlighted item
1634         if(Om_ip_selected != -1){               
1635
1636                 // move down all the other items                                
1637                 for(idx=Om_ip_selected; idx < Om_num_ips; idx++){
1638                         strcpy(Om_ip_addrs[idx],Om_ip_addrs[idx+1]);
1639                 }
1640
1641                 // make sure to decrement the starting index
1642                 Om_ip_start--;                  
1643                         
1644                 // check to make sure that the selected item is valid                   
1645                 Om_num_ips--;                   
1646                 if(Om_num_ips <= 0){
1647                         Om_ip_selected = -1;
1648                 } else {
1649                         if(Om_ip_selected > 0){
1650                                 Om_ip_selected--;       
1651                         } 
1652                 }                                               
1653         }
1654 }
1655
1656 // return 10, if successflu
1657 char Ip_str[IP_STRING_LEN+1];
1658 int Ip_validated_already = 0;
1659 int options_multi_verify_ip()
1660 {
1661         int result;
1662
1663         if(!Ip_validated_already){
1664                 // see if its a valid ip address
1665                 result = psnet_is_valid_ip_string(Ip_str);
1666         
1667                 // if the result is a valid ip string, return immediately
1668                 if(result){
1669                         return 10;
1670                 }
1671
1672                 // otherwise, change the popup text to indicate that it is invalid and wait for the user to click ok
1673                 popup_change_text(XSTR( "Ip string is invalid!", 386));
1674         }       
1675
1676         Ip_validated_already = 1;
1677
1678         // always wait for the user to hit the "cancel" button
1679         return 0;
1680 }
1681
1682 // attempt to add the currently entered ip address
1683 void options_multi_protocol_add_current_ip()
1684 {               
1685         // get the entered string
1686         Om_ip_input.get_text(Ip_str);
1687
1688         // this popup wil do several things. 
1689         // 1.) It will display a popup so the user isn't left scratching his head
1690         // 2.) If the address
1691         Ip_validated_already = 0;
1692         if(popup_till_condition(options_multi_verify_ip, XSTR( "Cancel", 387), XSTR( "Verifying ip address", 388)) == 10){
1693                 if(Om_num_ips < MAX_IP_ADDRS){
1694                         strcpy(Om_ip_addrs[Om_num_ips],Ip_str);
1695                         Om_ip_start = Om_num_ips;
1696                         Om_num_ips++;
1697                         
1698                         // if this is the first item on the list, select it
1699                         if(Om_num_ips == 1){
1700                                 Om_ip_selected = 0;
1701                         }
1702                 } else {
1703                         options_multi_add_notify(XSTR( "Max # of IP addresses reached!", 389));
1704                 }
1705         }                       
1706 }
1707
1708 // general options tab section -------------------------------------------
1709
1710 // load all the general tab controls
1711 void options_multi_load_gen_controls()
1712 {
1713         int idx;
1714         
1715         Assert(Om_window != NULL);
1716
1717         // instantiate all the buttons
1718         for(idx=0; idx<OM_GEN_NUM_BUTTONS; idx++){                              
1719                 // create the object
1720                 Om_gen_buttons[gr_screen.res][idx].button.create(Om_window, "", Om_gen_buttons[gr_screen.res][idx].x, Om_gen_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
1721
1722                 // set the sound to play when highlighted
1723                 Om_gen_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
1724
1725                 // set the ani for the button
1726                 Om_gen_buttons[gr_screen.res][idx].button.set_bmaps(Om_gen_buttons[gr_screen.res][idx].filename);
1727
1728                 // set the hotspot
1729                 Om_gen_buttons[gr_screen.res][idx].button.link_hotspot(Om_gen_buttons[gr_screen.res][idx].hotspot);
1730         }
1731
1732 #ifndef MAKE_FS1
1733         // text
1734         for(idx=0; idx<OM_GEN_NUM_TEXT; idx++){
1735                 Om_window->add_XSTR(&Om_gen_text[gr_screen.res][idx]);
1736         }
1737 #endif
1738
1739         // bogus control
1740         Om_gen_bogus.base_create(Om_window, UI_KIND_ICON, 0, 0, 0, 0);
1741 }
1742
1743 // disable/hide all the general tab controls
1744 void options_multi_disable_gen_controls()
1745 {
1746         int idx;
1747
1748         // go through all the controls
1749         for(idx=0;idx<OM_GEN_NUM_BUTTONS;idx++){
1750                 Om_gen_buttons[gr_screen.res][idx].button.hide();
1751                 Om_gen_buttons[gr_screen.res][idx].button.disable();
1752         }
1753
1754         // bogus control
1755         Om_gen_bogus.hide();
1756         Om_gen_bogus.disable();
1757 }
1758
1759 // enable/unhide all the general tab controls
1760 void options_multi_enable_gen_controls()
1761 {
1762         int idx;
1763
1764         // go through all the controls
1765         for(idx=0;idx<OM_GEN_NUM_BUTTONS;idx++){                
1766                 Om_gen_buttons[gr_screen.res][idx].button.enable();
1767                 Om_gen_buttons[gr_screen.res][idx].button.unhide();
1768         }
1769
1770         // bogus control
1771         Om_gen_bogus.enable();
1772         Om_gen_bogus.unhide();
1773 }
1774
1775 // initialize the general tab vars
1776 void options_multi_init_gen_vars()
1777 {
1778         // initialize the object update
1779         Om_gen_obj_update = Player->m_local_options.obj_update_level;
1780
1781         // initialize the accept pix var        
1782         if(Player->m_local_options.flags & MLO_FLAG_ACCEPT_PIX){
1783                 Om_gen_pix = 1;
1784         } else {
1785                 Om_gen_pix = 0;
1786         }
1787
1788         // initialize the xfer_multidata var
1789         if(Player->m_local_options.flags & MLO_FLAG_XFER_MULTIDATA){
1790                 Om_gen_xfer_multidata = 1;
1791         } else {
1792                 Om_gen_xfer_multidata = 0;
1793         }
1794
1795         // initialize the flush cache var
1796         if(Player->m_local_options.flags & MLO_FLAG_FLUSH_CACHE){
1797                 Om_gen_flush_cache = 1;
1798         } else {
1799                 Om_gen_flush_cache = 0;
1800         }
1801 }
1802
1803 // accept function for the general tab
1804 void options_multi_gen_accept()
1805 {
1806         // apply the object update level
1807         Player->m_local_options.obj_update_level = Om_gen_obj_update;
1808
1809         // apply the accept pix var
1810         Player->m_local_options.flags &= ~(MLO_FLAG_ACCEPT_PIX);
1811         if(Om_gen_pix){
1812                 Player->m_local_options.flags |= MLO_FLAG_ACCEPT_PIX;
1813         }
1814
1815         // apply the xfer multidata var
1816         Player->m_local_options.flags &= ~(MLO_FLAG_XFER_MULTIDATA);
1817         if(Om_gen_xfer_multidata){
1818                 Player->m_local_options.flags |= MLO_FLAG_XFER_MULTIDATA;
1819         } 
1820
1821         // apply the flush cache var
1822         Player->m_local_options.flags &= ~(MLO_FLAG_FLUSH_CACHE);
1823         if(Om_gen_flush_cache){
1824                 Player->m_local_options.flags |= MLO_FLAG_FLUSH_CACHE;
1825         }
1826 }
1827
1828 // do frame for the general tab
1829 void options_multi_gen_do()
1830 {
1831         // check for button presses
1832         options_multi_gen_check_buttons();
1833
1834         // draw the proper object update button
1835         switch(Om_gen_obj_update){
1836         case OBJ_UPDATE_LOW:
1837                 Om_gen_buttons[gr_screen.res][OM_GEN_OBJ_LOW].button.draw_forced(2);
1838                 break;
1839         case OBJ_UPDATE_MEDIUM:
1840                 Om_gen_buttons[gr_screen.res][OM_GEN_OBJ_MED].button.draw_forced(2);
1841                 break;
1842         case OBJ_UPDATE_HIGH:
1843                 Om_gen_buttons[gr_screen.res][OM_GEN_OBJ_HIGH].button.draw_forced(2);
1844                 break;
1845         case OBJ_UPDATE_LAN:
1846                 Om_gen_buttons[gr_screen.res][OM_GEN_OBJ_LAN].button.draw_forced(2);
1847                 break;
1848         default :
1849                 Int3();
1850         }
1851
1852         // draw the proper pix button
1853         if(Om_gen_pix){
1854                 Om_gen_buttons[gr_screen.res][OM_GEN_PIX_YES].button.draw_forced(2);
1855         } else {
1856                 Om_gen_buttons[gr_screen.res][OM_GEN_PIX_NO].button.draw_forced(2);
1857         }
1858
1859         // draw the proper xfer multidata button
1860         if(Om_gen_xfer_multidata){
1861                 Om_gen_buttons[gr_screen.res][OM_GEN_XFER_MULTIDATA_YES].button.draw_forced(2);
1862         } else {
1863                 Om_gen_buttons[gr_screen.res][OM_GEN_XFER_MULTIDATA_NO].button.draw_forced(2);
1864         }
1865
1866         // draw the proper flush cache button
1867         if(Om_gen_flush_cache){
1868                 Om_gen_buttons[gr_screen.res][OM_GEN_FLUSH_YES].button.draw_forced(2);
1869         } else {
1870                 Om_gen_buttons[gr_screen.res][OM_GEN_FLUSH_NO].button.draw_forced(2);
1871         }
1872 }
1873
1874 // check for button presses
1875 void options_multi_gen_check_buttons()
1876 {
1877         int idx;
1878
1879         // go through all the buttons
1880         for(idx=0;idx<OM_GEN_NUM_BUTTONS;idx++){
1881                 if(Om_gen_buttons[gr_screen.res][idx].button.pressed()){
1882                         options_multi_gen_button_pressed(idx);
1883                         break;
1884                 }
1885         }
1886 }
1887
1888 // a button was pressed
1889 void options_multi_gen_button_pressed(int n)
1890 {
1891         switch(n){
1892         // low object update level
1893         case OM_GEN_OBJ_LOW:
1894                 if(Om_gen_obj_update != OBJ_UPDATE_LOW){
1895                         gamesnd_play_iface(SND_USER_SELECT);
1896                         Om_gen_obj_update = OBJ_UPDATE_LOW;
1897                 } else {
1898                         gamesnd_play_iface(SND_GENERAL_FAIL);
1899                 }
1900                 break;
1901         
1902         // medium object update level
1903         case OM_GEN_OBJ_MED:
1904                 if(Om_gen_obj_update != OBJ_UPDATE_MEDIUM){
1905                         gamesnd_play_iface(SND_USER_SELECT);
1906                         Om_gen_obj_update = OBJ_UPDATE_MEDIUM;
1907                 } else {
1908                         gamesnd_play_iface(SND_GENERAL_FAIL);
1909                 }
1910                 break;
1911         
1912         // high object update level
1913         case OM_GEN_OBJ_HIGH:
1914                 if(Om_gen_obj_update != OBJ_UPDATE_HIGH){
1915                         gamesnd_play_iface(SND_USER_SELECT);
1916                         Om_gen_obj_update = OBJ_UPDATE_HIGH;
1917                 } else {
1918                         gamesnd_play_iface(SND_GENERAL_FAIL);
1919                 }
1920                 break;
1921
1922         // lan object update level
1923         case OM_GEN_OBJ_LAN:
1924                 if(Om_gen_obj_update != OBJ_UPDATE_LAN){
1925                         gamesnd_play_iface(SND_USER_SELECT);
1926                         Om_gen_obj_update = OBJ_UPDATE_LAN;
1927                 } else {
1928                         gamesnd_play_iface(SND_GENERAL_FAIL);
1929                 }
1930                 break;
1931         
1932         // accept pix
1933         case OM_GEN_PIX_YES:
1934                 if(!Om_gen_pix){
1935                         gamesnd_play_iface(SND_USER_SELECT);
1936                         Om_gen_pix = 1;
1937                 } else {
1938                         gamesnd_play_iface(SND_GENERAL_FAIL);
1939                 }
1940                 break;
1941         
1942         // don't accept pix
1943         case OM_GEN_PIX_NO:
1944                 if(Om_gen_pix){
1945                         gamesnd_play_iface(SND_USER_SELECT);
1946                         Om_gen_pix = 0;
1947                 } else {
1948                         gamesnd_play_iface(SND_GENERAL_FAIL);
1949                 }
1950                 break;
1951         
1952         // put missions in the multidate directory
1953         case OM_GEN_XFER_MULTIDATA_YES:
1954                 if(!Om_gen_xfer_multidata){
1955                         gamesnd_play_iface(SND_USER_SELECT);
1956                         Om_gen_xfer_multidata = 1;
1957                 } else {
1958                         gamesnd_play_iface(SND_GENERAL_FAIL);
1959                 }
1960                 break;
1961         
1962         // dont put missions in the multidata directory
1963         case OM_GEN_XFER_MULTIDATA_NO:
1964                 if(Om_gen_xfer_multidata){
1965                         gamesnd_play_iface(SND_USER_SELECT);
1966                         Om_gen_xfer_multidata = 0;
1967                 } else {
1968                         gamesnd_play_iface(SND_GENERAL_FAIL);
1969                 }
1970                 break;
1971         
1972         // flush the cache before each mission
1973         case OM_GEN_FLUSH_YES:
1974                 if(!Om_gen_flush_cache){
1975                         gamesnd_play_iface(SND_USER_SELECT);
1976                         Om_gen_flush_cache = 1;
1977                 } else {
1978                         gamesnd_play_iface(SND_GENERAL_FAIL);
1979                 }
1980                 break;
1981         
1982         // don't flush the cache before each mission
1983         case OM_GEN_FLUSH_NO:
1984                 if(Om_gen_flush_cache){
1985                         gamesnd_play_iface(SND_USER_SELECT);
1986                         Om_gen_flush_cache = 0;
1987                 } else {
1988                         gamesnd_play_iface(SND_GENERAL_FAIL);
1989                 }
1990                 break;  
1991         }
1992 }
1993
1994 // voice options tab section -------------------------------------------
1995
1996 // load all the voice tab controls
1997 void options_multi_load_vox_controls()
1998 {
1999         int idx;
2000         
2001         Assert(Om_window != NULL);
2002
2003         // instantiate all the buttons
2004         for(idx=0; idx<OM_VOX_NUM_BUTTONS; idx++){
2005                 // create the object
2006                 Om_vox_buttons[gr_screen.res][idx].button.create(Om_window, "", Om_vox_buttons[gr_screen.res][idx].x, Om_vox_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
2007
2008                 // set the sound to play when highlighted
2009                 Om_vox_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
2010
2011                 // set the ani for the button
2012                 Om_vox_buttons[gr_screen.res][idx].button.set_bmaps(Om_vox_buttons[gr_screen.res][idx].filename);
2013
2014                 // set the hotspot
2015                 Om_vox_buttons[gr_screen.res][idx].button.link_hotspot(Om_vox_buttons[gr_screen.res][idx].hotspot);
2016         }
2017
2018 #ifndef MAKE_FS1
2019         // text
2020         for(idx=0; idx<OM_VOX_NUM_TEXT; idx++){
2021                 Om_window->add_XSTR(&Om_vox_text[gr_screen.res][idx]);
2022         }
2023 #endif
2024         
2025         // sliders
2026         for ( idx = 0; idx < NUM_OM_VOX_SLIDERS; idx++ ) {
2027                  Om_vox_sliders[gr_screen.res][idx].slider.create(Om_window, Om_vox_sliders[gr_screen.res][idx].x, Om_vox_sliders[gr_screen.res][idx].y,
2028                                                                                                                                                 Om_vox_sliders[gr_screen.res][idx].dots, Om_vox_sliders[gr_screen.res][idx].filename,
2029                                                                                                                                                 Om_vox_sliders[gr_screen.res][idx].hotspot, Om_vox_sliders[gr_screen.res][idx].right_filename, Om_vox_sliders[gr_screen.res][idx].right_mask, Om_vox_sliders[gr_screen.res][idx].right_x, Om_vox_sliders[gr_screen.res][idx].right_y,
2030                                                                                                                                                 Om_vox_sliders[gr_screen.res][idx].left_filename, Om_vox_sliders[gr_screen.res][idx].left_mask, Om_vox_sliders[gr_screen.res][idx].left_x, Om_vox_sliders[gr_screen.res][idx].left_y,
2031                                                                                                                                                 Om_vox_sliders[gr_screen.res][idx].dot_w);
2032         }       
2033
2034         // create the player list select button
2035         Om_vox_plist_button.create(Om_window, "", Om_vox_plist_coords[gr_screen.res][0], Om_vox_plist_coords[gr_screen.res][1], Om_vox_plist_coords[gr_screen.res][2], Om_vox_plist_coords[gr_screen.res][3], 0, 1);
2036         Om_vox_plist_button.hide();
2037
2038         // build a list of net players
2039         Om_vox_num_players = 0;
2040         for(idx=0;idx<MAX_PLAYERS;idx++){
2041                 Om_vox_players[idx] = NULL;
2042
2043                 // if i'm not connected, do nothing
2044                 if((Net_player == NULL) || !(Net_player->flags & NETINFO_FLAG_CONNECTED)){
2045                         continue;
2046                 }
2047
2048                 // add all players I know about
2049                 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && (Net_player != &Net_players[idx])){
2050                         // set the netplayer pointer
2051                         Om_vox_players[Om_vox_num_players] = &Net_players[idx];
2052
2053                         // set his mute flag
2054                         Om_vox_player_flags[Om_vox_num_players] = (Multi_voice_local_prefs & (1<<idx)) ? 1 : 0;
2055
2056                         // increment the count
2057                         Om_vox_num_players++;
2058                 }
2059         }       
2060         
2061         // bogus control
2062         Om_vox_bogus.base_create(Om_window, UI_KIND_ICON, 0, 0, 0, 0);
2063 }
2064
2065 // disable/hide all the voice tab controls
2066 void options_multi_disable_vox_controls()
2067 {
2068         int idx;
2069
2070         // go through all the controls
2071         for(idx=0; idx<OM_VOX_NUM_BUTTONS; idx++){
2072                 Om_vox_buttons[gr_screen.res][idx].button.hide();
2073                 Om_vox_buttons[gr_screen.res][idx].button.disable();
2074         }
2075
2076         // hide the qos control
2077         Om_vox_sliders[gr_screen.res][OM_VOX_QOS_SLIDER].slider.hide();
2078         Om_vox_sliders[gr_screen.res][OM_VOX_QOS_SLIDER].slider.disable();      
2079
2080         // unset the sound buffer size so we don't display any waveforms
2081         Om_vox_voice_buffer_size = -1;
2082         Om_vox_voice_comp_size = -1;
2083         Om_vox_playback_handle = -1;
2084         Om_vox_test_status = OM_VOX_TEST_NONE;  
2085
2086         // disable the player list select button
2087         Om_vox_plist_button.disable();
2088
2089         // bogus controls
2090         Om_vox_bogus.hide();
2091         Om_vox_bogus.disable();
2092 }
2093
2094 // enable/unhide all the voice tab controls
2095 void options_multi_enable_vox_controls()
2096 {
2097         int idx;
2098
2099         // go through all the controls
2100         for(idx=0; idx<OM_VOX_NUM_BUTTONS; idx++){              
2101                 Om_vox_buttons[gr_screen.res][idx].button.enable();
2102                 Om_vox_buttons[gr_screen.res][idx].button.unhide();
2103         }
2104
2105         // unhide the qos control       
2106         Om_vox_sliders[gr_screen.res][OM_VOX_QOS_SLIDER].slider.enable();       
2107         Om_vox_sliders[gr_screen.res][OM_VOX_QOS_SLIDER].slider.unhide();       
2108
2109         // unset the sound buffer size so we don't display any waveforms
2110         Om_vox_voice_buffer_size = -1;
2111         Om_vox_voice_comp_size = -1;
2112         Om_vox_playback_handle = -1;
2113         Om_vox_test_status = OM_VOX_TEST_NONE;  
2114
2115         // select the first player on the list
2116         Om_vox_player_select = Om_vox_players[0];
2117         Om_vox_plist_start = 0;
2118
2119         // enable the player list select button
2120         Om_vox_plist_button.enable();
2121
2122         // bogus controls
2123         Om_vox_bogus.enable();
2124         Om_vox_bogus.unhide();
2125 }
2126
2127 // initialize the voice tab vars
2128 void options_multi_init_vox_vars()
2129 {
2130         // intialize the accept voice var
2131         if(Player->m_local_options.flags & MLO_FLAG_NO_VOICE){
2132                 Om_vox_accept_voice = 0;
2133         } else {
2134                 Om_vox_accept_voice = 1;
2135         }
2136 }
2137
2138 // accept function for the voice tab
2139 void options_multi_vox_accept()
2140 {
2141         int idx;
2142         int voice_pref_flags;
2143         
2144         // set the accept voice flag
2145         Player->m_local_options.flags &= ~(MLO_FLAG_NO_VOICE);
2146         if(!Om_vox_accept_voice){
2147                 Player->m_local_options.flags |= MLO_FLAG_NO_VOICE;
2148         }
2149
2150         // build the voice preferences stuff
2151         voice_pref_flags = 0xffffffff;
2152         for(idx=0;idx<Om_vox_num_players;idx++){
2153                 // if this guy is muted
2154                 if(!Om_vox_player_flags[idx]){
2155                         voice_pref_flags &= ~(1 << NET_PLAYER_INDEX(Om_vox_players[idx]));
2156                 }
2157         }
2158         multi_voice_set_prefs(voice_pref_flags);
2159 }
2160
2161 // do frame for the voice tab
2162 void options_multi_vox_do()
2163 {
2164         int handle;
2165         
2166         // check for button presses
2167         options_multi_vox_check_buttons();
2168
2169         // draw the proper accept voice button
2170         if(Om_vox_accept_voice){
2171                 Om_vox_buttons[gr_screen.res][OM_VOX_VOICE_YES].button.draw_forced(2);
2172         } else {
2173                 Om_vox_buttons[gr_screen.res][OM_VOX_VOICE_NO].button.draw_forced(2);
2174         }
2175
2176         // if the currently selected player is muted
2177         if((Om_vox_player_select != NULL) && !Om_vox_player_flags[options_multi_vox_plist_get(Om_vox_player_select)]){
2178                 Om_vox_buttons[gr_screen.res][OM_VOX_VOICE_MUTE].button.draw_forced(2);
2179         }
2180
2181         // process and display the player list
2182         options_multi_vox_process_player_list();
2183
2184         // if we're currently doing a voice test recording, process some stuff
2185         switch(Om_vox_test_status){
2186         case OM_VOX_TEST_RECORDING:     
2187                 multi_voice_test_process();
2188
2189                 // force draw the mic test button
2190                 Om_vox_buttons[gr_screen.res][OM_VOX_VOICE_TEST].button.draw_forced(2);
2191
2192                 // if we are no longer recording, switch to playback if possible
2193                 if(!multi_voice_test_recording()){
2194                         Om_vox_test_status = OM_VOX_TEST_PLAYBACK;
2195                         
2196                         if(Om_vox_voice_comp_size != -1){
2197                                 // stop any playing back sounds
2198                                 rtvoice_stop_playback_all();
2199
2200                                 // attempt to get a playback handle
2201                                 handle = multi_voice_test_get_playback_buffer();
2202                                 if(handle != -1){
2203                                         Om_vox_playback_handle = rtvoice_play_uncompressed(handle, Om_vox_comp_buffer, Om_vox_voice_comp_size);
2204
2205                                         // mark us as playing back
2206                                         Om_vox_test_status = OM_VOX_TEST_PLAYBACK;
2207                                 }
2208                                 // on error, notify the user something is wrong
2209                                 else {
2210                                         options_multi_add_notify(XSTR( "Error trying to playback recorded voice! Check your hardware", 390));
2211
2212                                         // mark us as doing nothing
2213                                         Om_vox_test_status = OM_VOX_TEST_NONE;
2214                                 }
2215                         } else {
2216                                 // mark us as doing nothing
2217                                 Om_vox_test_status = OM_VOX_TEST_NONE;
2218                         }                       
2219                 }
2220                 break;
2221         
2222         case OM_VOX_TEST_PLAYBACK:                      
2223                 // if we were playing a sound back, but now the sound is done
2224                 if((Om_vox_playback_handle != -1) && (ds_get_play_position(ds_get_channel(Om_vox_playback_handle)) >= (DWORD)Om_vox_voice_comp_size)){
2225                         // flush all playing sounds safely
2226                         rtvoice_stop_playback_all();
2227
2228                         // null the sound handle
2229                         Om_vox_playback_handle = -1;
2230
2231                         // set this so we know not to display any more waveforms
2232                         Om_vox_voice_buffer_size = -1;
2233                         Om_vox_voice_comp_size = -1;                    
2234
2235                         // free the status up
2236                         Om_vox_test_status = OM_VOX_TEST_NONE;
2237                 }
2238                 break;
2239         }
2240 }
2241
2242 // check for button presses
2243 void options_multi_vox_check_buttons()
2244 {
2245         int idx;
2246
2247         // go through all the buttons
2248         for(idx=0; idx<OM_VOX_NUM_BUTTONS; idx++){
2249                 if(Om_vox_buttons[gr_screen.res][idx].button.pressed()){
2250                         options_multi_vox_button_pressed(idx);
2251                         break;
2252                 }
2253         }
2254 }
2255
2256 // a button was pressed
2257 void options_multi_vox_button_pressed(int n)
2258 {
2259         switch(n){
2260         // accept voice button
2261         case OM_VOX_VOICE_YES:
2262                 if(!Om_vox_accept_voice){
2263                         gamesnd_play_iface(SND_USER_SELECT);
2264                         Om_vox_accept_voice = 1;
2265                 } else {
2266                         gamesnd_play_iface(SND_GENERAL_FAIL);
2267                 }
2268                 break;
2269         
2270         // don't accept voice button
2271         case OM_VOX_VOICE_NO:
2272                 if(Om_vox_accept_voice){
2273                         gamesnd_play_iface(SND_USER_SELECT);
2274                         Om_vox_accept_voice = 0;
2275                 } else {
2276                         gamesnd_play_iface(SND_GENERAL_FAIL);
2277                 }
2278                 break;
2279
2280         // mute/unmute button
2281         case OM_VOX_VOICE_MUTE:
2282                 if(Om_vox_player_select != NULL){
2283                         Om_vox_player_flags[options_multi_vox_plist_get(Om_vox_player_select)] = !Om_vox_player_flags[options_multi_vox_plist_get(Om_vox_player_select)];
2284                         gamesnd_play_iface(SND_USER_SELECT);
2285                 } else {
2286                         gamesnd_play_iface(SND_GENERAL_FAIL);
2287                 }
2288                 break;
2289
2290         // scroll the player list up
2291         case OM_VOX_PLIST_UP:
2292                 options_multi_vox_plist_scroll_up();
2293                 break;
2294
2295         // scroll the player list down
2296         case OM_VOX_PLIST_DOWN:
2297                 options_multi_vox_plist_scroll_down();
2298                 break;          
2299
2300         // mic test button
2301         case OM_VOX_VOICE_TEST:
2302                 // if in a multiplayer game, don't allow testing
2303                 if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_CONNECTED)){
2304                         options_multi_add_notify(XSTR( "Cannot test mic while in a multiplayer game!", 391));
2305                         break;
2306                 }
2307
2308                 // if this machine is not capable of playing
2309                 if(!Multi_voice_can_record){
2310                         options_multi_add_notify(XSTR( "DirectSoundCapture could not be initialized. To initialize DirectSoundCapture your sound card must be full duplex and your sound card drivers must support DirectSoundCapture", 392));
2311                 } else {
2312                         // if we're not already doing a record test
2313                         if(Om_vox_test_status == OM_VOX_TEST_NONE){
2314                                 // set the quality of sound
2315                                 rtvoice_set_qos(Om_vox_sliders[gr_screen.res][OM_VOX_QOS_SLIDER].slider.pos + 1);
2316
2317                                 // clear the comp buffer
2318                                 memset(Om_vox_comp_buffer,128,OM_VOX_COMP_SIZE);
2319
2320                                 Om_vox_test_status = OM_VOX_TEST_RECORDING;
2321                                 multi_voice_test_record_start();
2322                         }
2323                 }
2324                 break;
2325         }
2326 }
2327
2328 // screen shader
2329 extern shader Grey_shader;
2330
2331 // process and blit any voice waveform if necessary
2332 void options_multi_vox_process_waveform()
2333 {
2334         int c_width = OM_VOX_WAVE_WIDTH;
2335         int avg_len;
2336         int buf_offset;
2337         int idx,a_idx,running_avg;      
2338         
2339         // if we're not in recording or playback mode
2340         if(Om_vox_test_status == OM_VOX_TEST_NONE){
2341                 return;
2342         }
2343
2344         // grey the screen
2345         gr_set_shader(&Grey_shader);
2346         gr_shade(0,0,gr_screen.clip_width, gr_screen.clip_height);
2347
2348         switch(Om_vox_test_status){
2349         case OM_VOX_TEST_RECORDING:
2350                 // if we have no sound buffer size, do nothing
2351                 if(Om_vox_voice_buffer_size <= 0){
2352                         return;
2353                 }
2354
2355                 // if we are not recording, do nothing
2356                 if(Om_vox_test_status != OM_VOX_TEST_RECORDING){
2357                         return;
2358                 }
2359
2360                 // get the # of samples we'll average for one line
2361                 avg_len = Om_vox_voice_buffer_size / c_width;
2362
2363                 // blit the waveform
2364                 gr_set_color_fast(&Color_green);
2365                 buf_offset = 0;
2366                 for(idx=0; idx < c_width; idx++){
2367                         // reset the running average
2368                         running_avg = 0;
2369                         for(a_idx = 0; a_idx < avg_len; a_idx++){
2370                                 running_avg += (int)Om_vox_voice_buffer[buf_offset] - 128;                      
2371
2372                                 // increment the buffer offset
2373                                 buf_offset++;
2374                         }
2375
2376                         running_avg /= avg_len;
2377                         gr_line((gr_screen.max_w - OM_VOX_WAVE_WIDTH)/2 + idx, OM_VOX_WAVE_Y, (gr_screen.max_w - OM_VOX_WAVE_WIDTH)/2 + idx, OM_VOX_WAVE_Y + running_avg);
2378                 }               
2379
2380                 // if this packet would have been dropped, notify the user
2381                 if(multi_voice_test_packet_tossed()){
2382                         gr_set_color_fast(&Color_bright);
2383                         gr_string(OM_VOX_DROP_ICON_X,OM_VOX_DROP_ICON_Y, XSTR( "Packet Overflow", 393));
2384                 }               
2385                 break;
2386
2387         case OM_VOX_TEST_PLAYBACK:
2388                 // get the offset into the playing direct sound buffer
2389                 buf_offset = ds_get_play_position(ds_get_channel(Om_vox_playback_handle));              
2390
2391                 // get the # of samples we'll average for one line
2392                 avg_len = (int)((float)OM_VOX_RECORD_INT * ((1024.0f * 11.0f) / 1000.0f)) / c_width;                            
2393
2394                 // blit the waveform
2395                 gr_set_color_fast(&Color_red);          
2396                 for(idx=0; idx < c_width; idx++){
2397                         // reset the running average
2398                         running_avg = 0;
2399                         for(a_idx = 0; a_idx < avg_len; a_idx++){
2400                                 if(buf_offset < (OM_VOX_COMP_SIZE - 2)){
2401                                         running_avg += (int)Om_vox_comp_buffer[buf_offset] - 128;                       
2402
2403                                         // increment the buffer offset                          
2404                                         buf_offset++;
2405                                 }
2406                         }
2407
2408                         running_avg /= avg_len;                 
2409                         gr_line((gr_screen.max_w - OM_VOX_WAVE_WIDTH)/2 + idx, OM_VOX_WAVE_Y, (gr_screen.max_w - OM_VOX_WAVE_WIDTH)/2 + idx, OM_VOX_WAVE_Y + running_avg);
2410                 }                               
2411                 break;
2412         }
2413 }
2414
2415 // process/display the player list
2416 void options_multi_vox_process_player_list()
2417 {
2418         int idx;
2419         int y_start,p_count;
2420         int selected_index,click_y;
2421         char str[CALLSIGN_LEN+2];
2422
2423         // check for mouse clicks
2424         if(Om_vox_plist_button.pressed()){
2425                 Om_vox_plist_button.get_mouse_pos(NULL,&click_y);
2426                 selected_index = (click_y / 10) + Om_vox_plist_start;
2427
2428                 // if he clicked on a valid player, select him
2429                 if(Om_vox_players[selected_index] != NULL){
2430                         Om_vox_player_select = Om_vox_players[selected_index];
2431
2432                         nprintf(("Network","Selecting player %s\n",Om_vox_player_select->player->callsign));
2433                 }
2434         }
2435
2436         // draw the list of players
2437         p_count = 0;
2438         y_start = Om_vox_plist_coords[gr_screen.res][1];
2439         for(idx = Om_vox_plist_start; idx < Om_vox_num_players; idx++){
2440                 if(Om_vox_players[idx] != NULL){
2441                         // if he's the selected player, highlight him
2442                         if(Om_vox_players[idx] == Om_vox_player_select){
2443                                 gr_set_color_fast(&Color_bright);
2444                         } else {
2445                                 gr_set_color_fast(&Color_normal);
2446                         }
2447
2448                         // force fit his callsign
2449                         strcpy(str,Om_vox_players[idx]->player->callsign);
2450                         gr_force_fit_string(str, CALLSIGN_LEN+1, Om_vox_plist_coords[gr_screen.res][2]);
2451
2452                         // blit the callsign
2453                         gr_string(Om_vox_plist_coords[gr_screen.res][0], y_start, str);
2454
2455                         // increment the y index
2456                         y_start += 10;
2457
2458                         // increment the player count
2459                         p_count++;
2460                 }
2461
2462                 // if we've reached max display, break out
2463                 if(p_count >= Om_vox_plist_max_display[gr_screen.res]){
2464                         break;
2465                 }
2466         }
2467 }       
2468
2469 // get the index into the player list of the passed netplayer
2470 int options_multi_vox_plist_get(net_player *pl)
2471 {
2472         int idx;
2473
2474         for(idx=0;idx<Om_vox_num_players;idx++){
2475                 if(pl == Om_vox_players[idx]){
2476                         return idx;
2477                 }
2478         }
2479
2480         // should neve get here. hmmm.
2481         Int3();
2482         return -1;
2483 }
2484
2485 // scroll the player list down
2486 void options_multi_vox_plist_scroll_down()
2487 {
2488         if(Om_vox_num_players < Om_vox_plist_max_display[gr_screen.res]){
2489                 gamesnd_play_iface(SND_GENERAL_FAIL);
2490                 return;
2491         }
2492
2493         if((Om_vox_num_players - Om_vox_plist_start) >= Om_vox_plist_max_display[gr_screen.res]){
2494                 Om_vox_plist_start++;
2495                 gamesnd_play_iface(SND_USER_SELECT);
2496         } else {
2497                 gamesnd_play_iface(SND_GENERAL_FAIL);
2498         }
2499 }
2500
2501 // scroll the player list up
2502 void options_multi_vox_plist_scroll_up()
2503 {
2504         if(Om_vox_plist_start > 0){
2505                 Om_vox_plist_start--;
2506                 gamesnd_play_iface(SND_USER_SELECT);
2507         } else {
2508                 gamesnd_play_iface(SND_GENERAL_FAIL);
2509         }
2510 }
2511
2512
2513 // extern functions -----------------------------------------------------
2514
2515 // called when the options screen is initialized, pass in the UI window
2516 void options_multi_init(UI_WINDOW *options_window)
2517 {
2518         // assign the options window
2519         Om_window = options_window;
2520
2521         // load the background bitmaps
2522         options_multi_load_bmaps();     
2523
2524         // load the controls for the protocol area
2525         options_multi_load_protocol_controls();
2526
2527         // load the controls for the general tab
2528         options_multi_load_gen_controls();
2529
2530         // load the controls for the voice tab
2531         options_multi_load_vox_controls();
2532
2533         // disable all the protocol controls
2534         options_multi_disable_protocol_controls();
2535
2536         // disable all the general tab controls
2537         options_multi_disable_gen_controls();
2538
2539         // disable all the voice tab controls
2540         options_multi_disable_vox_controls();
2541
2542         // intialize the protocol section vars
2543         options_multi_init_protocol_vars();
2544
2545         // initialize the general tab vars
2546         options_multi_init_gen_vars();
2547
2548         // initialize the voice tab vars
2549         options_multi_init_vox_vars();
2550
2551         // intialize the multiplayer voice recording system
2552         if( !((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_CONNECTED)) ){
2553                 multi_voice_init();
2554         }
2555
2556         // set the default screen mode
2557         Om_mode = OM_MODE_NONE;
2558 }
2559
2560 // do frame for the multi options screen
2561 void options_multi_do(int key)
2562 {               
2563         // do frame for the protocol section
2564         options_multi_protocol_do(key);
2565
2566         // process and blit any notification messages
2567         options_multi_notify_process();
2568
2569         // process the proper tab control
2570         switch(Om_mode){
2571         case OM_MODE_GENERAL:
2572                 options_multi_gen_do();
2573                 break;
2574         case OM_MODE_VOX:
2575                 options_multi_vox_do();
2576                 break;
2577         default :
2578                 Int3();         
2579         }       
2580 }
2581
2582 // called when the entire options screen is closed
2583 void options_multi_close()
2584 {
2585         // null out the window handle
2586         Om_window = NULL;
2587
2588         // unload all background bitmaps
2589         options_multi_unload_bmaps();
2590
2591         // stop any playing voice
2592         rtvoice_stop_playback_all();
2593
2594         // unset the screen mode
2595         Om_mode = OM_MODE_NONE;
2596 }
2597
2598 // called if the accept button on the main options screen was hit
2599 void options_multi_accept()
2600 {       
2601         // accept function for the protocol section
2602         options_multi_protocol_accept();
2603
2604         // accept function for the general tab
2605         options_multi_gen_accept();
2606
2607         // accept function for the voice tab
2608         options_multi_vox_accept();
2609
2610         // if Net_player is not null, copy these new settings to him
2611         if(Net_player != NULL){
2612                 multi_options_local_load(&Net_player->p_info.options, NULL);            
2613         }
2614         multi_options_local_load(&Player->m_local_options, NULL);
2615
2616         // if we're connected to a game server, update our options on the server now
2617         if((Net_player != NULL) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && MULTI_CONNECTED(Net_players[MY_NET_PLAYER_NUM]) ){
2618                 multi_options_update_local();
2619         }
2620 }
2621
2622 // called when the multiplayer tab is hit - initializes/switches all necessary data.
2623 // NOTE : this is different from the initialization function, which is called only when the options menu is started
2624 void options_multi_select()
2625 {
2626 #ifndef FS1_DEMO
2627         // set the windows mask bitmap
2628         Assert(Om_mask_0 >= 0);
2629         Om_window->set_mask_bmap(Om_mask_0, Om_background_0_mask_fname[gr_screen.res]);
2630
2631         // set the default screen mode
2632         Om_mode = OM_MODE_GENERAL;
2633
2634         // clear any notification messages
2635         Om_notify_stamp = -1;   
2636
2637         // enable all the protocol controls
2638         options_multi_enable_protocol_controls();       
2639
2640         // enable the general tab controls
2641         options_multi_enable_gen_controls();
2642 #endif
2643 }
2644
2645 // return the bitmap handle of the current background bitmap, or -1 if the multiplayer tab is not active
2646 int options_multi_background_bitmap()
2647 {
2648 #ifndef FS1_DEMO
2649         // return the background bitmap mode based upon the current mode
2650         switch(Om_mode){
2651         case OM_MODE_GENERAL:
2652                 return Om_background_0;
2653
2654         case OM_MODE_VOX:
2655                 return Om_background_1;
2656         }
2657
2658         // unknown mode of some kind
2659         return -1;
2660 #endif
2661 }
2662
2663 // called when the multiplayer tab has been switched from
2664 void options_multi_unselect()
2665 {
2666         // unset the mode
2667         Om_mode = OM_MODE_NONE;
2668
2669         // disable all the protocol controls
2670         options_multi_disable_protocol_controls();
2671
2672         // disable all the general tab controls
2673         options_multi_disable_gen_controls();
2674
2675         // disable all the vox tab controls
2676         options_multi_disable_vox_controls();
2677
2678         // stop any test voice recording
2679         multi_voice_test_record_stop();
2680 }
2681
2682 // set voice sound buffer for display 
2683 void options_multi_set_voice_data(unsigned char *sound_buf,int buf_size,unsigned char *comp_buf, int comp_size, int uncomp_size, double gain)
2684 {
2685         // copy the buffer to the vox tab data
2686         if(buf_size > OM_VOX_BUF_SIZE){
2687                 memcpy(Om_vox_voice_buffer,sound_buf,OM_VOX_BUF_SIZE);
2688                 Om_vox_voice_buffer_size = OM_VOX_BUF_SIZE;
2689         } else {
2690                 memcpy(Om_vox_voice_buffer,sound_buf,buf_size);
2691                 Om_vox_voice_buffer_size = buf_size;
2692         }
2693
2694         // copy and uncompress the compressed buffer
2695         if(Om_vox_voice_comp_size == -1){
2696                 Om_vox_voice_comp_size = 0;
2697         }
2698         // if we can fit it, decompress this data
2699         if((Om_vox_voice_comp_size + uncomp_size) < OM_VOX_COMP_SIZE){
2700                 // uncompress the data
2701                 rtvoice_uncompress(comp_buf, comp_size, gain, Om_vox_comp_buffer + Om_vox_voice_comp_size, uncomp_size);
2702
2703                 Om_vox_voice_comp_size += uncomp_size;
2704         }
2705 }
2706
2707 // return whether we want to eat a tabbed keypress
2708 int options_multi_eat_tab()
2709 {
2710         // do we want to eat the tab key or not
2711         if(Om_tracker_passwd.has_focus() || Om_tracker_login.has_focus() || Om_tracker_squad_name.has_focus()){
2712                 return 1;
2713         }
2714
2715         return 0;
2716 }
2717