static void ProcessPacket(int packetid) { switch (packetid) { case 0: #region entityUpdate var entityUpdate = new EntityUpdate(reader); if (players.ContainsKey(entityUpdate.guid)) { var previous = players[entityUpdate.guid]; if (entityUpdate.modeTimer == 0) { if ((entityUpdate.mode == Mode.FireExplosion_After || (entityUpdate.mode == null && previous.mode == Mode.FireExplosion_After)) && previous.modeTimer < 1000) { firespammers[entityUpdate.guid]++; switch (firespammers[entityUpdate.guid]) { case 1: //nothing break; case 2: //warn new ChatMessage { message = "/pm #" + entityUpdate.guid + " stop spamming fire explosion, its a bannable abuse" }.Write(writer); break; default: //kick new ChatMessage { message = "/kick #" + entityUpdate.guid + " firespamming (black_bot)" }.Write(writer); break; } } else { //firespammers[entityUpdate.guid] = 0; } } entityUpdate.Merge(players[entityUpdate.guid]); } else { players.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.MP > 1f) { new ChatMessage { message = "/kick #" + entityUpdate.guid + " MP lock (black_bot)" }.Write(writer); } if (entityUpdate.name != null) { Console.ForegroundColor = ConsoleColor.DarkGreen; //Console.WriteLine(entityUpdate.guid + ": " + entityUpdate.name); } if (false && players[entityUpdate.guid].name.ToLower() == "²@blackrock") { maloxGuid = entityUpdate.guid; var opplayer = new EntityUpdate(); var x = players[entityUpdate.guid].position.x - players[personalGuid].position.x; var y = players[entityUpdate.guid].position.y - players[personalGuid].position.y; double distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); if (distance > 65536 * 40) { var follow = new EntityUpdate { position = players[entityUpdate.guid].position, guid = personalGuid }; follow.Write(writer); } if (entityUpdate.modeTimer < 50) { var shoot = new Shoot() { attacker = personalGuid, chunkX = (int)players[personalGuid].position.x / 0x1000000, chunkY = (int)players[personalGuid].position.y / 0x1000000, position = players[personalGuid].position, particles = 1f, mana = 1f, scale = 5f, projectile = ProjectileType.Arrow, }; shoot.position.x = players[maloxGuid].position.x + (long)(players[maloxGuid].rayHit.x * 0x10000); shoot.position.y = players[maloxGuid].position.y + (long)(players[maloxGuid].rayHit.y * 0x10000); shoot.position.z = players[maloxGuid].position.z + (long)((players[maloxGuid].rayHit.z + 15) * 0x10000); shoot.velocity.z = -40f; //shoot.velocity.x = (float)players[maloxGuid].position.x / 0x10000f + players[maloxGuid].rayHit.x - (float)players[personalGuid].position.x / 0x10000f; //shoot.velocity.y = (float)players[maloxGuid].position.y / 0x10000f + players[maloxGuid].rayHit.y - (float)players[personalGuid].position.y / 0x10000f; //shoot.velocity.z = (float)players[maloxGuid].position.z / 0x10000f + players[maloxGuid].rayHit.z - (float)players[personalGuid].position.z / 0x10000f; int range = 10; shoot.position.x -= (range - 1) / 2 * 0x10000; shoot.position.y -= (range - 1) / 2 * 0x10000; for (int i = 0; i < range; i++) { for (int j = 0; j < range; j++) { shoot.Write(writer); shoot.position.x += 0x10000; } shoot.position.x -= range * 0x10000; shoot.position.y += 0x10000; } } } goto case 2; //break; #endregion case 2: #region complete var antiTimeout = new EntityUpdate() { guid = personalGuid, position = players[personalGuid].position, lastHitTime = (int)swLasthittime.ElapsedMilliseconds }; antiTimeout.Write(writer); break; #endregion case 4: #region serverupdate var serverUpdate = new ServerUpdate(reader); foreach (var hit in serverUpdate.hits) { if (hit.attacker == hit.target) { continue; } Console.WriteLine(hit.attacker + " attacked " + hit.target + " with " + hit.damage); if (hit.damage > 500f && players[hit.attacker].entityClass == EntityClass.Rogue) { SendMessage("/kick #" + hit.attacker + " shuriken glitch (black_bot)"); } if (hit.target == personalGuid) { swLasthittime.Restart(); if (players[personalGuid].HP <= 0) { continue; } players[personalGuid].HP -= hit.damage / 2; var life = new EntityUpdate() { guid = personalGuid, HP = players[personalGuid].HP, lastHitTime = (int)swLasthittime.ElapsedMilliseconds }; life.Write(writer); if (players[personalGuid].HP <= 0) { SendMessage("/firework"); life.HP = players[personalGuid].HP = 3000f; life.lastHitTime = 0; life.Write(writer); swLasthittime.Restart(); } } } foreach (var chunkItemData in serverUpdate.chunkItems) { var c = new Chunk() { x = chunkItemData.chunkX, y = chunkItemData.chunkY }; if (!drops.ContainsKey(c)) { drops.Add(c, chunkItemData.droppedItems); } else { drops[c] = chunkItemData.droppedItems; } } break; #endregion case 5: #region time var time = new Time(reader); break; #endregion case 10: #region chat var chatMessage = new ChatMessage(reader, true); long sender = (long)chatMessage.sender; if (sender == 0) { Console.ForegroundColor = ConsoleColor.DarkGray; } else { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(players[sender].name + ": "); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(chatMessage.message); switch (chatMessage.message.ToLower()) { case ".heal_me": case ".kill_me": SendMessage("/pm #" + sender + " This command is no longer available"); break; case ".stun_me": new Hit { attacker = personalGuid, target = sender, damage = 0f, critical = true, stuntime = 10000, showlight = true, position = players[sender].position }.Write(writer); SendMessage("/pm #" + sender + " have fun sticking to the ground for 10 seconds :P"); break; case ".shutdown": if (chatMessage.message == ".shutdOWN") { SendMessage("goodbye"); Task.Delay(250).Wait(); Environment.Exit(0); } else { SendMessage("no permission"); } break; case ".clear": foreach (var kvp in drops) { for (int i = 0; i < kvp.Value.Count; i++) { var pickup = new EntityAction() { type = ActionType.PickUp, chunkX = kvp.Key.x, chunkY = kvp.Key.y, index = i, item = kvp.Value[i].item, }; pickup.Write(writer); pickup.Write(writer); } } //SendMessage(".\n\n\n\n\n\n\n\n\n\n."); break; case ".items": #region items double timePassed = swCooldown.ElapsedMilliseconds / 1000f; if (timePassed < 30f) { SendMessage("/pm #" + sender + " command is on cooldown (30sec)"); break; } bool fullyGeared = true; var pl = players[sender]; for (int i = 1; i < 9; i++) { if (pl.equipment[i].level < pl.level || pl.equipment[i].rarity != ItemRarity.Legendary) { fullyGeared = false; break; } } if (pl.equipment[10].type == 0 || pl.equipment[11].type == 0) { fullyGeared = false; } if (fullyGeared) { SendMessage("/pm #" + chatMessage.sender + " you already have maximum gear, don't spam items."); break; } swCooldown.Restart(); var port = new EntityUpdate { position = players[sender].position, guid = personalGuid }; port.Write(writer); players[personalGuid].position = port.position; var items = new List <Item>(); var rng = new Random(); for (byte i = 3; i <= 9; i++) { items.Add(new Item() { type = (ItemType)i, modifier = rng.Next(0x7FFFFFFF), rarity = ItemRarity.Legendary, level = (short)players[sender].level }); } items[5].material = (ItemMaterial)rng.Next(11, 12); items[6].material = (ItemMaterial)rng.Next(11, 12); items.Add(items[6]); ItemMaterial armorMaterial; switch (players[sender].entityClass) { case EntityClass.Warrior: //items[0].subtype = 0; items[0].material = ItemMaterial.Iron; for (int i = 0; i < 6; i++) { items.Add(new Item() { type = ItemType.Weapon, material = ItemMaterial.Iron, modifier = rng.Next(0x7FFFFFFF), rarity = ItemRarity.Legendary, level = (short)players[sender].level }); } items[8].subtype = 1; items[9].subtype = 2; items[10].subtype = 13; items[11].subtype = 15; items[12].subtype = 16; items[13].subtype = 17; armorMaterial = ItemMaterial.Iron; break; case EntityClass.Ranger: items[0].subtype = 6; items[0].material = ItemMaterial.Wood; for (int i = 0; i < 2; i++) { items.Add(new Item() { type = ItemType.Weapon, material = ItemMaterial.Wood, modifier = rng.Next(0x7FFFFFFF), rarity = ItemRarity.Legendary, level = (short)players[sender].level }); } items[8].subtype = 7; items[9].subtype = 8; armorMaterial = ItemMaterial.Linen; break; case EntityClass.Mage: items[0].subtype = 10; items[0].material = ItemMaterial.Wood; for (int i = 0; i < 3; i++) { items.Add(new Item() { type = ItemType.Weapon, material = (ItemMaterial)rng.Next(11, 12), modifier = rng.Next(0x7FFFFFFF), rarity = ItemRarity.Legendary, level = (short)players[sender].level }); } items[8].subtype = 11; items[8].material = ItemMaterial.Wood; items[9].subtype = 12; items[10].subtype = 12; armorMaterial = ItemMaterial.Silk; break; case EntityClass.Rogue: items[0].subtype = 3; items[0].material = ItemMaterial.Iron; for (int i = 0; i < 2; i++) { items.Add(new Item() { type = ItemType.Weapon, material = ItemMaterial.Iron, modifier = rng.Next(0x7FFFFFFF), rarity = ItemRarity.Legendary, level = (short)players[sender].level }); } items[8].subtype = 4; items[9].subtype = 5; armorMaterial = ItemMaterial.Cotton; break; default: goto case EntityClass.Warrior; } for (int i = 1; i <= 4; i++) { items[i].material = armorMaterial; } items.Add(new Item { type = ItemType.Special, material = ItemMaterial.Wood, }); var drop = new EntityAction { type = ActionType.Drop }; foreach (var that in items) { drop.item = that; drop.Write(writer); } SendMessage("items delivered"); #endregion break; case ".come_here": var port2 = new EntityUpdate { position = players[sender].position, guid = personalGuid }; port2.Write(writer); break; case ".info": case ".help": SendMessage("hi " + players[sender].name + "! I am a computer controlled player, created by Malox and @Blackrock. I can do various stuff, type .commands for more"); break; case ".commands": SendMessage(".info .commands .items .countdown come_here .stun_me .69 .restart .come_here"); break; case ".countdown": Task.Factory.StartNew(Countdown); break; case ".killall": if (chatMessage.message == ".kiLLaLL") { foreach (var p in players.Values) { if (p.guid < 1000 && p.guid > 2) { new EntityUpdate { position = p.position, guid = personalGuid }.Write(writer); Task.Delay(100).Wait(); new Hit { attacker = personalGuid, target = p.guid, damage = 10000f, }.Write(writer); Task.Delay(100).Wait(); } } } else { SendMessage("haha you wish!"); } break; case ".69": new EntityUpdate { position = players[sender].position, guid = personalGuid }.Write(writer); var sixtynine = new Hit { attacker = personalGuid, target = sender, damage = 138f, //-0.2f, critical = true, showlight = true, position = players[sender].position }; for (int i = 0; i < 30; i++) { sixtynine.damage *= -1; sixtynine.Write(writer); Task.Delay(50).Wait(); } break; case ".derp": // ".idontevenknow": if (chatMessage.message == ".dERp") { var tele = new EntityUpdate { position = new LongVector() { z = players[sender].position.z }, guid = personalGuid }; var dropperino = new EntityAction { type = ActionType.Drop, item = new Item() { type = ItemType.PetFood, //1, subtype = 19, //1, material = 0, level = 1, }, }; for (int i = 0; i < 25; i++) { for (int j = 0; j < 25; j++) { tele.position.x = players[sender].position.x + (i * 90000); tele.position.y = players[sender].position.y + (j * 90000); tele.Write(writer); dropperino.Write(writer); } } } else { SendMessage("no permission"); } break; case ".restart": SendMessage("I'll be right back"); throw new Exception(); case ".boost": if (chatMessage.message == ".bOOst") { var dayum = new Hit { attacker = personalGuid, target = sender, damage = -10000f, critical = true, showlight = true, position = players[sender].position }; for (int i = 0; i < 30; i++) { dayum.Write(writer); SendMessage("/firework"); Task.Delay(50).Wait(); } } else { SendMessage("no permission"); } break; case ".ping": SendMessage("pong!"); break; default: break; } if (chatMessage.message.Contains("change") && chatMessage.message.Contains("team") && chatMessage.sender != personalGuid) { SendMessage("./team_join red/blue"); } break; #endregion case 15: #region mapseed var mapSeed = new MapSeed(reader); break; #endregion case 16: #region join var join = new Join(reader); personalGuid = join.guid; var playerstats = new EntityUpdate() { position = new LongVector() { x = 550299161554, //8020800000, y = 550289388106, //8020800000, z = 6296719, }, rotation = new FloatVector(), velocity = new FloatVector(), acceleration = new FloatVector(), extraVel = new FloatVector(), viewportPitch = 0, physicsFlags = 0b00000000_00000000_00000000_00010001, //17 hostility = 0, entityType = EntityType.HumanMale, mode = 0, modeTimer = 0, combo = 0, lastHitTime = 0, appearance = new EntityUpdate.Appearance() { character_size = new FloatVector() { x = 0.9600000381f, y = 0.9600000381f, z = 2.160000086f }, head_model = 1249, hair_model = 1265, hand_model = 431, foot_model = 432, body_model = 1, tail_model = -1, shoulder2_model = -1, wings_model = -1, head_size = 1.00999999f, body_size = 1f, hand_size = 1f, foot_size = 0.9800000191f, shoulder2_size = 1f, weapon_size = 0.9499999881f, tail_size = 0.8000000119f, shoulder_size = 1f, wings_size = 1f, body_offset = new FloatVector() { z = -5f }, head_offset = new FloatVector() { y = 0.5f, z = 5f }, hand_offset = new FloatVector() { x = 6f, }, foot_offset = new FloatVector() { x = 3f, y = 1f, z = -10.5f }, back_offset = new FloatVector() { y = -8f, z = 2f }, }, entityFlags = 0b00000000_00000000_00000000_00100000, //64 roll = 0, stun = 0, slow = 0, ice = 0, wind = 0, showPatchTime = 0, entityClass = EntityClass.Warrior, specialization = 1, charge = 0, unused24 = new FloatVector(), unused25 = new FloatVector(), rayHit = new FloatVector(), HP = 3000f, MP = 0, block = 1, multipliers = new EntityUpdate.Multipliers() { HP = 100, attackSpeed = 1, damage = 1, armor = 1, resi = 1, }, unused31 = 0, unused32 = 0, level = 500, XP = 0, parentOwner = 0, unused36 = 0, powerBase = 0, unused38 = 0, unused39 = new IntVector(), spawnPos = new LongVector(), unused41 = new IntVector(), unused42 = 0, consumable = new Item(), equipment = new Item[13], name = "@BLACK_BOT", skillDistribution = new EntityUpdate.SkillDistribution() { ability1 = 5, ability2 = 5, ability3 = 5, }, manaCubes = 0, }; for (int i = 0; i < 13; i++) { playerstats.equipment[i] = new Item() { }; } var e = playerstats.equipment; e[1].type = ItemType.Amulet; e[1].modifier = 3; e[1].rarity = ItemRarity.Legendary; e[1].material = ItemMaterial.Silver; e[1].level = 647; e[2].type = ItemType.Chest; e[2].modifier = 63; e[2].rarity = ItemRarity.Epic; e[2].material = ItemMaterial.Iron; e[2].level = 647; e[3].type = ItemType.Boots; e[3].modifier = 63; e[3].rarity = ItemRarity.Legendary; e[3].material = ItemMaterial.Iron; e[3].level = 647; e[4].type = ItemType.Gloves; e[4].modifier = 0; e[4].rarity = ItemRarity.Legendary; e[4].material = ItemMaterial.Iron; e[4].level = 647; e[5].type = ItemType.Shoulder; e[5].modifier = 84; e[5].rarity = ItemRarity.Epic; e[5].material = ItemMaterial.Iron; e[5].level = 647; e[6].type = ItemType.Weapon; e[6].subtype = 2; e[6].modifier = -67; e[6].rarity = ItemRarity.Epic; e[6].material = ItemMaterial.Iron; e[6].level = 647; e[7] = e[6]; playerstats.Write(writer); swLasthittime.Start(); players.Add(personalGuid, playerstats); SendMessage("/login " + password); SendMessage("/trail 0 0 0"); SendMessage("online (version 3.4.1)"); break; #endregion case 17: //serving sending the right version if yours is wrong #region version var version = new ProtocolVersion(reader); break; #endregion case 18: #region server full //empty break; #endregion default: Console.WriteLine(string.Format("unknown packet id: {0}", packetid)); break; } }
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 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 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 ProcessClientPacket(int packetID) { switch ((PacketID)packetID) { case PacketID.EntityUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(creader); if (dynamicEntities.ContainsKey(entityUpdate.guid)) { entityUpdate.Filter(dynamicEntities[entityUpdate.guid]); entityUpdate.Merge(dynamicEntities[entityUpdate.guid]); } else { dynamicEntities.Add(entityUpdate.guid, entityUpdate); } if (entityUpdate.name != null) { RefreshPlayerlist(); } if (!entityUpdate.IsEmpty) { SendUDP(entityUpdate.CreateDatagram()); } break; #endregion case PacketID.EntityAction: #region entity action EntityAction entityAction = new EntityAction(creader); switch (entityAction.type) { case ActionType.Talk: #region Talk break; #endregion case ActionType.StaticInteraction: #region StaticInteraction ChatMessage x = new ChatMessage() { message = "You can't use this, your hands are too small.", sender = 0 }; SendToClient(x); break; #endregion case ActionType.PickUp: #region PickUp break; #endregion case ActionType.Drop: //send item back to dropper because dropping is disabled to prevent chatspam #region Drop if (form.radioButtonDestroy.Checked) { SendToClient(new ChatMessage() { message = "item destroyed", sender = 0, }); } 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); } SendToClient(serverUpdate); } break; #endregion case ActionType.CallPet: #region CallPet break; #endregion 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, Direction = hit.direction, Stuntime = hit.stuntime, Skill = hit.isYellow, Type = hit.type, ShowLight = hit.showlight, Critical = hit.critical }; SendUDP(attack.data); lastTarget = attack.Target; break; #endregion case PacketID.PassiveProc: #region passiveProc var passiveProc = new PassiveProc(creader); switch (passiveProc.type) { case ProcType.Bulwalk: SendToClient(new ChatMessage() { message = string.Format("bulwalk: {0}% dmg reduction", 1.0f - passiveProc.modifier), sender = 0, }); break; case ProcType.WarFrenzy: break; case ProcType.Camouflage: break; case ProcType.Poison: break; case ProcType.UnknownA: break; case ProcType.ManaShield: SendToClient(new ChatMessage() { message = string.Format("manashield: {0}", passiveProc.modifier), sender = 0, }); break; case ProcType.UnknownB: break; case ProcType.UnknownC: break; case ProcType.FireSpark: break; case ProcType.Intuition: break; case ProcType.Elusiveness: break; case ProcType.Swiftness: break; default: break; } 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 shoot = new Shoot(creader); var projectile = new Projectile() { Position = shoot.position, Velocity = shoot.velocity, Scale = shoot.scale, Particles = shoot.particles, Type = shoot.projectile, Source = (ushort)shoot.attacker, }; SendUDP(projectile.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 = new Vox("model.vox").Parse(), }; foreach (var block in serverUpdate.blockDeltas) { block.position.x += 0x802080; //(int)(dynamicEntities[guid].position.x / 0x10000);//8286946; block.position.y += 0x802080; //(int)(dynamicEntities[guid].position.y / 0x10000);//8344456; block.position.z += 150; // (int)(dynamicEntities[guid].position.z / 0x10000);//220; } SendToClient(serverUpdate); } if (chatMessage.message.ToLower() == @"/spawn") { CwRam.Teleport(new LongVector() { x = 0x8020800000, y = 0x8020800000, z = 0, }); break; } var chat = new Chat() { Sender = guid, //client doesn't send this Text = chatMessage.message }; 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; SendToClient(version); } else { SendToClient(new Join() { guid = guid, junk = new byte[0x1168] }); SendToClient(new MapSeed() { seed = mapseed }); foreach (var dynamicEntity in dynamicEntities.Values.ToList()) { SendToClient(dynamicEntity); } } break; #endregion default: form.Log("unknown client packet\n", Color.Magenta); 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); } }
public void ProcessDatagram(byte[] datagram, Player source) { switch ((DatagramID)datagram[0]) { case DatagramID.entityUpdate: #region entityUpdate var entityUpdate = new EntityUpdate(datagram); 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 (!source.entityData.IsEmpty) //dont filter the first packet //entityUpdate.Filter(player.entityData); { } if (!entityUpdate.IsEmpty) { //entityUpdate.Broadcast(players, 0); BroadcastUDP(entityUpdate.Data, source); if (entityUpdate.HP == 0 && source.entityData.HP > 0) { BroadcastUDP(Tomb.Show(source).Data); } else if (source.entityData.HP == 0 && entityUpdate.HP > 0) { BroadcastUDP(Tomb.Hide(source).Data); } entityUpdate.Merge(source.entityData); } break; #endregion case DatagramID.attack: #region attack var attack = new Attack(datagram); source.lastTarget = attack.Target; if (players.ContainsKey(attack.Target)) //in case the target is a tombstone { SendUDP(datagram, players[attack.Target]); } break; #endregion case DatagramID.shoot: #region shoot var shoot = new Resources.Datagram.Shoot(datagram); BroadcastUDP(datagram, source); //pass to all players except source break; #endregion case DatagramID.proc: #region proc var proc = new Proc(datagram); switch (proc.Type) { case ProcType.bulwalk: SendUDP(new Chat(string.Format("bulwalk: {0}% dmg reduction", 1.0f - proc.Modifier)).data, source); break; case ProcType.poison: var poisonTickDamage = new Attack() { Damage = proc.Modifier, Target = proc.Target }; var target = players[poisonTickDamage.Target]; Func <bool> tick = () => { bool f = players.ContainsKey(poisonTickDamage.Target); if (f) { SendUDP(poisonTickDamage.data, target); } return(!f); }; Tools.DoLater(tick, 500, 7); //Poison(players[proc.Target], poisonTickDamage); break; case ProcType.manashield: SendUDP(new Chat(string.Format("manashield: {0}", proc.Modifier)).data, source); break; case ProcType.warFrenzy: case ProcType.camouflage: case ProcType.fireSpark: case ProcType.intuition: case ProcType.elusivenes: case ProcType.swiftness: break; default: break; } BroadcastUDP(datagram, source); //pass to all players except source break; #endregion case DatagramID.chat: #region chat var chat = new Chat(datagram); if (chat.Text.StartsWith("/")) { Command.Server(chat.Text, source, this); //wip } else { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(players[chat.Sender].entityData.name + ": "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(chat.Text); BroadcastUDP(datagram, null, true); //pass to all players } break; #endregion case DatagramID.interaction: #region interaction var interaction = new Interaction(datagram); BroadcastUDP(datagram, source); //pass to all players except source break; #endregion case DatagramID.connect: #region connect var connect = new Connect(datagram) { Guid = (ushort)source.entityData.guid, Mapseed = Database.mapseed }; SendUDP(connect.data, source); foreach (Player player in players.Values) { if (player.playing) { SendUDP(player.entityData.Data, source); } } source.playing = true; //Task.Delay(100).ContinueWith(t => Load_world_delayed(source)); //WIP, causes crash when player disconnects before executed Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(source.IpEndPoint.Address + " is now playing"); break; #endregion case DatagramID.disconnect: #region disconnect var disconnect = new Disconnect(datagram); source.playing = false; BroadcastUDP(datagram, source, true); source.entityData = new EntityUpdate() { guid = source.entityData.guid }; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(source.IpEndPoint.Address + " is now lurking"); break; #endregion case DatagramID.specialMove: #region specialMove var specialMove = new SpecialMove(datagram); switch (specialMove.Id) { case SpecialMoveID.taunt: var targetGuid = specialMove.Guid; specialMove.Guid = (ushort)source.entityData.guid; SendUDP(specialMove.data, players[targetGuid]); break; case SpecialMoveID.cursedArrow: case SpecialMoveID.arrowRain: case SpecialMoveID.shrapnel: case SpecialMoveID.smokeBomb: case SpecialMoveID.iceWave: case SpecialMoveID.confusion: case SpecialMoveID.shadowStep: BroadcastUDP(specialMove.data, source); break; default: break; } break; #endregion case DatagramID.dummy: break; default: Console.WriteLine("unknown DatagramID: " + datagram[0]); break; } }
static void ProcessPacket(int packetid) { switch (packetid) { case 0: #region entityUpdate var entityUpdate = new EntityUpdate(reader); if (players.ContainsKey(entityUpdate.guid)) { entityUpdate.Merge(players[entityUpdate.guid]); } else { players.Add(entityUpdate.guid, entityUpdate); } if (players[entityUpdate.guid].name == "malox") { maloxGuid = entityUpdate.guid; var x = players[entityUpdate.guid].position.x - players[personalGuid].position.x; var y = players[entityUpdate.guid].position.y - players[personalGuid].position.y; double distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)); if (distance > 65536 * 40) { var follow = new EntityUpdate { position = players[entityUpdate.guid].position, guid = personalGuid }; follow.Write(writer); } if (entityUpdate.modeTimer < 50) { var shoot = new Shoot() { attacker = personalGuid, chunkX = (int)players[personalGuid].position.x / 0x1000000, chunkY = (int)players[personalGuid].position.y / 0x1000000, position = players[personalGuid].position, particles = 1f, mana = 1f, scale = 1f, projectile = 0, }; shoot.position.x = players[maloxGuid].position.x + (long)(players[maloxGuid].rayHit.x * 0x10000); shoot.position.y = players[maloxGuid].position.y + (long)(players[maloxGuid].rayHit.y * 0x10000); shoot.position.z = players[maloxGuid].position.z + (long)((players[maloxGuid].rayHit.z + 15) * 0x10000); shoot.velocity.z = -40f; //shoot.velocity.x = (float)players[maloxGuid].position.x / 0x10000f + players[maloxGuid].rayHit.x - (float)players[personalGuid].position.x / 0x10000f; //shoot.velocity.y = (float)players[maloxGuid].position.y / 0x10000f + players[maloxGuid].rayHit.y - (float)players[personalGuid].position.y / 0x10000f; //shoot.velocity.z = (float)players[maloxGuid].position.z / 0x10000f + players[maloxGuid].rayHit.z - (float)players[personalGuid].position.z / 0x10000f; int range = 20; shoot.position.x -= (range - 1) / 2 * 0x10000; shoot.position.y -= (range - 1) / 2 * 0x10000; for (int i = 0; i < range; i++) { for (int j = 0; j < range; j++) { shoot.Write(writer); shoot.position.x += 0x10000; } shoot.position.x -= range * 0x10000; shoot.position.y += 0x10000; } } } break; #endregion case 2: #region complete new EntityUpdate() { lastHitTime = (int)stopWatch.ElapsedMilliseconds }.Write(writer); break; #endregion case 4: #region serverupdate var serverUpdate = new ServerUpdate(reader); foreach (var hit in serverUpdate.hits) { if (hit.target == personalGuid) { stopWatch.Restart(); players[personalGuid].HP -= hit.damage; var life = new EntityUpdate() { HP = players[personalGuid].HP, }; life.Write(writer); if (players[personalGuid].HP <= 0) { life.HP = 1623f; life.Write(writer); } } } break; #endregion case 5: #region time var time = new Time(reader); break; #endregion case 10: #region chat var chatMessage = new ChatMessage(reader, true); if (chatMessage.sender == 0) { Console.ForegroundColor = ConsoleColor.DarkGray; } else { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(players[chatMessage.sender].name + ": "); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(chatMessage.message); if (chatMessage.message == "!give_me_items") { var port = new EntityUpdate { position = players[chatMessage.sender].position, guid = personalGuid }; port.Write(writer); players[personalGuid].position = port.position; var items = new List <Item>(); var rng = new Random(); for (byte i = 3; i <= 9; i++) { items.Add(new Item() { type = i, modifier = rng.Next(0x7FFFFFFF), rarity = 4, level = (short)players[chatMessage.sender].level }); } items[5].material = (byte)rng.Next(11, 12); items[6].material = (byte)rng.Next(11, 12); items.Add(items[6]); byte armorMaterial; switch (players[chatMessage.sender].entityClass) { case 0: //warrior //items[0].subtype = 0; items[0].material = 1; for (int i = 0; i < 6; i++) { items.Add(new Item() { type = 3, material = 1, modifier = rng.Next(0x7FFFFFFF), rarity = 4, level = (short)players[chatMessage.sender].level }); } items[8].subtype = 1; items[9].subtype = 2; items[10].subtype = 13; items[11].subtype = 15; items[12].subtype = 16; items[13].subtype = 17; armorMaterial = 1; break; case 1: //mage items[0].subtype = 10; items[0].material = 2; for (int i = 0; i < 3; i++) { items.Add(new Item() { type = 3, material = (byte)rng.Next(11, 12), modifier = rng.Next(0x7FFFFFFF), rarity = 4, level = (short)players[chatMessage.sender].level }); } items[8].subtype = 11; items[8].material = 2; items[9].subtype = 12; items[10].subtype = 12; armorMaterial = 25; break; case 2: //ranger items[0].subtype = 6; items[0].material = 2; for (int i = 0; i < 2; i++) { items.Add(new Item() { type = 3, material = 2, modifier = rng.Next(0x7FFFFFFF), rarity = 4, level = (short)players[chatMessage.sender].level }); } items[8].subtype = 7; items[9].subtype = 8; armorMaterial = 26; break; case 3: //rogue items[0].subtype = 3; items[0].material = 1; for (int i = 0; i < 2; i++) { items.Add(new Item() { type = 3, material = 1, modifier = rng.Next(0x7FFFFFFF), rarity = 4, level = (short)players[chatMessage.sender].level }); } items[8].subtype = 4; items[9].subtype = 5; armorMaterial = 27; break; default: goto case 0; } for (int i = 1; i <= 4; i++) { items[i].material = armorMaterial; } foreach (var that in items) { var drop = new EntityAction { type = (int)Database.ActionType.drop, item = that }; drop.Write(writer); } //item = new Item { // type = 3, // 3 = weapon // rarity = 4, // 4 = legendary // level = 647, // material = 1 //} } else if (chatMessage.message == "!come_here") { var port = new EntityUpdate { position = players[chatMessage.sender].position, guid = personalGuid }; port.Write(writer); } break; #endregion case 15: #region mapseed var mapSeed = new MapSeed(reader); break; #endregion case 16: #region join var join = new Join(reader); personalGuid = join.guid; var playerstats = new EntityUpdate() { position = new LongVector(), rotation = new FloatVector(), velocity = new FloatVector(), acceleration = new FloatVector(), extraVel = new FloatVector(), viewportPitch = 0, physicsFlags = 0b00000000_00000000_00000000_00010001, //17 hostility = 0, entityType = 0, mode = 0, modeTimer = 0, combo = 0, lastHitTime = 0, appearance = new Appearance() { character_size = new FloatVector() { x = 0.9600000381f, y = 0.9600000381f, z = 2.160000086f }, head_model = 1236, hair_model = 1280, hand_model = 430, foot_model = 432, body_model = 1, tail_model = -1, shoulder2_model = -1, wings_model = -1, head_size = 1.00999999f, body_size = 1f, hand_size = 1f, foot_size = 0.9800000191f, shoulder2_size = 1f, weapon_size = 0.9499999881f, tail_size = 0.8000000119f, shoulder_size = 1f, wings_size = 1f, body_offset = new FloatVector() { z = -5f }, head_offset = new FloatVector() { y = 0.5f, z = 5f }, hand_offset = new FloatVector() { x = 6f, }, foot_offset = new FloatVector() { x = 3f, y = 1f, z = -10.5f }, back_offset = new FloatVector() { y = -8f, z = 2f }, }, entityFlags = 0b00000000_00000000_00000000_00100000, //64 roll = 0, stun = 0, slow = 0, ice = 0, wind = 0, showPatchTime = 0, entityClass = 2, specialization = 0, charge = 0, unused24 = new FloatVector(), unused25 = new FloatVector(), rayHit = new FloatVector(), HP = 1623f, MP = 0, block = 1, multipliers = new Multipliers() { HP = 100, attackSpeed = 1, damage = 1, armor = 1, resi = 1, }, unused31 = 0, unused32 = 0, level = 500, XP = 0, parentOwner = 0, unused36 = 0, powerBase = 0, unused38 = 0, unused39 = new IntVector(), spawnPos = new LongVector(), unused41 = new IntVector(), unused42 = 0, consumable = new Item(), equipment = new Item[13], name = "ET_bot", skillDistribution = new SkillDistribution() { ability1 = 5, ability2 = 5, ability3 = 5, }, manaCubes = 0, }; for (int i = 0; i < 13; i++) { playerstats.equipment[i] = new Item(); } playerstats.Write(writer); stopWatch.Start(); players.Add(personalGuid, playerstats); break; #endregion case 17: //serving sending the right version if yours is wrong #region version var version = new ProtocolVersion(reader); break; #endregion case 18: #region server full //empty break; #endregion default: Console.WriteLine(string.Format("unknown packet id: {0}", packetid)); break; } }