public void TeleportPlayer(Player player, long x, long y, long z) { var staticEntity = new ServerUpdate.StaticEntity { chunkX = BitConverter.ToInt32(BitConverter.GetBytes(x), 3), chunkY = BitConverter.ToInt32(BitConverter.GetBytes(y), 3), id = 0, type = 18, position = new Resources.Utilities.LongVector() { x = x, y = y, z = z, }, rotation = 2, time = 1000, guid = player.entityData.guid }; var serverUpdate = new ServerUpdate(); serverUpdate.statics.Add(staticEntity); serverUpdate.Write(player.writer, true); staticEntity.guid = 0; serverUpdate.Write(player.writer, true); }
public static void TCP(string command, string parameter, Player player) { switch (command) { case "spawn": break; case "reload_world": break; case "xp": try { int amount = Convert.ToInt32(parameter); var xpDummy = new EntityUpdate() { guid = 1000, hostility = (byte)Hostility.enemy }; xpDummy.Write(player.writer); var kill = new ServerUpdate.Kill() { killer = player.entityData.guid, victim = 1000, xp = amount }; var serverUpdate = new ServerUpdate(); serverUpdate.kills.Add(kill); serverUpdate.Write(player.writer, true); break; } catch (Exception) { //invalid syntax } break; case "time": try { int index = parameter.IndexOf(":"); int hour = Convert.ToInt32(parameter.Substring(0, index)); int minute = Convert.ToInt32(parameter.Substring(index + 1)); var time = new Time() { time = (hour * 60 + minute) * 60000 }; time.Write(player.writer, true); } catch (Exception) { //invalid syntax } break; default: break; } }
public void ProcessPacket(int packetID, Player player) { switch ((PacketID)packetID) { case PacketID.entityUpdate: #region entity update var entityUpdate = new EntityUpdate(player.reader); string ACmessage = AntiCheat.Inspect(entityUpdate); if (ACmessage != "ok") { var kickMessage = new ChatMessage() { message = "illegal " + ACmessage }; kickMessage.Write(player.writer, true); Console.WriteLine(player.entityData.name + " kicked for illegal " + kickMessage.message); Thread.Sleep(100); //thread is about to run out anyway so np Kick(player); return; } if (entityUpdate.name != null) { Announce.Join(entityUpdate.name, player.entityData.name, players); } entityUpdate.entityFlags |= 1 << 5; //enable friendly fire flag for pvp if (!player.entityData.IsEmpty) { entityUpdate.Filter(player.entityData); } if (!entityUpdate.IsEmpty) { entityUpdate.Broadcast(players, 0); if (entityUpdate.HP == 0 && player.entityData.HP > 0) { Tomb.Show(player).Broadcast(players, 0); } else if (player.entityData.HP == 0 && entityUpdate.HP > 0) { Tomb.Hide(player).Broadcast(players, 0); } entityUpdate.Merge(player.entityData); } break; #endregion case PacketID.entityAction: #region action EntityAction entityAction = new EntityAction(player.reader); switch (entityAction.type) { case ActionType.talk: break; case ActionType.staticInteraction: //var staticEntity = new StaticEntity(); //staticEntity.chunkX = entityAction.chunkX; //staticEntity.chunkY = entityAction.chunkY; //staticEntity.id = entityAction.index; //staticEntity.type = 0; //staticEntity.position = player.entityData.position; //staticEntity.rotation = 0; //staticEntity.size.x = 2; //staticEntity.size.y = 1; //staticEntity.size.z = 1; //staticEntity.closed = 0; //staticEntity.time = 1000; //staticEntity.guid = player.entityData.guid; //var serverUpdate = new ServerUpdate(); //serverUpdate.statics.Add(staticEntity); //serverUpdate.Send(players, 0); break; case ActionType.pickup: //shouldn't occur since item drops are disabled break; case ActionType.drop: //send item back to dropper because dropping is disabled to prevent chatspam var pickup = new ServerUpdate.Pickup() { guid = player.entityData.guid, item = entityAction.item }; var serverUpdate6 = new ServerUpdate(); serverUpdate6.pickups.Add(pickup); serverUpdate6.Write(player.writer, true); break; case ActionType.callPet: var petItem = player.entityData.equipment[(int)Equipment.pet]; var pet = new EntityUpdate() { guid = 2000 + player.entityData.guid, position = player.entityData.position, hostility = (int)Hostility.pet, entityType = 28, appearance = player.entityData.appearance, HP = 999, parentOwner = 3000 + (long)player.entityData.guid, equipment = player.entityData.equipment, name = "doppelganger" }; pet.Broadcast(players, 0); pet = new EntityUpdate() { guid = 3000 + player.entityData.guid, position = player.entityData.position, hostility = (int)Hostility.pet, entityType = 28, mode = 106, appearance = player.entityData.appearance, HP = 999, parentOwner = (long)player.entityData.guid, equipment = player.entityData.equipment, name = "doppelganger" }; pet.Broadcast(players, 0); break; default: Console.WriteLine("unknown action (" + entityAction.type + ") by " + player.entityData.name); break; } break; #endregion case PacketID.hit: #region hit var hit = new Hit(player.reader); hit.damage *= 0.75f; if (players.ContainsKey(hit.target)) { var serverUpdate7 = new ServerUpdate(); serverUpdate7.hits.Add(hit); serverUpdate7.Broadcast(players, player.entityData.guid); } break; #endregion case PacketID.passiveProc: #region passiveProc var passiveProc = new PassiveProc(player.reader); var serverUpdate8 = new ServerUpdate(); serverUpdate8.passiveProcs.Add(passiveProc); serverUpdate8.Broadcast(players, player.entityData.guid); switch (passiveProc.type) { case ProcType.warFrenzy: case ProcType.camouflage: case ProcType.fireSpark: case ProcType.intuition: case ProcType.elusivenes: case ProcType.swiftness: //nothing particular yet break; case ProcType.manashield: var chatMessage6m = new ChatMessage() { message = string.Format("manashield: {0}", passiveProc.modifier), sender = 0 }; chatMessage6m.Write(player.writer, true); break; case ProcType.bulwalk: var chatMessage6b = new ChatMessage() { message = string.Format("bulwalk: {0}% dmg reduction", 1.0f - passiveProc.modifier), sender = 0 }; chatMessage6b.Write(player.writer, true); break; case ProcType.poison: if (players.ContainsKey(passiveProc.target)) //in case target is a tomb or sth { var poisonDmg = new Hit() { attacker = passiveProc.source, target = passiveProc.target, damage = passiveProc.modifier, position = players[passiveProc.target].entityData.position, type = DamageType.normal }; var poisonTick = new ServerUpdate(); poisonTick.hits.Add(poisonDmg); Poison(poisonTick, passiveProc.duration); } break; default: Console.WriteLine("unknown passiveProc.type: " + passiveProc.type); break; } break; #endregion case PacketID.shoot: #region shoot var shoot = new Shoot(player.reader); var serverUpdate9 = new ServerUpdate(); serverUpdate9.shoots.Add(shoot); serverUpdate9.Broadcast(players, player.entityData.guid); break; #endregion case PacketID.chat: #region chat var chatMessage = new ChatMessage(player.reader) { sender = player.entityData.guid }; if (chatMessage.message.StartsWith("/")) { string parameter = ""; string command = chatMessage.message.Substring(1); if (chatMessage.message.Contains(" ")) { int spaceIndex = command.IndexOf(" "); parameter = command.Substring(spaceIndex + 1); command = command.Substring(0, spaceIndex); } Command.TCP(command, parameter, player); //wip } else { chatMessage.Broadcast(players, 0); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("#" + player.entityData.guid + " " + player.entityData.name + ": "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(chatMessage.message); } break; #endregion case PacketID.chunk: #region chunk var chunk = new Chunk(player.reader); break; #endregion case PacketID.sector: #region sector var sector = new Chunk(player.reader); break; #endregion case PacketID.version: #region version var version = new ProtocolVersion(player.reader); if (version.version != 3) { version.version = 3; version.Write(player.writer, true); player.tcp.Close(); } else { player.entityData.guid = guidCounter; guidCounter++; var join = new Join() { guid = player.entityData.guid, junk = new byte[0x1168] }; join.Write(player.writer, true); var mapSeed = new MapSeed() { seed = Database.mapseed }; mapSeed.Write(player.writer, true); foreach (Player p in players.Values) { p.entityData.Write(player.writer); } players.Add(player.entityData.guid, player); Task.Delay(10000).ContinueWith(t => Load_world_delayed(player)); //WIP, causes crash when player disconnects before executed } break; #endregion default: Console.WriteLine("unknown packet ID: " + packetID); //causes some console spam, but allows resyncing with the player without DC or crash break; } }
public void Load_world_delayed(Player player) { try { worldUpdate.Write(player.writer, true); } catch { } }
public static void OnHotkey(int hotkeyID) { HotkeyID hotkey = (HotkeyID)hotkeyID; if (hotkey == HotkeyID.teleport_to_town) { CwRam.SetMode(Mode.teleport_to_city, 0); return; } bool spec = players[guid].specialization == 1; bool space = hotkeyID == 1; switch ((EntityClass)players[guid].entityClass) { case EntityClass.Rogue when spec: #region ninja if (hotkey == HotkeyID.ctrlSpace) { #region dash CwRam.SetMode(Mode.spin_run, 0); #endregion break; } #region blink if (players.ContainsKey(lastTarget)) { CwRam.Teleport(players[guid].position); } #endregion break; #endregion case EntityClass.Rogue: #region assassin if (hotkey == HotkeyID.ctrlSpace) { #region confusion var specialMove = new SpecialMove() { Guid = guid, Id = SpecialMoveID.confusion, }; SendUDP(specialMove.data); #endregion } else { #region shadow step var specialMove = new SpecialMove() { Guid = guid, Id = SpecialMoveID.shadowStep, }; SendUDP(specialMove.data); #endregion } break; #endregion case EntityClass.Warrior when spec: #region guardian if (hotkey == HotkeyID.ctrlSpace) { #region taunt var specialMove = new SpecialMove() { Guid = lastTarget, Id = SpecialMoveID.taunt, }; SendUDP(specialMove.data); #endregion } else { #region steel wall CwRam.SetMode(Mode.boss_skill_block, 0); #endregion } break; #endregion case EntityClass.Warrior: #region berserk if (hotkey == HotkeyID.ctrlSpace) { #region boulder toss CwRam.SetMode(Mode.boulder_toss, 0); #endregion } else { #region earth shatter CwRam.SetMode(Mode.earth_shatter, 0); #endregion } break; #endregion case EntityClass.Mage when spec: #region watermage if (hotkey == HotkeyID.ctrlSpace) { #region splash CwRam.SetMode(Mode.splash, 0); #endregion } else { #region ice wave //TODO #endregion } break; #endregion case EntityClass.Mage: #region firemage if (hotkey == HotkeyID.ctrlSpace) { #region lava CwRam.SetMode(Mode.lava, 0); #endregion } else { #region beam CwRam.SetMode(Mode.fireray, 0); #endregion } break; #endregion case EntityClass.Ranger when spec: #region scout if (hotkey == HotkeyID.ctrlSpace) { #region shrapnel //TODO #endregion } else { #region smoke bomb var specialMove = new SpecialMove() { Guid = guid, Id = SpecialMoveID.smokeBomb, }; SendUDP(specialMove.data); var fakeSmoke = new ServerUpdate(); fakeSmoke.particles.Add(new ServerUpdate.Particle() { count = 1000, spread = 5f, type = ParticleType.noGravity, size = 0.3f, velocity = new Resources.Utilities.FloatVector(), color = new Resources.Utilities.FloatVector() { x = 1f, y = 1f, z = 1f }, alpha = 1f, position = players[specialMove.Guid].position }); fakeSmoke.Write(cwriter); #endregion } break; #endregion case EntityClass.Ranger: #region sniper if (hotkey == HotkeyID.ctrlSpace) { #region cursed arrow //TODO #endregion } else { #region arrow rain //TODO #endregion } break; #endregion default: break; } CwRam.memory.WriteInt(CwRam.EntityStart + 0x1164, 3);//mana cubes }
public static void ProcessClientPacket(int packetID) { switch ((PacketID)packetID) { case PacketID.entityUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(creader); if (players.ContainsKey(entityUpdate.guid)) { entityUpdate.Filter(players[entityUpdate.guid]); entityUpdate.Merge(players[entityUpdate.guid]); } else { players.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.name != null) { RefreshPlayerlist(); } SendUDP(entityUpdate.Data); break; #endregion case PacketID.entityAction: #region entity action EntityAction entityAction = new EntityAction(creader); switch (entityAction.type) { case ActionType.talk: break; case ActionType.staticInteraction: break; case ActionType.pickup: break; case ActionType.drop: //send item back to dropper because dropping is disabled to prevent chatspam if (form.radioButtonDestroy.Checked) { new ChatMessage() { message = "item destroyed" }.Write(cwriter); } else { var serverUpdate = new ServerUpdate(); var pickup = new ServerUpdate.Pickup() { guid = guid, item = entityAction.item }; serverUpdate.pickups.Add(pickup); if (form.radioButtonDuplicate.Checked) { serverUpdate.pickups.Add(pickup); } serverUpdate.Write(cwriter); } break; case ActionType.callPet: var petCall = new SpecialMove() { Guid = guid }; SendUDP(petCall.data); break; default: //unknown type break; } break; #endregion case PacketID.hit: #region hit var hit = new Hit(creader); var attack = new Attack() { Target = (ushort)hit.target, Damage = hit.damage, Stuntime = hit.stuntime, Skill = hit.isYellow, Type = hit.type, ShowLight = hit.showlight == 1, Critical = hit.critical == 1 }; SendUDP(attack.data); lastTarget = attack.Target; break; #endregion case PacketID.passiveProc: #region passiveProc var passiveProc = new PassiveProc(creader); var proc = new Proc() { Target = (ushort)passiveProc.target, Type = passiveProc.type, Modifier = passiveProc.modifier, Duration = passiveProc.duration }; SendUDP(proc.data); break; #endregion case PacketID.shoot: #region shoot var shootPacket = new Resources.Packet.Shoot(creader); var shootDatagram = new Resources.Datagram.Shoot() { Position = shootPacket.position, Velocity = shootPacket.velocity, Scale = shootPacket.scale, Particles = shootPacket.particles, Projectile = shootPacket.projectile }; SendUDP(shootDatagram.data); break; #endregion case PacketID.chat: #region chat var chatMessage = new ChatMessage(creader); if (chatMessage.message.ToLower() == @"/plane") { Console.Beep(); var serverUpdate = new ServerUpdate() { blockDeltas = VoxModel.Parse("model.vox"), }; foreach (var block in serverUpdate.blockDeltas) { block.position.x += 8286946; block.position.y += 8344456; block.position.z += 220; } serverUpdate.Write(cwriter); } else { var chat = new Chat(chatMessage.message) { Sender = guid //client doesn't send this //(ushort)chatMessage.sender }; SendUDP(chat.data); } break; #endregion case PacketID.chunk: #region chunk var chunk = new Chunk(creader); break; #endregion case PacketID.sector: #region sector var sector = new Sector(creader); break; #endregion case PacketID.version: #region version var version = new ProtocolVersion(creader); if (version.version != 3) { version.version = 3; version.Write(cwriter, true); } else { var connect = new Connect(); SendUDP(connect.data); } break; #endregion default: form.Log("unknown client packet\n", Color.Magenta); break; } }
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; } }