private void Init()
 {
     if (ProtocolId is - 1)
     {
         Message    = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Messages, x => x.name == ProtocolName];
         ProtocolId = Message?.protocolID ?? -1;
     }
Exemple #2
0
        public void HandleExchangeRequestedTradeMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
        {
            int  type     = content["exchangeType"];
            long targetId = content["target"];
            long sourceId = content["source"];

            FastActionManager.Instance.SendLeaveDialog(proxy);
        }
Exemple #3
0
        public void HandleGameRolePlayShowActorMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
        {
            double     mapId = ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId;
            ActorModel model = Parse(content["informations"], mapId);

            if (model != null)
            {
                FastEventManager.Instance.Handle(FastEventEnum.PlayerEnterMap, model);
            }
        }
Exemple #4
0
        public List <NetworkElementField> GetSuper(NetworkElementField field)
        {
            List <NetworkElementField> result = new List <NetworkElementField>();

            if (field.super != "NetworkMessage")
            {
                result.AddRange(GetSuper(Protocol[ProtocolKeyEnum.Messages, x => x.name == field.super]));
            }

            return(result);
        }
Exemple #5
0
        private void ServerMessageInformation_OnMessageParsed(NetworkElementField obj, ProtocolJsonContent con)
        {
            ProxyManager.Instance[ProcessId].SERVER_MESSAGE_RCV++;
            if (ConfigurationManager.Instance.Startup.show_message)
            {
                Console.WriteLine($"[Server({FakeClient.RemoteIP})] {obj.name} ({obj.protocolID})");
                if (ConfigurationManager.Instance.Startup.show_message_content)
                {
                    Console.WriteLine($"{con}");
                }
            }

            HandlerManager.Instance.Handle((uint)obj.protocolID, this, con);
        }
        public void HandleCharacterSelectedSuccessMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
        {
            PlayerModel model = new PlayerModel()
            {
                Id         = content["infos"]["id"],
                Name       = content["infos"]["name"],
                Level      = content["infos"]["level"],
                IsMerchant = false
            };

            ProxyManager.Instance[proxy.ProcessId].CharacterSelected = model;

            FastEventManager.Instance.Handle(FastEventEnum.PlayerSelected, model);
        }
        /// <summary>
        /// PAS ENCORE FINI
        /// </summary>
        /// <param name="field"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static byte[] ToByte(this NetworkElementField field, ProtocolJsonContent content)
        {
            if (content is null)
            {
                return(new byte[0]);
            }
            if (field is null)
            {
                throw new Exception("field cannot be null");
            }

            try
            {
                using (BigEndianWriter writer = new BigEndianWriter())
                {
                    if (field.super_serialize)
                    {
                        NetworkElementField super = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.MessageAndTypes, x => x.name == field.super];
                        byte[] super_data         = super.ToByte(content);
                        writer.WriteBytes(super_data);
                    }

                    IEnumerable <ClassField> boolWrapper = field.fields.Where(x => x.use_boolean_byte_wrapper).OrderBy(x => x.boolean_byte_wrapper_position);
                    IEnumerable <ClassField> vars        = field.fields.Where(x => !boolWrapper.Contains(x)).OrderBy(x => x.position);

                    if (boolWrapper.Count() > 0)
                    {
                        byte[] flags = new byte[boolWrapper.LastOrDefault().position.Value + 1];

                        foreach (ClassField _bool in boolWrapper)
                        {
                            flags[_bool.position.Value] = BooleanByteWrapper.SetFlag(flags[_bool.position.Value], (byte)((_bool.boolean_byte_wrapper_position.Value - 1) % 8), content[_bool.name]);
                        }
                    }

                    foreach (ClassField _var in vars)
                    {
                        Parse(_var, content[_var.name], writer);
                    }

                    return(writer.Data);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e}");
                return(new byte[0]);
            }
        }
Exemple #8
0
        public void Send(int processId, NetworkElementField message, ProtocolJsonContent content, bool clientSide)
        {
            if (message is null)
            {
                return;
            }

            using (BigEndianWriter writer = new BigEndianWriter())
            {
                byte[] data = message.ToByte(content);

                int cmpLen = _cmpLen(data.Length);
                writer.WriteShort((short)((message.protocolID << 2) | cmpLen));
                ProxyManager.Instance[processId].FAKE_MESSAGE_SENT++;
                if (clientSide)
                {
                    writer.WriteUnsignedInt(ProxyManager.Instance[processId].FAKE_MSG_INSTANCE_ID);
                }
                switch (cmpLen)
                {
                case 0:
                    break;

                case 1:
                    writer.WriteByte((byte)data.Length);
                    break;

                case 2:
                    writer.WriteShort((short)data.Length);
                    break;

                case 3:
                    writer.WriteByte((byte)((data.Length >> 16) & 255));
                    writer.WriteShort((short)(data.Length & 65535));
                    break;
                }

                writer.WriteBytes(data);
                Send(writer.Data);
                if (ConfigurationManager.Instance.Startup.show_fake_message_sent)
                {
                    Console.WriteLine($"Fake Message sent to ({RemoteIP}) : (n°{ProxyManager.Instance[processId].FAKE_MSG_INSTANCE_ID}) [{message.name} ({message.protocolID})]");
                    if (ConfigurationManager.Instance.Startup.show_message_content)
                    {
                        Console.WriteLine($"{content}");
                    }
                }
            }
        }
        public static ProtocolJsonContent Parse(this NetworkElementField field, ref BigEndianReader reader, ProtocolJsonContent content = null)
        {
            if (content is null)
            {
                content = new ProtocolJsonContent();
            }
            if (field is null)
            {
                return(content);
            }

            try
            {
                if (field.super_serialize)
                {
                    NetworkElementField super = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.MessageAndTypes, x => x.name == field.super];
                    content = super.Parse(ref reader, content);
                }
                IEnumerable <ClassField> boolWrapper = field.fields.Where(x => x.use_boolean_byte_wrapper).OrderBy(x => x.boolean_byte_wrapper_position);
                IEnumerable <ClassField> vars        = field.fields.Where(x => !boolWrapper.Contains(x)).OrderBy(x => x.position);

                byte flag = 0;

                for (byte i = 0; i < boolWrapper.Count(); i++)
                {
                    ClassField _bool = boolWrapper.ElementAt(i);

                    if (i % 8 == 0)
                    {
                        flag = reader.ReadByte();
                    }

                    content[_bool.name] = BooleanByteWrapper.GetFlag(flag, i);
                }

                foreach (ClassField _var in vars)
                {
                    content[_var.name] = _var.Parse(ref reader);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e}");
            }

            return(content);
        }
Exemple #10
0
        private void ClientMessageInformation_OnMessageParsed(NetworkElementField obj, ProtocolJsonContent con)
        {
            ProxyManager.Instance[ProcessId].LAST_GLOBAL_INSTANCE_ID = ClientMessageInformation.Information.InstanceId;
            ProxyManager.Instance[ProcessId].SERVER_MESSAGE_RCV      = 0;
            uint instance_id = ClientMessageInformation.Information.InstanceId + ProxyManager.Instance[ProcessId].FAKE_MESSAGE_SENT;

            if (ConfigurationManager.Instance.Startup.show_message)
            {
                Console.WriteLine($"[Client({FakeClient.RemoteIP})] (n°{instance_id} | ({ClientMessageInformation.Information.InstanceId} + {ProxyManager.Instance[ProcessId].FAKE_MESSAGE_SENT})) {obj.name} ({obj.protocolID})");
                if (ConfigurationManager.Instance.Startup.show_message_content)
                {
                    Console.WriteLine($"{con}");
                }
            }

            FakeClient.Send(ClientMessageInformation.Information.ReWriteInstanceId(instance_id));
            HandlerManager.Instance.Handle((uint)obj.protocolID, this, con);
        }
        private static dynamic _readElement(this ClassField field, ref BigEndianReader reader)
        {
            if (IsPrimitiv(field.type))
            {
                string read_method = $"Read{field.write_method.Replace("write", "")}";
                return(read_method._readMethod(ref reader));
            }
            else
            {
                NetworkElementField network_element = null;
                ProtocolJsonContent content         = null;

                bool is_null = false;
                if (field.write_false_if_null_method != null && field.write_false_if_null_method != "")
                {
                    string check_null_method = $"Read{field.write_false_if_null_method.Replace("write", "")}";
                    is_null = check_null_method._readMethod(ref reader) == 0;
                }

                if (is_null)
                {
                    return(null);
                }

                if (!field.prefixed_by_type_id)
                {
                    network_element = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.name == field.type];
                }
                else
                {
                    string  read_id_method = $"Read{field.write_type_id_method.Replace("write", "")}";
                    dynamic protocol_id    = read_id_method._readMethod(ref reader);
                    content = new ProtocolJsonContent();
                    content["protocol_id"] = protocol_id;

                    network_element = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.protocolID == protocol_id];
                }

                return(network_element.Parse(ref reader, content));
            }
        }
        public static void _writeElement(ClassField field, dynamic value, ref BigEndianWriter writer)
        {
            if (IsPrimitiv(field.type))
            {
                string write_method = field.write_method.Replace("write", "Write");
                _writeMethod(write_method, value, ref writer);
            }
            else
            {
                NetworkElementField var_type = null;
                bool is_null = value is null;

                if (is_null && field.write_false_if_null_method != null && field.write_false_if_null_method != "")
                {
                    string check_null_method = field.write_false_if_null_method.Replace("write", "Write");
                    _writeMethod(check_null_method, 0, ref writer);
                    return;
                }

                if (is_null)
                {
                    throw new Exception($"{var_type.name} cannot be null");
                }

                if (!field.prefixed_by_type_id)
                {
                    var_type = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.name == field.type];
                }
                else
                {
                    string write_type_id_method = field.write_type_id_method.Replace("write", "Write");
                    _writeMethod(write_type_id_method, value["protocol_id"], ref writer);

                    var_type = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.protocolID == value["protocol_id"]];
                }

                writer.WriteBytes(var_type.ToByte(value as ProtocolJsonContent));
            }
        }
Exemple #13
0
 public void HandleProtocolRequiredMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
 {
     Console.WriteLine($"Test : {content["requiredVersion"]}");
 }
Exemple #14
0
        public void HandleGameContextRemoveElementMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
        {
            double mapId = ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId;

            FastEventManager.Instance.Handle(FastEventEnum.ElementRemovedMap, content["id"], mapId);
        }
Exemple #15
0
        public void HandleMapComplementaryInformationsDataMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content)
        {
            MapModel map = new MapModel()
            {
                MapId = content["mapId"]
            };

            ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId = map.MapId;

            foreach (ProtocolJsonContent actor in content["actors"])
            {
                ActorModel model = Parse(actor, content["mapId"]);
                if (model != null)
                {
                    map.Actors.Add(model);
                }
            }

            FastEventManager.Instance.Handle(FastEventEnum.PlayerSelectedEnterMap, map);
        }
Exemple #16
0
        public void Send(int processId, int protocolId, ProtocolJsonContent content, bool clientSide = true)
        {
            NetworkElementField message = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Messages, x => x.protocolID == protocolId];

            Send(processId, message, content, clientSide);
        }
        private ProtocolJsonContent Content(NetworkElementField field)
        {
            BigEndianReader reader = new BigEndianReader(Information.Data);

            return(field.Parse(ref reader));
        }