Skip to content

Commit de7d0c7

Browse files
Merge pull request #2214 from notimaginative/multi_packet_fixes
Multi packet fixes
2 parents 77adaa6 + 5f7b7ef commit de7d0c7

30 files changed

+1160
-850
lines changed

code/globalincs/globals.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939

4040
// from missionparse.h and then redefined to the same value in sexp.h
4141
#define TOKEN_LENGTH 32
42-
// ****************************************************************
43-
// DO NOT CHANGE THIS - IT WILL LIKELY BREAK FREESPACE2 PXO SUPPORT
44-
// TALK TO DAVE B FIRST
45-
// ****************************************************************
46-
#define MAX_SHIP_CLASSES_MULTI 130
4742

4843
#define MAX_SHIP_CLASSES 500
4944

code/menuui/barracks.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,6 @@ void barracks_button_pressed(int n)
11541154
break;
11551155

11561156
case B_PILOT_MULTI_MODE_BUTTON:
1157-
if ( Networking_disabled ) {
1158-
game_feature_disabled_popup();
1159-
break;
1160-
}
1161-
11621157
if (Player_sel_mode != PLAYER_SELECT_MODE_MULTI) {
11631158
gamesnd_play_iface(InterfaceSounds::USER_SELECT);
11641159
Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI;
@@ -1539,11 +1534,6 @@ void barracks_do_frame(float /*frametime*/)
15391534
break;
15401535

15411536
case KEY_TAB: // switch mode (simgle/multi)
1542-
if ( Networking_disabled ) {
1543-
game_feature_disabled_popup();
1544-
break;
1545-
}
1546-
15471537
if (Player_sel_mode == PLAYER_SELECT_MODE_SINGLE) {
15481538
Cur_pilot->flags |= PLAYER_FLAGS_IS_MULTI;
15491539
Cur_pilot->player_was_multi = 1;

code/menuui/optionsmenu.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,6 @@ void options_change_tab(int n)
586586

587587
switch (n) {
588588
case MULTIPLAYER_TAB:
589-
if ( Networking_disabled ) {
590-
game_feature_disabled_popup();
591-
return;
592-
}
593-
594589
if ( !Options_multi_inited ) {
595590
// init multiplayer
596591
options_multi_init(&Ui_window);

code/menuui/playermenu.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void player_select_init()
327327

328328
// if we found a pilot
329329
if ( player_select_get_last_pilot_info() ) {
330-
if (Player_select_last_is_multi && !Networking_disabled) {
330+
if (Player_select_last_is_multi) {
331331
player_select_init_player_stuff(PLAYER_SELECT_MODE_MULTI);
332332
} else {
333333
player_select_init_player_stuff(PLAYER_SELECT_MODE_SINGLE);
@@ -689,10 +689,6 @@ void player_select_button_pressed(int n)
689689

690690
case MULTI_BUTTON:
691691
Player_select_autoaccept = 0;
692-
if ( Networking_disabled ) {
693-
game_feature_disabled_popup();
694-
break;
695-
}
696692

697693
// switch to multiplayer mode
698694
if (Player_select_mode != PLAYER_SELECT_MODE_MULTI) {

code/mission/missioncampaign.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ campaign Campaign;
9797
* In the type field, we return if the campaign is a single player or multiplayer campaign.
9898
* The type field will only be valid if the name returned is non-NULL
9999
*/
100-
int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc)
100+
int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc, char **first_mission)
101101
{
102102
int i, success = 0;
103103
char campaign_type[NAME_LENGTH], fname[MAX_FILENAME_LEN];
@@ -154,6 +154,11 @@ int mission_campaign_get_info(const char *filename, char *name, int *type, int *
154154
if ((*type) != CAMPAIGN_TYPE_SINGLE) {
155155
skip_to_string("+Num Players:");
156156
stuff_int(max_players);
157+
// Cyborg17 - and the first mission name if we want it, too
158+
if (first_mission) {
159+
skip_to_string("$Mission:");
160+
*first_mission = stuff_and_malloc_string(F_NAME, nullptr);
161+
}
157162
}
158163

159164
// if we found a valid campaign type

code/mission/missioncampaign.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void mission_campaign_savefile_generate_root(char *filename, player *pl = NULL);
206206
// execute the corresponding mission_campaign_savefile functions.
207207

208208
// get name and type of specified campaign file
209-
int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc = NULL);
209+
int mission_campaign_get_info(const char *filename, char *name, int *type, int *max_players, char **desc = nullptr, char **first_mission = nullptr);
210210

211211
// get a listing of missions in a campaign
212212
int mission_campaign_get_mission_list(const char *filename, char **list, int max);

code/mission/missionparse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ int parse_create_object_sub(p_object *p_objp)
24472447
if (!object_is_docked(p_objp) || (p_objp->flags[Mission::Parse_Object_Flags::SF_Dock_leader]))
24482448
{
24492449
if ((Game_mode & GM_IN_MISSION) && MULTIPLAYER_MASTER && (p_objp->wingnum == -1))
2450-
send_ship_create_packet(&Objects[objnum], (p_objp == Arriving_support_ship) ? 1 : 0);
2450+
send_ship_create_packet(&Objects[objnum], (p_objp == Arriving_support_ship));
24512451
}
24522452
// also add this ship to the multi ship tracking and interpolation struct
24532453
multi_ship_record_add_ship(objnum);

code/missionui/missionscreencommon.cpp

Lines changed: 97 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,12 @@ int wss_get_mode(int from_slot, int from_list, int to_slot, int to_list, int wl_
13401340
}
13411341

13421342
// store all the unit data and pool data
1343-
int store_wss_data(ubyte *block, int max_size, interface_snd_id sound,int player_index)
1343+
int store_wss_data(ubyte *data, __UNUSED const unsigned int max_size, interface_snd_id sound, int player_index)
13441344
{
1345-
int j, i,offset=0;
1346-
short player_id;
1347-
short ishort;
1345+
int j, i, packet_size = 0;
1346+
ubyte val;
1347+
short player_id;
1348+
ushort pool_size;
13481349

13491350
// this function assumes that the data is going to be used over the network
13501351
// so make a non-network version of this function if needed
@@ -1354,72 +1355,64 @@ int store_wss_data(ubyte *block, int max_size, interface_snd_id sound,int player
13541355
if ( !(Game_mode & GM_MULTIPLAYER) )
13551356
return 0;
13561357

1357-
1358-
// write the ship pool
1359-
for ( i = 0; i < ship_info_size(); i++ ) {
1360-
if ( Ss_pool[i] > 0 ) {
1361-
block[offset++] = (ubyte)i;
1362-
Assert( Ss_pool[i] < UCHAR_MAX );
1363-
1364-
// take care of sign issues
1365-
if(Ss_pool[i] == -1){
1366-
block[offset++] = 0xff;
1367-
} else {
1368-
block[offset++] = (ubyte)Ss_pool[i];
1369-
}
1358+
// write the ship pool
1359+
pool_size = 0;
1360+
for (i = 0; i < ship_info_size(); i++) {
1361+
if (Ss_pool[i] > 0) {
1362+
++pool_size;
13701363
}
13711364
}
13721365

1373-
block[offset++] = 0xff; // signals start of weapons pool
1366+
ADD_USHORT(pool_size);
1367+
1368+
Assertion((((sizeof(short)+sizeof(short)) * pool_size) + packet_size) < max_size, "Size of ship pool exceeds max data size!");
1369+
1370+
for (i = 0; i < ship_info_size(); i++) {
1371+
if (Ss_pool[i] > 0) {
1372+
ADD_SHORT(static_cast<short>(i));
1373+
ADD_SHORT(static_cast<short>(Ss_pool[i]));
1374+
}
1375+
}
13741376

13751377
// write the weapon pool
1376-
for ( i = 0; i < weapon_info_size(); i++ ) {
1377-
if ( Wl_pool[i] > 0 ) {
1378-
block[offset++] = (ubyte)i;
1379-
ishort = INTEL_SHORT( (short)Wl_pool[i] );
1380-
memcpy(block+offset, &ishort, sizeof(short));
1381-
offset += sizeof(short);
1378+
pool_size = 0;
1379+
for (i = 0; i < weapon_info_size(); i++) {
1380+
if (Wl_pool[i] > 0) {
1381+
++pool_size;
13821382
}
13831383
}
13841384

1385-
// write the unit data
1385+
ADD_USHORT(pool_size);
13861386

1387-
block[offset++] = 0xff; // signals start of unit data
1387+
Assertion((((sizeof(short)+sizeof(short)) * pool_size) + packet_size) < max_size, "Size of weapon pool exceeds max data size!");
13881388

1389-
for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1390-
Assert( Wss_slots[i].ship_class < UCHAR_MAX );
1391-
if(Wss_slots[i].ship_class == -1){
1392-
block[offset++] = 0xff;
1393-
} else {
1394-
block[offset++] = (ubyte)(Wss_slots[i].ship_class);
1389+
for (i = 0; i < weapon_info_size(); i++) {
1390+
if (Wl_pool[i] > 0) {
1391+
ADD_SHORT(static_cast<short>(i));
1392+
ADD_SHORT(static_cast<short>(Wl_pool[i]));
13951393
}
1396-
for ( j = 0; j < MAX_SHIP_WEAPONS; j++ ) {
1397-
// take care of sign issues
1398-
Assert( Wss_slots[i].wep[j] < UCHAR_MAX );
1399-
if(Wss_slots[i].wep[j] == -1){
1400-
block[offset++] = 0xff;
1401-
} else {
1402-
block[offset++] = (ubyte)(Wss_slots[i].wep[j]);
1403-
}
1394+
}
14041395

1405-
Assert( Wss_slots[i].wep_count[j] < SHRT_MAX );
1406-
ishort = INTEL_SHORT( (short)Wss_slots[i].wep_count[j] );
1396+
// write the unit data
1397+
val = MAX_WSS_SLOTS;
1398+
ADD_DATA(val);
1399+
val = MAX_SHIP_WEAPONS;
1400+
ADD_DATA(val);
14071401

1408-
memcpy(&(block[offset]), &(ishort), sizeof(short) );
1409-
offset += sizeof(short);
1410-
}
1402+
Assertion((((sizeof(short) + ((sizeof(short)+sizeof(short)) * MAX_SHIP_WEAPONS)) * MAX_WSS_SLOTS) + packet_size) < max_size, "Size of wss data exceeds max data size!");
14111403

1412-
// mwa -- old way below -- too much space
1413-
//memcpy(block+offset, &Wss_slots[i], sizeof(wss_unit));
1414-
//offset += sizeof(wss_unit);
1404+
for (i = 0; i < MAX_WSS_SLOTS; i++) {
1405+
ADD_SHORT(static_cast<short>(Wss_slots[i].ship_class));
1406+
1407+
for (j = 0; j < MAX_SHIP_WEAPONS; j++) {
1408+
ADD_SHORT(static_cast<short>(Wss_slots[i].wep[j]));
1409+
Assert(Wss_slots[i].wep_count[j] < SHRT_MAX);
1410+
ADD_SHORT(static_cast<short>(Wss_slots[i].wep_count[j]));
1411+
}
14151412
}
14161413

14171414
// any sound index
1418-
if(!sound.isValid()){
1419-
block[offset++] = 0xff;
1420-
} else {
1421-
block[offset++] = (ubyte)sound.value();
1422-
}
1415+
ADD_SHORT(static_cast<short>(sound.value()));
14231416

14241417
// add a netplayer address to identify who should play the sound
14251418
player_id = -1;
@@ -1428,20 +1421,19 @@ int store_wss_data(ubyte *block, int max_size, interface_snd_id sound,int player
14281421
player_id = Net_players[player_index].player_id;
14291422
}
14301423

1431-
player_id = INTEL_SHORT( player_id );
1432-
memcpy(block+offset,&player_id,sizeof(player_id));
1433-
offset += sizeof(player_id);
1424+
ADD_SHORT(player_id);
14341425

1435-
Assert( offset < max_size );
1436-
return offset;
1426+
Assert( packet_size < static_cast<int>(max_size) );
1427+
return packet_size;
14371428
}
14381429

1439-
int restore_wss_data(ubyte *block)
1430+
int restore_wss_data(ubyte *data)
14401431
{
1441-
int i, j, sanity, offset=0;
1442-
ubyte b1, b2,sound;
1443-
short ishort;
1444-
short player_id;
1432+
int i, j, offset = 0;
1433+
ubyte num_slots, num_weapons;
1434+
short b1, b2;
1435+
short player_id, sound;
1436+
ushort pool_size;
14451437

14461438
// this function assumes that the data is going to be used over the network
14471439
// so make a non-network version of this function if needed
@@ -1452,86 +1444,73 @@ int restore_wss_data(ubyte *block)
14521444
return 0;
14531445

14541446
// restore ship pool
1455-
sanity=0;
14561447
memset(Ss_pool, 0, MAX_SHIP_CLASSES*sizeof(int));
1457-
for (;;) {
1458-
if ( sanity++ > MAX_SHIP_CLASSES ) {
1459-
Int3();
1460-
break;
1461-
}
1448+
GET_USHORT(pool_size);
14621449

1463-
b1 = block[offset++];
1464-
if ( b1 == 0xff ) {
1465-
break;
1466-
}
1467-
1468-
// take care of sign issues
1469-
b2 = block[offset++];
1470-
if(b2 == 0xff){
1471-
Ss_pool[b1] = -1;
1472-
} else {
1450+
for (i = 0; i < pool_size; i++) {
1451+
GET_SHORT(b1);
1452+
GET_SHORT(b2);
1453+
1454+
if (b1 < MAX_SHIP_CLASSES) {
14731455
Ss_pool[b1] = b2;
14741456
}
14751457
}
14761458

14771459
// restore weapons pool
1478-
sanity=0;
14791460
memset(Wl_pool, 0, MAX_WEAPON_TYPES*sizeof(int));
1480-
for (;;) {
1481-
if ( sanity++ > MAX_WEAPON_TYPES ) {
1482-
Int3();
1483-
break;
1461+
GET_USHORT(pool_size);
1462+
1463+
for (i = 0; i < pool_size; i++) {
1464+
GET_SHORT(b1);
1465+
GET_SHORT(b2);
1466+
1467+
if (b1 < MAX_SHIP_CLASSES) {
1468+
Wl_pool[b1] = b2;
14841469
}
1470+
}
14851471

1486-
b1 = block[offset++];
1487-
if ( b1 == 0xff ) {
1488-
break;
1472+
1473+
// restore unit data
1474+
for (i = 0; i < MAX_WSS_SLOTS; i++) {
1475+
Wss_slots[i].ship_class = -1;
1476+
1477+
for (j = 0; j < MAX_SHIP_WEAPONS; j++) {
1478+
Wss_slots[i].wep[j] = -1;
1479+
Wss_slots[i].wep_count[j] = 0;
14891480
}
1490-
1491-
memcpy(&ishort, block+offset, sizeof(short));
1492-
offset += sizeof(short);
1493-
Wl_pool[b1] = INTEL_SHORT( ishort );
14941481
}
14951482

1496-
for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1497-
if(block[offset] == 0xff){
1498-
Wss_slots[i].ship_class = -1;
1499-
} else {
1500-
Wss_slots[i].ship_class = block[offset];
1483+
GET_DATA(num_slots);
1484+
GET_DATA(num_weapons);
1485+
1486+
for (i = 0; i < num_slots; i++) {
1487+
GET_SHORT(b1);
1488+
1489+
if (i < MAX_WSS_SLOTS) {
1490+
Wss_slots[i].ship_class = b1;
15011491
}
1502-
offset++;
1503-
for ( j = 0; j < MAX_SHIP_WEAPONS; j++ ) {
1504-
// take care of sign issues
1505-
if(block[offset] == 0xff){
1506-
Wss_slots[i].wep[j] = -1;
1507-
offset++;
1508-
} else {
1509-
Wss_slots[i].wep[j] = (int)(block[offset++]);
1492+
1493+
for (j = 0; j < num_weapons; j++) {
1494+
GET_SHORT(b1);
1495+
GET_SHORT(b2);
1496+
1497+
if ( (i < MAX_WSS_SLOTS) && (j < MAX_SHIP_WEAPONS) ) {
1498+
Wss_slots[i].wep[j] = b1;
1499+
Wss_slots[i].wep_count[j] = b2;
15101500
}
1511-
1512-
memcpy( &ishort, &(block[offset]), sizeof(short) );
1513-
ishort = INTEL_SHORT( ishort );
1514-
Wss_slots[i].wep_count[j] = (int)ishort;
1515-
offset += sizeof(short);
15161501
}
1517-
1518-
// mwa -- old way below
1519-
//memcpy(&Wss_slots[i], block+offset, sizeof(wss_unit));
1520-
//offset += sizeof(wss_unit);
15211502
}
15221503

15231504
// read in the sound data
1524-
sound = block[offset++]; // the sound index
1505+
GET_SHORT(sound);
15251506

15261507
// read in the player address
1527-
memcpy(&player_id,block+offset,sizeof(player_id));
1528-
player_id = INTEL_SHORT( player_id );
1529-
offset += sizeof(short);
1508+
GET_SHORT(player_id);
15301509

15311510
// determine if I'm the guy who should be playing the sound
15321511
if((Net_player != NULL) && (Net_player->player_id == player_id)){
15331512
// play the sound
1534-
if(sound != 0xff){
1513+
if (sound >= 0) {
15351514
gamesnd_play_iface(static_cast<InterfaceSounds>(sound));
15361515
}
15371516
}

0 commit comments

Comments
 (0)