-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComm.c
More file actions
1683 lines (1444 loc) · 39.3 KB
/
Comm.c
File metadata and controls
1683 lines (1444 loc) · 39.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* The X Men, October 1996
* Copyright (c) 1996 Probe Entertainment Limited
* All Rights Reserved
*
* $Revision: 81 $
*
* $Header: /PcProjectX/Comm.c 81 11/11/98 16:00 Philipy $
*
* $Log: /PcProjectX/Comm.c $
*
* 81 11/11/98 16:00 Philipy
* various fixes for warnings / errors when compiling under VC6
*
* 80 14/10/98 9:31 Phillipd
*
* 79 18/09/98 14:15 Phillipd
*
* 78 14/09/98 15:35 Philipy
* added facility for server based collisions
*
* 77 7/09/98 11:44 Philipy
*
* 76 27/08/98 17:26 Philipy
* Pseudohost can select level, & migrates on quitting
* players booted to titles due to not having new level are now informed
*
* 75 20/08/98 15:28 Philipy
* You can now join server based games after being launched by a lobby.
* Level name is updated after pseudohost selects level
* AVI can now play if no sound hw exists
* started gamespy support
*
* 74 17/08/98 18:00 Philipy
* removed loads of unreferenced local variables
*
* 73 14/08/98 15:25 Philipy
* added trilinear option to menus
* fixed level name / shutdown packet in heartbeat
*
*
* 72 14/08/98 9:13 Phillipd
* DirectX6 is in effect.......
*
* 71 12/08/98 12:59 Phillipd
*
* 70 12/08/98 12:54 Phillipd
*
* 69 12/08/98 12:53 Phillipd
*
* 68 12/08/98 11:54 Phillipd
*
* 67 11/08/98 16:52 Philipy
* fixed bug which caused max players to always be set to 32 if lobby
* launched & lobby sets max players to 0.
* status request codes now expected in hex format ( eg.
* FFFFFFFFstatus\nfe<NULL> )
* heartbeat frequencies less than 5000 mS can now be specified. If none (
* or 0 ) specified, no heartbeat packets will be sent.
*
* 66 7/08/98 12:45 Philipy
* heartbeat now enabled for non tcp games ( if heartbeat.txt exists )
* status type 0 now treated as status type 254
* if lobby launched with max players set to 0, host is able to set max
* players
* shutdown udp packet now sent ( if specified in heartbeat.txt )
*
* 65 31/07/98 16:17 Philipy
* added PPS to session desc
*
* 64 28/07/98 14:44 Philipy
* all server timeouts now configurable
*
* 63 28/07/98 10:39 Philipy
* Max players now works properly for server games
*
* 62 16/07/98 10:53 Philipy
* fixed dissapearing session after level change on server based game
*
* 61 15/07/98 16:25 Philipy
* now handles pseudohost quitting in titles & server quitting ( in
* titiles or in game )
*
* 60 14/07/98 17:56 Philipy
* fixed pseudohost quitting in titles bug ( if server recieves
* MSG_GAMEPARAM after pseudohost has quit )
*
* 59 14/07/98 11:15 Philipy
* various patch bugs
* pseudohost quitting in titles
*
* 58 9/07/98 12:43 Philipy
* few minor fixes for patch release
*
* 57 7/07/98 18:03 Philipy
* added lobby autostart code ( when all players have recieved init msg )
* added num primary weapons menu option ( propergated to other players &|
* server )
* extracted new title text for localisation
*
* 56 3/07/98 11:53 Philipy
* heartbeat & quickstart stuff
*
* 55 6/22/98 2:16p Phillipd
* Option to reset the score for every level..............
*
* 54 17/06/98 19:33 Philipy
* more win98 stuff
*
* 53 16/06/98 16:32 Philipy
* more lobby / join game stuff
*
* 52 12/06/98 16:06 Philipy
* fixed lobby stuff for Wireplay
*
* 51 6/09/98 12:09p Phillipd
*
* 50 22/05/98 17:51 Philipy
* more work on session info
*
* 49 20/05/98 9:38 Philipy
* implemented front end server menus
* removed ( invalid ) ping from sessions menu
* changed EnumPlayers so that it solely uses MSG_NAME
*
* 48 5/12/98 12:46p Phillipd
*
* 47 11/05/98 15:15 Philipy
* added session info stuff ( game type, ping etc )
*
* 46 5/06/98 4:53p Phillipd
*
* 45 4/27/98 4:01p Phillipd
*
* 44 4/06/98 7:06p Phillipd
*
* 43 8/03/98 16:48 Philipy
* added CTF game bit for lobby hosted games
*
* 42 3/07/98 12:09p Phillipd
* Changing the lpDplayLobby pointer from version 2 to 1 was not a good
* idead Phil
* Hacking out our normal lobby code so it worked with this new pointer
* was an even worse idea.....
* Not checking it before checking it in was your worsed idea...
*
* 41 6/03/98 18:02 Philipy
*
* 40 6/03/98 17:57 Philipy
* added lobby support
*
* 39 3/06/98 5:13p Phillipd
*
* 38 4/03/98 12:33 Oliverc
* CTF mode fully enabled
*
* 37 3/03/98 16:59 Oliverc
* New multiplayer CTF mode stuff (1st attempt)
*
* 36 3/02/98 4:32p Phillipd
*
* 35 3/02/98 12:29p Phillipd
*
* 34 26/02/98 19:44 Oliverc
* Active movie files "cplay.c" and "media.c" no longer necessary
*
* 33 24/02/98 16:54 Oliverc
* 1st attempt at bounty hunt multiplayer game
*
* 32 1/16/98 2:54p Phillipd
*
* 31 1/09/98 10:31a Phillipd
* Bugs fixed......
*
* 30 12/17/97 5:19p Phillipd
*
* 29 12/10/97 10:39a Phillipd
* Players names are now propergated across the network when changed...
* Difficulty levels are functional....
*
* 28 11/29/97 4:35p Phillipd
* Xmem is now in effect...use it allways....
*
* 27 10/09/97 3:29p Phillipd
* External forces coming...
* Shield and Hull now floats
*
* 26 9/30/97 4:20p Phillipd
*
* 25 9/30/97 8:45a Phillipd
*
* 24 9/29/97 11:55a Phillipd
* Dawn of a new age with directplay 3
*
* 23 17/07/97 15:38 Collinsd
* BGObjects now use compobjs.
*
* 22 8/07/97 16:30 Collinsd
* Dicked about with include files FUCK!
*
* 21 6/24/97 11:12a Phillipd
*
* 20 6/18/97 11:27a Phillipd
*
* 19 6/16/97 4:15p Phillipd
* added random start positions for first time you get into a level...
*
* 18 6/14/97 1:11p Phillipd
* Back to Dplay2
*
* 17 6/10/97 9:01a Phillipd
*
* 16 6/03/97 10:46a Phillipd
*
* 15 4/25/97 2:51p Phillipd
*
* 14 4/10/97 4:29p Phillipd
* DirectPlay3 is here...
*
* 13 20-03-97 5:46p Collinsd
* Countdown timer now works in multiplayer.
*
* 12 2/14/97 3:21p Phillipd
*
* 11 2/11/97 5:11p Phillipd
*
* 10 2/07/97 4:59p Phillipd
*
* 9 1/10/97 11:30a Phillipd
* movies are now doable
*
* 8 12/27/96 12:33p Phillipd
* all files are not dependant on mydplay.h...just some..
* including it several times in the same files didnt help..
*
* 7 12/23/96 6:04p Phillipd
*
* 6 12/17/96 4:57p Phillipd
* Version Control Added..
*
* 5 12/14/96 5:04p Phillipd
*
* 4 11/22/96 9:20a Phillipd
*
* 3 11/20/96 2:42p Phillipd
* players can now restart and keep there score...
*
* 2 10/11/96 12:51p Phillipd
* Slight update...Destroy player is now handled as a system message..
*
* 1 10/10/96 3:09p Phillipd
* First SS update fo some of this...
* DirectPlay 2 here we go.....
*/
/*==========================================================================
*
* Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
*
* File: comm.c
* Content: DirectPlay related code
*
*
***************************************************************************/
#include "stdwin.h"
#include <dplay.h>
#include <stdio.h>
#include "comm.h"
#include "typedefs.h"
#include "new3d.h"
#include "quat.h"
#include "CompObjects.h"
#include "bgobjects.h"
#include "Object.h"
#include "mydplay.h"
#include "d3dappi.h"
#include "main.h"
#include "mydplay2.h"
#include "title.h"
#include "primary.h"
#include "XMem.h"
#include "dpthread.h"
#include "multiplayer.h"
/*
* Externals
*/
extern LIST PlayersList;
extern BOOL HarmTeamMates;
extern BOOL BrightShips;
extern BOOL MyBrightShips;
extern BOOL BikeExhausts;
extern int32 ColPerspective;
extern SLIDER CTFSlider;
extern int16 MaxKills;
extern BOOL ResetKillsPerLevel;
extern DPID PlayerIDs[ MAX_PLAYERS ];
extern DPID LobbyPlayerIDs[ MAX_PLAYERS ];
extern BOOL PseudoHostCanSetMaxPlayers;
extern SLIDER PacketsSlider;
/*
* Globals
*/
LPDPSESSIONDESC2 glpdpSD = NULL; // current session description
#ifdef MANUAL_SESSIONDESC_PROPAGATE
LPDPSESSIONDESC2 glpdpSD_copy = NULL; // current session description
#endif
LPDIRECTPLAYLOBBY2A lpDPlayLobby = NULL; //Lobby stuff...
//LPDIRECTPLAYLOBBYA lpDPlayLobby = NULL; //Lobby stuff...
LPDPLCONNECTION glpdplConnection = NULL; // connection settings
BOOL IsLobbyLaunched = FALSE;
BOOL LobbyAutoStart = FALSE;
extern DPID dcoID;
extern LPDIRECTPLAY4A glpDP; // directplay object pointer
extern DPSESSIONDESC2 Old_Session;
extern DWORD Old_WhoIAm;
extern DWORD Old_Kills;
extern DWORD Old_Deaths;
extern char Old_Name[256];
extern BOOL Rejoining;
extern BOOL TeamGame;
extern WORD Version;
extern HANDLE hPlayerEvent; // player event to use
extern SLIDER MaxPlayersSlider;
extern SLIDER TimeLimit;
extern BOOL BombTag;
extern BOOL CaptureTheFlag;
extern BOOL CTF;
extern BOOL BountyHunt;
extern uint16 RandomStartPosModify;
extern BOOL DplayRecieveThread;
extern BOOL UseShortPackets;
extern BOOL BigPackets;
extern BOOL IsServer;
extern BOOL IsHost; // is the user hosting/joining a game
extern SHORTNAMETYPE Names; // all the players short Names....
void DebugPrintf( const char * format, ... );
BOOL JoinASession ( MENUITEM * Item );
/*
* DPlayClose
*
* Wrapper for DirectPlay Close API
*/
HRESULT DPlayClose(void)
{
HRESULT hr=E_FAIL;
if (glpDP)
hr = IDirectPlayX_Close(glpDP);
return hr;
}
/*
* DPlayCreate
*
* Wrapper for DirectPlay Create API. Retrieves a DirectPlay3/DirectPlay3A interface
* based on the UNICODE flag
*
*/
HRESULT DPlayCreate(LPGUID lpGuid)
{
HRESULT hr=E_FAIL;
LPDIRECTPLAY lpDP=NULL;
// create a DirectPlay1 interface
if ((hr = DirectPlayCreate(lpGuid, &lpDP, NULL)) == DP_OK)
{
if (lpDP)
{
// query for a DirectPlay3(A) interface
#ifdef UNICODE
hr = IDirectPlay_QueryInterface(lpDP,&IID_IDirectPlay4,(LPVOID *)&glpDP);
#else
hr = IDirectPlay_QueryInterface(lpDP,&IID_IDirectPlay4A,(LPVOID *)&glpDP);
#endif
// no longer need the DirectPlay1 interface
IDirectPlay_Release(lpDP);
}
}
return hr;
}
/*
* DPlayCreatePlayer
*
* Wrapper for DirectPlay CreatePlayer API.
*/
HRESULT DPlayCreatePlayer(LPDPID lppidID, LPTSTR lptszPlayerName, HANDLE hEvent,
LPVOID lpData, DWORD dwDataSize)
{
HRESULT hr=E_FAIL;
DPNAME name;
if ( !IsLobbyLaunched )
SetupConnection( myglobs.hInstApp );
ZeroMemory(&name,sizeof(name));
name.dwSize = sizeof(DPNAME);
// if launched by lobby, use players config name ( if not player ) rather than name given by lobby
if ( IsLobbyLaunched )
{
if ( _stricmp( lptszPlayerName, DEFAULT_PLAYER_NAME ) )
{
strcpy( lptszPlayerName, Names[ WhoIAm ] );
}
}
#ifdef UNICODE
name.lpszShortName = lptszPlayerName;
#else
name.lpszShortNameA = lptszPlayerName;
#endif
if( DplayRecieveThread )
{
if (glpDP)
hr = IDirectPlayX_CreatePlayer(glpDP, lppidID, &name, hPlayerEvent, lpData,
dwDataSize, 0);
}else{
if (glpDP)
hr = IDirectPlayX_CreatePlayer(glpDP, lppidID, &name, NULL, lpData,
dwDataSize, 0);
}
switch( hr )
{
case DPERR_CANTADDPLAYER :
DebugPrintf("DPERR_CANTADDPLAYER\n");
break;
case DPERR_CANTCREATEPLAYER :
DebugPrintf("DPERR_CANTCREATEPLAYER\n");
break;
case DPERR_INVALIDFLAGS :
DebugPrintf("DPERR_INVALIDFLAGS\n");
break;
case DPERR_INVALIDPARAMS :
DebugPrintf("DPERR_INVALIDPARAMS\n");
break;
case DPERR_NOCONNECTION :
DebugPrintf("DPERR_NOCONNECTION\n");
break;
case DP_OK:
DebugPrintf("DP_OK\n");
break;
}
return hr;
}
void StoreSessionUserFields( LPDPSESSIONDESC2 lpDesc )
{
SYSTEMTIME SystemTime;
FILETIME FileTime;
WORD date;
WORD time;
// store the creation time for this session
GetSystemTime( &SystemTime );
SystemTimeToFileTime( &SystemTime , &FileTime );
FileTimeToDosDateTime( &FileTime , &date , &time );
lpDesc->dwUser1 = date + (time << 16);
lpDesc->dwUser2 = RandomStartPosModify; // only lower word is used...
if ( MaxKills > 255 ) // ensure 8 bit
MaxKills = 255;
lpDesc->dwUser2 |= ( MaxKills << MaxKills_Shift );
if ( TimeLimit.value > 30 )
TimeLimit.value = 30;
lpDesc->dwUser3 = 0;
lpDesc->dwUser3 |= ( TimeLimit.value << GameTimeBit_Shift );
lpDesc->dwUser3 |= ( TimeLimit.value << CurrentGameTime_Shift );
if( TeamGame )
lpDesc->dwUser3 |= TeamGameBit;
if( BombTag )
lpDesc->dwUser3 |= BombGameBit;
if( CTF )
lpDesc->dwUser3 |= CTFGameBit;
if( CaptureTheFlag )
lpDesc->dwUser3 |= FlagGameBit;
if ( BountyHunt )
lpDesc->dwUser3 |= BountyGameBit;
if ( UseShortPackets )
lpDesc->dwUser3 |= ShortPacketsBit;
if ( BigPackets )
lpDesc->dwUser3 |= BigPacketsBit;
// new additions ( previously in MSG_INIT )
if ( HarmTeamMates )
lpDesc->dwUser3 |= HarmTeamMatesBit;
if ( MyBrightShips )
lpDesc->dwUser3 |= BrightShipsBit;
if(ResetKillsPerLevel )
lpDesc->dwUser3 |= ResetKillsPerLevelBit;
if ( BikeExhausts )
lpDesc->dwUser3 |= BikeExhaustBit;
lpDesc->dwUser3 |= ( ColPerspective << Collision_Type_BitShift );
if ( IsServer )
lpDesc->dwUser3 |= SERVER_STATE_NeedHost;
lpDesc->dwUser3 |= CTF_Type_Encode( ( DWORD )CTFSlider.value );
if ( PseudoHostCanSetMaxPlayers )
lpDesc->dwUser3 |= EnableMaxPlayersChangeBit;
lpDesc->dwUser4 = Version; // only the lower word is used...
lpDesc->dwUser4 |= ( MaxPlayersSlider.value << MaxPlayers_Shift ); // max players must be stored seperately for server game
lpDesc->dwUser4 |= ( PacketsSlider.value << PacketsPerSecond_Shift );
}
/*
* DPlayCreateSession
*
* Wrapper for DirectPlay CreateSession API.Uses the global application guid (PROJX_GUID).
*/
HRESULT DPlayCreateSession(LPTSTR lptszSessionName)
{
HRESULT hr = E_FAIL;
DPSESSIONDESC2 dpDesc;
ZeroMemory(&dpDesc, sizeof(dpDesc));
dpDesc.dwSize = sizeof(dpDesc);
dpDesc.dwFlags = DPSESSION_MIGRATEHOST | DPSESSION_KEEPALIVE | DPSESSION_DIRECTPLAYPROTOCOL;
dpDesc.dwMaxPlayers = MaxPlayersSlider.value;
StoreSessionUserFields( &dpDesc );
Old_Session = dpDesc;
Old_WhoIAm = 0;
Old_Kills = 0;
Old_Deaths = 0;
#ifdef UNICODE
dpDesc.lpszSessionName = lptszSessionName;
#else
dpDesc.lpszSessionNameA = lptszSessionName;
#endif
// set the application guid
dpDesc.guidApplication = PROJX_GUID;
if (glpDP)
hr = IDirectPlayX_Open(glpDP, &dpDesc, DPOPEN_CREATE);
return hr;
}
/*
* DPlayDestroyPlayer
*
* Wrapper for DirectPlay DestroyPlayer API.
*/
HRESULT DPlayDestroyPlayer(DPID pid)
{
HRESULT hr=E_FAIL;
if (glpDP)
hr = IDirectPlayX_DestroyPlayer(glpDP, pid);
ShutdownConnection();
return hr;
}
/*
* DPlayEnumPlayers
*
* Wrapper for DirectPlay API EnumPlayers
*/
HRESULT DPlayEnumPlayers(LPGUID lpSessionGuid, LPDPENUMPLAYERSCALLBACK2 lpEnumCallback,
LPVOID lpContext, DWORD dwFlags)
{
HRESULT hr=E_FAIL;
if (glpDP)
hr = IDirectPlayX_EnumPlayers(glpDP, lpSessionGuid, lpEnumCallback, lpContext, dwFlags);
return hr;
}
/*
* DPlayEnumSessions
*
* Wrapper for DirectPlay EnumSessions API.
*/
HRESULT DPlayEnumSessions(DWORD dwTimeout, LPDPENUMSESSIONSCALLBACK2 lpEnumCallback,
LPVOID lpContext, DWORD dwFlags)
{
HRESULT hr = E_FAIL;
DPSESSIONDESC2 dpDesc;
ZeroMemory(&dpDesc, sizeof(dpDesc));
dpDesc.dwSize = sizeof(dpDesc);
dpDesc.guidApplication = PROJX_GUID;
if (glpDP)
{
hr = IDirectPlayX_EnumSessions(glpDP, &dpDesc, dwTimeout, lpEnumCallback,
lpContext, dwFlags);
}
return hr;
}
/*
* DPlayGetPlayerData
*
* Wrapper for DirectPlay GetPlayerData API.
*/
HRESULT DPlayGetPlayerData(DPID pid, LPVOID lpData, LPDWORD lpdwDataSize, DWORD dwFlags)
{
HRESULT hr=E_FAIL;
if (glpDP)
hr = IDirectPlayX_GetPlayerData(glpDP, pid, lpData, lpdwDataSize, dwFlags);
return hr;
}
/*
* DPlayGetSessionDesc
*
* Wrapper for DirectPlay GetSessionDesc API.
*/
HRESULT DPlayGetSessionDesc(void)
{
HRESULT hr=E_FAIL;
DWORD dwSize;
// free old session desc, if any
if (glpdpSD)
{
free(glpdpSD);
glpdpSD = NULL;
}
if (glpDP)
{
#ifdef MANUAL_SESSIONDESC_PROPAGATE
if ( glpdpSD_copy )
{
glpdpSD = (LPDPSESSIONDESC2) malloc( sizeof( *glpdpSD_copy ) );
if ( glpdpSD )
{
*glpdpSD = *glpdpSD_copy;
return DP_OK;
}else
{
return E_OUTOFMEMORY;
}
}
#endif
// first get the size for the session desc
if ((hr = IDirectPlayX_GetSessionDesc(glpDP, NULL, &dwSize)) == DPERR_BUFFERTOOSMALL)
{
// allocate memory for it
glpdpSD = (LPDPSESSIONDESC2) malloc(dwSize);
if (glpdpSD)
{
// now get the session desc
hr = IDirectPlayX_GetSessionDesc(glpDP, glpdpSD, &dwSize);
}
else
{
hr = E_OUTOFMEMORY;
}
}
}
return hr;
}
void UpdateSessionName( char *name )
{
DPSESSIONDESC2 tempsd;
DPlayGetSessionDesc();
if ( glpdpSD )
{
tempsd = *glpdpSD;
glpdpSD->lpszSessionNameA = name;
DPlaySetSessionDesc( 1 ); // 1 ensures new session desc is sent to all players via guaranteed msg
*glpdpSD = tempsd; // restore old SD so that it is freed properly.
DPlayGetSessionDesc(); // getting new SD will free up old one
}
}
/*
* DPlaySetSessionDesc
*
* Wrapper for DirectPlay SetSessionDesc API.
*/
HRESULT DPlaySetSessionDesc(DWORD flags)
{
HRESULT hr=E_FAIL;
if (glpDP && glpdpSD)
{
#ifdef MANUAL_SESSIONDESC_PROPAGATE
if ( glpdpSD_copy )
{
free ( glpdpSD_copy );
glpdpSD_copy = NULL;
}
#endif
// now set the session desc
hr = IDirectPlayX_SetSessionDesc(glpDP, glpdpSD, /*flags*/0 );
}
#ifdef MANUAL_SESSIONDESC_PROPAGATE
if ( hr == DP_OK )
{
if ( !flags ) // lazy way of preventing messages, since no flags are currently defined
// for IDirectPlayX::SetSessionDesc !!
{
SendGameMessage( MSG_SESSIONDESC, 0, 0, 0, 0 );
}
}
#endif
#ifdef DEBUG_ON
if ( hr != DP_OK )
{
switch ( hr )
{
case DPERR_ACCESSDENIED:
DebugPrintf("DPlaySetSessionDesc() error - DPERR_ACCESSDENIED\n");
break;
case DPERR_INVALIDPARAMS:
DebugPrintf("DPlaySetSessionDesc() error - DPERR_INVALIDPARAMS\n");
break;
case DPERR_NOSESSIONS:
DebugPrintf("DPlaySetSessionDesc() error - DPERR_NOSESSIONS\n");
break;
default:
DebugPrintf("DPlaySetSessionDesc() error - unknown\n");
}
}
#endif
return hr;
}
/*
* IsDPlay
*
* Returns TRUE if a DirectPlay interface exists, otherwise FALSE.
*/
BOOL IsDPlay(void)
{
return (glpDP ? TRUE:FALSE);
}
/*
* DPlayOpenSession
*
* Wrapper for DirectPlay OpenSession API.
*/
HRESULT DPlayOpenSession(LPGUID lpSessionGuid)
{
HRESULT hr = E_FAIL;
DPSESSIONDESC2 dpDesc;
ZeroMemory(&dpDesc, sizeof(dpDesc));
dpDesc.dwSize = sizeof(dpDesc);
// set the session guid
if (lpSessionGuid)
dpDesc.guidInstance = *lpSessionGuid;
// set the application guid
dpDesc.guidApplication = PROJX_GUID;
// open it
if (glpDP)
hr = IDirectPlayX_Open(glpDP, &dpDesc, DPOPEN_JOIN);
return hr;
}
/*
* DPlayRelease
*
* Wrapper for DirectPlay Release API.
*/
HRESULT DPlayRelease(void)
{
HRESULT hr = E_FAIL;
DPStopThread();
// flush all waiting guaranteed messages
ProcessGuaranteedMessages( TRUE , FALSE , FALSE );
if (glpDP != NULL)
{
// free session desc, if any
// if (glpdpSD)
// {
// free(glpdpSD);
// glpdpSD = NULL;
// }
// release dplay
hr = IDirectPlayX_Release(glpDP);
glpDP = NULL;
}
// if( lpDPlayLobby )
// {
// lpDPlayLobby->lpVtbl->Release(lpDPlayLobby);
// lpDPlayLobby = NULL;
// }
return hr;
}
/*
* DPlaySetPlayerData
*
* Wrapper for DirectPlay SetPlayerData API
*/
HRESULT DPlaySetPlayerData(DPID pid, LPVOID lpData, DWORD dwSize, DWORD dwFlags)
{
HRESULT hr=E_FAIL;
if (glpDP)
hr = IDirectPlayX_SetPlayerData(glpDP, pid, lpData, dwSize, dwFlags);
return hr;
}
/*
* DPlay Create Lobby interface...
*
* Wrapper for DirectPlay Lobby Create API
*/
HRESULT DPlayCreateLobby( void )
{
LPDIRECTPLAYLOBBYA lpDPlayLobbyA = NULL;
LPDIRECTPLAYLOBBY2A lpDPlayLobby2A = NULL;
HRESULT hr;
if (lpDPlayLobby)
{
lpDPlayLobby->lpVtbl->Release(lpDPlayLobby);
lpDPlayLobby = NULL;
}
// get ANSI DirectPlayLobby interface
hr = DirectPlayLobbyCreate(NULL, &lpDPlayLobbyA, NULL, NULL, 0);
if FAILED(hr)
goto FAILURE;
// get ANSI DirectPlayLobby2 interface
hr = lpDPlayLobbyA->lpVtbl->QueryInterface(lpDPlayLobbyA,
&IID_IDirectPlayLobby2A, (LPVOID *) &lpDPlayLobby2A);
if FAILED(hr)
goto FAILURE;
// don't need DirectPlayLobby interface anymore
lpDPlayLobbyA->lpVtbl->Release(lpDPlayLobbyA);
lpDPlayLobbyA = NULL;
/*
// fill modem combo box with available modems
// FillModemComboBox(hWnd, lpDPlayLobby2A);
*/
// Fill in the ANSI lobby interface
lpDPlayLobby = lpDPlayLobby2A;
return (DP_OK);
FAILURE:
DebugPrintf("DPlayCreateLobby failure\n");
if (lpDPlayLobbyA)
lpDPlayLobbyA->lpVtbl->Release(lpDPlayLobbyA);
if (lpDPlayLobby2A)
lpDPlayLobby2A->lpVtbl->Release(lpDPlayLobby2A);
return (hr);
}
/*
* DPlay Create a sevice provider address...
*
* Wrapper for DirectPlay CreateCompoundAddress API
*/
HRESULT CreateServiceProviderAddress( LPGUID lpGuid ,LPDIRECTPLAYLOBBY2A lpDPlayLobby, LPVOID *lplpAddress, LPDWORD lpdwAddressSize , char * TCPIPAddress)
{
DPCOMPOUNDADDRESSELEMENT addressElements[3];
// CHAR szPhoneNumberString[256];
// CHAR szModemString[256];
LPVOID lpAddress = NULL;
DWORD dwAddressSize = 0;
DWORD dwElementCount;
HRESULT hr;
dwElementCount = 0;
if (IsEqualGUID(lpGuid, &DPSPGUID_MODEM))
{
// Modem needs a service provider, a phone number string and a modem string
// service provider
addressElements[dwElementCount].guidDataType = DPAID_ServiceProvider;
addressElements[dwElementCount].dwDataSize = sizeof(GUID);
addressElements[dwElementCount].lpData = (LPVOID) &DPSPGUID_MODEM;
dwElementCount++;
#if 0
// add a modem string if available
lstrcpy(szModemString, "");
// This is where you would fill in the name of the modem...
addressElements[dwElementCount].guidDataType = DPAID_Modem;
addressElements[dwElementCount].dwDataSize = lstrlen(szModemString) + 1;
addressElements[dwElementCount].lpData = szModemString;
dwElementCount++;
// add phone number string
lstrcpy(szPhoneNumberString, "");
// This is where you would fill in the Phone number.. fill in szPhoneNumberString with the phone number...
addressElements[dwElementCount].guidDataType = DPAID_Phone;
addressElements[dwElementCount].dwDataSize = lstrlen(szPhoneNumberString) + 1;
addressElements[dwElementCount].lpData = szPhoneNumberString;
dwElementCount++;
#endif
}
// internet TCP/IP service provider
else if (IsEqualGUID(lpGuid, &DPSPGUID_TCPIP))
{
// TCP/IP needs a service provider and an IP address
// service provider
addressElements[dwElementCount].guidDataType = DPAID_ServiceProvider;
addressElements[dwElementCount].dwDataSize = sizeof(GUID);
addressElements[dwElementCount].lpData = (LPVOID) &DPSPGUID_TCPIP;
dwElementCount++;
// This is where you would fill in the IP Address..
addressElements[dwElementCount].guidDataType = DPAID_INet;
addressElements[dwElementCount].dwDataSize = lstrlen(TCPIPAddress) + 1;
addressElements[dwElementCount].lpData = (LPVOID) TCPIPAddress;
dwElementCount++;
}
// IPX service provider
else if (IsEqualGUID(lpGuid, &DPSPGUID_IPX))
{
// IPX just needs a service provider
// service provider
addressElements[dwElementCount].guidDataType = DPAID_ServiceProvider;
addressElements[dwElementCount].dwDataSize = sizeof(GUID);
addressElements[dwElementCount].lpData = (LPVOID) &DPSPGUID_IPX;
dwElementCount++;
}
// anything else, let service provider collect settings, if any
else
{
// service provider
addressElements[dwElementCount].guidDataType = DPAID_ServiceProvider;
addressElements[dwElementCount].dwDataSize = sizeof(GUID);
addressElements[dwElementCount].lpData = (LPVOID) lpGuid;
dwElementCount++;