Big net::msg conversion
This commit is contained in:
+185
-207
@@ -146,22 +146,22 @@ Make sure the event gets sent to all clients
|
||||
void SV_StartParticle(vec3_t org, vec3_t dir, int color, int count) {
|
||||
int i, v;
|
||||
|
||||
if (sv.datagram.cursize > MAX_DATAGRAM - 18)
|
||||
if (sv.datagram.size() > MAX_DATAGRAM - 18)
|
||||
return;
|
||||
MSG_WriteByte(&sv.datagram, svc_particle);
|
||||
MSG_WriteCoord(&sv.datagram, org[0], sv.protocolflags);
|
||||
MSG_WriteCoord(&sv.datagram, org[1], sv.protocolflags);
|
||||
MSG_WriteCoord(&sv.datagram, org[2], sv.protocolflags);
|
||||
sv.datagram.write_byte(svc_particle);
|
||||
sv.datagram.write_coord(org[0], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
sv.datagram.write_coord(org[1], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
sv.datagram.write_coord(org[2], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
for (i = 0; i < 3; i++) {
|
||||
v = dir[i] * 16;
|
||||
if (v > 127)
|
||||
v = 127;
|
||||
else if (v < -128)
|
||||
v = -128;
|
||||
MSG_WriteChar(&sv.datagram, v);
|
||||
sv.datagram.write_char(v);
|
||||
}
|
||||
MSG_WriteByte(&sv.datagram, count);
|
||||
MSG_WriteByte(&sv.datagram, color);
|
||||
sv.datagram.write_byte(count);
|
||||
sv.datagram.write_byte(color);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -192,7 +192,7 @@ void SV_StartSound(edict_t *entity, int channel, const char *sample, int volume,
|
||||
if (channel < 0 || channel > 7)
|
||||
Host_Error("SV_StartSound: channel = %i", channel);
|
||||
|
||||
if (sv.datagram.cursize > MAX_DATAGRAM - 21)
|
||||
if (sv.datagram.size() > MAX_DATAGRAM - 21)
|
||||
return;
|
||||
|
||||
// find precache number for sound
|
||||
@@ -227,32 +227,32 @@ void SV_StartSound(edict_t *entity, int channel, const char *sample, int volume,
|
||||
}
|
||||
//johnfitz
|
||||
|
||||
if (sv.datagram.cursize > MAX_DATAGRAM - 21)
|
||||
if (sv.datagram.size() > MAX_DATAGRAM - 21)
|
||||
return;
|
||||
|
||||
// directed messages go only to the entity the are targeted on
|
||||
MSG_WriteByte(&sv.datagram, svc_sound);
|
||||
MSG_WriteByte(&sv.datagram, field_mask);
|
||||
sv.datagram.write_byte(svc_sound);
|
||||
sv.datagram.write_byte(field_mask);
|
||||
if (field_mask & SND_VOLUME)
|
||||
MSG_WriteByte(&sv.datagram, volume);
|
||||
sv.datagram.write_byte(volume);
|
||||
if (field_mask & SND_ATTENUATION)
|
||||
MSG_WriteByte(&sv.datagram, attenuation * 64);
|
||||
sv.datagram.write_byte(attenuation * 64);
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (field_mask & SND_LARGEENTITY) {
|
||||
MSG_WriteShort(&sv.datagram, ent);
|
||||
MSG_WriteByte(&sv.datagram, channel);
|
||||
sv.datagram.write_short(ent);
|
||||
sv.datagram.write_byte(channel);
|
||||
} else
|
||||
MSG_WriteShort(&sv.datagram, (ent << 3) | channel);
|
||||
sv.datagram.write_short((ent << 3) | channel);
|
||||
if (field_mask & SND_LARGESOUND)
|
||||
MSG_WriteShort(&sv.datagram, sound_num);
|
||||
sv.datagram.write_short(sound_num);
|
||||
else
|
||||
MSG_WriteByte(&sv.datagram, sound_num);
|
||||
sv.datagram.write_byte(sound_num);
|
||||
//johnfitz
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
MSG_WriteCoord(&sv.datagram, entity->v.origin[i] + 0.5 * (entity->v.mins[i] + entity->v.maxs[i]),
|
||||
sv.protocolflags);
|
||||
sv.datagram.write_coord(entity->v.origin[i] + 0.5 * (entity->v.mins[i] + entity->v.maxs[i]),
|
||||
static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -279,15 +279,16 @@ void SV_LocalSound(client_t *client, const char *sample) {
|
||||
field_mask = SND_LARGESOUND;
|
||||
}
|
||||
|
||||
if (client->message.cursize > client->message.maxsize - 4)
|
||||
return;
|
||||
// TODO: replace maxsize call?
|
||||
// if (client->message.size() > client->message.maxsize - 4)
|
||||
// return;
|
||||
|
||||
MSG_WriteByte(&client->message, svc_localsound);
|
||||
MSG_WriteByte(&client->message, field_mask);
|
||||
client->message.write_byte(svc_localsound);
|
||||
client->message.write_byte(field_mask);
|
||||
if (field_mask & SND_LARGESOUND)
|
||||
MSG_WriteShort(&client->message, sound_num);
|
||||
client->message.write_short(sound_num);
|
||||
else
|
||||
MSG_WriteByte(&client->message, sound_num);
|
||||
client->message.write_byte(sound_num);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -315,51 +316,51 @@ void SV_SendServerinfo(client_t *client) {
|
||||
char message[2048];
|
||||
int i; //johnfitz
|
||||
|
||||
MSG_WriteByte(&client->message, svc_print);
|
||||
client->message.write_byte(svc_print);
|
||||
sprintf(message, "%c\nFITZQUAKE %1.2f SERVER (%i CRC)\n", 2, FITZQUAKE_VERSION, pr_crc);
|
||||
//johnfitz -- include fitzquake version
|
||||
MSG_WriteString(&client->message, message);
|
||||
client->message.write_string(message);
|
||||
|
||||
MSG_WriteByte(&client->message, svc_serverinfo);
|
||||
MSG_WriteLong(&client->message, sv.protocol); //johnfitz -- sv.protocol instead of PROTOCOL_VERSION
|
||||
client->message.write_byte(svc_serverinfo);
|
||||
client->message.write_long(sv.protocol); //johnfitz -- sv.protocol instead of PROTOCOL_VERSION
|
||||
|
||||
if (sv.protocol == PROTOCOL_RMQ) {
|
||||
// mh - now send protocol flags so that the client knows the protocol features to expect
|
||||
MSG_WriteLong(&client->message, sv.protocolflags);
|
||||
client->message.write_long(sv.protocolflags);
|
||||
}
|
||||
|
||||
MSG_WriteByte(&client->message, svs.maxclients);
|
||||
client->message.write_byte(svs.maxclients);
|
||||
|
||||
if (!coop.value && deathmatch.value)
|
||||
MSG_WriteByte(&client->message, GAME_DEATHMATCH);
|
||||
client->message.write_byte(GAME_DEATHMATCH);
|
||||
else
|
||||
MSG_WriteByte(&client->message, GAME_COOP);
|
||||
client->message.write_byte(GAME_COOP);
|
||||
|
||||
MSG_WriteString(&client->message, PR_GetString(sv.edicts->v.message));
|
||||
client->message.write_string(PR_GetString(sv.edicts->v.message));
|
||||
|
||||
//johnfitz -- only send the first 256 model and sound precaches if protocol is 15
|
||||
for (i = 1, s = sv.model_precache + 1; *s; s++, i++)
|
||||
if (sv.protocol != PROTOCOL_NETQUAKE || i < 256)
|
||||
MSG_WriteString(&client->message, *s);
|
||||
MSG_WriteByte(&client->message, 0);
|
||||
client->message.write_string(*s);
|
||||
client->message.write_byte(0);
|
||||
|
||||
for (i = 1, s = sv.sound_precache + 1; *s; s++, i++)
|
||||
if (sv.protocol != PROTOCOL_NETQUAKE || i < 256)
|
||||
MSG_WriteString(&client->message, *s);
|
||||
MSG_WriteByte(&client->message, 0);
|
||||
client->message.write_string(*s);
|
||||
client->message.write_byte(0);
|
||||
//johnfitz
|
||||
|
||||
// send music
|
||||
MSG_WriteByte(&client->message, svc_cdtrack);
|
||||
MSG_WriteByte(&client->message, sv.edicts->v.sounds);
|
||||
MSG_WriteByte(&client->message, sv.edicts->v.sounds);
|
||||
client->message.write_byte(svc_cdtrack);
|
||||
client->message.write_byte(sv.edicts->v.sounds);
|
||||
client->message.write_byte(sv.edicts->v.sounds);
|
||||
|
||||
// set view
|
||||
MSG_WriteByte(&client->message, svc_setview);
|
||||
MSG_WriteShort(&client->message, NUM_FOR_EDICT(client->edict));
|
||||
client->message.write_byte(svc_setview);
|
||||
client->message.write_short(NUM_FOR_EDICT(client->edict));
|
||||
|
||||
MSG_WriteByte(&client->message, svc_signonnum);
|
||||
MSG_WriteByte(&client->message, 1);
|
||||
client->message.write_byte(svc_signonnum);
|
||||
client->message.write_byte(1);
|
||||
|
||||
client->sendsignon = PRESPAWN_FLUSH;
|
||||
client->spawned = false; // need prespawn, spawn, etc
|
||||
@@ -401,9 +402,7 @@ void SV_ConnectClient(int clientnum) {
|
||||
client->active = true;
|
||||
client->spawned = false;
|
||||
client->edict = ent;
|
||||
client->message.data = client->msgbuf;
|
||||
client->message.maxsize = sizeof(client->msgbuf);
|
||||
client->message.allowoverflow = true; // we can catch it
|
||||
client->message = net::msg{};
|
||||
|
||||
if (sv.loadgame)
|
||||
memcpy(client->spawn_parms, spawn_parms, sizeof(spawn_parms));
|
||||
@@ -468,7 +467,7 @@ SV_ClearDatagram
|
||||
==================
|
||||
*/
|
||||
void SV_ClearDatagram(void) {
|
||||
SZ_Clear(&sv.datagram);
|
||||
sv.datagram.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -571,7 +570,7 @@ SV_WriteEntitiesToClient
|
||||
|
||||
=============
|
||||
*/
|
||||
void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg) {
|
||||
void SV_WriteEntitiesToClient(edict_t *clent, net::msg &msg) {
|
||||
int e, i;
|
||||
int bits;
|
||||
byte *pvs;
|
||||
@@ -616,15 +615,15 @@ void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg) {
|
||||
// assumed here. And, for protocol 85 the max size is actually 24 bytes.
|
||||
// For float coords and angles the limit is 40.
|
||||
// FIXME: Use tighter limit according to protocol flags and send bits.
|
||||
if (msg->cursize + 40 > msg->maxsize) {
|
||||
//johnfitz -- less spammy overflow message
|
||||
if (!dev_overflows.packetsize || dev_overflows.packetsize + CONSOLE_RESPAM_TIME < realtime) {
|
||||
console::info("Packet overflow!\n");
|
||||
dev_overflows.packetsize = realtime;
|
||||
}
|
||||
goto stats;
|
||||
//johnfitz
|
||||
}
|
||||
// if (msg->cursize + 40 > msg->maxsize) {
|
||||
// //johnfitz -- less spammy overflow message
|
||||
// if (!dev_overflows.packetsize || dev_overflows.packetsize + CONSOLE_RESPAM_TIME < realtime) {
|
||||
// console::info("Packet overflow!\n");
|
||||
// dev_overflows.packetsize = realtime;
|
||||
// }
|
||||
// goto stats;
|
||||
// //johnfitz
|
||||
// }
|
||||
|
||||
// send an update
|
||||
bits = 0;
|
||||
@@ -702,66 +701,66 @@ void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg) {
|
||||
//
|
||||
// write the message
|
||||
//
|
||||
MSG_WriteByte(msg, bits | U_SIGNAL);
|
||||
msg.write_byte(bits | U_SIGNAL);
|
||||
|
||||
if (bits & U_MOREBITS)
|
||||
MSG_WriteByte(msg, bits >> 8);
|
||||
msg.write_byte(bits >> 8);
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits & U_EXTEND1)
|
||||
MSG_WriteByte(msg, bits >> 16);
|
||||
msg.write_byte(bits >> 16);
|
||||
if (bits & U_EXTEND2)
|
||||
MSG_WriteByte(msg, bits >> 24);
|
||||
msg.write_byte(bits >> 24);
|
||||
//johnfitz
|
||||
|
||||
if (bits & U_LONGENTITY)
|
||||
MSG_WriteShort(msg, e);
|
||||
msg.write_short(e);
|
||||
else
|
||||
MSG_WriteByte(msg, e);
|
||||
msg.write_byte(e);
|
||||
|
||||
if (bits & U_MODEL)
|
||||
MSG_WriteByte(msg, ent->v.modelindex);
|
||||
msg.write_byte(ent->v.modelindex);
|
||||
if (bits & U_FRAME)
|
||||
MSG_WriteByte(msg, ent->v.frame);
|
||||
msg.write_byte(ent->v.frame);
|
||||
if (bits & U_COLORMAP)
|
||||
MSG_WriteByte(msg, ent->v.colormap);
|
||||
msg.write_byte(ent->v.colormap);
|
||||
if (bits & U_SKIN)
|
||||
MSG_WriteByte(msg, ent->v.skin);
|
||||
msg.write_byte(ent->v.skin);
|
||||
if (bits & U_EFFECTS)
|
||||
MSG_WriteByte(msg, (int) ent->v.effects & pr_effects_mask);
|
||||
msg.write_byte((int) ent->v.effects & pr_effects_mask);
|
||||
if (bits & U_ORIGIN1)
|
||||
MSG_WriteCoord(msg, ent->v.origin[0], sv.protocolflags);
|
||||
msg.write_coord(ent->v.origin[0], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
if (bits & U_ANGLE1)
|
||||
MSG_WriteAngle(msg, ent->v.angles[0], sv.protocolflags);
|
||||
msg.write_angle(ent->v.angles[0], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
if (bits & U_ORIGIN2)
|
||||
MSG_WriteCoord(msg, ent->v.origin[1], sv.protocolflags);
|
||||
msg.write_coord(ent->v.origin[1], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
if (bits & U_ANGLE2)
|
||||
MSG_WriteAngle(msg, ent->v.angles[1], sv.protocolflags);
|
||||
msg.write_angle(ent->v.angles[1], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
if (bits & U_ORIGIN3)
|
||||
MSG_WriteCoord(msg, ent->v.origin[2], sv.protocolflags);
|
||||
msg.write_coord(ent->v.origin[2], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
if (bits & U_ANGLE3)
|
||||
MSG_WriteAngle(msg, ent->v.angles[2], sv.protocolflags);
|
||||
msg.write_angle(ent->v.angles[2], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits & U_ALPHA)
|
||||
MSG_WriteByte(msg, ent->alpha);
|
||||
msg.write_byte(ent->alpha);
|
||||
if (bits & U_SCALE)
|
||||
MSG_WriteByte(msg, ent->scale);
|
||||
msg.write_byte(ent->scale);
|
||||
if (bits & U_FRAME2)
|
||||
MSG_WriteByte(msg, (int) ent->v.frame >> 8);
|
||||
msg.write_byte((int) ent->v.frame >> 8);
|
||||
if (bits & U_MODEL2)
|
||||
MSG_WriteByte(msg, (int) ent->v.modelindex >> 8);
|
||||
msg.write_byte((int) ent->v.modelindex >> 8);
|
||||
if (bits & U_LERPFINISH)
|
||||
MSG_WriteByte(msg, (byte) (Q_rint((ent->v.nextthink-sv.time)*255)));
|
||||
msg.write_byte((byte) (Q_rint((ent->v.nextthink-sv.time)*255)));
|
||||
//johnfitz
|
||||
}
|
||||
|
||||
//johnfitz -- devstats
|
||||
stats:
|
||||
if (msg->cursize > 1024 && dev_peakstats.packetsize <= 1024)
|
||||
console::dev_warn("%i byte packet exceeds standard limit of 1024 (max = %d).\n", msg->cursize, msg->maxsize);
|
||||
dev_stats.packetsize = msg->cursize;
|
||||
dev_peakstats.packetsize = std::max(msg->cursize, dev_peakstats.packetsize);
|
||||
if (msg.size() > 1024 && dev_peakstats.packetsize <= 1024)
|
||||
console::dev_warn("%i byte packet exceeds standard limit of 1024 (max = %d).\n", msg.size(), 1024); // TODO
|
||||
dev_stats.packetsize = msg.size();
|
||||
dev_peakstats.packetsize = std::max(static_cast<int>(msg.size()), dev_peakstats.packetsize);
|
||||
//johnfitz
|
||||
}
|
||||
|
||||
@@ -787,7 +786,7 @@ SV_WriteClientdataToMessage
|
||||
|
||||
==================
|
||||
*/
|
||||
void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) {
|
||||
void SV_WriteClientdataToMessage(edict_t *ent, net::msg &msg) {
|
||||
int bits;
|
||||
int i;
|
||||
edict_t *other;
|
||||
@@ -799,11 +798,11 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) {
|
||||
//
|
||||
if (ent->v.dmg_take || ent->v.dmg_save) {
|
||||
other = PROG_TO_EDICT(ent->v.dmg_inflictor);
|
||||
MSG_WriteByte(msg, svc_damage);
|
||||
MSG_WriteByte(msg, ent->v.dmg_save);
|
||||
MSG_WriteByte(msg, ent->v.dmg_take);
|
||||
msg.write_byte(svc_damage);
|
||||
msg.write_byte(ent->v.dmg_save);
|
||||
msg.write_byte(ent->v.dmg_take);
|
||||
for (i = 0; i < 3; i++)
|
||||
MSG_WriteCoord(msg, other->v.origin[i] + 0.5 * (other->v.mins[i] + other->v.maxs[i]), sv.protocolflags);
|
||||
msg.write_coord(other->v.origin[i] + 0.5 * (other->v.mins[i] + other->v.maxs[i]), static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
|
||||
ent->v.dmg_take = 0;
|
||||
ent->v.dmg_save = 0;
|
||||
@@ -816,9 +815,9 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) {
|
||||
|
||||
// a fixangle might get lost in a dropped packet. Oh well.
|
||||
if (ent->v.fixangle) {
|
||||
MSG_WriteByte(msg, svc_setangle);
|
||||
msg.write_byte(svc_setangle);
|
||||
for (i = 0; i < 3; i++)
|
||||
MSG_WriteAngle(msg, ent->v.angles[i], sv.protocolflags);
|
||||
msg.write_angle(ent->v.angles[i], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
ent->v.fixangle = 0;
|
||||
}
|
||||
|
||||
@@ -882,50 +881,50 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) {
|
||||
|
||||
// send the data
|
||||
|
||||
MSG_WriteByte(msg, svc_clientdata);
|
||||
MSG_WriteShort(msg, bits);
|
||||
msg.write_byte(svc_clientdata);
|
||||
msg.write_short(bits);
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits & SU_EXTEND1) MSG_WriteByte(msg, bits >> 16);
|
||||
if (bits & SU_EXTEND2) MSG_WriteByte(msg, bits >> 24);
|
||||
if (bits & SU_EXTEND1) msg.write_byte(bits >> 16);
|
||||
if (bits & SU_EXTEND2) msg.write_byte(bits >> 24);
|
||||
//johnfitz
|
||||
|
||||
if (bits & SU_VIEWHEIGHT)
|
||||
MSG_WriteChar(msg, ent->v.view_ofs[2]);
|
||||
msg.write_char(ent->v.view_ofs[2]);
|
||||
|
||||
if (bits & SU_IDEALPITCH)
|
||||
MSG_WriteChar(msg, ent->v.idealpitch);
|
||||
msg.write_char(ent->v.idealpitch);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (bits & (SU_PUNCH1 << i))
|
||||
MSG_WriteChar(msg, ent->v.punchangle[i]);
|
||||
msg.write_char(ent->v.punchangle[i]);
|
||||
if (bits & (SU_VELOCITY1 << i))
|
||||
MSG_WriteChar(msg, ent->v.velocity[i] / 16);
|
||||
msg.write_char(ent->v.velocity[i] / 16);
|
||||
}
|
||||
|
||||
// [always sent] if (bits & SU_ITEMS)
|
||||
MSG_WriteLong(msg, items);
|
||||
msg.write_long(items);
|
||||
|
||||
if (bits & SU_WEAPONFRAME)
|
||||
MSG_WriteByte(msg, ent->v.weaponframe);
|
||||
msg.write_byte(ent->v.weaponframe);
|
||||
if (bits & SU_ARMOR)
|
||||
MSG_WriteByte(msg, ent->v.armorvalue);
|
||||
msg.write_byte(ent->v.armorvalue);
|
||||
if (bits & SU_WEAPON)
|
||||
MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ent->v.weaponmodel)));
|
||||
msg.write_byte(SV_ModelIndex(PR_GetString(ent->v.weaponmodel)));
|
||||
|
||||
MSG_WriteShort(msg, ent->v.health);
|
||||
MSG_WriteByte(msg, ent->v.currentammo);
|
||||
MSG_WriteByte(msg, ent->v.ammo_shells);
|
||||
MSG_WriteByte(msg, ent->v.ammo_nails);
|
||||
MSG_WriteByte(msg, ent->v.ammo_rockets);
|
||||
MSG_WriteByte(msg, ent->v.ammo_cells);
|
||||
msg.write_short(ent->v.health);
|
||||
msg.write_byte(ent->v.currentammo);
|
||||
msg.write_byte(ent->v.ammo_shells);
|
||||
msg.write_byte(ent->v.ammo_nails);
|
||||
msg.write_byte(ent->v.ammo_rockets);
|
||||
msg.write_byte(ent->v.ammo_cells);
|
||||
|
||||
if (standard_quake) {
|
||||
MSG_WriteByte(msg, ent->v.weapon);
|
||||
msg.write_byte(ent->v.weapon);
|
||||
} else {
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (((int) ent->v.weapon) & (1 << i)) {
|
||||
MSG_WriteByte(msg, i);
|
||||
msg.write_byte(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -933,23 +932,23 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) {
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits & SU_WEAPON2)
|
||||
MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ent->v.weaponmodel)) >> 8);
|
||||
msg.write_byte(SV_ModelIndex(PR_GetString(ent->v.weaponmodel)) >> 8);
|
||||
if (bits & SU_ARMOR2)
|
||||
MSG_WriteByte(msg, (int) ent->v.armorvalue >> 8);
|
||||
msg.write_byte((int) ent->v.armorvalue >> 8);
|
||||
if (bits & SU_AMMO2)
|
||||
MSG_WriteByte(msg, (int) ent->v.currentammo >> 8);
|
||||
msg.write_byte((int) ent->v.currentammo >> 8);
|
||||
if (bits & SU_SHELLS2)
|
||||
MSG_WriteByte(msg, (int) ent->v.ammo_shells >> 8);
|
||||
msg.write_byte((int) ent->v.ammo_shells >> 8);
|
||||
if (bits & SU_NAILS2)
|
||||
MSG_WriteByte(msg, (int) ent->v.ammo_nails >> 8);
|
||||
msg.write_byte((int) ent->v.ammo_nails >> 8);
|
||||
if (bits & SU_ROCKETS2)
|
||||
MSG_WriteByte(msg, (int) ent->v.ammo_rockets >> 8);
|
||||
msg.write_byte((int) ent->v.ammo_rockets >> 8);
|
||||
if (bits & SU_CELLS2)
|
||||
MSG_WriteByte(msg, (int) ent->v.ammo_cells >> 8);
|
||||
msg.write_byte((int) ent->v.ammo_cells >> 8);
|
||||
if (bits & SU_WEAPONFRAME2)
|
||||
MSG_WriteByte(msg, (int) ent->v.weaponframe >> 8);
|
||||
msg.write_byte((int) ent->v.weaponframe >> 8);
|
||||
if (bits & SU_WEAPONALPHA)
|
||||
MSG_WriteByte(msg, ent->alpha); //for now, weaponalpha = client entity alpha
|
||||
msg.write_byte(ent->alpha); //for now, weaponalpha = client entity alpha
|
||||
//johnfitz
|
||||
}
|
||||
|
||||
@@ -960,31 +959,27 @@ SV_SendClientDatagram
|
||||
*/
|
||||
bool SV_SendClientDatagram(client_t *client) {
|
||||
byte buf[MAX_DATAGRAM];
|
||||
sizebuf_t msg;
|
||||
|
||||
msg.data = buf;
|
||||
msg.maxsize = sizeof(buf);
|
||||
msg.cursize = 0;
|
||||
net::msg msg{};
|
||||
|
||||
//johnfitz -- if client is nonlocal, use smaller max size so packets aren't fragmented
|
||||
if (std::strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0)
|
||||
msg.maxsize = DATAGRAM_MTU;
|
||||
// if (std::strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0)
|
||||
// msg.maxsize = DATAGRAM_MTU;
|
||||
//johnfitz
|
||||
|
||||
MSG_WriteByte(&msg, svc_time);
|
||||
MSG_WriteFloat(&msg, sv.time);
|
||||
msg.write_byte(svc_time);
|
||||
msg.write_float(sv.time);
|
||||
|
||||
// add the client specific data to the datagram
|
||||
SV_WriteClientdataToMessage(client->edict, &msg);
|
||||
SV_WriteClientdataToMessage(client->edict, msg);
|
||||
|
||||
SV_WriteEntitiesToClient(client->edict, &msg);
|
||||
SV_WriteEntitiesToClient(client->edict, msg);
|
||||
|
||||
// copy the server datagram if there is space
|
||||
if (msg.cursize + sv.datagram.cursize < msg.maxsize)
|
||||
SZ_Write(&msg, sv.datagram.data, sv.datagram.cursize);
|
||||
// if (msg.cursize + sv.datagram.cursize < msg.maxsize)
|
||||
msg.write(sv.datagram.data(), sv.datagram.size());
|
||||
|
||||
// send the datagram
|
||||
if (NET_SendUnreliableMessage(client->netconnection, &msg) == -1) {
|
||||
if (NET_SendUnreliableMessage(client->netconnection, msg) == -1) {
|
||||
SV_DropClient(true); // if the message couldn't send, kick off
|
||||
return false;
|
||||
}
|
||||
@@ -1007,9 +1002,9 @@ void SV_UpdateToReliableMessages(void) {
|
||||
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) {
|
||||
if (!client->active)
|
||||
continue;
|
||||
MSG_WriteByte(&client->message, svc_updatefrags);
|
||||
MSG_WriteByte(&client->message, i);
|
||||
MSG_WriteShort(&client->message, host_client->edict->v.frags);
|
||||
client->message.write_byte(svc_updatefrags);
|
||||
client->message.write_byte(i);
|
||||
client->message.write_short(host_client->edict->v.frags);
|
||||
}
|
||||
|
||||
host_client->old_frags = host_client->edict->v.frags;
|
||||
@@ -1019,10 +1014,10 @@ void SV_UpdateToReliableMessages(void) {
|
||||
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) {
|
||||
if (!client->active)
|
||||
continue;
|
||||
SZ_Write(&client->message, sv.reliable_datagram.data, sv.reliable_datagram.cursize);
|
||||
client->message.write(sv.reliable_datagram.data(), sv.reliable_datagram.size());
|
||||
}
|
||||
|
||||
SZ_Clear(&sv.reliable_datagram);
|
||||
sv.reliable_datagram.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -1035,16 +1030,11 @@ message buffer
|
||||
=======================
|
||||
*/
|
||||
void SV_SendNop(client_t *client) {
|
||||
sizebuf_t msg;
|
||||
byte buf[4];
|
||||
net::msg msg{};
|
||||
|
||||
msg.data = buf;
|
||||
msg.maxsize = sizeof(buf);
|
||||
msg.cursize = 0;
|
||||
msg.write_char(svc_nop);
|
||||
|
||||
MSG_WriteChar(&msg, svc_nop);
|
||||
|
||||
if (NET_SendUnreliableMessage(client->netconnection, &msg) == -1)
|
||||
if (NET_SendUnreliableMessage(client->netconnection, msg) == -1)
|
||||
SV_DropClient(true); // if the message couldn't send, kick off
|
||||
client->last_message = realtime;
|
||||
}
|
||||
@@ -1081,11 +1071,12 @@ void SV_SendClientMessages(void) {
|
||||
}
|
||||
if (host_client->sendsignon == PRESPAWN_SIGNONBUFS) {
|
||||
bool local = SV_IsLocalClient(host_client);
|
||||
while (host_client->signonidx < sv.num_signon_buffers) {
|
||||
sizebuf_t *signon = sv.signon_buffers[host_client->signonidx];
|
||||
if (host_client->message.cursize + signon->cursize > host_client->message.maxsize)
|
||||
break;
|
||||
SZ_Write(&host_client->message, signon->data, signon->cursize);
|
||||
while (host_client->signonidx < sv.signons.size()) {
|
||||
auto signon = sv.signons[host_client->signonidx];
|
||||
// if (host_client->message.cursize + signon->cursize > host_client->message.maxsize)
|
||||
// break;
|
||||
|
||||
host_client->message.write(signon.data(), signon.size());
|
||||
host_client->signonidx++;
|
||||
// only send multiple buffers at once when playing locally,
|
||||
// otherwise we send one signon at a time to avoid overflowing
|
||||
@@ -1093,28 +1084,28 @@ void SV_SendClientMessages(void) {
|
||||
if (!local)
|
||||
break;
|
||||
}
|
||||
if (host_client->signonidx == sv.num_signon_buffers)
|
||||
if (host_client->signonidx == sv.signons.size())
|
||||
host_client->sendsignon = PRESPAWN_SIGNONMSG;
|
||||
}
|
||||
if (host_client->sendsignon == PRESPAWN_SIGNONMSG) {
|
||||
if (host_client->message.cursize + 2 < host_client->message.maxsize) {
|
||||
MSG_WriteByte(&host_client->message, svc_signonnum);
|
||||
MSG_WriteByte(&host_client->message, 2);
|
||||
//if (host_client->message.siz + 2 < host_client->message.maxsize) {
|
||||
host_client->message.write_byte(svc_signonnum);
|
||||
host_client->message.write_byte(2);
|
||||
host_client->sendsignon = PRESPAWN_FLUSH;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
// check for an overflowed message. Should only happen
|
||||
// on a very fucked up connection that backs up a lot, then
|
||||
// changes level
|
||||
if (host_client->message.overflowed) {
|
||||
SV_DropClient(true);
|
||||
host_client->message.overflowed = false;
|
||||
continue;
|
||||
}
|
||||
// if (host_client->message.overflowed) {
|
||||
// SV_DropClient(true);
|
||||
// host_client->message.overflowed = false;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (host_client->message.cursize || host_client->dropasap) {
|
||||
if (!host_client->message.empty() || host_client->dropasap) {
|
||||
if (!NET_CanSendMessage(host_client->netconnection)) {
|
||||
// I_Printf ("can't write\n");
|
||||
continue;
|
||||
@@ -1124,9 +1115,9 @@ void SV_SendClientMessages(void) {
|
||||
SV_DropClient(false); // went to another level
|
||||
else {
|
||||
if (NET_SendMessage(host_client->netconnection
|
||||
, &host_client->message) == -1)
|
||||
, host_client->message) == -1)
|
||||
SV_DropClient(true); // if the message couldn't send, kick off
|
||||
SZ_Clear(&host_client->message);
|
||||
host_client->message.clear();
|
||||
host_client->last_message = realtime;
|
||||
if (host_client->sendsignon == PRESPAWN_FLUSH)
|
||||
host_client->sendsignon = PRESPAWN_DONE;
|
||||
@@ -1156,15 +1147,11 @@ SV_AddSignonBuffer
|
||||
================
|
||||
*/
|
||||
static void SV_AddSignonBuffer(void) {
|
||||
sizebuf_t *sb;
|
||||
if (sv.num_signon_buffers >= MAX_SIGNON_BUFFERS)
|
||||
if (sv.signons.size() >= MAX_SIGNON_BUFFERS)
|
||||
Host_Error("SV_AddSignonBuffer overflow\n");
|
||||
|
||||
sb = (sizebuf_t *) Hunk_AllocName(sizeof(sizebuf_t) + SIGNON_SIZE, "signon");
|
||||
sb->data = (byte *) (sb + 1);
|
||||
sb->maxsize = SIGNON_SIZE;
|
||||
sv.signon_buffers[sv.num_signon_buffers++] = sb;
|
||||
sv.signon = sb;
|
||||
sv.signons.emplace_back();
|
||||
sv.current_signon = sv.signons.size() - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1173,7 +1160,7 @@ SV_ReserveSignonSpace
|
||||
================
|
||||
*/
|
||||
void SV_ReserveSignonSpace(int numbytes) {
|
||||
if (sv.signon->cursize + numbytes > sv.signon->maxsize)
|
||||
if (sv.signons[sv.current_signon].size() + numbytes > SIGNON_SIZE)
|
||||
SV_AddSignonBuffer();
|
||||
}
|
||||
|
||||
@@ -1271,42 +1258,42 @@ void SV_CreateBaseline(void) {
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits)
|
||||
MSG_WriteByte(sv.signon, svc_spawnbaseline2);
|
||||
sv.signons[sv.current_signon].write_byte(svc_spawnbaseline2);
|
||||
else
|
||||
MSG_WriteByte(sv.signon, svc_spawnbaseline);
|
||||
sv.signons[sv.current_signon].write_byte(svc_spawnbaseline);
|
||||
//johnfitz
|
||||
|
||||
MSG_WriteShort(sv.signon, entnum);
|
||||
sv.signons[sv.current_signon].write_short(entnum);
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits)
|
||||
MSG_WriteByte(sv.signon, bits);
|
||||
sv.signons[sv.current_signon].write_byte(bits);
|
||||
|
||||
if (bits & B_LARGEMODEL)
|
||||
MSG_WriteShort(sv.signon, svent->baseline.modelindex);
|
||||
sv.signons[sv.current_signon].write_short(svent->baseline.modelindex);
|
||||
else
|
||||
MSG_WriteByte(sv.signon, svent->baseline.modelindex);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.modelindex);
|
||||
|
||||
if (bits & B_LARGEFRAME)
|
||||
MSG_WriteShort(sv.signon, svent->baseline.frame);
|
||||
sv.signons[sv.current_signon].write_short(svent->baseline.frame);
|
||||
else
|
||||
MSG_WriteByte(sv.signon, svent->baseline.frame);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.frame);
|
||||
//johnfitz
|
||||
|
||||
MSG_WriteByte(sv.signon, svent->baseline.colormap);
|
||||
MSG_WriteByte(sv.signon, svent->baseline.skin);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.colormap);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.skin);
|
||||
for (i = 0; i < 3; i++) {
|
||||
MSG_WriteCoord(sv.signon, svent->baseline.origin[i], sv.protocolflags);
|
||||
MSG_WriteAngle(sv.signon, svent->baseline.angles[i], sv.protocolflags);
|
||||
sv.signons[sv.current_signon].write_coord(svent->baseline.origin[i], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
sv.signons[sv.current_signon].write_angle(svent->baseline.angles[i], static_cast<net::rmq_flags>(sv.protocolflags));
|
||||
}
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if (bits & B_ALPHA)
|
||||
MSG_WriteByte(sv.signon, svent->baseline.alpha);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.alpha);
|
||||
//johnfitz
|
||||
|
||||
if (bits & B_SCALE)
|
||||
MSG_WriteByte(sv.signon, svent->baseline.scale);
|
||||
sv.signons[sv.current_signon].write_byte(svent->baseline.scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1320,15 +1307,11 @@ Tell all the clients that the server is changing levels
|
||||
*/
|
||||
void SV_SendReconnect(void) {
|
||||
byte data[128];
|
||||
sizebuf_t msg;
|
||||
net::msg msg{};
|
||||
|
||||
msg.data = data;
|
||||
msg.cursize = 0;
|
||||
msg.maxsize = sizeof(data);
|
||||
|
||||
MSG_WriteChar(&msg, svc_stufftext);
|
||||
MSG_WriteString(&msg, "reconnect\n");
|
||||
NET_SendToAll(&msg, 5.0);
|
||||
msg.write_char( svc_stufftext);
|
||||
msg.write_string("reconnect\n");
|
||||
NET_SendToAll(msg, 5.0);
|
||||
|
||||
if (!isDedicated)
|
||||
command::execute_string("reconnect\n", command::source::command);
|
||||
@@ -1427,13 +1410,8 @@ void SV_SpawnServer(const char *server) {
|
||||
sv.max_edicts = std::clamp((int) max_edicts.value,MIN_EDICTS, MAX_EDICTS); //johnfitz -- max_edicts cvar
|
||||
sv.edicts = (edict_t *) malloc(sv.max_edicts * pr_edict_size); // ericw -- sv.edicts switched to use malloc()
|
||||
|
||||
sv.datagram.maxsize = sizeof(sv.datagram_buf);
|
||||
sv.datagram.cursize = 0;
|
||||
sv.datagram.data = sv.datagram_buf;
|
||||
|
||||
sv.reliable_datagram.maxsize = sizeof(sv.reliable_datagram_buf);
|
||||
sv.reliable_datagram.cursize = 0;
|
||||
sv.reliable_datagram.data = sv.reliable_datagram_buf;
|
||||
sv.datagram = net::msg{};
|
||||
sv.reliable_datagram = net::msg{};
|
||||
|
||||
SV_AddSignonBuffer();
|
||||
|
||||
@@ -1510,8 +1488,8 @@ void SV_SpawnServer(const char *server) {
|
||||
SV_CreateBaseline();
|
||||
|
||||
//johnfitz -- warn if signon buffer larger than standard server can handle
|
||||
for (i = 0, signonsize = 0; i < sv.num_signon_buffers; i++)
|
||||
signonsize += sv.signon_buffers[i]->cursize;
|
||||
for (i = 0, signonsize = 0; i < sv.signons.size(); i++)
|
||||
signonsize += sv.signons[i].size();
|
||||
if (signonsize > 64000 - 2)
|
||||
console::dev_warn("%i byte signon buffer exceeds QS limit of 63998.\n", signonsize);
|
||||
else if (signonsize > 8000 - 2)
|
||||
|
||||
Reference in New Issue
Block a user