public void Send(Packet packet) { if (Sock != null && Sock.Connected) { using (MemoryStream Stream = new MemoryStream( )) using (BinaryWriter PacketBuilder = new BinaryWriter(Stream)) { //RaiseEvent if event is linked if (PacketSent != null) { PacketSent(this, packet); } SendCounter++; PacketBuilder.Write((byte)0x00);// Sec Bytes Count PacketBuilder.Write((ushort)packet.Data.Length); // Data Bytes Count PacketBuilder.Write((ushort)(packet.Opcode << 1)); // Opcode PacketBuilder.Write(SendCounter); // Counter PacketBuilder.Write((byte)0x0E); // Header Length PacketBuilder.Write(1); PacketBuilder.Write(packet.Data); Send(Stream.ToArray( )); } } }
public static void PacketReceived(Server sender, Packet packet) { //Program.frm1.AddLog("(C - S) " + packet.ToString()); Player player = Players.Find(sender); for (int i = 0; i < 3; i++) { if (player != null) break; Thread.Sleep(100); player = Players.Find(sender); } if (player == null) sender.Kick(); if (player.CharName != "") Program.frm1.AddLog(player.CharName + " : (C - S) " + packet.ToString()); else Program.frm1.AddLog(player.AccountName + " : (C - S) " + packet.ToString()); switch (packet.Opcode) { case 0x7FD4: // Login Request { player.AccountName = packet.ReadString(31); AccountData AccData = new AccountData(player.AccountName); Packet LoginResponse = new Packet(0x7FD2); LoginResponse.WriteString(player.AccountName, 31); LoginResponse.WriteString("test", 31); sender.Send(LoginResponse); LoginResponse = new Packet(0x0001); LoginResponse.WriteUInt(2); int z = AccData.Characters.Count; while (z < 2) { //3rd Char LoginResponse.WriteUInt(10); for (int i = 0; i < 128; i++) LoginResponse.WriteByte(0); z++; } foreach (CharData x in AccData.Characters) { LoginResponse.WriteUInt(1); LoginResponse.WriteString(x.Name, 17); LoginResponse.WriteInt(Data.GetStyle(x.Gender, x.Nation, x.Face, x.Hair)); LoginResponse.WriteByte((byte)x.Job);//Job LoginResponse.WriteByte(0); LoginResponse.WriteUInt(0); LoginResponse.WriteByte(x.Level); // level LoginResponse.WriteUShort(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(x.ClothesItems.FindSlot(0).Model); // top LoginResponse.WriteUInt(x.ClothesItems.FindSlot(1).Model); // bottom LoginResponse.WriteUInt(x.ClothesItems.FindSlot(2).Model);// right hand weapon LoginResponse.WriteUInt(x.ClothesItems.FindSlot(3).Model);// left hand weapon LoginResponse.WriteUInt(x.ClothesItems.FindSlot(4).Model); // hat LoginResponse.WriteUInt(x.ClothesItems.FindSlot(5).Model); // wing & suit LoginResponse.WriteUInt(x.ClothesItems.FindSlot(6).Model); // Gauntlet LoginResponse.WriteUInt(x.ClothesItems.FindSlot(7).Model); // boot LoginResponse.WriteUInt(x.ClothesItems.FindSlot(8).Model); // 1st Necklace LoginResponse.WriteUInt(x.ClothesItems.FindSlot(9).Model); // 2nd Necklace LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUInt(0); LoginResponse.WriteUShort(0); } sender.Send(LoginResponse); } break; case 0x0002: { packet.ReadInt(); string CharName = packet.ReadString(17); int nStyle = packet.ReadInt(); CharData class_CharData = new CharData(player, player.AccountName, CharName); class_CharData.Name = CharName; class_CharData.Nation = Data.GetCharNation(nStyle); class_CharData.Gender = Data.GetCharGender(nStyle); class_CharData.Hair = Data.GetCharHair(nStyle, class_CharData.Nation, class_CharData.Gender); class_CharData.Face = Data.GetCharFace(nStyle, class_CharData.Nation, class_CharData.Gender); class_CharData.CreateCharData();//save character data to file. Packet LoginResponse = new Packet(0x0003); sender.Send(LoginResponse); } break; case 0x0004: { string CharName = packet.ReadString(17); string FileName = "Accounts\\" + player.AccountName + "\\" + CharName; if (File.Exists(FileName)) File.Delete(FileName); Packet LoginResponse = new Packet(0x0005); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); LoginResponse.WriteUInt(1); sender.Send(LoginResponse); } break; case 0x0010: { player.CharName = packet.ReadString(17); Packet LoginResponse = new Packet(0x0013); LoginResponse.WriteUInt(1); sender.Send(LoginResponse); } break; case 0x0014: player.SendCharData(); break; case 0x0124: Packets.Movement.UpdatePosition(packet, player); break; case 0x0121: Packets.Movement.BeginMove(packet, player); break; case 0x0453: Packets.ItemControl.ChangeSlot(packet, player); break; case 0x0411: Packets.ItemControl.Equip(packet, player); break; case 0x0415: Packets.ItemControl.TakeOff(packet, player); break; case 0x0229: Packets.Communication.Expressing(packet, player); break; case 0x7E02: Packets.Msngr.MemberInsert(packet, player); break; case 0x0710: Packets.Party.PartyRequest(packet, player); break; case 0x0801: Packets.PVP.Open(packet, player); break; case 0x0807: Packets.PVP.Close(packet, player); break; case 0x0808: Packets.PVP.CreateRoom(packet, player); break; case 0x0816: Packets.PVP.ExitRoom(packet, player); break; case 0x0471: Packets.Movement.RideHorse(packet, player); break; case 0x0133: { int MapIndex = Maps.MapsData.Find(player.CharData.Map); if (MapIndex != -1) Maps.AddPlayer(player, Maps.MapsData[MapIndex]); } break; case 0x0222: Packets.Chatting.Whisper(packet, player); break; case 0x0220: { byte Length = packet.ReadByte(); string Text = packet.ReadString(Length); if (!player.CharData.isInPVP) { int MapIndex = Maps.MapsData.Find(player.CharData.Map); foreach (Player x in Maps.MapsData[MapIndex].Players) { Packet newPacket = new Packet(0x0221); newPacket.WriteUInt(player.ID); newPacket.WriteString(player.CharData.Name, 17); newPacket.WriteByte(0); newPacket.WriteByte(Length); newPacket.WriteString(Text, Length); x.Sock.Send(newPacket); } } else { foreach (Player x in Packets.PVP.Players) { Packet newPacket = new Packet(0x0221); newPacket.WriteUInt(player.ID); newPacket.WriteString(player.CharData.Name, 17); newPacket.WriteByte(63); newPacket.WriteByte(Length); newPacket.WriteString(Text, Length); x.Sock.Send(newPacket); } } } break; #region DropEld case 0x0406: { byte Result = 0; uint Dropped = packet.ReadUInt(); if (player.CharData.Gold >= Dropped) { player.CharData.Gold -= Dropped; Result = 1; } Packet Response = new Packet(0x0407); Response.WriteByte(Result); Response.WriteUInt(player.CharData.Gold); player.Sock.Send(Response); } break; #endregion } }
public static void PacketSent(Server sender, Packet packet) { Player player = Players.Find(sender); for (int i = 0; i < 3; i++) { if (player != null) break; Thread.Sleep(100); player = Players.Find(sender); } if (player == null) sender.Kick( ); if (player.CharName != "") Program.frm1.AddLog(player.CharName + " : (S - C) " + packet.ToString( )); else Program.frm1.AddLog(player.AccountName + " : (S - C) " + packet.ToString( )); }
public void SendCharData( ) { Packet LoginResponse = new Packet(0x0015); LoginResponse.WriteString(CharName, 17); LoginResponse.WriteString("hi everybody :))", 31); LoginResponse.WriteInt(Data.GetStyle( CharData.Gender, CharData.Nation, CharData.Face, CharData.Hair)); // style LoginResponse.WriteByte((byte)CharData.Job); // job LoginResponse.WriteByte(0); LoginResponse.WriteULong(CharData.EXP); // EXP LoginResponse.WriteByte(CharData.Level); // Level LoginResponse.WriteUInt(1); LoginResponse.WriteByte(1); LoginResponse.WriteUInt(CharData.Fame); // Fame LoginResponse.WriteUInt(CharData.NationRate); // NationRate LoginResponse.WriteUShort(CharData.Map); // Map LoginResponse.WriteInt(Data.GetGameCoord(CharData.Map, CharData.Coord)); // Coord LoginResponse.WriteUInt(CharData.CurHP); // CurHP 82 LoginResponse.WriteUInt(CharData.CurSP); // CurSp 150 LoginResponse.WriteUInt(CharData.CurMP); // CurMP LoginResponse.WriteByte(0); LoginResponse.WriteUShort(CharData.MovingSpeed); // Moving Speed 1 -> map size LoginResponse.WriteUShort(CharData.AbbillityMin);//PAMin LoginResponse.WriteUShort(CharData.AbbillityMax);//PAMax LoginResponse.WriteUShort(CharData.PhysicalDef); // PhysicalDef LoginResponse.WriteUShort(CharData.MagicalDef); // MagicalDef LoginResponse.WriteByte(8); // Attack Speed LoginResponse.WriteUShort(CharData.AbbillityMin); // MAMin LoginResponse.WriteUShort(CharData.AbbillityMax); // MAMax LoginResponse.WriteUInt(CharData.MaxHP); // MaxHP LoginResponse.WriteUInt(CharData.MaxSP); //MaxSP LoginResponse.WriteUInt(CharData.MaxMP); // MaxMP LoginResponse.WriteUShort(CharData.Power);//Power LoginResponse.WriteUShort(CharData.Vitality); // Vitality LoginResponse.WriteUShort(CharData.Sympathy); // Sympathy LoginResponse.WriteUShort(CharData.Intelligence); // Intelligence LoginResponse.WriteUShort(CharData.Stamina); //Stamina LoginResponse.WriteUShort(CharData.Dexterity); // Dexterity LoginResponse.WriteByte(CharData.Charisma); // Charisma Random rd = new Random(); int nLuck = rd.Next(-10, 10); LoginResponse.WriteByte((byte)nLuck); // Random Luck value LoginResponse.WriteUShort(CharData.AbilltyPoint); // Ability LvlUp Point LoginResponse.WriteUShort(CharData.LeftSP); // Left SP LoginResponse.WriteUShort(CharData.TotalSP); // Total SP LoginResponse.WriteUInt(CharData.WonPVPs); // WonPVPs LoginResponse.WriteUInt(CharData.TotalPVPs); // TotalPVPs LoginResponse.WriteUInt(CharData.Gold); // Gold LoginResponse.WriteUShort(0); LoginResponse.WriteInt( (CharData.ClothesItems.Count << 00) + // Clothes Items Count (CharData.GeneralItems.Count << 05) + // General Items Count (0 << 11) + // Items Count (0 << 17) + // Quest Items Count (CharData.Skills.Count << 22)); // Skills Count LoginResponse.WriteByte(1); // Buffs Count LoginResponse.WriteInt( (0 << 00) + (1 << 08) + (0 << 18) + (0 << 24)); // ?? Counts LoginResponse.WriteByte(3); // Boosters Count LoginResponse.WriteByte((byte)CharData.RidingItems.Count); // Riding Items Count LoginResponse.WriteByte(0); // Count LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); LoginResponse.WriteByte(0x01); #region Clothes Items for (int i = 0; i < CharData.ClothesItems.Count; i++) { LoginResponse.WriteUInt(CharData.ClothesItems[i].ID); LoginResponse.WriteUShort(CharData.ClothesItems[i].Model); // Item Type LoginResponse.WriteBool(true); LoginResponse.WriteByte((byte)CharData.ClothesItems[i].Slot); // Item Slot LoginResponse.WriteUInt(1); LoginResponse.WriteUShort(CharData.ClothesItems[i].Durabillty); // Durability LoginResponse.WriteUShort(CharData.ClothesItems[i].RemainTime); // Remain Time } #endregion #region General Items for (int i = 0; i < CharData.GeneralItems.Count; i++) { LoginResponse.WriteUInt(CharData.GeneralItems[i].ID); // Item ID LoginResponse.WriteUShort(CharData.GeneralItems[i].Model); // Item Model LoginResponse.WriteBool(true); LoginResponse.WriteByte((byte)CharData.GeneralItems[i].Slot); // Item Slot LoginResponse.WriteUInt(1); LoginResponse.WriteUShort(CharData.GeneralItems[i].Durabillty); // Durabillty LoginResponse.WriteUShort(CharData.GeneralItems[i].RemainTime); // Remain Time } #endregion if (false) { #region General Items1 for (int i = 0; i < 1; i++) { LoginResponse.WriteUInt(11012); LoginResponse.WriteUShort(11053); // Item ID LoginResponse.WriteByte(0x04); LoginResponse.WriteByte(0); // Item Slot LoginResponse.WriteUInt(1); LoginResponse.WriteUShort(1); // Durabillty LoginResponse.WriteUShort(1); // Remain Time } #endregion #region Quest Items for (int i = 0; i < 1; i++) { LoginResponse.WriteUInt(11012); LoginResponse.WriteUShort(11053); // Item ID LoginResponse.WriteByte(0x04); LoginResponse.WriteByte(0); // Item Slot LoginResponse.WriteUInt(1); LoginResponse.WriteUShort(1); // Durabillty LoginResponse.WriteUShort(1); // Remain Time } #endregion } #region Skills for (int i = 0; i < CharData.Skills.Count; i++) { LoginResponse.WriteUShort(CharData.Skills[i]); // Skill ID } #endregion LoginResponse.WriteUShort(125); // Buffs //LoginResponse.WriteUInt(525); //2<<0 //LoginResponse.WriteByte(4); //LoginResponse.WriteUShort(0x720); //2<<18 //LoginResponse.WriteByte(0x2B); LoginResponse.WriteUInt(1); LoginResponse.WriteUShort(1); LoginResponse.WriteString("dsadas", 70); LoginResponse.WriteUShort(0x720); //2<<8 LoginResponse.WriteByte(3); /*LoginResponse.WriteUShort(8347); //2<<24 LoginResponse.WriteByte(11); LoginResponse.WriteUShort(8347); LoginResponse.WriteByte(4); LoginResponse.WriteByte(4);*/ #region Boosters LoginResponse.WriteUShort(11114); // Booster ID LoginResponse.WriteUInt(500); // Booster Remain Time LoginResponse.WriteUShort(11115); LoginResponse.WriteUInt(500); LoginResponse.WriteUShort(11116); LoginResponse.WriteUInt(500); #endregion LoginResponse.WriteUInt(1); LoginResponse.WriteByte(5); // Frontier level LoginResponse.WriteString("hii", 15); // Frontier NickName LoginResponse.WriteUInt(1000); // Frontier MemberShipFee #region Riding Items for (int i = 0; i < CharData.RidingItems.Count; i++) { LoginResponse.WriteUInt(CharData.RidingItems[i].ID); // Item ID LoginResponse.WriteUShort(CharData.RidingItems[i].Model); // Item Model LoginResponse.WriteByte(1); LoginResponse.WriteByte((byte)CharData.RidingItems[i].Slot); // Item Slot LoginResponse.WriteUInt(2); LoginResponse.WriteUShort(CharData.RidingItems[i].Durabillty); // Durabillty LoginResponse.WriteUShort(CharData.RidingItems[i].RemainTime); // Remain Time } #endregion LoginResponse.WriteString("1234567890abcd", 14); Sock.Send(LoginResponse); }
private void button2_Click(object sender, EventArgs e) { ushort Map = ushort.Parse(textBox1.Text); Point Coord = new Point(int.Parse(textBox2.Text), int.Parse(textBox3.Text)); CharData x = MainClass.Players[0].CharData; Server y = MainClass.Players[0].Sock; Packet Teleporting = new Packet(0x0132); Teleporting.WriteInt(Data.GetGameCoord(Map, Coord)); Teleporting.WriteUShort(Map); Teleporting.WriteByte(1); y.Send(Teleporting); int MapIndex = Maps.MapsData.Find(x.Map); if (MapIndex != -1) Maps.RemovePlayer(MainClass.Players[0], Maps.MapsData[MapIndex]); x.Map = Map; x.Coord = Coord; }
private void WaitForData(IAsyncResult DataAsync) { if (!isClosing) { Socket Worker = null; try { Worker = (Socket)DataAsync.AsyncState; int rcvdBytes = Worker.EndReceive(DataAsync); if (rcvdBytes > 0) { int Length = 0; Buffer = CsSec.DecryptPacket(SubArray(Buffer, 2, BitConverter.ToUInt16(Buffer, 0))); Packet packet = new Packet(Buffer, false, out Length); //RaiseEvent if event is linked if (PacketReceived != null) { PacketReceived(this, packet); } } else { isClosing = true; //RaisEvent if (Disconnected != null) { Disconnected(this); } } } catch (SocketException se) { if (se.SocketErrorCode == SocketError.ConnectionReset || se.SocketErrorCode == SocketError.InvalidArgument) //Client Disconnected { isClosing = true; //RaisEvent if (Disconnected != null) { Disconnected(this); } //Mark worker as null to stop reciveing. Worker = null; } else { } } finally { if (Worker != null) { try { Buffer = new byte[8192]; Worker.BeginReceive(Buffer, 0, 8192, SocketFlags.None, new AsyncCallback(WaitForData), Worker); } catch { } } } } }