Пример #1
0
        internal static bool PeekAddonUpdates(int _MinutesSinceLastPeek)
        {
            VF.NetworkClient netClient = new VF.NetworkClient(g_Host, g_Port);
            netClient.WaitForConnect(TimeSpan.FromSeconds(60));
            try
            {
                {
                    VF.NetworkOutgoingMessage             newMessage = netClient.CreateMessage();
                    WLN_RequestPacket_AddonUpdateInfoPeek request    = new WLN_RequestPacket_AddonUpdateInfoPeek();
                    request.UserID               = Settings.UserID;
                    request.LauncherVersion      = StaticValues.LauncherVersion;
                    request.MinutesSinceLastPeek = _MinutesSinceLastPeek;

                    newMessage.WriteByte((byte)WLN_PacketType.Request_AddonUpdateInfoPeek);
                    newMessage.WriteClass(request);
                    netClient.SendMessage(newMessage);
                }
                WLN_ResponsePacket_AddonUpdateInfoPeek response = new WLN_ResponsePacket_AddonUpdateInfoPeek();
                if (netClient.RecvPacket_VF(WLN_PacketType.Response_AddonUpdateInfoPeek, out response) == true)
                {
                    if (response.AddonUpdatesAvailable != null)
                    {
                        return(response.AddonUpdatesAvailable.Count > 0);
                    }
                }
            }
            finally
            {
                netClient.Disconnect();
                netClient = null;
            }
            return(false);
        }
Пример #2
0
        internal static List <WLN_ResponsePacket_GetNewsSince> GetNewsSince(DateTime _LastNewsDateTime, List <string> _NewsSourcesWanted)
        {
            List <WLN_ResponsePacket_GetNewsSince> newsPackets = new List <WLN_ResponsePacket_GetNewsSince>();

            VF.NetworkClient netClient = new VF.NetworkClient(g_Host, g_Port);
            netClient.WaitForConnect(TimeSpan.FromSeconds(60));
            try
            {
                {
                    VF.NetworkOutgoingMessage      newMessage = netClient.CreateMessage();
                    WLN_RequestPacket_GetNewsSince request    = new WLN_RequestPacket_GetNewsSince();
                    request.LastNewsDateTime = _LastNewsDateTime;
                    request.NewsSources      = _NewsSourcesWanted;

                    newMessage.WriteByte((byte)WLN_PacketType.Request_GetNewsSince);
                    newMessage.WriteClass(request);
                    netClient.SendMessage(newMessage);
                }
                if (netClient.RecvPacket_VF(WLN_PacketType.Response_GetNewsSince, out newsPackets) == true)
                {
                    return(newsPackets);
                }
                else
                {
                    newsPackets = new List <WLN_ResponsePacket_GetNewsSince>();
                }
            }
            catch (Exception)
            {
                newsPackets = new List <WLN_ResponsePacket_GetNewsSince>();
            }
            finally
            {
                netClient.Disconnect();
                netClient = null;
            }
            return(newsPackets);
        }
Пример #3
0
        //public static void SendPacket_VF<T_Data>(this NetClient _Client, WLN_PacketType _PacketType, T_Data _Data, bool _Flush = true)
        //{
        //    NetOutgoingMessage newMessage = _Client.CreateMessage();
        //    newMessage.Write((byte)_PacketType);
        //    var memoryReturnBuffer = new System.IO.MemoryStream();
        //    Serializer.Serialize(memoryReturnBuffer, _Data);
        //    memoryReturnBuffer.Position = 0;
        //    byte[] returnBytes = new byte[memoryReturnBuffer.Length];
        //    memoryReturnBuffer.Read(returnBytes, 0, (int)memoryReturnBuffer.Length);
        //    newMessage.Write((int)returnBytes.Length);
        //    newMessage.Write(returnBytes);
        //    _Client.SendMessage(newMessage, NetDeliveryMethod.ReliableOrdered, 0);
        //    if (_Flush == true)
        //        _Client.FlushSendQueue();
        //}
        //public static void SendPacket_VF<T_Data>(this NetConnection _Connection, WLN_PacketType _PacketType, T_Data _Data)
        //{
        //    NetOutgoingMessage newMessage = _Connection.Peer.CreateMessage();
        //    newMessage.Write((byte)_PacketType);
        //    var memoryReturnBuffer = new System.IO.MemoryStream();
        //    Serializer.Serialize(memoryReturnBuffer, _Data);
        //    memoryReturnBuffer.Position = 0;
        //    byte[] returnBytes = new byte[memoryReturnBuffer.Length];
        //    memoryReturnBuffer.Read(returnBytes, 0, (int)memoryReturnBuffer.Length);
        //    newMessage.Write((int)returnBytes.Length);
        //    newMessage.Write(returnBytes);
        //    _Connection.SendMessage(newMessage, NetDeliveryMethod.ReliableOrdered, 0);
        //}
        //public static T_Data RecvPacketData_VF<T_Data>(this NetIncomingMessage _Message)
        //{
        //    int packetLength = _Message.ReadInt32();
        //    byte[] rawData = _Message.ReadBytes(packetLength);
        //    var memoryBuffer = new System.IO.MemoryStream(rawData);
        //    T_Data dataReceived = Serializer.Deserialize<T_Data>(memoryBuffer);
        //    return dataReceived;
        //}
        public static bool RecvPacket_VF <T_Data>(this VF.NetworkClient _Client, WLN_PacketType _PacketType, out T_Data _RetData, TimeSpan _Timeout)
        {
            DateTime startRecv = DateTime.Now;

            if (_Client.WaitForConnect(_Timeout) == false)
            {
                throw new Exception("Not Connected");
            }
            VF.NetworkIncommingMessage msg;
            while (_Client.IsConnected())
            {
                msg = _Client.WaitMessage(_Timeout);
                if (msg != null)
                {
                    if (msg.MessageType == VF.NetworkMessageType.RawData)
                    {
                        WLN_PacketType packetType = (WLN_PacketType)msg.ReadByte();
                        if (packetType == _PacketType)
                        {
                            _RetData = msg.ReadClass <T_Data>();
                            return(true);
                        }
                        else
                        {
                            _RetData = default(T_Data);
                            return(false);// throw new Exception("Unexpected Packet");
                        }
                    }
                }
                if ((DateTime.Now - startRecv) > _Timeout)
                {
                    throw new TimeoutException("Could not receive packet within the time period");
                }
            }
            _RetData = default(T_Data);
            throw new Exception("Not Connected");
        }