public static void ClientReadyHandler(ZoneClient client, Packet packet) { if (client.Admin > 0) { client.Character.DropMessage("AdminLevel = {0}; ClientLoad = {1};", client.Admin, ClientManager.Instance.ZoneLoad); } Handler4.SendUsablePoints(client); if (!client.Character.IsDead) { // Just logged on. client.Character.Map.FinalizeAdd(client.Character); } else { // Reviving, not readding for this one! MapInfo mi; if (DataProvider.Instance.MapsByID.TryGetValue(client.Character.MapID, out mi)) { client.Character.State = PlayerState.Normal; client.Character.Map.SendCharacterLeftMap(client.Character, false); client.Character.Position.X = mi.RegenX; client.Character.Position.Y = mi.RegenY; client.Character.Map.SendCharacterEnteredMap(client.Character); } client.Character.SetHP(client.Character.MaxHP / 4); } }
public static void HandleSetStatPoint(ZoneClient client, Packet packet) { byte stat; if (!packet.TryReadByte(out stat)) { Log.WriteLine(LogLevel.Warn, "Couldn't read HandleSetStatPoint packet. {0}", client); return; } if (client.Character.character.UsablePoints == 0) { Log.WriteLine(LogLevel.Warn, "User tried to set stat point while not having any left. {0}", client); } else { // LETS DO ET switch (stat) { case 0: client.Character.Str++; break; case 1: client.Character.Dex++; break; case 2: client.Character.End++; break; case 3: client.Character.Int++; break; case 4: client.Character.Spr++; break; default: { Log.WriteLine(LogLevel.Warn, "User tried to set stat point on unknown stat {0} {1}", stat, client); return; } } client.Character.character.UsablePoints--; Program.Entity.SaveChanges(); SendSetUsablePoint(client, stat); } }
public static void SendPing(ZoneClient character) { using (var packet = new Packet(SH2Type.Ping)) { character.SendPacket(packet); } }
public static void EquipHandler(ZoneClient client, Packet packet) { sbyte slot; if (!packet.TryReadSByte(out slot)) { Log.WriteLine(LogLevel.Warn, "Error reading equipping slot."); return; } Item item; if (client.Character.InventoryItems.TryGetValue(slot, out item)) { if (item is Equip) { if (((Equip)item).Info.Level > client.Character.Level) { FailedEquip(client.Character, 645); // 85 02 } else { client.Character.EquipItem((Equip)item); } } else { FailedEquip(client.Character); Log.WriteLine(LogLevel.Warn, "{0} equippped an item. What a moron.", client.Character.Name); } } }
public static void DeselectObjectHandler(ZoneClient client, Packet packet) { if (client.Character.SelectedObject != null) { client.Character.SelectedObject.SelectedBy.Remove(client.Character); client.Character.SelectedObject = null; } }
public static void SendError(ZoneClient client, ServerError error) { using (Packet pack = new Packet(SH3Type.Error)) { pack.WriteShort((byte)error); client.SendPacket(pack); } }
public static void DropItemHandler(ZoneClient client, Packet packet) { sbyte slot; if (!packet.TryReadSByte(out slot)) { Log.WriteLine(LogLevel.Warn, "Invalid drop request."); return; } client.Character.DropItemRequest(slot); }
public static void EnhancementHandler(ZoneClient client, Packet packet) { sbyte weapslot, stoneslot; if (!packet.TryReadSByte(out weapslot) || !packet.TryReadSByte(out stoneslot)) { Log.WriteLine(LogLevel.Warn, "Invalid item enhance request."); return; } client.Character.UpgradeItem(weapslot, stoneslot); }
public static void HandleReviveToTown(ZoneClient character, Packet packet) { if (character.Character.IsDead) { // Lets revive. MapInfo mi; if (DataProvider.Instance.MapsByID.TryGetValue(character.Character.MapID, out mi)) { SendRevive(character, mi.ID, mi.RegenX, mi.RegenY); // Will resend the loaded packet } } }
public static void AttackSkillHandler(ZoneClient client, Packet packet) { ushort skill; if (!packet.TryReadUShort(out skill)) { Log.WriteLine(LogLevel.Warn, "Could not read skillID from attack entity skill function. {0}", client); return; } if (!client.Character.SkillsActive.ContainsKey(skill)) { Log.WriteLine(LogLevel.Warn, "User tried to attack with a wrong skill. {0} {1} ", skill, client); return; } client.Character.AttackSkill(skill, null); }
public static void questionHandler(ZoneClient client, Packet packet) { byte answer; if (!packet.TryReadByte(out answer)) { Log.WriteLine(LogLevel.Warn, "Received invalid question response."); return; } ZoneCharacter character = client.Character; if (character.Question == null) return; else if (character.Question.Answers.Count <= answer) return; character.Question.Function(character, answer); character.Question = null; }
public static void UseSPStoneHandler(ZoneClient client, Packet packet) { if (client.Character.StonesSP == 0) { using (var p = new Packet(SH20Type.ErrorUseStone)) { client.SendPacket(p); } } else { client.Character.HealSP((uint)client.Character.BaseStats.SoulSP); using (var p = new Packet(SH20Type.StartSPStoneCooldown)) { client.SendPacket(p); } } }
public static void EmoteHandler(ZoneClient client, Packet packet) { ZoneCharacter character = client.Character; byte action; if (!packet.TryReadByte(out action)) { Log.WriteLine(LogLevel.Warn, "{0} did empty emote.", character.Name); return; } if (action > 74) { character.CheatTracker.AddCheat(CheatTypes.EMOTE, 500); return; } using (var broad = Animation(character, action)) { character.Broadcast(broad, true); } }
public bool AddClient(ZoneClient client) { if (client.Character == null) { Log.WriteLine(LogLevel.Warn, "ClientManager trying to add character = null.", client.Username); return false; } else if (clientsByName.ContainsKey(client.Character.Name)) { Log.WriteLine(LogLevel.Warn, "Character {0} is already registered to client manager!", client.Character.Name); return false; } else { if (!clientsByName.TryAdd(client.Character.Name, client)) { Log.WriteLine(LogLevel.Warn, "Could not add client to list!"); return false; } } return true; }
public static void BeginInteractionHandler(ZoneClient client, Packet packet) { ushort entityid; if (!packet.TryReadUShort(out entityid)) { Log.WriteLine(LogLevel.Warn, "Error reading interaction attempt."); return; } ZoneCharacter character = client.Character; MapObject obj; if (character.Map.Objects.TryGetValue(entityid, out obj)) { NPC npc = obj as NPC; if (npc != null) { if (npc.Gate != null) { MapInfo mi = null; if (DataProvider.Instance.MapsByName.TryGetValue(npc.Gate.MapServer, out mi)) { Question q = new Question(string.Format("Do you want to move to {0} field?", mi.FullName), new QuestionCallback(AnswerOnGateQuestion), npc); q.Add("Yes", "No"); q.Send(character, 500); character.Question = q; } else { character.DropMessage("You can't travel to this place."); } } else { SendNPCInteraction(client, npc.ID); } } } else Log.WriteLine(LogLevel.Warn, "{0} selected invalid object.", character.Name); }
public static void SelectObjectHandler(ZoneClient client, Packet packet) { ushort id; if (!packet.TryReadUShort(out id)) { Log.WriteLine(LogLevel.Warn, "Could not read entity select request."); return; } MapObject mo; // Try to see if there is a map object with this ID if (!client.Character.Map.Objects.TryGetValue(id, out mo)) { return; // Nothing found. Just return lawl } mo.SelectedBy.Add(client.Character); if (mo is ZoneCharacter || mo is Mob) { client.Character.SelectedObject = mo; SendStatsUpdate(mo, client, false); } }
public static void TransferKeyHandler(ZoneClient client, Packet packet) { ushort randomID; string characterName, checksums; //TODO: check in securityclient if (!packet.TryReadUShort(out randomID) || !packet.TryReadString(out characterName, 16) || !packet.TryReadString(out checksums, 832)) { Log.WriteLine(LogLevel.Warn, "Invalid game transfer."); return; } ClientTransfer transfer = ClientManager.Instance.GetTransfer(characterName); if (transfer == null || transfer.HostIP != client.Host || transfer.RandID != randomID) { Log.WriteLine(LogLevel.Warn, "{0} tried to login without a valid client transfer.", client.Host); //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS); Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching); return; } try { ClientManager.Instance.RemoveTransfer(characterName); ZoneCharacter character = new ZoneCharacter(characterName); if (character.AccountID != transfer.AccountID) { Log.WriteLine(LogLevel.Warn, "Character is logging in with wrong account ID."); Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching); //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS); return; } client.Authenticated = true; client.Admin = transfer.Admin; client.AccountID = transfer.AccountID; client.Username = transfer.Username; client.Character = character; character.Client = client; if (ClientManager.Instance.AddClient(client)) { character.SendGetIngameChunk(); //TODO: world server notification over WCF? Log.WriteLine(LogLevel.Debug, "{0} logged in successfully!", character.Name); } } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Error loading character {0}: {1} - {2}", characterName, ex.ToString(), ex.StackTrace); Handler4.SendConnectError(client, ConnectErrors.ErrorInCharacterInfo); } }
public static void UseSkillWithTargetHandler(ZoneClient client, Packet packet) { ushort skillid, victimid; if (!packet.TryReadUShort(out skillid) || !packet.TryReadUShort(out victimid)) { Log.WriteLine(LogLevel.Warn, "Couldn't read useskill packet {0}", client); return; } Skill skill; if (!client.Character.SkillsActive.TryGetValue(skillid, out skill)) { Log.WriteLine(LogLevel.Warn, "User tried to use a wrong skill. {0} {1} ", skillid, client); return; } MapObject victim; if (!client.Character.MapSector.Objects.TryGetValue(victimid, out victim)) { Log.WriteLine(LogLevel.Warn, "User tried to do something with an unknown victim. {0} {1} {2}", skillid, victimid, client); } var self = client.Character; if (skill.Info.DemandType == 6) { if (!(victim is ZoneCharacter)) return; var zc = victim as ZoneCharacter; // Only Heal has this // Some heal calculation here uint amount = 12 * (uint)Program.Randomizer.Next(1, 300); //lulz if (amount > victim.MaxHP - victim.HP) { amount = victim.MaxHP - victim.HP; } zc.HP += amount; ushort id = self.UpdateCounter; SendSkillStartSelf(self, skillid, victimid, id); SendSkillStartOthers(self, skillid, victimid, id); SendSkillOK(self); SendSkillAnimationForPlayer(self, skillid, id); // Damage as heal val :D SendSkill(self, id, victimid, amount, zc.HP, zc.UpdateCounter); } else { if (!(victim is Mob)) return; uint dmgmin = (uint)self.GetWeaponDamage(true); uint dmgmax = (uint)(self.GetWeaponDamage(true) + (self.GetWeaponDamage(true) % 3)); uint amount = (uint)Program.Randomizer.Next((int)dmgmin, (int)dmgmax); if (amount > victim.HP) { victim.HP = 0; } else { victim.HP -= amount; } ushort id = self.UpdateCounter; SendSkillStartSelf(self, skillid, victimid, id); SendSkillStartOthers(self, skillid, victimid, id); SendSkillOK(self); SendSkillAnimationForPlayer(self, skillid, id); SendSkill(self, id, victimid, amount, victim.HP, victim.UpdateCounter, 0x01, 0x01); if (!victim.IsDead) { victim.Attack(self); } } }
public static void SendConnectError(ZoneClient client, ConnectErrors error) { using (var packet = new Packet(SH4Type.ConnectError)) { packet.WriteUShort((ushort)error); client.SendPacket(packet); } }
public static void StopAttackMeleeHandler(ZoneClient client, Packet packet) { client.Character.AttackStop(); }
public static void UseSkillWithPositionHandler(ZoneClient client, Packet packet) { ushort skillid; uint x, y; if (!packet.TryReadUShort(out skillid) || !packet.TryReadUInt(out x) || !packet.TryReadUInt(out y)) { Log.WriteLine(LogLevel.Warn, "Couldn't read UseSkillWithPosition packet. {0} ", client); return; } Skill skill; if (!client.Character.SkillsActive.TryGetValue(skillid, out skill)) { Log.WriteLine(LogLevel.Warn, "User tried to use a wrong skill. {0} {1} ", skillid, client); return; } var self = client.Character; var block = self.Map.Block; if (x == 0 || y == 0 || x > block.Width || y > block.Height) { Log.WriteLine(LogLevel.Warn, "User tried to use skill out of map boundaries. {0} {1} {2} {3}", x, y, skillid, client); return; } var pos = new Vector2((int)x, (int)y); if (skill.Info.MaxTargets <= 1) { // No AoE skill :s Log.WriteLine(LogLevel.Warn, "User tried to use skill with no MaxTargets or less than 1. {0} {1}", skillid, client); return; } self.AttackSkillAoE(skillid, x, y); }
public static void SendRevive(ZoneClient client, ushort mapid, int x, int y) { using (var packet = new Packet(SH4Type.Revive)) { packet.WriteUShort(mapid); packet.WriteInt(x); packet.WriteInt(y); client.SendPacket(packet); } }
public static void SendStatsUpdate(MapObject pObject, ZoneClient to, bool selectedby) { using (var packet = new Packet(SH9Type.StatUpdate)) { packet.WriteBool(selectedby); packet.WriteUShort(pObject.MapObjectID); if (pObject is ZoneCharacter) { ((ZoneCharacter)pObject).WriteUpdateStats(packet); } else { ((Mob)pObject).WriteUpdateStats(packet); } to.SendPacket(packet); } }
public static void SendReviveWindow(ZoneClient client, byte minutesTillExpire) { using (var packet = new Packet(SH4Type.ReviveWindow)) { packet.WriteByte(minutesTillExpire); // It's not a short, the byte after it is buffershit client.SendPacket(packet); } }
public static void AttackMeleeHandler(ZoneClient client, Packet packet) { client.Character.Attack(null); }
public static void HandlePong(ZoneClient character, Packet packet) { character.HasPong = true; }
public static void SendSetUsablePoint(ZoneClient client, byte stat) { using (var packet = new Packet(SH4Type.SetPointOnStat)) { packet.WriteByte(stat); // amount client.SendPacket(packet); } }
public void RemoveClient(ZoneClient client) { if(client.Character == null) return; ZoneClient deleted; clientsByName.TryRemove(client.Character.Name, out deleted); if (deleted != client) { Log.WriteLine(LogLevel.Warn, "There was a duplicate client object registered for {0}.", client.Character.Name); } }
public static void HandleUnknown(ZoneClient client, Packet packet) { // I have no idea what this does... Maybe some aggro request? }
public static void SendUsablePoints(ZoneClient client) { using (var packet = new Packet(SH4Type.CharacterPoints)) { packet.WriteByte(client.Character.character.UsablePoints); client.SendPacket(packet); } }