private void CreatePacket()
        {
            eMessageType eOpCode = (eMessageType)m_bOpCode;

            ResetPacketHeader();

            m_PacketDataStream.Position = 0;             // reset position so it is ready for reading

            Packet packet = ClientConnectionUtil.ProcessClientPacket(eOpCode, m_PacketDataStream, this);

            if (packet != null)
            {
                m_vPacketsToProcess.Enqueue(new SinglePacketProcessor(packet));
                EngineControler.Instance.QueForProcessing(this);
            }
            else
            {
                AOutput.Log("Create packet failed!");
            }

            if (m_vSocketData.Count > 0)
            {
                EngineControler.Instance.QueForTick(this);
            }
        }
Exemplo n.º 2
0
        public static void Add(eMessageType type, string text)
        {
            Message message = new Message(type, text);

            Messages.Add(message);
            AddToFile(message);
        }
        /// <summary>
        /// Processes an incoming packet to an ClientConnection interface
        /// </summary>
        /// <param name="messageType">Packet message identifier</param>
        /// <param name="packetStream">Packet stream data</param>
        /// <param name="client">Client interface to handle the packet</param>
        /// <param name="bThrowOnError">True to throw an exception instead of logging</param>
        /// <returns>Packet to process or NULL if a control packet dispatched to the client</returns>
        public static Packet ProcessClientPacket(eMessageType messageType, Stream packetStream, ClientConnection client, bool bThrowOnError)
        {
            // string userName = ( client.ConnectionUser != null ) ? client.ConnectionUser.Login : "******";

            Packet packet = PacketFactory.Instance.ParseData(messageType, packetStream, client);

//             if( packet is LogoutPacket )
//             {
//                 client.SignalLogout();
//                 return null;
//             }
            //else
            if (packet.IsValid)
            {
                return(packet);
            }

            if (bThrowOnError)
            {
                throw new InvalidOperationException(string.Format(@"Invalid Packet Data Received For Type '{0}'. {1}", messageType, "userName"));
            }
            else
            {
                AOutput.Log(string.Format(@"Invalid Packet Data Received For Type '{0}'. {1}", messageType, "userName"));
            }

            return(null);
        }
Exemplo n.º 4
0
        public override void Decode(byte[] buffer, int offset, int length)
        {
            BEncodedValue val;

            using (RawReader reader = new RawReader(new MemoryStream(buffer, offset, length, false), false))
            {
                BEncodedDictionary d = BEncodedDictionary.Decode <BEncodedDictionary>(reader);
                int totalSize        = 0;

                if (d.TryGetValue(MessageTypeKey, out val))
                {
                    messageType = (eMessageType)((BEncodedNumber)val).Number;
                }
                if (d.TryGetValue(PieceKey, out val))
                {
                    piece = (int)((BEncodedNumber)val).Number;
                }
                if (d.TryGetValue(TotalSizeKey, out val))
                {
                    totalSize = (int)((BEncodedNumber)val).Number;
                    metadata  = new byte[Math.Min(totalSize - piece * BlockSize, BlockSize)];
                    reader.Read(metadata, 0, metadata.Length);
                }
            }
        }
Exemplo n.º 5
0
	public void RegisterFunction(eMessageType _type, MessageFunction _func)
	{
		if(m_dicFunction.ContainsKey(_type) == true)
			m_dicFunction.Remove(_type);
		
		m_dicFunction.Add(_type, _func);
	}
Exemplo n.º 6
0
        public void Trace(eMessageType type, string message, params object[] args)
        {
            try
            {
                if (this.TelemetryFactory != null && this.TelemetryClient != null && !string.IsNullOrEmpty(message))
                {
                    var level = eSeverityLevel.Information;
                    if (type == eMessageType.Warning)
                    {
                        level = eSeverityLevel.Warning;
                    }
                    else if (type == eMessageType.Error)
                    {
                        level = eSeverityLevel.Error;
                    }

                    if (this.TelemetryClient != null && this.TelemetryFactory != null)
                    {
                        var msgTelemetry = this.TelemetryFactory.BuildMessageTelemetry(string.Format(message, args), level);
                        this.TelemetryClient.Track(msgTelemetry);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// <see cref="Message.DeserializeSelf"/>.
        /// </summary>
        protected override bool DeserializeSelf(byte[] data)
        {
            if (data.Length < 5)
            {
                return(false);
            }
            eMessageType type = (eMessageType)data[0];

            if (type != Type)
            {
                return(false);
            }
            ushort id, dimension;

            id        = (ushort)((data[1] << 8) + data[2]);
            dimension = (ushort)((data[3] << 8) + data[4]);
            if (data.Length < 5 + dimension * 4)
            {
                return(false);
            }
            values         = new float[dimension];
            this.id        = id;
            this.dimension = dimension;
            for (int i = 0; i < dimension; i++)
            {
                uint bytes = 0;
                bytes    |= (uint)data[5 + 4 * i + 0] << 24;
                bytes    |= (uint)data[5 + 4 * i + 1] << 16;
                bytes    |= (uint)data[5 + 4 * i + 2] << 8;
                bytes    |= (uint)data[5 + 4 * i + 3] << 0;
                values[i] = UintToFloat(bytes);
            }

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Construct message from bytestream.
        /// </summary>
        /// <returns>Returns null on failure.</returns>
        public static Message Deserialize(byte[] data)
        {
            eMessageType type = (eMessageType)data[0];
            Message      message;

            switch (type)
            {
            case eMessageType.LAYOUT:
                message = new LayoutMessage();
                break;

            case eMessageType.DATA:
                message = new DataMessage();
                break;

            case eMessageType.PATH:
                message = new PathMessage();
                break;

            default:
                message = null;
                break;
            }
            bool isOk = false;

            if (message != null)
            {
                isOk = message.DeserializeSelf(data);
            }
            return(isOk ? message : null);
        }
        public void Initialize_With_Message_Details_And_Message_And_ParamArray_Contains_Message_Details_Properties_And_Message_Formatted_By_ParamArray()
        {
            eMessageActionSets expectedActionSet     = eMessageActionSets.YesNoCancel;
            eMessageType       expectedMessageType   = eMessageType.Warning;
            eMessageActions    expectedActionDefault = eMessageActions.Cancel;

            MessageDetails messageDetails = new MessageDetails(expectedActionSet, expectedMessageType, expectedActionDefault);

            string baseMessage = "A new message{0}with a new value of {1}";

            object[] argArray        = { @"/n", 42 };
            string   expectedMessage = string.Format(baseMessage, argArray);

            MessengerEventArgs messengerEventArg = new MessengerEventArgs(messageDetails, baseMessage, argArray);

            Assert.AreEqual(expectedMessage, messengerEventArg.Message);
            Assert.AreEqual(expectedActionDefault, messengerEventArg.ActionDefault);
            Assert.AreEqual(expectedActionSet, messengerEventArg.ActionSet);
            Assert.AreEqual(expectedMessageType, messengerEventArg.MessageType);

            Assert.AreEqual("", messengerEventArg.Title);
            Assert.AreEqual("", messengerEventArg.Footer);
            Assert.AreEqual("", messengerEventArg.PromptList);
            Assert.AreEqual(defaultAction, messengerEventArg.Action);
            Assert.AreEqual(defaultHandled, messengerEventArg.Handled);
        }
Exemplo n.º 10
0
 public bool GetAnnex(string value, GamePlayer player, ref string msg, ref bool result, ref eMessageType eMsg)
 {
     int gid = int.Parse(value);
     using (PlayerBussiness db = new PlayerBussiness())
     {
         ItemInfo goods = db.GetUserItemSingle(gid);
         if (goods != null)
         {
             if (goods.TemplateID == 11408)
             {
                 player.AddMedal(goods.Count);
                 return true;
             }
             else
             {
                 if (player.AddItem(goods))
                 {
                     eMsg = eMessageType.Normal;
                     return true;
                 }
                 else
                 {
                     eMsg = eMessageType.ERROR;
                     result = false;
                     msg = LanguageMgr.GetTranslation(goods.GetBagName()) + LanguageMgr.GetTranslation("MailGetAttachHandler.NoPlace");
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 11
0
 public cBufferedMessage(eMessageType MessageType, string PacketType, string MessageId, string SendString)
 {
     this.MessageType = MessageType;
     sPacketType      = PacketType;
     sMessageId       = MessageId;
     sSendString      = SendString;
 }
        private void AdvisorSay(Guid advisorID, string text, eMessageType messageType)
        {
            if (advisors.ContainsKey(advisorID) && advisors[advisorID].Child.HasValue)
            {
                advisors[advisorID].Messages.Add(
                    new Message()
                {
                    ID          = advisors[advisorID].Messages.Count,
                    From        = advisorID,
                    MessageType = messageType,
                    Received    = DateTime.Now,
                    Text        = InsertEmoticon(text)
                });

                var childId = advisors[advisorID].Child.Value;
                if (children.ContainsKey(childId))
                {
                    children[childId].Messages.Add(
                        new Message()
                    {
                        ID          = children[childId].Messages.Count,
                        From        = advisorID,
                        MessageType = messageType,
                        Received    = DateTime.Now,
                        Text        = InsertEmoticon(text)
                    });
                }
            }
        }
 /// <summary>
 /// Writes a message to the plugin trace log.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="message"></param>
 /// <param name="args"></param>
 public virtual void Trace(eMessageType type, string message, params object[] args)
 {
     if (!string.IsNullOrEmpty(message))
     {
         var msg = type.ToString() + ": " + message;
         this.TracingService.Trace(msg, args);
     }
 }
Exemplo n.º 14
0
 public void SendMessage(eMessageType type, string msg)
 {
     if (this.m_host != null)
     {
         GSPacketIn pkg = this.m_host.Out.SendMessage(type, msg);
         this.SendToAll(pkg, this.m_host);
     }
 }
Exemplo n.º 15
0
 public UserMessage(eMessageType MessageType, string Caption, string Message, MessageBoxButton ButtonsType, MessageBoxResult DefualtResualt)
 {
     this.MessageType    = MessageType;
     this.Caption        = Caption;
     this.Message        = Message;
     this.ButtonsType    = ButtonsType;
     this.DefualtResualt = DefualtResualt;
 }
Exemplo n.º 16
0
        public override int HandlePacket(GamePlayer player, GSPacketIn packet)
        {
            eMessageType eMsg         = eMessageType.Normal;
            string       msg          = "UserChangeItemColorHandler.Success";
            int          Card_bagType = packet.ReadInt();
            int          Card_place   = packet.ReadInt();
            int          bagType      = packet.ReadInt();
            int          place        = packet.ReadInt();
            string       color        = packet.ReadString();
            string       skin         = packet.ReadString();
            int          templateID   = packet.ReadInt();
            ItemInfo     item         = player.MainBag.GetItemAt(place);
            ItemInfo     card         = player.PropBag.GetItemAt(Card_place);

            if (item != null)
            {
                player.BeginChanges();
                try
                {
                    bool changed = false;
                    if (card != null && card.IsValidItem())
                    {
                        player.PropBag.RemoveItem(card, eItemRemoveType.Use);
                        changed = true;
                    }
                    else
                    {
                        ItemTemplateInfo    template = ItemMgr.FindItemTemplate(templateID);
                        List <ShopItemInfo> Template = ShopMgr.FindShopbyTemplatID(templateID);
                        int Money = 0;
                        for (int i = 0; i < Template.Count; i++)
                        {
                            if (Template[i].APrice1 == -1 && Template[i].AValue1 != 0)
                            {
                                Money = Template[i].AValue1;
                            }
                        }
                        if (Money <= player.PlayerCharacter.Money)
                        {
                            player.RemoveMoney(Money, LogMoneyType.Item, LogMoneyType.Item_Color);
                            changed = true;
                        }
                    }
                    if (changed)
                    {
                        item.Color = ((color == null) ? "" : color);
                        item.Skin  = ((skin == null) ? "" : skin);
                        player.MainBag.UpdateItem(item);
                    }
                }
                finally
                {
                    player.CommitChanges();
                }
            }
            player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0]));
            return(0);
        }
Exemplo n.º 17
0
 protected void RaiseMessage(string message, string extendedMessage = "", eMessageType messageType = eMessageType.Info)
 {
     if (this.Message != null)
     {
         Message(this, new MessageEventArgs {
             Message = message, MessageExtended = extendedMessage, MessageType = messageType
         });
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageDetails"/> class.
 /// </summary>
 /// <param name="messageActionSet">Decision combination types to display with the message.</param>
 /// <param name="messageType">Type of message.</param>
 /// <param name="messageDefault">Default action to take.</param>
 public MessageDetails(
     eMessageActionSets messageActionSet = eMessageActionSets.OkOnly,
     eMessageType messageType            = eMessageType.None,
     eMessageActions messageDefault      = eMessageActions.None)
 {
     MessageType   = messageType;
     ActionSet     = messageActionSet;
     ActionDefault = messageDefault;
 }
        /// <summary>
        /// Converts the message enum to the corresponding MessageBox enum.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>MessageBoxImage.</returns>
        protected static MessageBoxImage toMessageBox(eMessageType value)
        {
            switch (value)
            {
            case eMessageType.Asterisk:
            {
                return(MessageBoxImage.Asterisk);
            }

            case eMessageType.Error:
            {
                return(MessageBoxImage.Error);
            }

            case eMessageType.Exclamation:
            {
                return(MessageBoxImage.Exclamation);
            }

            case eMessageType.Hand:
            {
                return(MessageBoxImage.Hand);
            }

            case eMessageType.Information:
            {
                return(MessageBoxImage.Information);
            }

            case eMessageType.None:
            {
                return(MessageBoxImage.None);
            }

            case eMessageType.Question:
            {
                return(MessageBoxImage.Question);
            }

            case eMessageType.Stop:
            {
                return(MessageBoxImage.Stop);
            }

            case eMessageType.Warning:
            {
                return(MessageBoxImage.Warning);
            }

            default:
            {
                return(MessageBoxImage.None);
            }
            }
        }
Exemplo n.º 20
0
 public Message(eMessageType type, JSONObject data = null)
 {
     _type = type;
     if (data == null)
     {
         _data = JSONObject.nullJO;
     }
     else
     {
         _data = data;
     }
 }
Exemplo n.º 21
0
    public void PopUpPanelTwo(string msg,
                              eMessageType msgType = eMessageType.Normal)
    {
        message.text = msg;

        //		if (msgType == eMessageType.Normal)
        //			message.color = Color.white;
        //		else if (msgType == eMessageType.Warning)
        //			message.color = Color.yellow;
        //		else if (msgType == eMessageType.Error)
        //			message.color = Color.red;
    }
Exemplo n.º 22
0
        public void InitializeWithOptionalProperties_All_Contains_All()
        {
            eMessageActionSets expectedActionSet   = eMessageActionSets.YesNoCancel;
            eMessageType       expectedMessageType = eMessageType.Warning;
            eMessageActions    expectedDefault     = eMessageActions.Cancel;

            MessageDetails messageDetails = new MessageDetails(expectedActionSet, expectedMessageType, expectedDefault);

            Assert.AreEqual(expectedDefault, messageDetails.ActionDefault);
            Assert.AreEqual(expectedActionSet, messageDetails.ActionSet);
            Assert.AreEqual(expectedMessageType, messageDetails.MessageType);

            Assert.AreEqual(defaultAction, messageDetails.Action);
        }
Exemplo n.º 23
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (client.Player.PlayerCharacter.MarryInfoID != 0)
            {
                return(1);
            }

            bool         IsPublishEquip = packet.ReadBoolean();
            string       Introduction   = packet.ReadString();
            int          UserID         = client.Player.PlayerCharacter.ID;
            eMessageType eMsg           = eMessageType.Normal;
            string       msg            = "MarryInfoAddHandler.Fail";

            int needGold = 10000;

            if (needGold > client.Player.PlayerCharacter.Gold)
            {
                eMsg = eMessageType.ERROR;
                msg  = "MarryInfoAddHandler.Msg1";
            }
            else
            {
                client.Player.SaveIntoDatabase();
                MarryInfo info = new MarryInfo();
                info.UserID         = UserID;
                info.IsPublishEquip = IsPublishEquip;
                info.Introduction   = Introduction;
                info.RegistTime     = DateTime.Now;

                using (PlayerBussiness db = new PlayerBussiness())
                {
                    if (db.AddMarryInfo(info))
                    {
                        client.Player.RemoveGold(needGold);
                        msg = "MarryInfoAddHandler.Msg2";
                        client.Player.PlayerCharacter.MarryInfoID = info.ID;
                        client.Out.SendMarryInfoRefresh(info, info.ID, true);
                    }
                }
            }


            client.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg));

            return(0);
        }
Exemplo n.º 24
0
        public override int HandlePacket(GamePlayer player, GSPacketIn packet)
        {
            int result;

            if (player.PlayerCharacter.MarryInfoID != 0)
            {
                result = 1;
            }
            else
            {
                bool         IsPublishEquip = packet.ReadBoolean();
                string       Introduction   = packet.ReadString();
                int          UserID         = player.PlayerCharacter.ID;
                eMessageType eMsg           = eMessageType.Normal;
                string       msg            = "MarryInfoAddHandler.Fail";
                int          needGold       = 10000;
                if (needGold > player.PlayerCharacter.Gold)
                {
                    eMsg = eMessageType.ERROR;
                    msg  = "MarryInfoAddHandler.Msg1";
                }
                else
                {
                    player.SaveIntoDatabase();
                    MarryInfo info = new MarryInfo();
                    info.UserID         = UserID;
                    info.IsPublishEquip = IsPublishEquip;
                    info.Introduction   = Introduction;
                    info.RegistTime     = DateTime.Now;
                    using (PlayerBussiness db = new PlayerBussiness())
                    {
                        if (db.AddMarryInfo(info))
                        {
                            player.RemoveGold(needGold);
                            msg = "MarryInfoAddHandler.Msg2";
                            player.PlayerCharacter.MarryInfoID = info.ID;
                            player.Out.SendMarryInfoRefresh(info, info.ID, true);
                        }
                    }
                }
                player.Out.SendMessage(eMsg, LanguageMgr.GetTranslation(msg, new object[0]));
                result = 0;
            }
            return(result);
        }
Exemplo n.º 25
0
        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId      = extensionId;
            this.messageType = type;
            this.metadata    = metadata;
            this.piece       = piece;

            dict = new BEncodedDictionary();
            dict.Add(MessageTypeKey, (BEncodedNumber)(int)messageType);
            dict.Add(PieceKey, (BEncodedNumber)piece);

            if (messageType == eMessageType.Data)
            {
                Check.Metadata(metadata);
                dict.Add(TotalSizeKey, (BEncodedNumber)metadata.Length);
            }
        }
Exemplo n.º 26
0
        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId = extensionId;
            MetadataMessageType = type;
            MetadataPiece = metadata;
            Piece = piece;

            dict = new BEncodedDictionary();
            dict.Add(MessageTypeKey, (BEncodedNumber) (int) MetadataMessageType);
            dict.Add(PieceKey, (BEncodedNumber) piece);

            if (MetadataMessageType == eMessageType.Data)
            {
                Check.Metadata(metadata);
                dict.Add(TotalSizeKey, (BEncodedNumber) metadata.Length);
            }
        }
Exemplo n.º 27
0
    public void PopUpPanel(string msg, System.Action callback, eMessageType msgType = eMessageType.Normal)
    {
        m_callback   = callback;
        message.text = msg;

        if (msgType == eMessageType.Normal)
        {
            message.color = Color.white;
        }
        else if (msgType == eMessageType.Warning)
        {
            message.color = Color.yellow;
        }
        else if (msgType == eMessageType.Error)
        {
            message.color = Color.red;
        }
    }
Exemplo n.º 28
0
        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId         = extensionId;
            MetadataMessageType = type;
            MetadataPiece       = metadata;
            Piece = piece;

            dict = new BEncodedDictionary {
                { MessageTypeKey, (BEncodedNumber)(int)MetadataMessageType },
                { PieceKey, (BEncodedNumber)piece }
            };

            if (MetadataMessageType == eMessageType.Data)
            {
                Check.Metadata(metadata);
                dict.Add(TotalSizeKey, (BEncodedNumber)metadata.Length);
            }
        }
Exemplo n.º 29
0
        public LTMetadata(byte extensionId, eMessageType type, int piece, byte[] metadata)
            : this()
        {
            ExtensionId = extensionId;
            _messageType = type;
            MetadataPiece = metadata;
            Piece = piece;

            _dict = new BEncodedDictionary
                        {
                            {MessageTypeKey, (BEncodedNumber) (int) _messageType},
                            {PieceKey, (BEncodedNumber) piece}
                        };

            if (_messageType != eMessageType.Data)
                return;

            Check.Metadata(metadata);
            _dict.Add(TotalSizeKey, (BEncodedNumber) metadata.Length);
        }
Exemplo n.º 30
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            if (client.Player.PlayerCharacter.MarryInfoID != 0)
            {
                return(1);
            }
            bool         isPublishEquip = packet.ReadBoolean();
            string       introduction   = packet.ReadString();
            int          iD             = client.Player.PlayerCharacter.ID;
            eMessageType type           = eMessageType.Normal;
            string       translateId    = "MarryInfoAddHandler.Fail";
            int          num            = 10000;

            if (num > client.Player.PlayerCharacter.Gold)
            {
                type        = eMessageType.ERROR;
                translateId = "MarryInfoAddHandler.Msg1";
            }
            else
            {
                client.Player.SaveIntoDatabase();
                MarryInfo marryInfo = new MarryInfo();
                marryInfo.UserID         = iD;
                marryInfo.IsPublishEquip = isPublishEquip;
                marryInfo.Introduction   = introduction;
                marryInfo.RegistTime     = DateTime.Now;
                using (PlayerBussiness playerBussiness = new PlayerBussiness())
                {
                    if (playerBussiness.AddMarryInfo(marryInfo))
                    {
                        client.Player.RemoveGold(num);
                        translateId = "MarryInfoAddHandler.Msg2";
                        client.Player.PlayerCharacter.MarryInfoID = marryInfo.ID;
                        client.Out.SendMarryInfoRefresh(marryInfo, marryInfo.ID, true);
                    }
                }
            }
            client.Out.SendMessage(type, LanguageMgr.GetTranslation(translateId, new object[0]));
            return(0);
        }
 public void setMessage(string ip_str_mess_title, string ip_str_mess_content, eMessageType eMessageType)
 {
     m_lbl_mess_title.Text = ip_str_mess_title;
     m_lbl_mess_content.Text = ip_str_mess_content;
     switch (eMessageType)
     {
         case eMessageType.Warning:
             strClassMessage += "warning";
             break;
         case eMessageType.Error:
             strClassMessage += "danger";
             break;
         case eMessageType.Success:
             strClassMessage += "success";
             break;
         case eMessageType.Info:
             strClassMessage += "info";
             break;
         default:
             break;
     }
 }
Exemplo n.º 32
0
        public override void Trace(eMessageType type, string message, params object[] args)
        {
            base.Trace(type, message, args);
            if (!string.IsNullOrEmpty(message))
            {
                if (this.TelemetryClient != null && this.TelemetryFactory != null)
                {
                    var level = eSeverityLevel.Information;
                    if (type == eMessageType.Warning)
                    {
                        level = eSeverityLevel.Warning;
                    }
                    else if (type == eMessageType.Error)
                    {
                        level = eSeverityLevel.Error;
                    }

                    var msgTelemetry = this.TelemetryFactory.BuildMessageTelemetry(string.Format(message, args), level);
                    this.TelemetryClient.Track(msgTelemetry);
                }
            }
        }
Exemplo n.º 33
0
        public override void Decode(byte[] buffer, int offset, int length)
        {
            using (var reader = new RawReader(new MemoryStream(buffer, offset, length, false), false))
            {
                var decode = BEncodedValue.Decode <BEncodedDictionary>(reader);

                BEncodedValue val;
                if (decode.TryGetValue(MessageTypeKey, out val))
                {
                    _messageType = (eMessageType)((BEncodedNumber)val).Number;
                }
                if (decode.TryGetValue(PieceKey, out val))
                {
                    Piece = (int)((BEncodedNumber)val).Number;
                }
                if (decode.TryGetValue(TotalSizeKey, out val))
                {
                    var totalSize = (int)((BEncodedNumber)val).Number;
                    MetadataPiece = new byte[Math.Min(totalSize - Piece * BlockSize, BlockSize)];
                    reader.Read(MetadataPiece, 0, MetadataPiece.Length);
                }
            }
        }
Exemplo n.º 34
0
	public void ReleaseFunction(eMessageType _type)
	{
		if(m_dicFunction.ContainsKey(_type) == true)
			m_dicFunction.Remove(_type);
	}
Exemplo n.º 35
0
 public GSPacketIn SendMessage(eMessageType type, string message)
 {
     Console.WriteLine(message);
     return null;
 }
Exemplo n.º 36
0
 public virtual GSPacketIn SendMessage(eMessageType type, string message)
 {
     GSPacketIn pkg = new GSPacketIn((byte)ePackageType.SYS_MESS);
     pkg.WriteInt((int)type);
     pkg.WriteString(message);
     SendTCP(pkg);
     return pkg;
 }
Exemplo n.º 37
0
 public void SendMessage(eMessageType type, string msg)
 {
     if (m_host != null)
     {
         GSPacketIn pkg = m_host.Out.SendMessage(type, msg);
         SendToAll(pkg, m_host);
     }
 }
Exemplo n.º 38
0
 private void ChildSay(Guid childID, string text, eMessageType messageType)
 {
     if (children.ContainsKey(childID) && children[childID].Advisor.HasValue)
     {
         children[childID].Messages.Add(
             new Message()
             {
                 ID = children[childID].Messages.Count,
                 From = childID,
                 MessageType = messageType,
                 Received = DateTime.Now,
                 Text = InsertEmoticon(text)
             });
         var advisorID = children[childID].Advisor.Value;
         if (advisors.ContainsKey(advisorID))
         {
             advisors[advisorID].Messages.Add(
                 new Message()
                 {
                     ID = advisors[advisorID].Messages.Count,
                     From = childID,
                     MessageType = messageType,
                     Received = DateTime.Now,
                     Text = InsertEmoticon(text)
                 });
         }
     }
 }
Exemplo n.º 39
0
        /// <summary>
        /// Outputs an error message in red
        /// </summary>
        /// <param name="message">message to write</param>
        /// <param name="type">Which type of message shall we send</param>
        public static void WriteMessage(string message, eMessageType type)
        {
            #if DEBUG
            switch (type)
            {
                case eMessageType.Error:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                case eMessageType.Debug:
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;
                case eMessageType.Normal:
                    Console.ForegroundColor = ConsoleColor.White;
                    break;
            }

            if (filewriter != null)
                filewriter.WriteLine(message);
            #endif
            if (m_consoleEnabled)
                Console.WriteLine(message);
        }
Exemplo n.º 40
0
	public Msg_TargetIndication( AsBaseEntity _sender, eMessageType _typeCalled)
	{
		m_MessageType = eMessageType.TARGET_INDICATION;

		sender_ = _sender;
		typeCalled_ = _typeCalled;
	}
Exemplo n.º 41
0
        public override void Decode(byte[] buffer, int offset, int length)
        {
            using (var reader = new RawReader(new MemoryStream(buffer, offset, length, false), false))
            {
                var decode = BEncodedValue.Decode<BEncodedDictionary>(reader);

                BEncodedValue val;
                if (decode.TryGetValue(MessageTypeKey, out val))
                    _messageType = (eMessageType) ((BEncodedNumber) val).Number;
                if (decode.TryGetValue(PieceKey, out val))
                    Piece = (int) ((BEncodedNumber) val).Number;
                if (decode.TryGetValue(TotalSizeKey, out val))
                {
                    var totalSize = (int) ((BEncodedNumber) val).Number;
                    MetadataPiece = new byte[Math.Min(totalSize - Piece*BlockSize, BlockSize)];
                    reader.Read(MetadataPiece, 0, MetadataPiece.Length);
                }
            }
        }
Exemplo n.º 42
0
        public LTMetadata(PeerId id, eMessageType type, int piece, byte[] metadata)
            : this(id.ExtensionSupports.MessageId(Support), type, piece, metadata)
        {

        }
Exemplo n.º 43
0
 public LTMetadata(PeerId id, eMessageType type, int piece, byte[] metadata)
     : this(id.ExtensionSupports.MessageId(Support), type, piece, metadata)
 {
 }
Exemplo n.º 44
0
        public override void Decode(byte[] buffer, int offset, int length)
        {
            BEncodedValue val;
            using (RawReader reader = new RawReader(new MemoryStream(buffer, offset, length, false), false))
            {
                BEncodedDictionary d = BEncodedDictionary.Decode<BEncodedDictionary>(reader);
                int totalSize = 0;

                if (d.TryGetValue(MessageTypeKey, out val))
                    messageType = (eMessageType)((BEncodedNumber)val).Number;
                if (d.TryGetValue(PieceKey, out val))
                    piece = (int)((BEncodedNumber)val).Number;
                if (d.TryGetValue(TotalSizeKey, out val))
                {
                    totalSize = (int)((BEncodedNumber)val).Number;
                    metadata = new byte[Math.Min(totalSize - piece * BlockSize, BlockSize)];
                    reader.Read(metadata, 0, metadata.Length);
                }
            }
        }
Exemplo n.º 45
0
 public Message(eMessageType type)
 {
     IsReceived = false;
     this.Type  = type;
 }
Exemplo n.º 46
0
        public LTMetadata(PeerId id, eMessageType type, int piece)
            : this (id, type, piece, null)
        {

        }