Exemplo n.º 1
0
        public ChatViewModel(int gamenum, KailleraWindowController mgr, Game game = null)
        {
            wind         = new ChatWindow();
            gameNumber   = gamenum;
            wind.Userup += UpdateUsers;
            updater     += wind.WindowUpdate;
            wind.listBox1.ItemsSource = DisplayUsers;
            wind.addBuddyList        += addBuddy;

            wind.Logger = ChatLogger.getLog(game);

            //Set small line height to avoid large line breaks
            Paragraph p = wind.richTextBox1.Document.Blocks.FirstBlock as Paragraph;

            p.LineHeight           = 1;
            wind.textBox1.KeyDown += Chat_sendMessageIfEnter;

            wind.Closed += (object sender, EventArgs e) => winClosed(sender, e);

            wind.gameNumber = gamenum;

            //If this is a game chat, we want to leave the game upon window close
            if (gamenum != 0)
            {
                wind.Closed += beginLeaveGame;
                wind.Title   = game.name;
            }
            wind.Show();

            //Make this the active window in the tray manager
            KailleraTrayManager.Instance.addActiveWindow(wind);
        }
Exemplo n.º 2
0
    IEnumerator PayHomeless()
    {
        paying = true;

        yield return(new WaitForSeconds(Random.Range(minimumTimeToPay, minimumTimeToPay + 3)));

        ///////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////
        //// CODE TO GIVE MONEY STORED IN minimumToPay TO HOMELESS MAN ////
        ///////////////////////////////////////////////////////////////////
        ///// LEAVE IF TO ENSURE NPC IS STILL WATCHING HOMELESS MAN! //////
        ///////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////
        if (staring)
        {
            float moneyToAdd = (Mathf.FloorToInt(Random.Range(minimumToPayPennies, maximumToPayPennies)) / 100.0f);

            CultureInfo gb = CultureInfo.GetCultureInfo("en-GB");

            ChatLogger.SendChatMessage(PlayerName + " has given you " + moneyToAdd.ToString("c2", gb), Color.cyan);
            GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Money += moneyToAdd;
            //GameObject.Find("Money Text").GetComponent<Text>().text = (int.Parse(GameObject.Find("MoneyCounter").GetComponent<Text>().text) + Mathf.FloorToInt(Random.Range(minimumToPay, minimumToPay + 5))).ToString();
        }

        paying = false;
    }
Exemplo n.º 3
0
    public void ShopItemBought(string name)
    {
        //var Player = GameObject.FindGameObjectWithTag("Player");
        //Player.GetComponent<PlayerManager>();
        var item = ShopItems.FirstOrDefault(i => i.ItemName == name);

        if (item.Cost <= GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Money)
        {
            if (item.ModifierList.All(i => CheckAddable(i)))
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Money -= item.Cost;
                string change = "";
                foreach (var modifier in item.ModifierList)
                {
                    change += modifier.Key.ToString() + " " + (modifier.Value < 0 ? "decreased " : "increased ") + "by " + modifier.Value + " | ";
                    AddStat(modifier);
                }
                change = change.TrimEnd('|', ' ');
                CultureInfo gb  = CultureInfo.GetCultureInfo("en-GB");
                string      msg = item.ItemName + " purchased for " + item.Cost.ToString("c2", gb);
                ChatLogger.SendChatMessage(msg, Color.white);
                ChatLogger.SendChatMessage(change, Color.green);
            }
        }
        else
        {
            ChatLogger.SendChatMessage("You do not have enough money for this item", Color.red);
        }
    }
Exemplo n.º 4
0
        private Task Bot_MessageReceived(
            SocketMessage arg)
        {
            lock (this.LogIDHistory)
            {
                if (this.LogIDHistory.Contains(arg.Id))
                {
                    return(Task.CompletedTask);
                }

                this.LogIDHistory.Add(arg.Id);
            }

            var activeChannels = this.GetActiveChannels();

            if (activeChannels == null)
            {
                return(Task.CompletedTask);
            }

            var ch = activeChannels
                     .FirstOrDefault(x =>
                                     x.DiscordChannelID == arg.Channel.Id.ToString());

            if (ch == null)
            {
                return(Task.CompletedTask);
            }

            var model = ChatLogModel.FromDiscordLog(arg);

            model.ChatCode = ch.ChatCode;
            model.IsMe     = string.Equals(
                model.OriginalSpeaker,
                SharlayanController.Instance.CurrentPlayer?.Name,
                StringComparison.OrdinalIgnoreCase);

            if (!model.IsMe ||
                model.DiscordLog.Attachments.Any())
            {
                WPFHelper.Dispatcher.Invoke(() =>
                {
                    ChatLogsModel.AddToBuffers(model);
                });

                var chName = !string.IsNullOrEmpty(ch.ChannelShortName) ?
                             ch.ChannelShortName :
                             ch.ChannelName;

                ChatLogger.Write(
                    chName,
                    model.Speaker,
                    model.SpeakerAlias,
                    model.Message);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
 private void CheckLevelProgress()
 {
     if (playerData.Experience >= (playerData.Level * 120))
     {
         playerData.Level++;
         playerData.Experience = 0;
         ChatLogger.SendChatMessage("Leveled Up! Now level " + playerData.Level, Color.magenta);
     }
 }
Exemplo n.º 6
0
        public ChatPresenter(ChatForm view, ChatService service, ChatLogger logger)
        {
            _view    = view;
            _service = service;
            _logger  = logger;

            //Looks dirty, idk how to make it better, maybe singleton di?
            view.Presenter = this;
        }
Exemplo n.º 7
0
        public MainWindow()
        {
            InitializeComponent();
            ILog log = new ChatLogger(this.chatBox, this.Dispatcher);

            this.services = new Services(log);
            this.currentUsers.DataContext = this.services.UserManager;

            this.Closed += this.SendDisconnect;
        }
Exemplo n.º 8
0
        public NewMessageActor(ChannelConfiguration config)
        {
            this.Configuration = config;

            this.ChatLogger = Context.ActorSelection(ChatLoggerActor.Path)
                              .ResolveOne(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();

            this.Receive <OnMessageReceivedArgs>((args) => {
                Debug.WriteLine(args.ChatMessage.Username + ": " + args.ChatMessage.Message);
                ChatLogger.Tell(new ChatLogMessage(LogLevel.Information, Configuration.ChannelName, args.ChatMessage.Username + ": " + args.ChatMessage.Message));
            });
        }
Exemplo n.º 9
0
        private AbstractLogger getChainOfLoggers()
        {
            AbstractLogger errorLogger   = new ErrorLogger();
            AbstractLogger fileLogger    = new FileLogger();
            AbstractLogger consoleLogger = new ConsoleLogger();
            AbstractLogger chatLogger    = new ChatLogger(chatLog);

            errorLogger.setNextLogger(fileLogger);
            fileLogger.setNextLogger(consoleLogger);
            consoleLogger.setNextLogger(chatLogger);

            return(errorLogger);
        }
Exemplo n.º 10
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var view      = new ChatForm();
            var logger    = new ChatLogger(view);
            var service   = new ChatService(logger);
            var presenter = new ChatPresenter(view, service, logger);

            service.InitHook(presenter);
            presenter.Run();
        }
Exemplo n.º 11
0
        private async Task AddChannelToTrack(TrackNewFollowers arg)
        {
            // Check if the channel is already subscribed to with the WebHook API
            if (_FollowerChannels.Contains(arg.ChannelName))
            {
                return;
            }

            _FollowerChannels.Add(arg.ChannelName);

            await SubscribeToTwitchWebhook(arg.ChannelName, arg.ChannelId);

            ChatLogger.Tell(new ChatLogMessage(Microsoft.Extensions.Logging.LogLevel.Debug, "- global -", $"Now tracking followers for channel {arg.ChannelName}"));
        }
Exemplo n.º 12
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            byte[] senderId = BitConverter.GetBytes(client.Character.CharacterId);
            Array.Reverse(senderId);

            ChannelBase channel = client.ChatServer().GetChannel(packet);

            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadByte();
            string text        = reader.ReadString();
            string channelName = channel.ChannelName;

            // Check if it is a Chat Command (starting with a dot)
            if (!ProcessServerCommand(text, client))
            {
                byte[] newpacket = new byte[packet.Length + 4];

                Array.Copy(packet, 0, newpacket, 0, 9);
                Array.Copy(senderId, 0, newpacket, 9, 4);
                Array.Copy(packet, 9, newpacket, 13, packet.Length - 9);
                newpacket[2] = (byte)(packet.Length >> 8);
                newpacket[3] = (byte)packet.Length;

                foreach (Client recipient in client.ChatServer().ConnectedClients.Values)
                {
                    if (recipient.Channels.Contains(channel))
                    {
                        if (!recipient.KnownClients.Contains(client.Character.CharacterId) &&
                            (recipient.Character.CharacterId != client.Character.CharacterId))
                        {
                            byte[] pname = PlayerName.Create(client, client.Character.CharacterId);
                            recipient.Send(pname);
                            recipient.KnownClients.Add(client.Character.CharacterId);
                        }

                        recipient.Send(newpacket);
                    }
                }

                client.ChannelMessageReceived(channel, client.Character.characterName, text);
            }

            ChatLogger.WriteString(channelName, text, client.Character.characterName);
        }
Exemplo n.º 13
0
    private void Start()
    {
        HungerBarProg = GameObject.Find("HungerBarProg").GetComponent <RawImage>();
        ThirstBarProg = GameObject.Find("ThirstBarProg").GetComponent <RawImage>();
        CleanBarProg  = GameObject.Find("CleanlinessBarProg").GetComponent <RawImage>();
        WarmthBarProg = GameObject.Find("WarmthBarProg").GetComponent <RawImage>();
        MoraleBarProg = GameObject.Find("MoraleBarProg").GetComponent <RawImage>();

        MoneyCounter = GameObject.Find("MoneyCounter").GetComponent <Text>();

        playerData = SaveSystem.LoadPlayerData();

        ChatLogger.SendChatMessage("Game Started, Good luck!", Color.yellow);
        AOEEffect   = true;
        AOERange    = 75;
        actionTimer = ScriptableObject.CreateInstance <PlayerAction>();
        actionTimer.Init(15, true);
    }
Exemplo n.º 14
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            // TODO: Fix this mess.
            ushort data_length = BitConverter.ToUInt16(new[] { packet[3], packet[2] }, 0);

            byte[] sender_ID = BitConverter.GetBytes(client.Character.characterId);
            Array.Reverse(sender_ID);
            MemoryStream m_stream = new MemoryStream();

            m_stream.Write(packet, 0, 9);
            m_stream.Write(sender_ID, 0, 4);
            m_stream.Write(packet, 9, packet.Length - 9);
            m_stream.Capacity = (int)m_stream.Length;
            byte[] message    = m_stream.GetBuffer();
            byte[] new_length = BitConverter.GetBytes(message.Length - 4);
            message[2] = new_length[1];
            message[3] = new_length[0];
            m_stream.Close();
            m_stream.Dispose();

            foreach (Client m_client in client.Server.Clients)
            {
                if (!m_client.KnownClients.Contains(client.Character.characterId))
                {
                    byte[] pname = PlayerName.New(client, client.Character.characterId);
                    m_client.Send(pname);
                    m_client.KnownClients.Add(client.Character.characterId);
                }

                m_client.Send(message);
            }

            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadUInt16();
            reader.ReadByte();
            string text        = reader.ReadString();
            string channelName = ChatChannels.GetChannel(packet).Name;

            ChatLogger.WriteString(channelName, text, client.Character.characterName);
        }
Exemplo n.º 15
0
        public NewMessageActor(ChannelConfiguration config, IEnumerable <IFeature> features)
        {
            this.Configuration = config;

            this.ChatLogger = Context.ActorSelection(ChatLoggerActor.Path)
                              .ResolveOne(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult();

            // TODO:  This should be a static method on the ChannelActor object
            _ChannelActor = Context.ActorSelection($"/user/channelmanager/channel_{config.ChannelName}");

            // Cheer 100 nothing_else_matters 05/07/19
            // Cheer 200 cpayette 05/07/19
            // Cheer 300 pakmanjr 05/07/19
            this.Features = features.ToArray();
            foreach (var f in Features)
            {
                f.BroadcastMessage = (msg) => _ChannelActor.Tell(new MSG.BroadcastMessage(msg));
                f.WhisperMessage   = (user, msg) => _ChannelActor.Tell(new MSG.WhisperMessage(user, msg));
            }

            this.Receive <OnMessageReceivedArgs>((args) =>
            {
                Debug.WriteLine(args.ChatMessage.DisplayName + ": " + args.ChatMessage.Message);
                ChatLogger.Tell(new MSG.ChatLogMessage(LogLevel.Information, Configuration.ChannelName, args.ChatMessage.DisplayName + ": " + args.ChatMessage.Message));

                foreach (var f in Features.Where(f => f.IsEnabled))
                {
                    // TODO: Ensure we pass badges and emotes through to the feature
                    f.FeatureTriggered(args.ChatMessage.DisplayName + ": " + args.ChatMessage.Message);
                }
            });
            this.Receive <MSG.GetFeatureForChannel>(f =>
            {
                if (f.Channel != Configuration.ChannelName || !Features.Any(feature => feature.GetType() == f.FeatureType))
                {
                    return;
                }
                Sender.Tell(Features.First(feature => f.FeatureType == feature.GetType()));
            });
        }
Exemplo n.º 16
0
        private void SubscribeChatLog()
        {
            Thread.Sleep(TimeSpan.FromSeconds(DetectProcessInterval));
            AppLogger.Write("FFXIV chat log subscriber started.");

            var previousPlayerName = string.Empty;

            while (true)
            {
                var interval    = TimeSpan.FromMilliseconds(Config.Instance.ChatLogPollingInterval);
                var isExistLogs = false;

                try
                {
                    // スレッドプライオリティを更新する
                    if (Thread.CurrentThread.Priority != Config.Instance.ChatLogSubscriberThreadPriority)
                    {
                        Thread.CurrentThread.Priority = Config.Instance.ChatLogSubscriberThreadPriority;
                    }

                    if (!this.IsAttached ||
                        !Reader.CanGetChatLog())
                    {
                        interval = TimeSpan.FromSeconds(DetectProcessInterval);
                        continue;
                    }

                    var targetLogs = default(IEnumerable <ChatLogItem>);

                    try
                    {
                        if (this.isWorking)
                        {
                            continue;
                        }

                        this.isWorking = true;

                        if (this.currentPlayer != null &&
                            !string.IsNullOrEmpty(this.currentPlayer.Name))
                        {
                            if (!string.IsNullOrEmpty(previousPlayerName) &&
                                previousPlayerName != this.currentPlayer.Name)
                            {
                                this.previousArrayIndex = 0;
                                this.previousOffset     = 0;
                            }

                            previousPlayerName = this.CurrentPlayer.Name;
                        }

                        var result = Reader.GetChatLog(this.previousArrayIndex, this.previousOffset);
                        if (result == null)
                        {
                            continue;
                        }

                        this.previousArrayIndex = result.PreviousArrayIndex;
                        this.previousOffset     = result.PreviousOffset;

                        if (!result.ChatLogItems.Any())
                        {
                            continue;
                        }

                        targetLogs = result.ChatLogItems
                                     .Where(x => ChatCodes.All.Contains(x.Code));

                        isExistLogs = targetLogs.Any();
                    }
                    finally
                    {
                        this.isWorking = false;
                    }

                    if (isExistLogs)
                    {
                        var models = targetLogs
                                     .Select(x => ChatLogModel.FromXIVLog(x, this.currentPlayerNames))
                                     .ToArray();

                        WPFHelper.Dispatcher.Invoke(() =>
                        {
                            ChatLogsModel.AddToBuffers(models);
                        });

                        foreach (var model in models)
                        {
                            if (model.IsMe)
                            {
                                var playerName = this.currentPlayer?.Name;
                                if (string.IsNullOrEmpty(playerName))
                                {
                                    playerName = previousPlayerName;

                                    if (string.IsNullOrEmpty(playerName))
                                    {
                                        playerName = Config.Instance.ActiveProfile?.CharacterName;
                                    }
                                }

                                DiscordBotController.Instance.SendMessage(
                                    model.ChatCode,
                                    playerName,
                                    Config.Instance.ActiveProfile?.Alias,
                                    model.Message);
                            }

                            var chName = !string.IsNullOrEmpty(model.ChannelShortName) ?
                                         model.ChannelShortName :
                                         model.ChannelName;

                            ChatLogger.Write(
                                chName,
                                model.Speaker,
                                model.SpeakerAlias,
                                model.Message);
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    return;
                }
                catch (Exception ex)
                {
                    AppLogger.Error("Happened exception from chat log subscriber.", ex);
                    interval = TimeSpan.FromSeconds(DetectProcessInterval * 2);
                }
                finally
                {
                    var now = DateTime.Now;

                    if (isExistLogs)
                    {
                        this.lastChatLogReceivedTimestamp = now;
                        Thread.Yield();
                    }
                    else
                    {
                        if ((now - this.lastChatLogReceivedTimestamp) > ChatIdelThreshold)
                        {
                            interval = ChatIdleInterval;
                        }

                        Thread.Sleep(interval);
                    }
                }
            }
        }
Exemplo n.º 17
0
    private bool CheckAddable(KeyValuePair <StatType, float> modifier)
    {
        switch (modifier.Key)
        {
        case StatType.Hunger:
            var hungerval = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Hunger + modifier.Value;
            if (hungerval <= 100 && hungerval > 0)
            {
                return(true);
            }
            else if (hungerval <= 0)
            {
                ChatLogger.SendChatMessage("You are too hungry for this item. (" + hungerval + "/100)", Color.red);
                return(false);
            }
            else
            {
                ChatLogger.SendChatMessage("You are not hungry enough to eat this item. (" + hungerval + "/100)", Color.red);
                return(false);
            }

        case StatType.Hydration:
            var hydrationval = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Hydration + modifier.Value;
            if (hydrationval <= 100 && hydrationval > 0)
            {
                return(true);
            }
            else if (hydrationval <= 0)
            {
                ChatLogger.SendChatMessage("You are too thirsty for this item. (" + hydrationval + "/100)", Color.red);
                return(false);
            }
            else
            {
                ChatLogger.SendChatMessage("You are not thirsty enough to eat this item. (" + hydrationval + "/100)", Color.red);
                return(false);
            }

        case StatType.Warmth:
            var warmthval = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Warmth + modifier.Value;
            if (warmthval <= 100 && warmthval > 0)
            {
                return(true);
            }
            else if (warmthval <= 0)
            {
                ChatLogger.SendChatMessage("You are too cold for this item. (" + warmthval + "/100)", Color.red);
                return(false);
            }
            else
            {
                ChatLogger.SendChatMessage("You are to hot right now. (" + warmthval + "/100)", Color.red);
                return(false);
            }

        case StatType.Cleanliness:
            var cleanlinessval = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>().playerData.Cleanliness + modifier.Value;
            if (cleanlinessval <= 100 && cleanlinessval > 0)
            {
                return(true);
            }
            else if (cleanlinessval <= 0)
            {
                ChatLogger.SendChatMessage("You are too dirty for this item. (" + cleanlinessval + "/100)", Color.red);
                return(false);
            }
            else
            {
                ChatLogger.SendChatMessage("You do not fancy this right now. (" + cleanlinessval + "/100)", Color.red);
                return(false);
            }

        default:
            return(false);
        }
    }
Exemplo n.º 18
0
 public ChatService(ChatLogger logger)
 {
     _logger = logger;
 }
Exemplo n.º 19
0
 void Awake()
 {
     Instance = this;
 }