private void OnServerLeave(TerrariaApi.Server.LeaveEventArgs Args)
        {
            TShockAPI.TSPlayer aPlayer = TShockAPI.TShock.Players[Args.Who];
            if (aPlayer != null && aPlayer.RealPlayer)
            {
                IBasicProperties ReplyProps = OverallInformations.channel.CreateBasicProperties();
                Request01 RequestContent = new Request01()
                {
                    RequestType = "APlayerLeave",
                    Parameters = new List<string>()
                    {
                        aPlayer.Name
                    }
                };
                string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
                byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

                OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: ReplyProps, body: RequestBytes);
            }
        }
        private void OnServerCommand(TerrariaApi.Server.CommandEventArgs Args)
        {
            if (Args.Handled)
            {
                return;
            }

            IBasicProperties ReplyProps = OverallInformations.channel.CreateBasicProperties();
            Request01 RequestContent = new Request01()
            {
                RequestType = "ServerCommand",
                Parameters = new List<string>()
                {
                    Newtonsoft.Json.JsonConvert.SerializeObject(new TShockACommandInformations() { CommandText = Args.Command })
                }
            };
            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: ReplyProps, body: RequestBytes);
        }
        private void OnServerChat(TerrariaApi.Server.ServerChatEventArgs Args)
        {
            if (Args.Handled)
            {
                return;
            }

            TShockAPI.TSPlayer aPlayer = TShockAPI.TShock.Players[Args.Who];
            IBasicProperties ReplyProps = OverallInformations.channel.CreateBasicProperties();
            TShockAChatInformations aChat = new TShockAChatInformations();

            if (aPlayer != null)
            {
                aChat.PlayerName = aPlayer.Name;
            }

            if (aPlayer.User != null)
            {
                aChat.UserName = aPlayer.User.Name;
            }

            aChat.RawText = Args.Text;

            Request01 RequestContent = new Request01()
            {
                RequestType = "ServerChat",
                Parameters = new List<string>()
                {
                    Newtonsoft.Json.JsonConvert.SerializeObject(aChat)
                }
            };

            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: ReplyProps, body: RequestBytes);
        }
        private void OnPostLogin(TShockAPI.Hooks.PlayerPostLoginEventArgs Args)
        {
            IBasicProperties replyProps = OverallInformations.channel.CreateBasicProperties();
            Request01 RequestContent = new Request01()
            {
                RequestType = "APlayerLogin",
                Parameters = new List<string>()
                {
                    Args.Player.Name,
                    Args.Player.User.Name
                }
            };
            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: replyProps, body: RequestBytes);
        }
        private void OnPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs Args)
        {
            if (Args.Handled)
            {
                return;
            }

            IBasicProperties ReplyProps = OverallInformations.channel.CreateBasicProperties();
               TShockACommandInformations aCommand = new TShockACommandInformations()
            {
                CommandName = Args.CommandName,
                CommandPrefix = Args.CommandPrefix,
                CommandText = Args.CommandText,
                Parameters = Args.Parameters,
                PlayerName = Args.Player.Name
            };

            if (Args.Player.User != null)
            {
                aCommand.UserName = Args.Player.User.Name;
            }

            Request01 RequestContent = new Request01()
            {
                RequestType = "PlayerCommand",
                Parameters = new List<string>()
                {
                    Newtonsoft.Json.JsonConvert.SerializeObject(aCommand)
                }
            };

            string RequestString = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] RequestBytes = Encoding.UTF8.GetBytes(RequestString);

            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: ReplyProps, body: RequestBytes);
        }
        private void ConnectToRabbitMQBroker()
        {
            OverallInformations.factory = new ConnectionFactory()
            {
                HostName = OverallInformations.RabbitMQHost,
                Port = OverallInformations.RabbitMQPort,
                UserName = OverallInformations.RabbitMQUserName,
                Password = OverallInformations.RabbitMQPassword,
                VirtualHost = OverallInformations.RabbitMQVirtualHost
            };

            bool IsConnectionOpened = false;
            do
            {
                try
                {
                    OverallInformations.conn = OverallInformations.factory.CreateConnection();
                    IsConnectionOpened = true;
                }
                catch (Exception) { }
            }
            while (!IsConnectionOpened);

            // channel chỉ dùng trong thread chung.
            OverallInformations.channel = OverallInformations.conn.CreateModel();
            OverallInformations.channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerTShockExchange, type: "direct", durable: false, autoDelete: true, arguments: null);

            new Task(() => TShockControllerWorker()).Start();

            IBasicProperties replyProps = OverallInformations.channel.CreateBasicProperties();
            Request01 RequestContent = new Request01()
            {
                RequestType = "TShockStarting",
                Parameters = new List<string>()
            };
            string message = Newtonsoft.Json.JsonConvert.SerializeObject(RequestContent);
            byte[] messageBytes = Encoding.UTF8.GetBytes(message);
            OverallInformations.channel.BasicPublish(exchange: OverallInformations.LauncherServerTShockExchange, routingKey: OverallInformations.LauncherServerGetRequestFromTShockRouterKey, basicProperties: replyProps, body: messageBytes);
        }