public static void ProcessDatagram(byte[] datagram) { var serverUpdate = new ServerUpdate(); switch ((DatagramID)datagram[0]) { case DatagramID.entityUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(datagram); if (entityUpdate.guid == guid) { CwRam.Teleport(entityUpdate.position); break; } else { entityUpdate.Write(cwriter); } if (players.ContainsKey(entityUpdate.guid)) { entityUpdate.Merge(players[entityUpdate.guid]); } else { players.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.name != null) { RefreshPlayerlist(); } break; #endregion case DatagramID.attack: #region attack var attack = new Attack(datagram); var hit = new Hit() { target = attack.Target, damage = attack.Damage, critical = attack.Critical ? 1 : 0, stuntime = attack.Stuntime, position = players[attack.Target].position, isYellow = attack.Skill, type = attack.Type, showlight = (byte)(attack.ShowLight ? 1 : 0) }; serverUpdate.hits.Add(hit); serverUpdate.Write(cwriter); break; #endregion case DatagramID.shoot: #region shoot var shootDatagram = new Resources.Datagram.Shoot(datagram); var shootPacket = new Resources.Packet.Shoot() { position = shootDatagram.Position, velocity = shootDatagram.Velocity, scale = shootDatagram.Scale, particles = shootDatagram.Particles, projectile = shootDatagram.Projectile, chunkX = (int)shootDatagram.Position.x / 0x1000000, chunkY = (int)shootDatagram.Position.y / 0x1000000 }; serverUpdate.shoots.Add(shootPacket); serverUpdate.Write(cwriter); break; #endregion case DatagramID.proc: #region proc var proc = new Proc(datagram); var passiveProc = new PassiveProc() { target = proc.Target, type = proc.Type, modifier = proc.Modifier, duration = proc.Duration }; serverUpdate.passiveProcs.Add(passiveProc); serverUpdate.Write(cwriter); break; #endregion case DatagramID.chat: #region chat var chat = new Chat(datagram); var chatMessage = new ChatMessage() { sender = chat.Sender, message = chat.Text }; try { chatMessage.Write(cwriter, true); } catch (Exception ex) { if (!(ex is NullReferenceException || ex is ObjectDisposedException)) { throw; } } if (chat.Sender == 0) { form.Log(chat.Text + "\n", Color.Magenta); } else { form.Log(players[chat.Sender].name + ": ", Color.Cyan); form.Log(chat.Text + "\n", Color.White); } break; #endregion case DatagramID.time: #region time var igt = new InGameTime(datagram); var time = new Time() { time = igt.Time }; time.Write(cwriter); break; #endregion case DatagramID.interaction: #region interaction var interaction = new Interaction(datagram); var entityAction = new EntityAction() { chunkX = interaction.ChunkX, chunkY = interaction.ChunkY, index = interaction.Index, type = ActionType.staticInteraction }; //serverUpdate..Add(); //serverUpdate.Write(cwriter); break; #endregion case DatagramID.staticUpdate: #region staticUpdate var staticUpdate = new StaticUpdate(datagram); var staticEntity = new ServerUpdate.StaticEntity() { chunkX = (int)(staticUpdate.Position.x / (65536 * 256)), chunkY = (int)(staticUpdate.Position.y / (65536 * 256)), id = staticUpdate.Id, type = (int)staticUpdate.Type, position = staticUpdate.Position, rotation = (int)staticUpdate.Direction, size = staticUpdate.Size, closed = staticUpdate.Closed ? 1 : 0, time = staticUpdate.Time, guid = staticUpdate.User }; var staticServerUpdate = new ServerUpdate(); staticServerUpdate.statics.Add(staticEntity); staticServerUpdate.Write(cwriter, true); break; #endregion case DatagramID.block: //var block = new Block(datagram); //TODO break; case DatagramID.particle: #region particle var particleDatagram = new Resources.Datagram.Particle(datagram); var particleSubPacket = new ServerUpdate.Particle() { position = particleDatagram.Position, velocity = particleDatagram.Velocity, color = new Resources.Utilities.FloatVector() { x = particleDatagram.Color.R / 255, y = particleDatagram.Color.G / 255, z = particleDatagram.Color.B / 255 }, alpha = particleDatagram.Color.A / 255, size = particleDatagram.Size, count = particleDatagram.Count, type = particleDatagram.Type, spread = particleDatagram.Spread }; serverUpdate.particles.Add(particleSubPacket); serverUpdate.Write(cwriter, true); break; #endregion case DatagramID.connect: #region connect var connect = new Connect(datagram); guid = connect.Guid; var join = new Join() { guid = guid, junk = new byte[0x1168] }; join.Write(cwriter, true); var mapseed = new MapSeed() { seed = connect.Mapseed }; mapseed.Write(cwriter, true); break; #endregion case DatagramID.disconnect: #region disconnect var disconnect = new Disconnect(datagram); var pdc = new EntityUpdate() { guid = disconnect.Guid, hostility = 255, //workaround for DC because i dont like packet2 HP = 0 }; pdc.Write(cwriter); players.Remove(disconnect.Guid); RefreshPlayerlist(); break; #endregion case DatagramID.specialMove: var specialMove = new SpecialMove(datagram); switch (specialMove.Id) { case SpecialMoveID.taunt: if (players.ContainsKey(specialMove.Guid)) { CwRam.Teleport(players[specialMove.Guid].position); CwRam.Freeze(5000); } break; case SpecialMoveID.cursedArrow: break; case SpecialMoveID.arrowRain: break; case SpecialMoveID.shrapnel: break; case SpecialMoveID.smokeBomb: var smoke = new ServerUpdate(); smoke.particles.Add(new ServerUpdate.Particle() { count = 1000, spread = 5f, type = ParticleType.noGravity, size = 5f, velocity = new Resources.Utilities.FloatVector(), color = new Resources.Utilities.FloatVector() { x = 1f, y = 1f, z = 1f }, alpha = 1f, position = players[specialMove.Guid].position }); smoke.Write(cwriter); break; case SpecialMoveID.iceWave: break; case SpecialMoveID.confusion: break; case SpecialMoveID.shadowStep: break; default: break; } break; default: break; } }
private static void ProcessDatagram(byte[] datagram) { var serverUpdate = new ServerUpdate(); bool writeServerUpdate = false; switch ((DatagramID)datagram[0]) { case DatagramID.DynamicUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(datagram); if (status == BridgeStatus.Playing) { if (entityUpdate.guid == guid) { CwRam.Teleport(entityUpdate.position); break; } SendToClient(entityUpdate); } if (dynamicEntities.ContainsKey(entityUpdate.guid)) { entityUpdate.Merge(dynamicEntities[entityUpdate.guid]); } else { dynamicEntities.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.name != null) { RefreshPlayerlist(); } break; #endregion case DatagramID.Attack: #region attack var attack = new Attack(datagram); CwRam.Knockback(attack.Direction); var hit = new Hit() { target = attack.Target, damage = attack.Damage, direction = attack.Direction, critical = attack.Critical, stuntime = attack.Stuntime, position = dynamicEntities[attack.Target].position, isYellow = attack.Skill, type = attack.Type, showlight = attack.ShowLight, }; serverUpdate.hits.Add(hit); writeServerUpdate = true; break; #endregion case DatagramID.Projectile: #region Projectile var projectile = new Projectile(datagram); var shoot = new Shoot() { attacker = projectile.Source, position = projectile.Position, velocity = projectile.Velocity, scale = projectile.Scale, particles = projectile.Particles, mana = projectile.Particles, projectile = projectile.Type, chunkX = (int)projectile.Position.x / 0x1000000, chunkY = (int)projectile.Position.y / 0x1000000 }; var angle = Math.Atan2(shoot.velocity.y, shoot.velocity.x); shoot.position.x += (long)(Math.Cos(angle) * 0x10000); shoot.position.y += (long)(Math.Sin(angle) * 0x10000); serverUpdate.shoots.Add(shoot); writeServerUpdate = true; break; #endregion case DatagramID.Proc: #region proc var proc = new Proc(datagram); if (proc.Type == ProcType.Poison && proc.Target == guid) { var su = new ServerUpdate(); su.hits.Add(new Hit() { damage = proc.Modifier, target = guid, position = dynamicEntities[guid].position, }); bool tick() { bool f = status == BridgeStatus.Playing && dynamicEntities[guid].HP > 0; if (f) { SendToClient(su); } return(!f); } Tools.DoLater(tick, 500, 7); } var passiveProc = new PassiveProc() { target = proc.Target, type = proc.Type, modifier = proc.Modifier, duration = proc.Duration }; serverUpdate.passiveProcs.Add(passiveProc); writeServerUpdate = true; break; #endregion case DatagramID.Chat: #region chat var chat = new Chat(datagram); var chatMessage = new ChatMessage() { sender = chat.Sender, message = chat.Text }; if (status == BridgeStatus.Playing) { SendToClient(chatMessage); } if (chat.Sender == 0) { form.Log(chat.Text + "\n", Color.Magenta); } else { form.Log(dynamicEntities[chat.Sender].name + ": ", Color.Cyan); form.Log(chat.Text + "\n", Color.White); } break; #endregion case DatagramID.Time: #region time var igt = new InGameTime(datagram); var time = new Time() { time = igt.Milliseconds }; if (status == BridgeStatus.Playing) { SendToClient(time); } break; #endregion case DatagramID.Interaction: #region interaction var interaction = new Interaction(datagram); var entityAction = new EntityAction() { chunkX = interaction.ChunkX, chunkY = interaction.ChunkY, index = interaction.Index, type = ActionType.StaticInteraction }; writeServerUpdate = true; break; #endregion case DatagramID.StaticUpdate: #region staticUpdate var staticUpdate = new StaticUpdate(datagram); var staticEntity = new ServerUpdate.StaticEntity() { chunkX = (int)(staticUpdate.Position.x / (65536 * 256)), chunkY = (int)(staticUpdate.Position.y / (65536 * 256)), id = staticUpdate.Id, type = staticUpdate.Type, position = staticUpdate.Position, rotation = (int)staticUpdate.Direction, size = staticUpdate.Size, closed = staticUpdate.Closed, time = staticUpdate.Time, guid = staticUpdate.User }; serverUpdate.statics.Add(staticEntity); writeServerUpdate = true; break; #endregion case DatagramID.Block: //var block = new Block(datagram); //TODO break; case DatagramID.Particle: #region particle var particleDatagram = new Particle(datagram); var particleSubPacket = new ServerUpdate.Particle() { position = particleDatagram.Position, velocity = particleDatagram.Velocity, color = new Resources.Utilities.FloatVector() { x = particleDatagram.Color.R / 255, y = particleDatagram.Color.G / 255, z = particleDatagram.Color.B / 255 }, alpha = particleDatagram.Color.A / 255, size = particleDatagram.Size, count = particleDatagram.Count, type = particleDatagram.Type, spread = particleDatagram.Spread }; serverUpdate.particles.Add(particleSubPacket); break; #endregion case DatagramID.RemoveDynamicEntity: #region RemoveDynamicEntity var rde = new RemoveDynamicEntity(datagram); entityUpdate = new EntityUpdate() { guid = rde.Guid, hostility = (Hostility)255, //workaround for DC because i dont like packet2 HP = 0 }; if (status == BridgeStatus.Playing) { SendToClient(entityUpdate); } dynamicEntities.Remove(rde.Guid); RefreshPlayerlist(); break; #endregion case DatagramID.SpecialMove: #region speicalMove var specialMove = new SpecialMove(datagram); switch (specialMove.Id) { case SpecialMoveID.Taunt: if (dynamicEntities.ContainsKey(specialMove.Guid)) { if (status == BridgeStatus.Playing) { CwRam.Teleport(dynamicEntities[specialMove.Guid].position); CwRam.Freeze(5000); } } break; case SpecialMoveID.CursedArrow: break; case SpecialMoveID.ArrowRain: break; case SpecialMoveID.Shrapnel: var su = new ServerUpdate(); var blood_hit = new Hit() { damage = 5f, target = specialMove.Guid, }; su.hits.Add(blood_hit); var blood_particles = new ServerUpdate.Particle() { count = 10, spread = 2f, type = ParticleType.Normal, size = 0.1f, velocity = new FloatVector() { z = 1f, }, color = new FloatVector() { x = 1f, y = 0f, z = 0f }, alpha = 1f, }; su.particles.Add(blood_particles); bool tick() { bool f = status == BridgeStatus.Playing && dynamicEntities[specialMove.Guid].HP > 0; if (f) { blood_hit.position = blood_particles.position = dynamicEntities[specialMove.Guid].position; SendToClient(su); } return(!f); } Tools.DoLater(tick, 50, 100); break; case SpecialMoveID.SmokeBomb: serverUpdate.particles.Add(new ServerUpdate.Particle() { count = 1000, spread = 5f, type = ParticleType.NoGravity, size = 5f, velocity = new Resources.Utilities.FloatVector(), color = new Resources.Utilities.FloatVector() { x = 1f, y = 1f, z = 1f }, alpha = 1f, position = dynamicEntities[specialMove.Guid].position }); writeServerUpdate = true; break; case SpecialMoveID.IceWave: if (specialMove.Guid != guid) //distance small enough { CwRam.Freeze(3000); } serverUpdate.particles.Add(new ServerUpdate.Particle() { count = 100, spread = 4f, type = ParticleType.NoGravity, size = 0.3f, velocity = new FloatVector(), color = new FloatVector() { x = 0f, y = 1f, z = 1f }, alpha = 1f, position = dynamicEntities[specialMove.Guid].position }); serverUpdate.particles.Add(new ServerUpdate.Particle() { count = 100, spread = 10f, type = ParticleType.NoGravity, size = 0.1f, velocity = new FloatVector(), color = new FloatVector() { x = 1f, y = 1f, z = 1f }, alpha = 1f, position = dynamicEntities[specialMove.Guid].position }); serverUpdate.particles.Add(new ServerUpdate.Particle() { count = 100, spread = 2f, type = ParticleType.NoGravity, size = 0.7f, velocity = new FloatVector(), color = new FloatVector() { x = 0f, y = 0f, z = 1f }, alpha = 1f, position = dynamicEntities[specialMove.Guid].position }); writeServerUpdate = true; break; case SpecialMoveID.Confusion: break; case SpecialMoveID.ShadowStep: break; default: break; } break; #endregion default: form.Log("unknown datagram ID: " + datagram[0], Color.Red); break; } if (status == BridgeStatus.Playing && writeServerUpdate) { SendToClient(serverUpdate); } }