internal static void OnPlayerChat(Player player, byte requestId, byte type, string target, string message) { if (message.StartsWith("//")) { // Message is a command // TODO : This should be better parsed and // requires permission checks message = message.TrimStart('/'); // pars[0] = Command // pars[1..n] = parameters string[] pars = message.Split(' '); switch (pars[0]) { case "item": break; case "monster": int mobId = Int32.Parse(pars[1]); Monster.SpawnMonster(mobId, player.Position); break; case "set": break; } } else { // It's a common message ClientPacketHandler.send_Chat(player, type, message, target); } }
internal void UnequipItem(int wearType) { uint handle = this.Equip[wearType]; if (handle == 0) { ConsoleUtils.Write(ConsoleMsgType.Error, "Trying to unequip inexistant item."); return; } this.Equip[wearType] = 0; ClientPacketHandler.send_WearChange(this, handle, -1, this.Inventory[handle].Enhance); if (Stats.PCCalculate(this)) { ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); } ClientPacketHandler.send_Property(this, "max_havoc", Globals.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", Globals.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", Globals.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x00C9); ClientPacketHandler.send_CharacterView(this); }
internal void EquipItem(int wearType, uint itemHandle) { if (!this.Inventory.ContainsKey(itemHandle)) { ConsoleUtils.Write(ConsoleMsgType.Error, "Trying to access invalid handle in player inventory.\n"); return; } Item i = this.Inventory[itemHandle]; this.Equip[(int)i.WearInfo] = itemHandle; ClientPacketHandler.send_WearChange(this, itemHandle, (short)i.WearInfo, this.Inventory[itemHandle].Enhance); if (Stats.PCCalculate(this)) { ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); } ClientPacketHandler.send_Property(this, "max_havoc", Globals.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", Globals.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", Globals.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x00C8); ClientPacketHandler.send_CharacterView(this); }
internal static void OnUserJoinGame(Player player, string charName) { ClientPacketHandler.send_UrlList(player, UrlList); if (!player.LoadCharacter(charName)) { return; } }
/// <summary> /// Sets the character's position /// </summary> /// <param name="jobLv"></param> private void SetPosition(float x, float y, byte layer) { this.Position = new Point(x, y); this.Layer = layer; ClientPacketHandler.send_Property(this, "x", 0, true, this.Position.X.ToString()); ClientPacketHandler.send_Property(this, "y", 0, true, this.Position.Y.ToString()); ClientPacketHandler.send_Property(this, "layer", 0, true, this.Layer.ToString()); }
internal static void PcWalkCheck(Player player, float startX, float startY, Point[] movePos) { if (!Settings.CheckCollision) { ClientPacketHandler.send_PCMoveTo(player, movePos.ToArray()); return; } //ConsoleUtils.Write(ConsoleMsgType.Debug, "[Debug Move] startX: {0} ; startY: {1} ; Points: {2}\n", startX, startY, movePos.Length); //for (int i = 0; i < movePos.Length; i++) // ConsoleUtils.Write(ConsoleMsgType.Debug, "--> MovePos[{0}]: ( {1}, {2} )\n", i, (int)movePos[i].X, (int)movePos[i].Y); List <Point> moves = new List <Point>(); int mapX = 10; int mapY = 3; bool endOfTest = false; for (int i = 0; i < movePos.Length; i++) { int fromX, fromY; if (i == 0) { fromX = (int)startX; fromY = (int)startY; } else { fromX = (int)movePos[i - 1].X; fromY = (int)movePos[i - 1].Y; } Map m = Maps[mapX][mapY]; for (int j = 0; j < m.Collisions.Length; j++) { if (Geometry.DoIntersect(new Point(fromX, fromY), movePos[i], m.Collisions[j].P1, m.Collisions[j].P2)) { //ConsoleUtils.Write(ConsoleMsgType.Debug, "Intersects with ({0}, {1}) ({2}, {3})!\n", (int)m.Collisions[j].P1.X, (int)m.Collisions[j].P1.Y, (int)m.Collisions[j].P2.X, (int)m.Collisions[j].P2.Y); endOfTest = true; break; } } if (endOfTest) { break; } else { //ConsoleUtils.Write(ConsoleMsgType.Debug, "OK! ( {0}, {1} )\n", movePos[i].X, movePos[i].Y); moves.Add(movePos[i]); } } //Console.Write("End of Move Process\n"); ClientPacketHandler.send_PCMoveTo(player, moves.ToArray()); }
internal static void OnUserJoin(Player player, string userId, byte[] key) { if (!UserJoinPool.ContainsKey(userId) || !UserJoinPool[userId].Key.SequenceEqual(key)) { // TODO : Invalid User - disconect Console.Write("User Authentication Failed\n"); return; } player.UserId = userId; player.AccountId = UserJoinPool[userId].AccountId; player.Permission = UserJoinPool[userId].Permission; UserJoinPool.Remove(userId); ClientPacketHandler.send_PacketResponse(player, 0x07D5); }
internal void Update() { lock (this) { // Note : This method is not really good int movSpd = 10; int deltaTime = (Environment.TickCount); deltaTime -= this.LastUpdate; float toX = this.Position.X + (new Random().Next(-movSpd * deltaTime, movSpd * deltaTime) / 1000); float toY = this.Position.Y + (new Random().Next(-movSpd * deltaTime, movSpd * deltaTime) / 1000); this.LastUpdate = Environment.TickCount; ClientPacketHandler.send_PCMoveTo(this, new Point(toX, toY)); } }
/// <summary> /// Tries to Level UP character Job /// </summary> internal void JobLevelUp() { int reqJp = 0; switch (JobId2Depth(this.Job)) { case Db.JobDepth.Basic: reqJp = Jp0Table[this.JobLevel]; break; case Db.JobDepth.First: reqJp = Jp1Table[this.JobLevel]; break; case Db.JobDepth.Second: reqJp = Jp2Table[this.JobLevel]; break; case Db.JobDepth.Master: reqJp = Jp3Table[this.JobLevel]; break; } if (reqJp <= 0) // Max level reached { return; } else if (this.JP < reqJp) // Not enough JP { return; } this.JP -= reqJp; this.JobLevel++; ClientPacketHandler.send_Property(this, "jp", this.JP); ClientPacketHandler.send_Property(this, "job_level", this.JobLevel); ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_PacketResponse(this, 0x019A, 0, this.Handle); }
private static void OnRegionChange(Player player, uint newRX, uint newRY) { Region r = Regions[newRX + (player.RegionX - newRX) * 1][newRY + (player.RegionY - newRY) * 1]; if (r != null) { for (int i = 0; i < r.Npcs.Count; i++) { ClientPacketHandler.send_EntityAck(GObjectManager.Npcs[r.Npcs[i]]); ClientPacketHandler.send_EntityState(player, GObjectManager.Npcs[r.Npcs[i]].Handle, 0x0); ClientPacketHandler.send_Packet516(player, GObjectManager.Npcs[r.Npcs[i]].Handle); } } player.RegionX = newRX; player.RegionY = newRY; ClientPacketHandler.send_RegionAck(player, newRX, newRY); }
/// <summary> /// Deletes a character form an account /// </summary> /// <param name="charName">the name of the character to delete</param> internal void DeleteCharacter(string charName) { Database db = new Database(Server.UserDbConString); int r = db.DeleteQuery( "DELETE FROM `char` WHERE `account_id` = @accId AND `name` = @charName", new string[] { "accId", "charName" }, new object[] { this.AccountId, charName } ); if (r > 0) { ClientPacketHandler.send_PacketResponse(this, 0x07D3, 0); } else { ClientPacketHandler.send_PacketResponse(this, 0x07D3, 1); } }
/// <summary> /// Checks if a character name is already in use /// </summary> /// <param name="name">the name to be checked</param> internal void CharNameExists(string name) { Database db = new Database(Server.UserDbConString); MySqlDataReader reader = db.ReaderQuery( "SELECT `char_id` " + "FROM `char` " + "WHERE `name` = @name " + "LIMIT 0,1", new string[] { "@name" }, new object[] { name } ); if (reader.Read()) { // Character exists ClientPacketHandler.send_PacketResponse(this, (short)0x07D6, 1); } else { // Character doesn't exists ClientPacketHandler.send_PacketResponse(this, (short)0x07D6); } }
private void PacketReceived(Player p, PacketStream data) { ClientPacketHandler.PacketReceived(p, data); }
internal static void AddMobToRegion(Monster mob) { GetRegion(mob.Position.X, mob.Position.Y).Monsters.Add(mob.Handle); ClientPacketHandler.send_EntityAck(mob); }
public NetworkManager() { ServerPacketHandler.Start(); ClientPacketHandler.Start(); }
public static void LevelUp(GameObject obj, int skillId, byte targetLv) { if (!SkillDb.DB.ContainsKey(skillId)) // Skill doesn't exists { return; } if (obj.Type == GameObjectType.Player) { Player player = (Player)obj; short curLevel = 0; bool haveSkill = false; if (player.SkillList.ContainsKey(skillId)) { curLevel = player.SkillList[skillId].Level; haveSkill = true; } int jpCost = SkillDb.DB[skillId].RequiredJp[targetLv]; if (jpCost > player.JP) { return; } player.JP -= jpCost; if (haveSkill) { Database db = new Database(Server.UserDbConString); player.SkillList[skillId].Level = targetLv; db.WriteQuery( "UPDATE `skill` SET `level` = @level WHERE `char_id` = @cid AND `id` = @skid", new string[] { "level", "cid", "skid" }, new object[] { player.SkillList[skillId].Level, player.CharId, skillId } ); } else { Skill skill = new Skill() { Id = skillId, Level = targetLv, TotalCooldown = SkillDb.DB[skillId].CooldownTime }; Database db = new Database(Server.UserDbConString); player.SkillList.Add(skillId, skill); db.WriteQuery( "INSERT INTO `skill` (`char_id`, `id`, `level`) VALUES (@cid, @skid, @level)", new string[] { "level", "cid", "skid" }, new object[] { player.SkillList[skillId].Level, player.CharId, skillId } ); } ClientPacketHandler.send_Property(player, "tp", player.TP); ClientPacketHandler.send_UpdateExp(player); //ClientPacketHandler.send_UpdateStats(this, false); //ClientPacketHandler.send_UpdateStats(this, true); //ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); //ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); //ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_SkillList(player, new Skill[] { player.SkillList[skillId] }); ClientPacketHandler.send_PacketResponse(player, 0x0192, 0, (uint)skillId); } }
/// <summary> /// Loads a character data /// </summary> /// <param name="charName">the name of the character</param> /// <returns>true on success, false otherwise</returns> internal bool LoadCharacter(string charName) { Database db = new Database(Server.UserDbConString); // TODO : Query CleanUP MySqlDataReader reader = db.ReaderQuery( "SELECT `char_id`,`slot`,`sex`,`race`," + "`hair_id`,`face_id`,`body_id`,`hands_id`,`feet_id`," + "`face_detail_id`,`hair_color`,`skin_color`,`x`,`y`,`layer`," + "`save_x`,`save_y`,`level`,`exp`,`job`,`job_level`, `client_info`," + "`jp`" + " FROM `char`" + " WHERE `account_id` = @accId AND `name` = @name AND `delete_date`= 0", new string[] { "accId", "name" }, new object[] { this.AccountId, charName } ); if (!reader.Read()) { // Character not in account ConsoleUtils.Write(ConsoleMsgType.Warning, "User trying to get a character that is not in his account.\n"); return(false); } this.MaxStamina = Globals.MaxStamina; this.MaxChaos = 0; this.MaxHavoc = 0; this.Gold = 0; this.Chaos = 0; this.TP = 0; this.HairColor = (int)reader["hair_color"]; this.HairId = (int)reader["hair_id"]; this.FaceId = (int)reader["face_id"]; this.BodyId = (int)reader["body_id"]; this.HandsId = (int)reader["hands_id"]; this.FeetId = (int)reader["feet_id"]; this.Name = charName; this.Race = (Races)(int)reader["race"]; this.Sex = (int)reader["sex"]; // TODO : FIX this.SkinColor = (uint)(int)reader["skin_color"]; this.CharId = (int)reader["char_id"]; this.Position = new Point((int)reader["x"], (int)reader["y"]); this.Layer = (byte)(int)reader["layer"]; this.ClientInfo = (string)reader["client_info"]; this.LoadQuest(); this.RegionX = RegionMngr.GetRegionX(this.Position.X); this.RegionY = RegionMngr.GetRegionY(this.Position.Y); //==== Character level/job/skills/buffs loading this.Level = (int)reader["level"]; this.Job = (short)reader["job"]; this.JobLevel = (int)reader["job_level"]; this.JP = (long)reader["jp"]; this.LoadInventory(); this.LoadSummons(); this.LoadStats(); this.LoadSkills(); // TODO Most of these packets probably can be placed in their own methods ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); ClientPacketHandler.send_Property(this, "max_havoc", this.MaxHavoc); ClientPacketHandler.send_Property(this, "max_chaos", this.MaxChaos); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_LoginResult(this); ClientPacketHandler.send_InventoryList(this); ClientPacketHandler.send_EquipSummon(this); ClientPacketHandler.send_CharacterView(this); ClientPacketHandler.send_UpdateGoldChaos(this); ClientPacketHandler.send_Property(this, "tp", this.TP); ClientPacketHandler.send_Property(this, "chaos", this.Chaos); ClientPacketHandler.send_UpdateLevel(this); ClientPacketHandler.send_UpdateExp(this); ClientPacketHandler.send_Property(this, "job", this.Job); ClientPacketHandler.send_Property(this, "job_level", this.JobLevel); ClientPacketHandler.send_Property(this, "job_0", 0); ClientPacketHandler.send_Property(this, "jlv_0", 0); ClientPacketHandler.send_Property(this, "job_1", 0); ClientPacketHandler.send_Property(this, "jlv_1", 0); ClientPacketHandler.send_Property(this, "job_2", 0); ClientPacketHandler.send_Property(this, "jlv_2", 0); if (this.SkillList.Count > 0) { ClientPacketHandler.send_SkillList(this, this.SkillList.Values.ToArray()); } ClientPacketHandler.send_Packet404(this); ClientPacketHandler.send_Packet1005(this); ClientPacketHandler.send_BeltSlotInfo(this); ClientPacketHandler.send_GameTime(this); ClientPacketHandler.send_Property(this, "huntaholic_point", 0); ClientPacketHandler.send_Property(this, "huntaholic_ent", 12); ClientPacketHandler.send_Property(this, "ap", 0); ClientPacketHandler.send_Packet4700(this); ClientPacketHandler.send_Property(this, "alias", 0, true, ""); ClientPacketHandler.send_Property(this, "ethereal_stone", 0); ClientPacketHandler.send_Property(this, "dk_count", 0); ClientPacketHandler.send_Property(this, "pk_count", 0); ClientPacketHandler.send_Property(this, "immoral", 0); ClientPacketHandler.send_Property(this, "stamina", 0); ClientPacketHandler.send_Property(this, "max_stamina", this.MaxStamina); ClientPacketHandler.send_Property(this, "channel", 1); ClientPacketHandler.send_EntityState(this); if (this.ClientInfo != "") { ClientPacketHandler.send_Property(this, "client_info", 0, true, this.ClientInfo); } ClientPacketHandler.send_QuestList(this); ClientPacketHandler.send_Packet625(this); ClientPacketHandler.send_Packet626(this); ClientPacketHandler.send_Packet627(this); ClientPacketHandler.send_Packet629(this); ClientPacketHandler.send_Packet631(this, 1); ClientPacketHandler.send_Packet631(this, 2); ClientPacketHandler.send_Packet631(this, 3); ClientPacketHandler.send_Packet631(this, 4); ClientPacketHandler.send_Packet631(this, 5); //PacketParser.send_Packet22(sid, 2); //PacketParser.send_Packet22(sid, 3); ClientPacketHandler.send_Property(this, "playtime", 0); ClientPacketHandler.send_Property(this, "playtime_limit1", 1080000); ClientPacketHandler.send_Property(this, "playtime_limit2", 1800000); ClientPacketHandler.send_LocationInfo(this); ClientPacketHandler.send_WeatherInfo(this); ClientPacketHandler.send_Property(this, "playtime", 0); //PacketParser.send_Packet22(sid, 4); //PacketParser.send_Packet08(sid, 1); ///ClientPacketHandler.send_GameTime(this); //PacketParser.send_Packet1101(this, 2); ///ClientPacketHandler.send_LocationInfo(this); ClientPacketHandler.send_Property(this, "stamina_regen", 30); ClientPacketHandler.send_UpdateStats(this, false); ClientPacketHandler.send_UpdateStats(this, true); return(true); }
/// <summary> /// Creates a new character /// </summary> /// <param name="name">char name</param> /// <param name="sex">sex</param> /// <param name="race">race</param> /// <param name="hairId">hair ID</param> /// <param name="faceId">Face ID</param> /// <param name="bodyId">Body ID</param> /// <param name="handsId">Hands ID</param> /// <param name="feetId">Feet ID</param> /// <param name="hairColor">Hair Color</param> /// <param name="faceDetail">Face Detail</param> /// <param name="clothesId">Clothers ID (601/602)</param> /// <param name="skinColor">Skin Color</param> internal void CreateCharacter(string name, int sex, int race, int hairId, int faceId, int bodyId, int handsId, int feetId, int hairColor, int faceDetail, int clothesId, int skinColor) { Database db = new Database(Server.UserDbConString); float x = 0; float y = 0; short job = 0; int startWeapon = 0; int startBag = 480001; int startOutfit = 0; // Defines start job and position switch (race) { case (int)Races.Asura: x = 168356; y = 55399; job = 300; startWeapon = 103100; // Beginner's Dirk if (clothesId == 601) { startOutfit = 230100; } else { startOutfit = 230109; } break; case (int)Races.Deva: x = 164335; y = 49510; job = 100; startWeapon = 106100; // Beginner's Mace if (clothesId == 601) { startOutfit = 240100; } else { startOutfit = 240109; } break; case (int)Races.Gaia: x = 164474; y = 52932; job = 200; startWeapon = 112100; //Trainee's Small Axe if (clothesId == 601) { startOutfit = 220100; } else { startOutfit = 220109; } break; } int charId = (int)db.WriteQuery( "INSERT INTO `char`(" + "`account_id`,`slot`," + "`name`,`sex`,`race`," + "`hair_id`, `face_id`, `body_id`, `hands_id`," + "`feet_id`, `face_detail_id`, `hair_color`," + "`skin_color`, `x`, `y`, `layer`," + "`save_x`, `save_y`," + "`level`, `exp`," + "`job`, `job_level`, `job_exp`,`jp`," + "`job_0`, `job0_level`," + "`job_1`, `job1_level`," + "`job_2`, `job2_level`," + "`create_date`, `delete_date`," + "`client_info`" + ") VALUES (" + "@accId,0," + "@name,@sex,@race," + "@hairId,@faceId,@bodyId,@handId," + "@feetId,@faceDetailId,@hairColor," + "@skinColor,@x,@y,0," + "0,0," + "1,0," + "@job,1,0,0," + "0,0," + "0,0," + "0,0," + "@createDate,0," + "@clientInfo" + ")", new string[] { "accId", "name", "sex", "race", "hairId", "faceId", "bodyId", "handId", "feetId", "faceDetailId", "hairColor", "skinColor", "x", "y", "job", "createDate", "clientInfo" }, new object[] { this.AccountId, name, sex, race, hairId, faceId, bodyId, handsId, feetId, faceDetail, hairColor, skinColor, x, y, job, TimeUtils.GetTimeStamp(DateTime.Now), "QS2=0,2,0|QS2=1,2,2|QS2=11,2,1|QS2=24,2,7|QS2=25,2,8|QS2=35,2,28" } ); Item startItem = new Item(); startItem.Code = startBag; startItem.WearInfo = Item.WearType.BagSlot; startItem.Count = 1; Item.CharacterGetItem(charId, startItem); startItem.Code = startWeapon; startItem.WearInfo = Item.WearType.RightHand; Item.CharacterGetItem(charId, startItem); startItem.Code = startOutfit; startItem.WearInfo = Item.WearType.Armor; Item.CharacterGetItem(charId, startItem); ClientPacketHandler.send_PacketResponse(this, (short)0x07D2); }
/// <summary> /// Loads and sends the list of characters of this account /// </summary> internal void SendCharacterList() { Database db = new Database(Server.UserDbConString); // TODO : Query CleanUP MySqlDataReader reader = db.ReaderQuery( "SELECT `char_id`,`slot`,`name`,`sex`,`race`," + "`hair_id`,`face_id`,`body_id`,`hands_id`,`feet_id`," + "`face_detail_id`,`hair_color`,`skin_color`,`x`,`y`,`layer`," + "`save_x`,`save_y`,`level`,`exp`,`job`,`job_level`,`create_date`" + " FROM `char`" + " WHERE `account_id` = @accId AND `delete_date`= 0", new string[] { "accId" }, new object[] { this.AccountId } ); List <CharacterListEntry> chars = new List <CharacterListEntry>(); Database db2 = new Database(Server.UserDbConString); while (reader.Read()) { CharacterListEntry c = new CharacterListEntry(); c.Name = (string)reader["name"]; c.Race = (int)reader["race"]; c.Sex = (int)reader["sex"]; c.SkinColor = (int)reader["skin_color"]; c.HairColor = (int)reader["hair_color"]; c.Job = (short)reader["job"]; c.JobLevel = (int)reader["job_level"]; c.Level = (int)reader["level"]; c.HairId = (int)reader["hair_id"]; c.FaceId = (int)reader["face_id"]; c.BodyId = (int)reader["body_id"]; c.HandsId = (int)reader["hands_id"]; c.FeetId = (int)reader["feet_id"]; c.CreateDate = (int)reader["create_date"]; MySqlDataReader equipList = db2.ReaderQuery( "SELECT `code`, `equip`" + " FROM `item`" + " WHERE `char_id` = @charId AND `equip` >= 0", new string[] { "charId" }, new object[] { (int)reader["char_id"] } ); while (equipList.Read()) { c.Equip[(int)equipList["equip"]] = (int)equipList["code"]; } equipList.Close(); chars.Add(c); } db.Dispose(); ClientPacketHandler.send_CharacterList(this, chars.ToArray()); }