Пример #1
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            String Name = mapleBuffer.read <string>();
            bool   ret  = Common.Tools.MapleCharacterUtil.getIdByName(Name);

            client.SendDatat(LoginPakcet.CharNameResponse(Name, !ret));
        }
Пример #2
0
 /// <summary>
 /// 玩家基本消息
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="chr"></param>
 /// <param name="client"></param>
 public static void addCharStats(MapleBuffer buffer, CCharacter chr, CMapleClient client)
 {
     buffer.add <int>(chr.Id);
     buffer.add(chr.Name, 0x13);
     buffer.add <byte>(client.UserInfo.Gender);
     buffer.add <byte>(byte.Parse(chr.Skin.ToString()));
     buffer.add <int>(chr.Face);
     buffer.add <int>(chr.Hair);
     buffer.add <long>(0);
     buffer.add <byte>((byte)chr.Level);
     buffer.add <short>(chr.Job);
     buffer.add <short>(chr.Str);
     buffer.add <short>(chr.Dex);
     buffer.add <short>(chr.Int_);
     buffer.add <short>(chr.Luk);
     buffer.add <short>(chr.Hp);
     buffer.add <short>(chr.Mp);
     buffer.add <short>(chr.Maxhp);
     buffer.add <short>(chr.Maxmp);
     buffer.add <short>(chr.Ap);
     buffer.add <short>(chr.Sp);
     buffer.add <int>(chr.Exp);
     buffer.add <short>(chr.Fame);
     buffer.add <int>(chr.MapId);
     buffer.add <byte>(chr.Spawnpoint);
     buffer.addTime(150842304000000000L);
     buffer.add <long>(0);
 }
Пример #3
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            int cid = mapleBuffer.read <int>();

            //
            client.SendDatat(LoginPakcet.getServerIP(new byte[] { 127, 0, 0, 1 }, 7575, cid));
        }
Пример #4
0
 /// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="Commans"></param>
 /// <param name="client"></param>
 public void Execute(string Name, string[] Commans, CMapleClient client)
 {
     try
     {
         if (!m_Command.ContainsKey(Name))
         {
             //找不到该命令.
             Console.WriteLine(@"该""{0}""命令不存在!", Name);
         }
         else
         {
             if (Commans.Length < m_Command[Name].Key.Parameters)
             {
                 Console.WriteLine(@"""{0}""命令使用错误:{1}", m_Command[Name].Key.Name, m_Command[Name].Key.Explain);
             }
             else if (m_Command[Name].Value.Execute(client, Commans) >= 1)
             {
                 Console.WriteLine(@"""{0}"":{0}执行完毕!", Name);
             }
             else
             {
                 Console.WriteLine(@"""{0}"":{0}执行失败!", Name);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(@"""{0}""命令异常:{1}", Name, e.Message);
     }
 }
Пример #5
0
        protected override void Encode(IChannelHandlerContext context, MaplePakcet message, IByteBuffer output)
        {
            using (message)
            {
                CMapleClient client = context.GetAttribute <CMapleClient>(CMapleClient.attributeKey).Get();
                if (client == null)
                {
                    output.WriteBytes(message.ToArray());
                }
                else
                {
                    //加密
                    using (MapleBuffer buffer = new MapleBuffer())
                    {
                        byte[] header = new byte[4];
                        client.m_SendIv.GetHeaderToClient(message.ToArray().Length, header);
                        client.m_SendIv.Transform();
                        buffer.add(header);
                        buffer.add(message.ToArray());

                        System.Console.WriteLine("发送封包:{0}", HexTool.toString(message.ToArray()));
                        output.WriteBytes(buffer.ToArray());
                    }
                }
            }
        }
Пример #6
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //TODO:游戏聊天(50%)
            //聊天消息
            string Text = mapleBuffer.read <string>();

            //管理员命令:!<命令> 参数
            //玩家命令:@<命令> 参数
            //以空格作为分割.分割1:命令头部,分割2:参数(参数以逗号分割.)
            string[] commands = Text.Split(" ");
            if (commands.Length >= 2)
            {
                //识别该说话为命令.
                if (commands[0].StartsWith("!<") && commands[0].EndsWith(">"))
                {
                    if (client.CharacterInfo.character.Gm >= 0)//只有管理员才能使用命令,
                    {
                        //存在该符号
                        string Command = commands[0].Trim().TrimStart("!<".ToCharArray()).TrimEnd(">".ToCharArray());
                        Console.WriteLine("玩家:" + client.CharacterInfo.character.Name + "使用命令:" + Command);
                        Commands.CommandProcessor.Processor.Execute(Command, commands[1].Split(","), client);
                    }
                }
                else if (commands[0].StartsWith("@<") && commands[0].EndsWith(">"))
                {
                    //玩家命令...
                }
            }
            else
            {
                client.SendDatat(PlayerPakcet.GetChatText(client.CharacterInfo.character.Id, Text));
            }
        }
Пример #7
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //TODO:选择服务器(0%)
            short serverId = mapleBuffer.read <byte>();

            client.SendDatat(LoginPakcet.getServerStatus(0));
        }
Пример #8
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            CMapleClient client = context.GetAttribute <CMapleClient>(CMapleClient.attributeKey).Get();

            if (client.DecoderState == -1)
            {
                //检测长度
                if (input.WriterIndex >= 4)
                {
                    int packetHeader = input.ReadInt();
                    client.DecoderState = MapleCipher.getPacketLength(packetHeader);//MapleAESOFB.getPacketLength(packetHeader);
                    int aaa = 0;
                    client.m_RecvIv.Transform();
                }
                else
                {
                    return;
                }
            }


            if (input.ReadableBytes >= client.DecoderState)
            {
                client.DecoderState = -1;
                //IntPtr DecoderState = context.GetAttribute<IntPtr>(MapleClient.DecoderState).Get();
                //获取数据长度,创建一个空数组
                byte[] DecodePakcet = new byte[input.ReadableBytes];

                //读取正常数据区域
                input.ReadBytes(DecodePakcet);
                //解密成功后返回数据
                output.Add(DecodePakcet);
            }
        }
Пример #9
0
 public static MaplePakcet AddPlayer(CMapleClient client, CCharacter chr)
 {
     using (MapleBuffer buffer = new MapleBuffer())
     {
         buffer.add <byte>(0);
         addCharEntry(buffer, chr, client);
         return(new MaplePakcet(buffer.ToArray()));
     }
 }
Пример #10
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            int serverid = mapleBuffer.read <byte>();
            int channel  = mapleBuffer.read <byte>();

            int id = client.UserInfo.Id;
            Dictionary <CCharacter, Dictionary <short, CItem> > Playerlist = CMapleCharacter.ShowAllCharacter(id, serverid);

            client.SendDatat(LoginPakcet.ShowPlayList(client, Playerlist, (byte)serverid));


            //TODO:获取角色列表(0%)
        }
Пример #11
0
 public static MaplePakcet ShowPlayList(CMapleClient client, Dictionary <CCharacter, Dictionary <short, CItem> > PlayerList, byte worldid)
 {
     using (MapleBuffer buffer = new MapleBuffer())
     {
         buffer.add <byte>(0);
         buffer.add <int>(0);
         buffer.add <byte>((byte)PlayerList.Count);
         foreach (KeyValuePair <CCharacter, Dictionary <short, CItem> > chr in PlayerList)
         {
             addCharEntry(buffer, chr.Key, client, chr.Value);
         }
         return(new MaplePakcet(buffer.ToArray()));
     }
 }
Пример #12
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            byte ChannelId = mapleBuffer.read <byte>();

            ChannelInfo state = new ChannelInfo();

            Task.Run(async() =>
            {
                state = (await ChannelServices.sChannelService.GetChannelInfo(ChannelId));
            }).Wait();

            client.SendDatat(PlayerPakcet.GetChannelChange(state.Address, state.port));
            //把该玩家从地图中删除对象.
            MapleMapFactory.MapFactory.GetMap(client.CharacterInfo.character.MapId).RemovePlayer(client.CharacterInfo);
        }
Пример #13
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //TODO:游戏登陆(0%)
            int cid = mapleBuffer.read <int>();

            //加载角色信息
            CCharacter mapleCharacter = CMapleCharacter.LoadData(cid, client);

            client.SendDatat(PlayerPakcet.GetCharInfo(ChannelServices.ChannelId, mapleCharacter, client));
            Console.WriteLine("角色信息:" + mapleCharacter.Name);
            //进行添加到地图列表中...
            MapleMapFactory.MapFactory.GetMap(client.CharacterInfo.character.MapId).AddPlayer(client.CharacterInfo);

            //CMapleMap.AddPlayer(mapleCharacter.MapId, client.CharacterInfo);
        }
Пример #14
0
        public static MaplePakcet GetCharInfo(int Channelid, CCharacter chr, CMapleClient client)
        {
            using (MapleBuffer buffer = new MapleBuffer())
            {
                buffer.add <int>(Channelid);//频道
                buffer.add <byte>(0);
                buffer.add <byte>(1);
                buffer.add <int>(new System.Random().Next());
                buffer.add <int>(new System.Random().Next());
                buffer.add <int>(new System.Random().Next());
                buffer.add <int>(0);

                AddCharacterInfo(buffer, chr, client);
                return(new MaplePakcet(buffer.ToArray()));
            }
        }
Пример #15
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            System.Console.WriteLine("发现用户:" + context.Channel.RemoteAddress.ToString());
            //027配套

            //创建一个客户端
            byte[]       ivRecv = { 70, 114, 122, 82 };
            byte[]       ivSend = { 82, 48, 120, 115 };
            CMapleClient client = new CMapleClient(27, ivRecv, ivSend, context.Channel);

            context.Channel.WriteAndFlushAsync(GetHello(27, ivRecv, ivSend));


            //设置客户端
            context.GetAttribute <CMapleClient>(CMapleClient.attributeKey).Set(client);
        }
Пример #16
0
 public static void Run(short id, MapleBuffer mapleBuffer, CMapleClient client)
 {
     if (mHandler.ContainsKey(id))
     {
         object[] attributes = mHandler[id].GetType().GetCustomAttributes(typeof(PacketHead), true);//.Attributes;
         foreach (object packethead in attributes)
         {
             if (packethead is PacketHead)
             {
                 Console.WriteLine("运行:" + ((PacketHead)packethead).Text);
             }
         }
         mHandler[id].Handle(mapleBuffer, client);
     }
     else
     {
         System.Console.WriteLine("包头:{0}[{1}]", id, mapleBuffer.ToString());
     }
 }
Пример #17
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //TODO:帐号注册(已完成)
            string UserNmae = mapleBuffer.read <string>();
            string UserPass = mapleBuffer.read <string>();

            CUserInfo info = new Common.Client.SQL.CUserInfo
            {
                Name      = mapleBuffer.read <string>(),
                BirthTime = mapleBuffer.read <string>(),

                HomePhone = mapleBuffer.read <string>(),
            };

            string[] Text = new string[4];
            for (int i = 0; i < 4; i++)
            {
                Text[i] = mapleBuffer.read <string>();
            }

            info.Problem = String.Join(",", Text);

            info.Email   = mapleBuffer.read <string>();
            info.IDCard  = mapleBuffer.read <string>();
            info.PhoneId = mapleBuffer.read <string>();

            //创建帐号
            CUser user = MySqlFactory.GetFactory.Insert <CUser>(new CUser
            {
                Name   = UserNmae,
                Passw  = UserPass,
                Gender = mapleBuffer.read <byte>(),
            }
                                                                );

            if (user == null)
            {
                client.SendDatat(LoginPakcet.RegisterAccount(true));
                return;
            }
            info.accid = user.Id;
            MySqlFactory.GetFactory.InsertAsync <CUserInfo>(info);
        }
Пример #18
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //TODO:帐号检查(已完成)
            CUser user = new CUser()
            {
                Name = mapleBuffer.read <string>(),
            };

            if (MySqlFactory.GetFactory.Query <CUser>().Where(a =>
                                                              a.Name.Equals(user.Name)
                                                              ).FirstOrDefault() == null)
            {
                client.SendDatat(LoginPakcet.CheckAccount(user.Name, false));
            }
            else
            {
                client.SendDatat(LoginPakcet.CheckAccount(user.Name, true));
            }
        }
Пример #19
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //封包: 01 05 00 61 64 6D 69 6E 05 00 61 61 61 61 61 00 00 E0 4C 68 02 E1 D9 62 59 24 00 00 00 00 BF F5 00 00 00 00

            //TODO:登陆帐号(5%)
            CUser user = new CUser()
            {
                Name  = mapleBuffer.read <string>(),
                Passw = mapleBuffer.read <string>(),
            };


            //MySqlContext context = new MySqlContext(MySqlFactory.GetFactory);//MySqlFactory.GetFactory.Query<CUser>();
            IQuery <CUser> q = MySqlFactory.GetFactory.Query <CUser>();

            CUser UserInfo = (CUser)q.Where(a => a.Name.Equals(user.Name)).FirstOrDefault();

            if (UserInfo == null)
            {
                //client.SendDatat(LoginPakcet.getLoginFailed(5));
                //TODO:自动注册功能(100%)
                client.SendDatat(LoginPakcet.ShowRegister(true));
            }
            else
            {
                if (!user.Passw.Equals(UserInfo.Passw))
                {
                    System.Console.WriteLine("密码错误..");
                    client.SendDatat(LoginPakcet.getLoginFailed(4));
                    return;
                }
                //TODO:登陆请求(50%)
                client.UserInfo = UserInfo;
                client.SendDatat(LoginPakcet.getAuthSuccessRequest(UserInfo));
                //发送全部世界..
                for (int i = 0; i < WorldEntity.GetWorld().Count; i++)
                {
                    client.SendDatat(LoginPakcet.getServerList(WorldEntity.GetWorld()[i]));
                }
                client.SendDatat(LoginPakcet.getEndOfServerList());
            }
        }
Пример #20
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            try
            {
                MapleBuffer buffer = new MapleBuffer((byte[])message);
                if (buffer.Available < 2)
                {
                    return;
                }
                System.Console.WriteLine("封包: {0}", buffer.ToString());

                CMapleClient client = context.GetAttribute <CMapleClient>(CMapleClient.attributeKey).Get();
                if (client != null)
                {
                    short packetId = buffer.read <byte>();
                    CommonGlobal.Run(packetId, buffer, client);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("错误:" + e);
            }
        }
Пример #21
0
        //TODO:玩家信息(100%)
        public static void AddCharacterInfo(MapleBuffer buffer, CCharacter chr, CMapleClient client)
        {
            buffer.add <short>(-1);
            AddCharStats(buffer, chr, client);
            buffer.add <byte>(20);
            buffer.add <int>(0);//金币

            //装备与道具
            AddInventoryInfo(buffer, client.CharacterInfo);

            //技能
            buffer.add <short>(0);

            //任务
            buffer.add <short>(0);
            buffer.add <short>(0);
            //戒指
            buffer.add <short>(0);
            for (int i = 0; i < 5; i++)
            {
                buffer.add <int>(0);
            }
        }
Пример #22
0
        public override void Handle(MapleBuffer mapleBuffer, CMapleClient client)
        {
            //封包: 0B 08 00 78 7A 6B 6D 78 64 61 35 [20 4E 00 00] [4E 75 00 00] [82 DE 0F 00] [A2 2C 10 00] [81 5B 10 00] [F0 DD 13 00] 04 06 0A 05
            CCharacter character = new CCharacter()
            {
                Name   = mapleBuffer.read <string>(),
                Face   = mapleBuffer.read <int>(),
                Hair   = mapleBuffer.read <int>(),
                Userid = client.UserInfo.Id,
                Party  = 1,
                Gm     = 0,
                Hp     = 50,
                Mp     = 50,
                MapId  = 0,
                Maxhp  = 50,
                Maxmp  = 50,
                Job    = 0,
                Sp     = 0,
                World  = 0,
                Level  = 1,
                Exp    = 0,
            };

            int[] Euqip = new int[4];
            for (int i = 0; i < Euqip.Length; i++)
            {
                Euqip[i] = mapleBuffer.read <int>();
            }
            Dictionary <short, int> dictionary = new Dictionary <short, int>();

            for (int i = 0; i < Euqip.Length; i++)
            {
                switch (i)
                {
                case 0:
                    dictionary.Add(-5, Euqip[i]);
                    break;

                case 1:
                    dictionary.Add(-6, Euqip[i]);
                    break;

                case 2:
                    dictionary.Add(-7, Euqip[i]);
                    break;

                case 3:
                    dictionary.Add(-9, Euqip[i]);
                    break;
                }
            }

            //dictionary.Add(-)

            character.Str  = mapleBuffer.read <byte>();
            character.Dex  = mapleBuffer.read <byte>();
            character.Int_ = mapleBuffer.read <byte>();
            character.Luk  = mapleBuffer.read <byte>();

            if (CMapleCharacter.CreatorPlayer(client.UserInfo.Id, client, character, dictionary))
            {
                client.SendDatat(LoginPakcet.AddPlayer(client, character));
            }
        }
Пример #23
0
 public abstract void Handle(MapleBuffer mapleBuffer, CMapleClient client);
Пример #24
0
 public int Execute(CMapleClient client, string[] paramArrayOfString)
 {
     client.SendDatat(PlayerPakcet.ServerMessage(1, "游戏升级命令!" + int.Parse(paramArrayOfString[0])));
     return(1);
 }
Пример #25
0
 public int Execute(CMapleClient client, string[] paramArrayOfString)
 {
     Console.WriteLine("玩家:" + client.CharacterInfo.character.Name);
     return(-1);
 }
Пример #26
0
        public static void addCharEntry(MapleBuffer buffer, CCharacter chr, CMapleClient client, Dictionary <short, CItem> dictionary = null)
        {
            addCharStats(buffer, chr, client);

            if (client.CharacterInfo != null)
            {
                foreach (KeyValuePair <short, CItem> Equip in client.CharacterInfo.GetMapleInventory(Common.Client.Inventory.InventoryType.佩戴).getInventory())
                {
                    short Posint = (short)(Equip.Key * -1);
                    if (Posint < 100)
                    {
                        buffer.add <byte>((byte)(int.Parse(Posint.ToString()) & 0xFF));
                        buffer.add <int>(Equip.Value.ItemId);
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <short, CItem> Equip in dictionary)
                {
                    short Posint = (short)(Equip.Key * -1);
                    if (Posint < 100)
                    {
                        buffer.add <byte>((byte)(int.Parse(Posint.ToString()) & 0xFF));
                        buffer.add <int>(Equip.Value.ItemId);
                    }
                }
            }


            buffer.add <byte>(0);

            if (client.CharacterInfo != null)
            {
                foreach (KeyValuePair <short, CItem> Equip in client.CharacterInfo.GetMapleInventory(Common.Client.Inventory.InventoryType.佩戴).getInventory())
                {
                    short Posint = (short)(Equip.Key * -1);
                    if (Posint > 100)
                    {
                        buffer.add <byte>((byte)(int.Parse(Posint.ToString()) & 0xFF));
                        buffer.add <int>(Equip.Value.ItemId);
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <short, CItem> Equip in dictionary)
                {
                    short Posint = (short)(Equip.Key * -1);
                    if (Posint > 100)
                    {
                        buffer.add <byte>((byte)(int.Parse(Posint.ToString()) & 0xFF));
                        buffer.add <int>(Equip.Value.ItemId);
                    }
                }
            }

            //Dictionary<byte, int> maskedEquip = new Dictionary<byte, int>();
            //maskedEquip.Add(1, 1002067);
            //foreach (KeyValuePair<byte, int> Equip in maskedEquip)
            //{
            //    buffer.add<byte>(Equip.Key);
            //    buffer.add<int>(Equip.Value);
            //}

            buffer.add <byte>(0);
        }
Пример #27
0
 public abstract void SendDestroyData(CMapleClient c, MaplePakcet pakcet);
Пример #28
0
 public abstract void SendSpawnData(CMapleClient c, MaplePakcet pakcet);