Name | Author | Game Mode | Rating | |||||
---|---|---|---|---|---|---|---|---|
Anniversary Bash 21 Levels | Jazz2Online | Multiple | N/A |
namespace acNetworking {
void doReceive(jjSTREAM &in packet, int clientID) {
int8 senderPlayerID;
packet.pop(senderPlayerID);
if (jjIsServer && clientID != jjPlayers[senderPlayerID].clientID) return; //Check for packet validity
uint8 packetType;
packet.pop(packetType);
switch (packetType) {
case PACKET_AOE:
{
uint8 spellID;
packet.pop(spellID);
jjPLAYER@ caster = jjPlayers[senderPlayerID];
if (jjIsServer) {
sendAOEPacket(senderPlayerID, spellID);
}
acSpells::doAOE(caster, spellID, caster.xPos, caster.yPos);
}
break;
case PACKET_EFFECT:
{
uint8 effectID;
int8 targetPlayerID;
uint duration;
packet.pop(effectID);
packet.pop(targetPlayerID);
packet.pop(duration);
if (jjIsServer) {
sendEffectPacket(senderPlayerID, effectID, targetPlayerID, duration);
}
acSpells::doEffect(effectID, targetPlayerID, duration);
}
break;
case PACKET_MASS_EFFECT:
{
uint8 effectID;
uint duration;
int8[] targets;
packet.pop(effectID);
packet.pop(duration);
while (!packet.isEmpty()) {
int8 target;
packet.pop(target);
targets.insertLast(target);
}
if (jjIsServer) {
sendMassEffectPacket(senderPlayerID, effectID, targets, duration);
}
acSpells::doMassEffect(effectID, targets, duration);
}
break;
case PACKET_CHANNELING_STARTED:
{
uint8 spellEnumValue;
packet.pop(spellEnumValue);
if (debugModeOn) jjAlert("Channeling started");
if (jjIsServer) {
sendChannelingStartedPacket(senderPlayerID, spellEnumValue);
string channeledSpellKey = acSpells::getSpellKeyByEnumValue(spellEnumValue);
if (channeledSpellKey != "") {
players[senderPlayerID].setChanneledSpellKey(channeledSpellKey);
}
}
else {
string channeledSpellKey = acSpells::getSpellKeyByEnumValue(spellEnumValue);
if (channeledSpellKey != "" && !jjPlayers[senderPlayerID].isLocal) {
players[senderPlayerID].setChanneledSpellKey(channeledSpellKey);
}
}
}
break;
case PACKET_CHANNELING_STOPPED:
{
if (jjIsServer) {
sendChannelingStoppedPacket(senderPlayerID);
players[senderPlayerID].unSetChanneledSpellKey();
}
else {
players[senderPlayerID].unSetChanneledSpellKey();
}
}
break;
case PACKET_PLAYER_DEAD:
{
if (debugModeOn) jjAlert("Received");
if (jjIsServer) {
sendPlayerDeadPacket(senderPlayerID);
}
acEngine::doDeadPlayer(senderPlayerID);
}
break;
case PACKET_WALL_OF_FIRE:
{
float xOrigin;
float yOrigin;
int height;
packet.pop(xOrigin);
packet.pop(yOrigin);
packet.pop(height);
if (jjIsServer) {
sendWallOfFirePacket(senderPlayerID, xOrigin, yOrigin, height);
}
Spell@ spell = cast<Spell@>(spells["I"]);
uint duration = (spell.baseDuration + players[senderPlayerID].spellDurationBonus) * SECOND;
acSpells::doWallOfFire(jjPlayers[senderPlayerID], spell, xOrigin, yOrigin, height, duration);
}
break;
case PACKET_CHAIN_LIGHTNING_SERVER:
{
int8[] targets;
while (!packet.isEmpty()) {
int8 target;
packet.pop(target);
targets.insertLast(target);
}
array<ChainLightningTarget@> chainLightningTargets = acSpells::doChainLightning(senderPlayerID, targets);
sendChainLightningPacketToClients(senderPlayerID, chainLightningTargets);
chainLightningTargetGroups.insertLast(chainLightningTargets);
}
break;
case PACKET_CHAIN_LIGHTNING_CLIENT:
{
array<ChainLightningTarget@> chainLightningTargets;
while (!packet.isEmpty()) {
int8 id;
int8 parentID;
int8 playerID;
packet.pop(id);
packet.pop(parentID);
packet.pop(playerID);
chainLightningTargets.insertLast(ChainLightningTarget(id, playerID, 0, CHAIN_LIGHTNING_DEFAULT_DURATION, parentID));
}
chainLightningTargetGroups.insertLast(chainLightningTargets);
}
break;
case PACKET_CAPTURE_GEM_MINE:
{
if (jjIsServer) {
sendCaptureGemMinePacket(senderPlayerID);
}
if (gemMine.ownerID == jjLocalPlayers[0].playerID) {
jjAlert("Your gem mine was captured by " + jjPlayers[senderPlayerID].name + "!",
false, STRING::MEDIUM);
}
gemMine.capture(senderPlayerID);
}
break;
case PACKET_SKILL_DAMAGE:
{
if (jjIsServer) {
sendSkillPacket(senderPlayerID, packetType);
}
players[senderPlayerID].spellDamageBonus++;
}
break;
case PACKET_SKILL_DURATION:
{
if (jjIsServer) {
sendSkillPacket(senderPlayerID, packetType);
}
players[senderPlayerID].spellDurationBonus += 10;
}
break;
case PACKET_REQ_SYNC_DATA:
{
sendSkillData(clientID);
sendEffectData(clientID);
sendWallOfFireData(clientID);
sendGemMineOwnerData(clientID);
sendDemoModeData(clientID);
}
break;
case PACKET_SYNC_EFFECTS:
{
while (!packet.isEmpty()) {
int8 effectPlayerID;
uint8 effectID;
uint duration;
packet.pop(effectPlayerID);
packet.pop(effectID);
packet.pop(duration);
acSpells::doEffect(effectID, effectPlayerID, duration, false);
}
}
break;
case PACKET_SYNC_SKILLS:
{
while (!packet.isEmpty()) {
int8 skillPlayerID;
packet.pop(skillPlayerID);
packet.pop(players[skillPlayerID].spellDamageBonus);
packet.pop(players[skillPlayerID].magicResist);
}
}
break;
case PACKET_SYNC_WALLS_OF_FIRE:
{
while (!packet.isEmpty()) {
int8 wallPlayerID;
float xOrigin;
float yOrigin;
int8 height;
uint duration;
packet.pop(wallPlayerID);
packet.pop(xOrigin);
packet.pop(yOrigin);
packet.pop(height);
packet.pop(duration);
jjPLAYER@ caster = jjPlayers[wallPlayerID];
Spell@ spell = cast<Spell@>(spells["I"]);
acSpells::doWallOfFire(caster, spell, xOrigin, yOrigin, height, duration);
}
}
break;
case PACKET_SYNC_GEM_MINE:
{
int lockElapsed;
packet.pop(lockElapsed);
gemMine.lockElapsed = lockElapsed;
gemMine.ownerID = senderPlayerID;
}
break;
case PACKET_SYNC_DEMO_MODE:
{
packet.pop(demoModeOn);
if (demoModeOn) ownSpells = acInit::loadSpells();
else acUtils::disableDemoMode();
}
break;
}
}
void sendAOEPacket(int8 senderPlayerID, uint8 spellID) {
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(uint8(PACKET_AOE));
packet.push(spellID);
jjSendPacket(packet);
}
void sendSkillPacket(int8 senderPlayerID, uint8 skill) {
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(skill);
jjSendPacket(packet);
}
void sendEffectPacket(int8 senderPlayerID, uint8 effectID, int8 targetPlayerID, uint duration) {
jjSTREAM packet;
packet.push(senderPlayerID); //This is always jjLocalPlayers[0].playerID, unless it is a forwarded packet by the server
packet.push(uint8(PACKET_EFFECT));
packet.push(effectID);
packet.push(targetPlayerID);
packet.push(duration);
jjSendPacket(packet);
}
void sendMassEffectPacket(int8 senderPlayerID, uint8 effectID, int8[] targets, uint duration) {
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(uint8(PACKET_MASS_EFFECT));
packet.push(effectID);
packet.push(duration);
for (uint i = 0; i < targets.length; i++) {
packet.push(targets[i]);
}
jjSendPacket(packet);
}
void sendChannelingStartedPacket(int8 senderPlayerID, uint8 spellEnumValue) {
if (jjGameState == GAME::STOPPED) return;
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(uint8(PACKET_CHANNELING_STARTED));
packet.push(spellEnumValue);
jjSendPacket(packet);
}
void sendChannelingStoppedPacket(int8 senderPlayerID) {
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(uint8(PACKET_CHANNELING_STOPPED));
jjSendPacket(packet);
}
void sendPlayerDeadPacket(int8 senderPlayerID) {
jjSTREAM packet;
packet.push(senderPlayerID);
packet.push(uint8(PACKET_PLAYER_DEAD));
jjSendPacket(packet);
}
void sendChainLightningPacketToServer(int8 playerID, int8[] targets) {
jjSTREAM packet;
packet.push(playerID);
packet.push(uint8(PACKET_CHAIN_LIGHTNING_SERVER));
for (uint i = 0; i < targets.length; i++) {
packet.push(targets[i]);
}
jjSendPacket(packet);
}
void sendChainLightningPacketToClients(int8 playerID, array<ChainLightningTarget@> chainLightningTargets) {
jjSTREAM packet;
packet.push(playerID);
packet.push(uint8(PACKET_CHAIN_LIGHTNING_CLIENT));
for (uint i = 0; i < chainLightningTargets.length; i++) {
ChainLightningTarget@ target = chainLightningTargets[i];
packet.push(target.id);
packet.push(target.parentID);
packet.push(target.playerID);
}
jjSendPacket(packet);
}
void sendWallOfFirePacket(int8 playerID, float xOrigin, float yOrigin, int height) {
jjSTREAM packet;
packet.push(playerID);
packet.push(uint8(PACKET_WALL_OF_FIRE));
packet.push(xOrigin);
packet.push(yOrigin);
packet.push(height);
jjSendPacket(packet);
}
void sendCaptureGemMinePacket(int8 playerID) {
jjSTREAM packet;
packet.push(playerID);
packet.push(uint8(PACKET_CAPTURE_GEM_MINE));
jjSendPacket(packet, -jjPlayers[playerID].clientID);
}
void sendReqSyncDataPacket() {
jjSTREAM packet;
packet.push(jjLocalPlayers[0].playerID);
packet.push(uint8(PACKET_REQ_SYNC_DATA));
jjSendPacket(packet);
}
void sendEffectData(int clientID) {
jjSTREAM packet;
packet.push(jjLocalPlayers[0].playerID);
packet.push(uint8(PACKET_SYNC_EFFECTS));
for (uint i = 0; i < 32; i++) {
jjPLAYER@ play = jjPlayers[i];
if (play.isInGame) {
Player@ asPlayer = players[play.playerID];
for (uint j = 0; j < asPlayer.activeEffects.length; j++) {
Effect@ effect = asPlayer.activeEffects[j];
packet.push(play.playerID);
packet.push(uint8(effect.enumValue));
packet.push(effect.elapsed);
}
}
}
jjSendPacket(packet, clientID);
}
void sendSkillData(int clientID) {
jjSTREAM packet;
packet.push(jjLocalPlayers[0].playerID);
packet.push(uint8(PACKET_SYNC_SKILLS));
for (uint i = 0; i < 32; i++) {
jjPLAYER@ play = jjPlayers[i];
if (play.isInGame) {
Player@ asPlayer = players[play.playerID];
packet.push(play.playerID);
packet.push(asPlayer.spellDamageBonus);
packet.push(asPlayer.magicResist);
}
}
jjSendPacket(packet, clientID);
}
void sendWallOfFireData(int clientID) {
jjSTREAM packet;
packet.push(jjLocalPlayers[0].playerID);
packet.push(uint8(PACKET_SYNC_WALLS_OF_FIRE));
for (uint i = 0; i < activeWallsOfFire.length; i++) {
WallOfFire@ wallOfFire = activeWallsOfFire[i];
packet.push(wallOfFire.caster.playerID);
packet.push(wallOfFire.xOrigin);
packet.push(wallOfFire.yOrigin);
packet.push(wallOfFire.height);
packet.push(wallOfFire.elapsed);
}
jjSendPacket(packet, clientID);
}
void sendGemMineOwnerData(int clientID) {
jjSTREAM packet;
packet.push(gemMine.ownerID);
packet.push(uint8(PACKET_SYNC_GEM_MINE));
packet.push(gemMine.lockElapsed);
jjSendPacket(packet, clientID);
}
void sendDemoModeData(int clientID) {
jjSTREAM packet;
packet.push(jjLocalPlayers[0].playerID);
packet.push(uint8(PACKET_SYNC_DEMO_MODE));
packet.push(demoModeOn);
jjSendPacket(packet, clientID);
}
}
Jazz2Online © 1999-INFINITY (Site Credits). We have a Privacy Policy. Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats.
Eat your lima beans, Johnny.