public static byte[] FriendGroupManage(string type,string groupname, short groupid, int targetid)
 {
     PacketWriter Writer = new PacketWriter();
     switch (type)
     {
         case "ADD":
             Writer.Create(OperationCode.SERVER_FRIEND_GROUP);
             Writer.Byte(1);
             Writer.Text(groupname);
             Writer.Word(groupid);
             break;
         case "REMOVE":
             Writer.Create(OperationCode.SERVER_FRIEND_GROUP_REMOVE);
             Writer.Byte(1);
             Writer.Word(groupid);
             break;
         case "MOVE":
             Writer.Create(OperationCode.SERVER_FRIEND_GROUP_MANAGE_FRIEND);
             Writer.Byte(1);
             Writer.DWord(targetid);
             Writer.Word(groupid);
             break;
     }
     return Writer.GetBytes();
 }
 public static byte[] ServerListPacket(int cliVersion)
 {
     //Create a new packet writer to create our packet
     PacketWriter W = new PacketWriter();
     //Write the opcode from server to client
     W.Create(Opcodes.SERVER.SERVER_SERVERLIST);
     //Structure of packet below
     W.Word(0x0201);
     W.Text("CLOWEN_DEV_PROJECT");
     W.Byte(0);
     //Repeat the following packet data below for each server in the list
     foreach (KeyValuePair<int, Definitions.Serverdef.ServerDetails> Gameservers in Definitions.Serverdef.Serverlist)
     {
         if (cliVersion == Definitions.Serverdef.SilkroadClientVersion)
         {
             W.Bool(true);
             W.Word(Gameservers.Value.id);
             W.Text(Gameservers.Value.name);
             W.Word(Gameservers.Value.usedSlots);
             W.Word(Gameservers.Value.maxSlots);
             W.Byte(Gameservers.Value.status);
         }
     }
     //Static 0 byte
     W.Byte(0);
     //Send the created packet back to the request (client).
     return W.GetBytes();
 }
        public static byte[] AlchemyResponse(bool isSuccess, ObjData.slotItem sItem, byte type, byte totalblue)
        {
            PacketWriter Writer = new PacketWriter();
            Writer.Create(OperationCode.SERVER_ALCHEMY);
            Writer.Byte(1);
            Writer.Byte(2);
            Writer.Bool(isSuccess);
            Writer.Byte(sItem.Slot);
            if (!isSuccess) { Writer.Byte(0); }
            Writer.DWord(0);
            Writer.DWord(sItem.ID);
            Writer.Byte(sItem.PlusValue);
            Writer.LWord(0);
            Writer.DWord(sItem.Durability);
            Writer.Byte(ObjData.Manager.ItemBlue[sItem.dbID].totalblue);
            for (int i = 0; i <= ObjData.Manager.ItemBlue[sItem.dbID].totalblue - 1; i++)
            {
                Writer.DWord(ObjData.Manager.MagicOptions.Find(mg => (mg.Name == Convert.ToString(ObjData.Manager.ItemBlue[sItem.dbID].blue[i]))).ID);
                Writer.DWord(ObjData.Manager.ItemBlue[sItem.dbID].blueamount[i]);
            }
            Writer.Word(1);
            Writer.Word(2);
            Writer.Word(3);

            return Writer.GetBytes();
        }
 public static byte[] _3()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_MAIN);
     Writer.Word(0x0101);
     Writer.Word(0x0500);
     Writer.Byte(0x60);
     return Writer.GetBytes();
 }
 public static byte[] _4()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_MAIN);
     Writer.Word(0x0300);
     Writer.Word(0x0200);
     Writer.Word(0x0200);
     return Writer.GetBytes();
 }
 public static byte[] LoadGame_5()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_PATCH);
     Writer.Word(0x0101);
     Writer.Word(0);
     Writer.Byte(0xA1);
     return Writer.GetBytes();
 }
 public static byte[] FriendDecline(string name)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_FRIEND_INVITE);
     Writer.Byte(2);
     Writer.Word(0x640B);
     Writer.Byte(0);
     Writer.Word(0x000B);
     Writer.Text(name);
     return Writer.GetBytes();
 }
 public static byte[] _2()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_MAIN);
     Writer.Word(0x0100);
     Writer.Word(0x0100);
     Writer.Byte(0x69);
     Writer.Byte(0x0C);
     Writer.DWord(0x00000005);
     Writer.Byte(0x02);
     return Writer.GetBytes();
 }
 public static byte[] LoadGame_2()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_PATCH);
     Writer.Word(0x0100);
     Writer.Word(0x0100);
     Writer.Byte(0x69);
     Writer.Byte(0x0C);
     Writer.DWord(0x00000005);
     Writer.Byte(0x02);
     return Writer.GetBytes();
 }
 public static byte[] ConnectSucces(string ip, short port, byte type)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_GATEWAY_LOGIN_RESPONSE);
     Writer.Byte(1);
     Writer.Byte(type);
     Writer.Byte(0);
     Writer.Word(0);
     Writer.Text(ip);
     Writer.Word(port);
     Writer.Byte(3);
     return Writer.GetBytes();
 }
        public static byte[] NewsPacket()
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(Opcodes.SERVER.SERVER_MAIN);
            Writer.Byte(0);
            Writer.Byte((byte)Definitions.Serverdef.News_List.Count);

            foreach (Definitions.Serverdef.NewsList n in Definitions.Serverdef.News_List)
            {
                Writer.Text(n.Title);
                Writer.Text(n.Article);
                Writer.Word(n.Year);
                Writer.Word(n.Month);
                Writer.Word(n.Day);
                Writer.Word(0); // Hour
                Writer.Word(0); // Minute
                Writer.Word(0); // Second
                Writer.Word(0); // MiliSecond
            }

            Writer.Word(0);

            return Writer.GetBytes();
        }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Update arrow amount
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public static byte[] Arrow(short amount)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_ARROW_UPDATE);
     Writer.Word(amount);
     return Writer.GetBytes();
 }
 public static byte[] ConnectWrong(ushort type)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_GATEWAY_LOGIN_RESPONSE);
     Writer.Word(type);
     return Writer.GetBytes();
 }
 public static byte[] ActualVersion()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(Opcodes.SERVER.SERVER_MAIN);
     Writer.Word(0x100);
     return Writer.GetBytes();
 }
 public static byte[] TeleportStart()
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_TELEPORTSTART);
     Writer.Byte(2);
     Writer.Word(1);
     return Writer.GetBytes();
 }
 public static byte[] StallCloseGlobal(int charid)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_STALL_CLOSE);
     Writer.DWord(charid);
     Writer.Word(0);
     return Writer.GetBytes();
 }
 public static byte[] BerserkNotRun()
 {
     PacketWriter Write = new PacketWriter();
     Write.Create(OperationCode.SERVER_PLAYER_BERSERK);
     Write.Byte(2);
     Write.Word(3);
     return Write.GetBytes();
 }
 public static byte[] Angle(int UniqueID, ushort angle)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_ANGLE);
     Writer.DWord(UniqueID);
     Writer.Word(angle);
     return Writer.GetBytes();
 }
 public static byte[] Message(ushort opcode, ushort id)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(opcode);
     Writer.Byte(2);
     Writer.Word(id);
     return Writer.GetBytes();
 }
 public static byte[] MakeAliasError(string name, byte switchinfo)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_MAKE_ALIAS);
     Writer.Byte(2);
     Writer.Word(0);
     Writer.Byte(0);
     Writer.Text(name);
     return Writer.GetBytes();
 }
 public static byte[] guide(byte info1, byte info2, byte info3)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_SEND_GUIDE);
     Writer.Word(info1);
     Writer.DWord(info2);
     Writer.Word(info3);
     Writer.Byte(0);
     return Writer.GetBytes();
 }
 public static byte[] StallItemMain(List<WorldMgr.stall.stallItem> ItemList)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_STALL_ACTION);
     Writer.Byte(1);
     Writer.Byte(2);
     Writer.Word(0);
     StallItemPacket(ItemList, Writer);
     return Writer.GetBytes();
 }
 public static byte[] GuildSetTitle2(int guildid, int charid, string title)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_GUILD_SET_TITLE2);
     Writer.Byte(1);
     Writer.DWord(guildid);
     Writer.DWord(charid);
     Writer.Word(title.Length);
     Writer.String(title);
     return Writer.GetBytes();
 }
        public static byte[] StallBuyItem2(string charname, byte stallslot, List<WorldMgr.stall.stallItem> ItemList)
        {
            PacketWriter Writer = new PacketWriter();
            Writer.Create(OperationCode.SERVER_STALL_PLAYERUPDATE);
            Writer.Byte(3);
            Writer.Byte(stallslot);
            Writer.Word(charname.Length);
            Writer.String(charname);
            StallItemPacket(ItemList, Writer);

            return Writer.GetBytes();
        }
 public static byte[] StopMovement(ObjData.vektor p)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_PICKUPITEM_MOVE);
     Writer.DWord(p.ID);
     Writer.Byte(p.xSec);
     Writer.Byte(p.ySec);
     Writer.Float(p.x);
     Writer.Float(p.z);
     Writer.Float(p.y);
     Writer.Word(0/*p.Angle*/); // Angle
     return Writer.GetBytes();
 }
 public static byte[] JoinResponseMessage(short type)
 {
     //Create new packet writer
     PacketWriter Writer = new PacketWriter();
     //Add opcode
     Writer.Create(OperationCode.SERVER_PARTY_MESSAGES);
     //Add static byte
     Writer.Byte(1);
     //Add type short (1 = joined , 2 = no reponse)
     Writer.Word(type);
     //Return bytes to client
     return Writer.GetBytes();
 }
        public static byte[] PartyRequest(byte Type, int id, byte type)
        {
            //Create new packet writer
            PacketWriter Writer = new PacketWriter();
            //Add opcode
            Writer.Create(OperationCode.SERVER_PARTY_REQUEST);
            //Write type byte
            Writer.Byte(Type);
            //Create switch on type
            switch (Type)
            {
                case 6:
                    //Union invite
                    Writer.DWord(id);
                    break;
                case 5:
                    //Guild invitation
                    Writer.DWord(id);
                    PlayerMgr InvitedPlayer = Helpers.GetInformation.GetPlayer(id);
                    Writer.Word(InvitedPlayer.Character.Information.Name.Length);
                    Writer.String(InvitedPlayer.Character.Information.Name);
                    Writer.Word(InvitedPlayer.Character.Network.Guild.Name.Length);
                    Writer.String(InvitedPlayer.Character.Network.Guild.Name);
                    break;
                case 2:
                    //Party invite
                    Writer.DWord(id);
                    Writer.Byte(type);
                    break;
                case 1:
                    //Exchange invite
                    Writer.DWord(id);
                    break;
            }

            return Writer.GetBytes();
        }
 public static byte[] GuildSetOnline(WorldMgr.guild c, int memberid)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_GUILD_ONLINE);
     Writer.DWord(memberid);
     Writer.DWord(c.Guildid);
     Writer.Text(c.Name);
     Writer.Word(0);
     Writer.DWord(0);
     Writer.DWord(0);
     Writer.DWord(0);
     Writer.Byte(0);
     Writer.Byte(1);
     return Writer.GetBytes();
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Buy Item From Item Mall
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public static byte[] BuyItemFromMall(byte type1, byte type2, byte type3, byte type4, byte type5, byte slot)
 {
     PacketWriter Writer = new PacketWriter();
     Writer.Create(OperationCode.SERVER_ITEM_MOVE);    //Select opcode
     Writer.Byte(1);                             //Static Byte 1
     Writer.Byte(0x18);                          //Static Byte 0x18 /switch possible perhaps
     Writer.Byte(type1);                         // Recheck
     Writer.Byte(type2);                         // Recheck
     Writer.Byte(type3);                         // Recheck
     Writer.Byte(type4);                         // Recheck
     Writer.Byte(type5);                         // Recheck
     Writer.Byte(1);                             //Static Byte 1
     Writer.Byte(slot);                          //Select To Slot
     Writer.Word(1);                             //Static
     Writer.DWord(0);                            //Static
     return Writer.GetBytes();
 }
        public static byte[] Movement(ObjData.vektor p)
        {
            PacketWriter Writer = new PacketWriter();
                Writer.Create(OperationCode.SERVER_MOVEMENT);     //Select opcode
                Writer.DWord(p.ID);                         //Player ID
                Writer.Bool(true);                          //Bool 1
                Writer.Byte(p.xSec);                        //Player X Sector
                Writer.Byte(p.ySec);                        //Player Y Sector
                if (!FileDB.CheckCave(p.xSec, p.ySec))
                {
                Writer.Word(p.x);                    //Player X Location
                Writer.Word(p.z);                    //Player Z Location
                Writer.Word(p.y);                    //Player Y Location
                }
                else
                {
                    if (p.x < 0)
                    {
                        Writer.Word(p.x);
                        Writer.Word(0xFFFF);
                    }
                    else
                    {
                        Writer.DWord(p.x);
                    }
                    Writer.DWord(p.z);

                    if (p.y < 0)
                    {
                        Writer.Word(p.y);
                        Writer.Word(0xFFFF);
                    }
                    else
                    {
                        Writer.DWord(p.y);
                    }
                }
                Writer.Bool(false);
                /* ReSearch this is ext packets
                Writer.Byte(p.xSec);                        //Player X Sector
                Writer.Byte(p.ySec);                        //Player Y Sector
                Writer.Word(p.x);                    //Player X Location
                Writer.DWord(p.z);                    //Player Z Location
                Writer.Word(p.y);         */           //Player Y Location
                return Writer.GetBytes();
        }