コード例 #1
0
        private static bool SendShopRequest(Request01 RequestIn, out string ResponseOut)
        {
            bool OrderOk = false;
            ResponseOut = String.Empty;

            string message = Newtonsoft.Json.JsonConvert.SerializeObject(RequestIn);
            byte[] messageBytes = Encoding.UTF8.GetBytes(message);

            string corrID = Guid.NewGuid().ToString();
            IBasicProperties replyProps = OverallInformations.channel.CreateBasicProperties();
            replyProps.CorrelationId = corrID;
            replyProps.ReplyTo = OverallInformations.replyQueueOk.QueueName;

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.ShopLightRouterKey, basicProperties: replyProps, body: messageBytes);

            LauncherClient.LauncherReadyEvent.WaitOne();

            if (LauncherClient.ea.BasicProperties.CorrelationId == corrID)
            {
                ResponseOut = Encoding.UTF8.GetString(LauncherClient.ea.Body);
                OrderOk = true;
            }

            return OrderOk;
        }
コード例 #2
0
        private void Login_Button_Click(object sender, RoutedEventArgs e)
        {
            Request01 OutgoingContent = new Request01() { RequestType = "Launcher.Login", Parameters = new List<string>() };
            OutgoingContent.Parameters.Add(OverallInformations.SeasonID);
            OutgoingContent.Parameters.Add(UserName_TextBox.Text);
            OutgoingContent.Parameters.Add(Main_PasswordBox.Password);

            string ResponseString;
            if (LauncherClient.SendLightRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                    MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
                else
                {
                    ResponseStruct LoginResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                    if (LoginResult.Status == ResponseStatusType.Done)
                    {
                        Login_Button.IsEnabled = false;
                        Logout_Button.IsEnabled = true;
                        UserName_TextBox.IsEnabled = false;
                        Main_PasswordBox.IsEnabled = false;
                        OpenTradingSystem_Button.IsEnabled = true;
                        // ChatButton.IsEnabled = true;
                        LogorReg_CheckBox.IsEnabled = false;
                        MessageBox.Show(LauncherClient.MsgString(null, LoginResult.Broadcast));
                    }
                    else if (LoginResult.Status == ResponseStatusType.Fail)
                    {
                        MessageBox.Show(LauncherClient.MsgString(LoginResult.Error, LoginResult.Broadcast));
                    }
                    else
                    {
                        MessageBox.Show("Không rõ dữ liệu trả về từ Server.");
                    }
                }
            }
        }
コード例 #3
0
        private static bool AddClient(out string SeasonID)
        {
            bool Result = false;

            SeasonID = String.Empty;

            Request01 OutgoingContent = new Request01() { RequestType = "Launcher.AddClient", Parameters = new List<string>() { OverallInformations.replyQueueOk.QueueName } };

            string ResponseString;
            if (SendLightRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    MessageBox.Show(String.Join("\n", "Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client.", "Vui lòng chờ đợi, hoặc xem thông báo của Admin."));
                }
                else if (!string.IsNullOrWhiteSpace(ResponseString))
                {
                    SeasonID = ResponseString;
                    Result = true;
                }
            }

            return Result;
        }
コード例 #4
0
        private void GetStandardBalance(out string Result)
        {
            Result = "0";

            Request01 OutgoingContent = new Request01() { RequestType = "Shop.GetBalance", Parameters = new List<string>() };
            OutgoingContent.Parameters.Add(OverallInformations.SeasonID);
            OutgoingContent.Parameters.Add("Standard Balance");

            string ResponseString;
            if (SendShopRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    // Không cần thiết phải thông báo.
                }
                else
                {
                    ResponseStruct GetBalanceResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                    if (GetBalanceResult.Status == ResponseStatusType.Done)
                    {
                        Result = Convert.ToString(GetBalanceResult.Content);
                    }
                }
            }
        }
コード例 #5
0
        private void GetRatio(out string Ratio)
        {
            Ratio = String.Empty;

            Request01 OutgoingContent = new Request01() { RequestType = "Shop.GetMarketInfo", Parameters = new List<string>() };
            OutgoingContent.Parameters.Add(OverallInformations.SeasonID);
            OutgoingContent.Parameters.Add("RatioPremiumVs.Standard");

            string ResponseString;
            if (SendShopRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
                    Ratio = "0";
                }
                else
                {
                    ResponseStruct GetRatioResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                    if (GetRatioResult.Status == ResponseStatusType.Done)
                    {
                        Ratio = Convert.ToString(GetRatioResult.Content);
                    }
                    else if (GetRatioResult.Status == ResponseStatusType.Fail)
                    {
                        MessageBox.Show(LauncherClient.MsgString(GetRatioResult.Error, GetRatioResult.Broadcast));
                        Ratio = "0";
                    }
                }
            }
        }
コード例 #6
0
 private void GetPriceOfAnEvent()
 {
     Request01 OutGoingContent = new Request01() { RequestType = "Shop.GetAnEvent", Parameters = new List<string>() { OverallInformations.SeasonID, Convert.ToString(((ComboBoxItem)ListOfEvents_ComboBox.SelectedItem).Content) } };
     string ResponseString;
     if (SendShopRequest(OutGoingContent, out ResponseString))
     {
         ResponseStruct GetPriceResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
         if (GetPriceResult.Status == ResponseStatusType.Done)
         {
             List<int> ListOfPrices = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(Convert.ToString(GetPriceResult.Content));
             EventStandardPrice_Label.Content = String.Format("Standard Price: {0} Credits", String.Format(CultureInfo.InvariantCulture, "{0:#,#0}", ListOfPrices[0]));
             EventPremiumPrice_Label.Content = String.Format("Premium Price: {0} Credits", String.Format(CultureInfo.InvariantCulture, "{0:#,#0}", ListOfPrices[1]));
         }
         else if (GetPriceResult.Status == ResponseStatusType.Fail)
         {
             EventStandardPrice_Label.Content = "Standard Price: Not available now.";
             EventPremiumPrice_Label.Content = "Premium Price: Not available now.";
         }
     }
 }
コード例 #7
0
 private void GetListOfEvents()
 {
     ListOfEvents_ComboBox.Items.Clear();
     Request01 OutGoingContent = new Request01() { RequestType = "Shop.GetListOfEvents", Parameters = new List<string>() { OverallInformations.SeasonID } };
     string ResponseString;
     if (SendShopRequest(OutGoingContent, out ResponseString))
     {
         ResponseStruct GetListOfEventsResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
         if (GetListOfEventsResult.Status == ResponseStatusType.Done)
         {
             List<string> ListOfEvents = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(Convert.ToString(GetListOfEventsResult.Content));
             foreach (string aEvent in ListOfEvents)
             {
                 ComboBoxItem aCbItem = new ComboBoxItem();
                 aCbItem.Content = aEvent;
                 ListOfEvents_ComboBox.Items.Add(aCbItem);
             }
         }
         else if (GetListOfEventsResult.Status == ResponseStatusType.Fail)
         {
             ListOfEvents_ComboBox.Items.Add(new ComboBoxItem().Content = "Không thể lấy danh sách event.");
         }
     }
     ListOfEvents_ComboBox.SelectedIndex = 0;
 }
コード例 #8
0
        private void GetItemTypes()
        {
            Request01 OutgoingContent = new Request01() { RequestType = "Shop.GetItemTypes", Parameters = new List<string>() };
            OutgoingContent.Parameters.Add(OverallInformations.SeasonID);

            string ResponseString;
            if (SendShopRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
                }
                else
                {
                    ResponseStruct ItemTypesResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                    if (ItemTypesResult.Status == ResponseStatusType.Done)
                    {
                        List<string> ItemTypeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(Convert.ToString(ItemTypesResult.Content));
                        Category_ListView.Items.Clear();
                        foreach (string i in ItemTypeList)
                        {
                            Category_ListView.Items.Add(i);
                        }
                    }
                    else if (ItemTypesResult.Status == ResponseStatusType.Fail)
                    {
                        MessageBox.Show(LauncherClient.MsgString(ItemTypesResult.Error, ItemTypesResult.Broadcast));
                    }
                }
            }
        }
コード例 #9
0
        private static void LauncherAntiCheatWorker()
        {
            using (IModel channel = OverallInformations.conn.CreateModel())
            {
                channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerClientExchange, type: "direct", durable: false, autoDelete: true, arguments: null);
                QueueDeclareOk replyQueueOk = channel.QueueDeclare();
                channel.QueueBind(queue: replyQueueOk.QueueName, exchange: OverallInformations.LauncherServerClientExchange, routingKey: replyQueueOk.QueueName, arguments: null);

                AntiCheat AntiCheatInstance = new AntiCheat();
                Request01 OutgoingContent;
                string Reason = String.Empty;

                string corrId = Guid.NewGuid().ToString();
                IBasicProperties replyProps = channel.CreateBasicProperties();
                replyProps.ReplyTo = replyQueueOk.QueueName;
                replyProps.CorrelationId = corrId;

                while (true)
                {
                    OutgoingContent = new Request01()
                    {
                        RequestType = "Launcher.AntiCheat.General",
                        Parameters = new List<string>()
                        {
                            OverallInformations.SeasonID
                        }
                    };

                    if (AntiCheatInstance.CheckCheat(out Reason))
                    {
                        OutgoingContent.Parameters.Add(Reason);
                        channel.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherAntiCheatRouterKey, basicProperties: replyProps, body: Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(OutgoingContent)));
                    }
                    // -----
                    OutgoingContent = new Request01()
                    {
                        RequestType = "Launcher.AntiCheat.FileTerraria",
                        Parameters = new List<string>()
                        {
                            OverallInformations.SeasonID
                        }
                    };

                    string FileCase;
                    string CheckSumString;
                    AntiCheatInstance.CheckFileTerraria(out FileCase, out CheckSumString);

                    OutgoingContent.Parameters.Add(FileCase);
                    OutgoingContent.Parameters.Add(CheckSumString);

                    channel.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherAntiCheatRouterKey, basicProperties: replyProps, body: Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(OutgoingContent)));

                    Thread.Sleep(new TimeSpan(0, 0, 10));
                }
            }
        }
コード例 #10
0
        private void Buy_Button_Click(object sender, RoutedEventArgs e)
        {
            if (Items_ListView.SelectedItem == null)
            {
                MessageBox.Show("Chọn Item trước khi tiến hành mua.");
            }
            else
            {
                Request01 OutgoingContent = new Request01() { RequestType = "Shop.BuyRegularItem", Parameters = new List<string>() };
                ShopItemInformations shopItem = (ShopItemInformations)Items_ListView.SelectedItem;
                ComboBoxItem comboBoxItem = (ComboBoxItem)CurrencyComboBox.SelectedItem;
                OutgoingContent.Parameters.Add(OverallInformations.SeasonID);
                OutgoingContent.Parameters.Add(shopItem.ItemName);
                OutgoingContent.Parameters.Add(ItemCountTextBox.Text);
                OutgoingContent.Parameters.Add(Convert.ToString(comboBoxItem.Content));

                string ResponseString;
                if (SendShopRequest(OutgoingContent, out ResponseString))
                {
                    if (ResponseString == "#")
                    {
                        MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
                    }
                    else
                    {
                        ResponseStruct BuyResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                        if (BuyResult.Status == ResponseStatusType.Done)
                        {
                            MessageBox.Show(LauncherClient.MsgString(BuyResult.Error, BuyResult.Broadcast));
                        }
                        else if (BuyResult.Status == ResponseStatusType.Fail)
                        {
                            MessageBox.Show(LauncherClient.MsgString(BuyResult.Error, BuyResult.Broadcast));
                        }
                    }
                }
            }
        }
コード例 #11
0
 private void BuyNpc_Button_Click(object sender, RoutedEventArgs e)
 {
     if (Npcs_ListView.SelectedItem != null)
     {
         Request01 OutGoingContent = new Request01() { RequestType = "Shop.BuyNpc", Parameters = new List<string>() { OverallInformations.SeasonID, Convert.ToString(((ShopNpcInformations)Npcs_ListView.SelectedItem).NpcID), NpcCount_TextBox.Text, Convert.ToString(((ComboBoxItem)BuyNpcPaymentMethod_ComboBox.SelectedItem).Content) } };
         string ResponseString;
         if (SendShopRequest(OutGoingContent, out ResponseString))
         {
             ResponseStruct BuyNpcResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
             if (BuyNpcResult.Status == ResponseStatusType.Done)
             {
                 MessageBox.Show(LauncherClient.MsgString(BuyNpcResult.Error, BuyNpcResult.Broadcast));
             }
             else if (BuyNpcResult.Status == ResponseStatusType.Fail)
             {
                 MessageBox.Show(LauncherClient.MsgString(BuyNpcResult.Error, BuyNpcResult.Broadcast));
             }
         }
     }
     else
     {
         MessageBox.Show("NPC chưa được chọn. Hãy chọn một NPC để tiếp tục.");
     }
 }
コード例 #12
0
 private void BuyEvent_Button_Click(object sender, RoutedEventArgs e)
 {
     Request01 OutGoingContent = new Request01() { RequestType = "Shop.BuyEvent", Parameters = new List<string>() { OverallInformations.SeasonID, Convert.ToString(((ComboBoxItem)ListOfEvents_ComboBox.SelectedItem).Content), Convert.ToString(((ComboBoxItem)BuyEventPaymentMethod_ComboBox.SelectedItem).Content), "1" } };
     string ResponseString;
     if (SendShopRequest(OutGoingContent, out ResponseString))
     {
         ResponseStruct BuyEventResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
         if (BuyEventResult.Status == ResponseStatusType.Done)
         {
             MessageBox.Show(LauncherClient.MsgString(BuyEventResult.Error, BuyEventResult.Broadcast));
         }
         else if (BuyEventResult.Status == ResponseStatusType.Fail)
         {
             MessageBox.Show(LauncherClient.MsgString(BuyEventResult.Error, BuyEventResult.Broadcast));
         }
     }
 }
コード例 #13
0
        private static void LauncherImageWorker()
        {
            using (IModel channel = OverallInformations.conn.CreateModel())
            {
                channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerClientExchange, type: "direct", durable: false, autoDelete: true, arguments: null);
                QueueDeclareOk replyQueueOk = channel.QueueDeclare();
                channel.QueueBind(queue: replyQueueOk.QueueName, exchange: OverallInformations.LauncherServerClientExchange, routingKey: replyQueueOk.QueueName, arguments: null);

                ScreenCapture screenCapture = new ScreenCapture();
                Base64Utils base64Utils = new Base64Utils();
                Request01 OutgoingContent = new Request01() { RequestType = "Launcher.Image", Parameters = new List<string>() };
                OutgoingContent.Parameters.Add(OverallInformations.SeasonID);
                OutgoingContent.Parameters.Add("");

                string corrId = Guid.NewGuid().ToString();
                IBasicProperties replyProps = channel.CreateBasicProperties();
                replyProps.ReplyTo = replyQueueOk.QueueName;
                replyProps.CorrelationId = corrId;

                while (true)
                {
                    try
                    {
                        System.Drawing.Image capturedimage = screenCapture.Snip();
                        OutgoingContent.Parameters[1] = base64Utils.ImageToBase64(capturedimage, System.Drawing.Imaging.ImageFormat.Png);
                    }
                    catch (Exception)
                    {
                        OutgoingContent.Parameters[1] = string.Empty;
                    }
                    finally
                    {
                        if (!string.IsNullOrWhiteSpace(OutgoingContent.Parameters[1]))
                        {
                            string message = Newtonsoft.Json.JsonConvert.SerializeObject(OutgoingContent);
                            byte[] messageBytes = Encoding.UTF8.GetBytes(message);
                            channel.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherImageRouterKey, basicProperties: replyProps, body: messageBytes);
                        }
                    }
                    Thread.Sleep(new TimeSpan(0, 1, 0));
                }
            }
        }
コード例 #14
0
 private void BossTypes_ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (BossTypes_ListView.SelectedItem != null)
     {
         Request01 OutGoingContent = new Request01() { RequestType = "Shop.GetBossesByType", Parameters = new List<string>() { OverallInformations.SeasonID, Convert.ToString(BossTypes_ListView.SelectedItem) } };
         string ResponseString;
         if (SendShopRequest(OutGoingContent, out ResponseString))
         {
             if (ResponseString == "#")
             {
                 MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
             }
             else
             {
                 ResponseStruct GetBossesResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                 if (GetBossesResult.Status == ResponseStatusType.Done)
                 {
                     List<ShopBossInformations> ListOfBosses = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ShopBossInformations>>(Convert.ToString(GetBossesResult.Content));
                     Bosses_ListView.Items.Clear();
                     foreach (ShopBossInformations aBoss in ListOfBosses)
                     {
                         Bosses_ListView.Items.Add(aBoss);
                     }
                 }
                 else if (GetBossesResult.Status == ResponseStatusType.Fail)
                 {
                     MessageBox.Show(LauncherClient.MsgString(GetBossesResult.Error, GetBossesResult.Broadcast));
                 }
             }
         }
     }
     else
     {
         Bosses_ListView.Items.Clear();
     }
 }
コード例 #15
0
        private void ChangeCurrencyButton_Click(object sender, RoutedEventArgs e)
        {
            Request01 OutgoingContent = new Request01() { RequestType = "Shop.ChangeCurrency", Parameters = new List<string>() { OverallInformations.SeasonID, "Premium Balance to Standard Balance", Convert.ToString((int)slider.Value) } };

            string ResponseString;
            if (SendShopRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    MessageBox.Show("Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client." + "\n" + "Vui lòng chờ đợi, hoặc xem thông báo của Admin.");
                }
                else
                {
                    ResponseStruct ChangeCurrencyResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseStruct>(ResponseString);
                    if (ChangeCurrencyResult.Status == ResponseStatusType.Done)
                    {
                        MessageBox.Show(LauncherClient.MsgString(ChangeCurrencyResult.Error, ChangeCurrencyResult.Broadcast));
                        ChangeCurrencyRefreshAll();
                    }
                    else if (ChangeCurrencyResult.Status == ResponseStatusType.Fail)
                    {
                        MessageBox.Show(LauncherClient.MsgString(ChangeCurrencyResult.Error, ChangeCurrencyResult.Broadcast));
                    }
                }
            }
        }
コード例 #16
0
        private void SendChatText()
        {
            if (!String.IsNullOrWhiteSpace(TypeChatTextBox.Text))
            {
                IBasicProperties ReplyProps = ChannelToSend.CreateBasicProperties();
                ReplyProps.ReplyTo = ToSendQueue.QueueName;
                ReplyProps.CorrelationId = "JustAnID";

                Request01 RequestContent = new Request01()
                {
                    RequestType = "Launcher.SendChat",
                    Parameters = new List<string>()
                {
                    OverallInformations.SeasonID,
                    TypeChatTextBox.Text
                }
                };
                string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
                byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);
                ChannelToSend.BasicPublish(exchange: OverallInformations.LauncherServerClientExchange, routingKey: OverallInformations.LauncherLightRouterKey, basicProperties: ReplyProps, body: RequestBytes);
                TypeChatTextBox.Clear();
            }
        }
コード例 #17
0
        private static bool CheckVersion(string Version)
        {
            bool Result = false;

            Request01 OutgoingContent = new Request01() { RequestType = "Launcher.CheckVersion", Parameters = new List<string>() { Version } };

            string ResponseString;
            if (SendLightRequest(OutgoingContent, out ResponseString))
            {
                if (ResponseString == "#")
                {
                    MessageBox.Show(String.Join("\n", "Hiện tại Server không tiếp nhận mọi yêu cầu từ phía Client.", "Vui lòng chờ đợi, hoặc xem thông báo của Admin."));
                }
                else if ((ResponseString == "OK"))
                {
                    Result = true;
                }
                else
                {
                    MessageBox.Show("Phiên bản Launcher Client đã cũ. Hãy cập nhật lên phiên bản mới nhất để tiếp tục.");
                }
            }

            return Result;
        }