public void ServerFound(BroadcastPacket brdPacket) { //Extract port from package ushort port = NUUtilities.GetUInt16(brdPacket.packet.GetCleanData()); IPEndPoint endPoint = new IPEndPoint(brdPacket.senderIp, port); //Try to add server if (!availableServers.Add(endPoint)) { return; } //Instantiate GUI Prefab GameObject serverEntry = GameObject.Instantiate(serverEntryPrefab, serverListPanel); Text[] texts = serverEntry.GetComponentsInChildren <Text>(); //Update IPAddress texts[0].text = brdPacket.senderIp.ToString(); //Update Port texts[1].text = port.ToString(); Button connect = serverEntry.GetComponentInChildren <Button>(); connect.onClick.AddListener(() => { ConnectToServer(endPoint, serverEntry); }); }
private void ProcessBroadcastPacket(BroadcastPacket packet) { if (onCustomPacket != null) { AddTask(() => onCustomPacket.Invoke(packet)); } }
private void ProcessBroadcastPacket(BroadcastPacket pkt) { string msg = pkt.Message; using (var dbx = new Database()) { var acc = dbx.Verify(pkt.Username, pkt.Password); if (acc == null) { return; } if (acc.Rank >= 5) { foreach (ClientProcessor i in RealmManager.Clients.Values) { i.SendPacket(new TextPacket { BubbleTime = 0, Stars = -1, Name = "#" + acc.Name, Text = " " + msg }); } } } }
public static void LightningSkillRequest(Database.Player pAttacker, int targetID) { Output.WriteLine("SkillHandler::LightningSkillRequest"); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.SkillAnim(pAttacker.PlayerPID, targetID, 2, 2)); GameServer.world.broadcastQueue.Enqueue(bPacket); //Monster attackedMob = World.Monsters[mobID]; //attackedMob.broadcastPacket(new PlayAnimation(mobID, pAttacker.UniqueID, 4)); }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Here we go. Let's define the functions that get called whenever a skill is executed. * This is the place where you wanna start to create your own custom skills. Perhaps some * kind of scripting support will be added in the far future. * */ public static void SkillRequest(int skillID, Database.Player.RACE race, Database.Player pAttacker, int targetID = 0, Map.Nod position = null) { Skill skill = null; Dictionary <int, Skill> dict = null; ActiveSkill activeSkill; if (!pAttacker.activeSkillList.TryGetValue(skillID, out activeSkill)) { throw new KeyNotFoundException(); } try { switch (race) { case Database.Player.RACE.KNIGHT: dict = knightSkillList; break; case Database.Player.RACE.MAGE: dict = mageSkillList; break; case Database.Player.RACE.ARCHER: dict = archerSkillList; break; default: throw new NullReferenceException(); break; } skill = dict[skillID]; } catch (KeyNotFoundException e) { Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to execute a skill for that no handler exists. " + e.Source.ToString() + " : " + e.TargetSite.ToString()); } catch (NullReferenceException) { // Should never ever happen -.- Output.WriteLine("SkillHandler::GetSkillExecuteHandler " + "Someone tried to request a skill for an unknown race!"); } //This is place where we do actions for requested skill Output.WriteLine("SkillRequest: " + skill.name); if (activeSkill.ElapsedCoolDown() > 0 && activeSkill.ElapsedCoolDown() < skill.coolDown) { Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest - can't cast skill (still on CoolDown)"); Output.WriteLine(ConsoleColor.Red, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); return; } Output.WriteLine(ConsoleColor.DarkGreen, "SkillHandler::SkillRequest CoolDown: " + activeSkill.ElapsedCoolDown().ToString()); pAttacker.isCastingSkill = true; pAttacker.currentCastingSkillID = skillID; activeSkill.StartCast(); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.SkillAnim(pAttacker.PlayerPID, targetID, activeSkill.skillID, activeSkill.skillLvl)); GameServer.world.broadcastQueue.Enqueue(bPacket); }
private void Connection_ProductArrayChanged(object sender, EventArgs e) { this.Products = new List <CashShopProductListElement>(); this.BeautyShopProducts = new List <CashShopProductListElement>(); this.ProductByProductID = new Dictionary <int, CashShopProductListElement>(this.Connection.ProductArray.Count); this.ProductByItemClass = new Dictionary <string, CashShopProductListElement>(this.Connection.ProductArray.Count); this.ProductByCashShopItemKey = new Dictionary <CashShopItemKey, CashShopProductListElement>(this.Connection.ProductArray.Count); try { foreach (Product product in this.Connection.ProductArray) { Log <CashShopService> .Logger.InfoFormat("product - {0} : {1} ", product.ProductNo, product.ProductID); CashShopProductListElement cashShopProductListElement = new CashShopProductListElement(product); this.Products.Add(cashShopProductListElement); if (this.ProductByProductID.ContainsKey(cashShopProductListElement.ProductNo)) { Log <CashShopService> .Logger.ErrorFormat("Duplicate ProductNo[{0}]", cashShopProductListElement.ProductNo); } else { this.ProductByProductID.Add(cashShopProductListElement.ProductNo, cashShopProductListElement); } if (!this.ProductByItemClass.ContainsKey(cashShopProductListElement.ProductID)) { this.ProductByItemClass.Add(cashShopProductListElement.ProductID, cashShopProductListElement); } CashShopItemKey key = new CashShopItemKey(cashShopProductListElement.ProductID, cashShopProductListElement.SalePrice, (int)cashShopProductListElement.ProductExpire); if (this.ProductByCashShopItemKey.ContainsKey(key)) { Log <CashShopService> .Logger.InfoFormat("Duplicate CashShopItemKey[{0}/{1}/{2}]", cashShopProductListElement.ProductID, cashShopProductListElement.SalePrice, cashShopProductListElement.ProductExpire); } else { this.ProductByCashShopItemKey.Add(key, cashShopProductListElement); } if (this.BeautyShopCategories.ContainsKey(cashShopProductListElement.CategoryNo)) { this.BeautyShopProducts.Add(cashShopProductListElement); } } Log <CashShopService> .Logger.Info("Product Changed!"); foreach (int serviceID in base.LookUp.FindIndex("FrontendServiceCore.FrontendService")) { BroadcastPacket op = BroadcastPacket.Create <ChangedCashShopMessage>(new ChangedCashShopMessage()); base.RequestOperation(serviceID, op); } } catch (Exception ex) { Log <CashShopService> .Logger.Error(ex); } }
public static void LightningSkillExecute(Database.Player pAttacker, int targetID) { Output.WriteLine("SkillHandler::LightningSkillExecute"); //GameServer.world.BroadcastPacket(pConn.client.GetPlayer(), new Packet.SendPacketHandlers.AttackMag(casterID, targetID, skill_id, skill_lvl)); BroadcastPacket bPacket = new BroadcastPacket((uint)pAttacker.PosX, (uint)pAttacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(pAttacker.PlayerPID, targetID, 2, 2)); GameServer.world.broadcastQueue.Enqueue(bPacket); //Monster attackedMob = World.Monsters[mobID]; //Packet attackPacket = new ExecuteSkill(pAttacker.UniqueID, attackedMob.UniqueID, 4, 1, 1, 31, 0); //attackedMob.broadcastPacket(attackPacket); //attackedMob.getDamage((ushort)Server.rand.Next(100), pAttacker); }
private void Connection_CategoryArrayChanged(object sender, EventArgs e) { if (ServiceCore.FeatureMatrix.IsEnable("BeautyShopItemSyncNISMS")) { string @string = ServiceCore.FeatureMatrix.GetString("BeautyShopCategoryByNISMS"); string[] array = @string.Split(new char[] { ';' }); if (array.Count <string>() == 2) { this.BeautyShopCategoryName = array[0]; this.BeautyShopIgnoreCategoryName = array[1]; } } this.Categories = new List <CashShopCategoryListElement>(); this.BeautyShopCategories = new Dictionary <int, CashShopCategoryListElement>(); foreach (Category category in this.Connection.CategoryArray) { Log <CashShopService> .Logger.InfoFormat("category - {0} : {1} ", category.CategoryNo, category.CategoryName); this.Categories.Add(new CashShopCategoryListElement(category)); if (category.CategoryName.Equals(this.BeautyShopCategoryName)) { this.BeautyShopCategoryNo = category.CategoryNo; this.BeautyShopCategories.Add(category.CategoryNo, new CashShopCategoryListElement(category)); } if (this.BeautyShopCategories.ContainsKey(category.ParentCategoryNo)) { if (category.CategoryName.Equals(this.BeautyShopIgnoreCategoryName)) { this.BeautyShopIgnoreCategoryNo = category.CategoryNo; } else { this.BeautyShopCategories.Add(category.CategoryNo, new CashShopCategoryListElement(category)); } } } Log <CashShopService> .Logger.Info("Categories Changed!"); foreach (int serviceID in base.LookUp.FindIndex("FrontendServiceCore.FrontendService")) { BroadcastPacket op = BroadcastPacket.Create <ChangedCashShopMessage>(new ChangedCashShopMessage()); base.RequestOperation(serviceID, op); } }
public void Despawn(Object pAttacker) { BroadcastPacket bPacket = null; if (despawnTimer != null) { despawnTimer.Dispose(); } //GameServer.world.BroadcastPacket(PosX, PosY, World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobDespawn(uniqueID)); bPacket = new BroadcastPacket((uint)PosX, (uint)PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.MobDespawn(uniqueID)); if (bPacket != null) { GameServer.world.BroadcastPacket((int)bPacket.X, (int)bPacket.Y, (uint)bPacket.Range, bPacket.Packet); } base.Spawn.Respawn(); //Output.WriteLine("Mob::Despawn MOB ID: " + InternalID.ToString() + " Pos [" + PosX.ToString() + "," + PosY.ToString() + "]"); GameServer.world.RemoveMonster(this); return; }
private void ProcessBroadcastPacket(BroadcastPacket pkt) { Account acc; var msg = pkt.Message; if ((acc = new Database().Verify(pkt.Username, pkt.Password)) != null) { if (acc.Rank >= 5) { foreach (var i in RealmManager.Clients.Values) { i.SendPacket(new TextPacket { BubbleTime = 0, Stars = -1, Name = "#" + acc.Name, Text = " " + msg }); } } } }
public static void Chat(Connection pConn, byte[] data) { MemoryStream stream = new MemoryStream(data); BinaryReader br; string text = ""; string name = ""; using (br = new BinaryReader(stream)) { stream.Position = Program.receivePrefixLength;//set strem position to begin of data (beafore is header data) text = br.ReadString(); name = br.ReadString(); } if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::Chat Name: " + name + " Text: " + text); } //GameServer.world.BroadcastPacket(pConn.client.GetPlayer(), new Packet.SendPacketHandlers.Chat(name, text)); BroadcastPacket bPacket = new BroadcastPacket((uint)pConn.client.GetPlayer().PosX, (uint)pConn.client.GetPlayer().PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.Chat(name, text)); GameServer.world.broadcastQueue.Enqueue(bPacket); }
public static void AttackPhysical(Connection pConn, byte[] data) { if (Program.DEBUG_recv) { Output.WriteLine("RecvPacketHandlers::AttackPhysical"); } int attackerID = BitConverter.ToInt32(data, Program.receivePrefixLength); // pr.ReadInt32 (); int targetID = BitConverter.ToInt32(data, Program.receivePrefixLength + 4); // pr.ReadInt32 (); int type = BitConverter.ToInt32(data, Program.receivePrefixLength + 4 + 4);; // pr.ReadInt32 (); int lvl = BitConverter.ToInt32(data, Program.receivePrefixLength + 4 + 4 + 4);; // pr.ReadInt32 (); pConn.client.GetPlayer().isCastingSkill = false; //GameServer.world.BroadcastPacket(pConn.client.GetPlayer(), new Packet.SendPacketHandlers.AttackPhy(attackerID, targetID, type, lvl)); if (pConn.client.GetPlayer().moving) { pConn.client.GetPlayer().StopMove(); } BroadcastPacket bPacket = new BroadcastPacket((uint)pConn.client.GetPlayer().PosX, (uint)pConn.client.GetPlayer().PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackPhy(attackerID, targetID, type, lvl)); GameServer.world.broadcastQueue.Enqueue(bPacket); //mobID = pReader.ReadUInt32(); //pConn.Player.AttackWithoutSkill((int)mobID); }
private void client_Broadcast(BroadcastPacket packet) { Invoke(new MethodInvoker(() => MessageBox.Show(packet.Message, @"Server Broadcast", MessageBoxButtons.OK, MessageBoxIcon.Exclamation))); }
/// <summary> /// This function sends data to the socket using the endPoint specified in sendFile() /// </summary> /// <param name="sock"></param> /// <param name="endPoint"></param> private void SendData(Socket sock, EndPoint endPoint) { // read from file string[] lines = System.IO.File.ReadAllLines(fileName); // add packet number to lines string[] outputLines = new string[lines.Length]; for (int i = 0; i < lines.Length; i++) { int lineNum = i + 1; outputLines[i] = lineNum.ToString(); outputLines[i] += lines[i]; } byte[][] allLines = new byte[lines.Length][]; // send to byte arrays for (int i = 0; i < lines.Length; i++) { allLines[i] = System.Text.Encoding.ASCII.GetBytes(outputLines[i]); } //Ensure that the number of bits is below 1020, need to find a better solution. for (int i = 0; i < lines.Length; i++) { if (allLines[i].Length > 1020) { Console.WriteLine("Error: line size greater than packet size at line: " + i); Environment.Exit(1); } } // send start packet BroadcastPacket startPacket = new BroadcastPacket(allLines.Length); Console.WriteLine("Sending start packet."); sock.SendTo(startPacket.getPacket(), startPacket.getPacket().Length, SocketFlags.None, endPoint); Thread.Sleep(2000); for (int i = 0; i < allLines.Length; i++) { BroadcastPacket packet = new BroadcastPacket(i + 1, allLines[i]); Console.WriteLine("Sending data: " + i); sock.SendTo(packet.getPacket(), packet.getPacket().Length, SocketFlags.None, endPoint); Thread.Sleep(2000); } }
public void DoAction() { BroadcastPacket bPacket = null; //skill if (actSkill != null) { if (skill == null) { Output.WriteLine("Action::DoAction skill can't be null"); return; } Output.WriteLine("Action::DoAction Skill attack"); //check if target is correct one and is in skill range ect. //distance.. switch (skill.demageFlag) { //skills that need to give target entity case SKILL_DEMAGE_FLAG.SINGLE_TARGET_FLAG: case SKILL_DEMAGE_FLAG.MULTI_TARGET_FLAG: { int range = GameServer.world.GetDistance(attacker.PosX, attacker.PosY, targetID); Output.WriteLine("Action::DoAction Range from attacker to target = " + range.ToString()); if (range > skill.range) { Output.WriteLine("Action::DoAction Target outside skill range! (" + range.ToString() + "->" + skill.range.ToString() + ")"); break; } Database.Entity entity = GameServer.world.GetEntity(targetID); if (entity == null) { break; } Database.Entity.Attacker att = new Database.Entity.Attacker(); att.dmgDeal = CalculateMagicDmg(attacker, entity); att.attackerID = attacker.InternalID; entity.IsAttacked = true; entity.AddAttacker(att); position.X = (uint)entity.PosX; position.Y = (uint)entity.PosY; bPacket = new BroadcastPacket((uint)attacker.PosX, (uint)attacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(attacker.InternalID, targetID, actSkill.skillID, actSkill.skillLvl)); entity.GetDemage(att.dmgDeal); Output.WriteLine("Action::DoAction Attacker demage: " + att.dmgDeal.ToString()); } break; //skills that are place related not target entity case SKILL_DEMAGE_FLAG.POSITION_TARGET_FLAG: case SKILL_DEMAGE_FLAG.CON_45_FLAG: case SKILL_DEMAGE_FLAG.CON_90_FLAG: case SKILL_DEMAGE_FLAG.AOE_TARGET_FLAG: { int range = GameServer.world.GetDistance(attacker.PosX, attacker.PosY, (int)position.X, (int)position.Y); Output.WriteLine("Action::DoAction Range from attacker to target = " + range.ToString()); if (range > skill.range) { Output.WriteLine("Action::DoAction Target outside skill range! (" + range.ToString() + "->" + skill.range.ToString() + ")"); break; } //GameServer.world.get bPacket = new BroadcastPacket((uint)attacker.PosX, (uint)attacker.PosY, (int)World.DEBUG_SIGHT_RANGE, new Packet.SendPacketHandlers.AttackMag(attacker.InternalID, targetID, actSkill.skillID, actSkill.skillLvl)); } break; default: Output.WriteLine("Skill has inncorrect DEMAGE FLAG SET"); break; } if (bPacket != null) { GameServer.world.BroadcastPacket((int)bPacket.X, (int)bPacket.Y, (uint)bPacket.Range, bPacket.Packet); } //GameServer.world.broadcastQueue.Enqueue(bPacket); } else//physical attack { Output.WriteLine("Action::DoAction Normall attack"); } }