Пример #1
0
        private DataTable cb_Changed()
        {
            DataTable dtResults = new DataTable();

            if (cbInputMonth.SelectedIndex != 0 && cbInputYear.SelectedIndex != 0 && cbLocation.SelectedIndex != 0)
            {
                StatMessage statMessage = new StatMessage()
                {
                    cpu_name = Environment.MachineName
                };
                foreach (Location mLoc in locations)
                {
                    if (mLoc.loc_name.ToLower().Contains(cbLocation.GetItemText(cbLocation.SelectedItem).ToLower()))
                    {
                        statMessage.id_loc   = mLoc.id;
                        statMessage.location = cbLocation.GetItemText(cbLocation.SelectedItem).ToLower();
                    }
                }
                statMessage.year      = cbInputYear.GetItemText(cbInputYear.SelectedItem);
                statMessage.month     = cbInputMonth.GetItemText(cbInputMonth.SelectedItem).ToLower();
                statMessage.stat_type = "GetMonthlyStat";
                dtResults             = apiStatWrapper.GetMonthlyStats(statMessage);
            }
            return(dtResults);
        }
Пример #2
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="stat">
        /// </param>
        /// <param name="value">
        /// </param>
        /// <param name="announce">
        /// </param>
        public static void Send(IZoneClient client, int stat, uint value, bool announce)
        {
            var statMessage = new StatMessage
            {
                Identity = client.Character.Identity,
                Stats    =
                    new[]
                {
                    new GameTuple <CharacterStat, uint>
                    {
                        Value1 =
                            (CharacterStat)stat,
                        Value2 = value
                    }
                }
            };
            var statM = new Message {
                Body = statMessage
            };

            if (!client.Character.DoNotDoTimers)
            {
                client.Character.Playfield.Publish(
                    new IMSendAOtomationMessageToClient {
                    client = client, message = statM
                });
            }

            /* announce to playfield? */
            if (announce)
            {
                client.Character.Playfield.AnnounceOthers(statMessage, client.Character.Identity);
            }
        }
        public Task SendStatus()
        {
            uint receivedCount = _transceiver.ReceivedOkCount +
                                 _transceiver.ReceivedBadCrcCount +
                                 _transceiver.ReceivedTimeoutCount;

            Debug.WriteLine($"Packages: {receivedCount} / {_transceiver.ReceivedOkCount} / {_forwardedFrameCount}");

            var statMessage = new StatMessage(
                DateTime.UtcNow,
                _positionProvider.Position.Latitude,
                _positionProvider.Position.Longitude,
                (int)Math.Round(_positionProvider.Position.Altitude),
                receivedCount,
                _transceiver.ReceivedOkCount,
                _forwardedFrameCount,
                100, // Let's make it easy and say everything's fine!
                0,   // This is just a packet-forwarder; no messages will be transmitted.
                0);  // This is just a packet-forwarder; no messages will be transmitted.

            JsonObject jsonData = JsonSerializer.ToJson(statMessage);

            Debug.WriteLine("Sending JSON: " + jsonData);

            return(PushData(jsonData));
        }
Пример #4
0
        protected virtual void HandleStatMessage(StatMessage Message)
        {
            Message.Stat.ResolveResources(resourceManager, false);

            if (Message.Stat.Resource != null)
            {
                Message.Stat.Resource.DecompressAll();
            }
        }
Пример #5
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="statsToUpdate">
        /// </param>
        public static void SendBulk(IZoneClient client, Dictionary <int, uint> statsToUpdate)
        {
            if (statsToUpdate.Count == 0)
            {
                return;
            }

            var toPlayfieldIds = new List <int>();

            foreach (KeyValuePair <int, uint> keyValuePair in statsToUpdate)
            {
                if (client.Controller.Character.Stats[keyValuePair.Key].AnnounceToPlayfield)
                {
                    toPlayfieldIds.Add(keyValuePair.Key);
                }
            }

            var toPlayfield = new List <GameTuple <CharacterStat, uint> >();
            var toClient    = new List <GameTuple <CharacterStat, uint> >();

            foreach (KeyValuePair <int, uint> keyValuePair in statsToUpdate)
            {
                var statValue = new GameTuple <CharacterStat, uint>
                {
                    Value1 = (CharacterStat)keyValuePair.Key,
                    Value2 = keyValuePair.Value
                };
                toClient.Add(statValue);

                if (toPlayfieldIds.Contains(keyValuePair.Key))
                {
                    toPlayfield.Add(statValue);
                }
            }

            var message = new StatMessage
            {
                Identity = client.Controller.Character.Identity,
                Stats    = toClient.ToArray()
            };

            client.SendCompressed(message);

            /* announce to playfield? */
            if (toPlayfieldIds.Count > 0)
            {
                message.Stats = toPlayfield.ToArray();
                client.Controller.Character.Playfield.AnnounceOthers(message, client.Controller.Character.Identity);
            }
        }
        public void StatMessageTest()
        {
            var expected = new StatMessage
            {
                Identity = Identity.None,
                Stats    =
                    new[]
                {
                    new GameTuple <CharacterStat, uint>
                    {
                        Value1 =
                            CharacterStat
                            .ACGEntranceStyles,
                        Value2 = 1
                    },
                    new GameTuple <CharacterStat, uint>
                    {
                        Value1 =
                            CharacterStat
                            .BackMesh,
                        Value2 = 3
                    },
                    new GameTuple <CharacterStat, uint>
                    {
                        Value1 =
                            CharacterStat
                            .CATAnim,
                        Value2 = 5
                    }
                }
            };

            var actual = (StatMessage)this.SerializeDeserialize(expected);

            this.AssertN3Message(expected, actual);

            var expectedChars = expected.Stats.GetEnumerator();
            var actualChars   = actual.Stats.GetEnumerator();

            while (expectedChars.MoveNext())
            {
                actualChars.MoveNext();
                var expectedChar = (GameTuple <CharacterStat, uint>)expectedChars.Current;
                var actualChar   = (GameTuple <CharacterStat, uint>)actualChars.Current;

                Assert.AreEqual(expectedChar.Value1, actualChar.Value1);
                Assert.AreEqual(expectedChar.Value2, actualChar.Value2);
            }
        }
Пример #7
0
        private void DynamicButton_Click(object sender, EventArgs e, Form passedForm)
        {
            //Form1 frmMain = (Form1)Application.OpenForms["Form1"];
            timerHide = 0;
            StatMessage statMessage = new StatMessage()
            {
                cpu_name     = Environment.MachineName,
                stat_user    = statUser,
                created_by   = statUser.user_name,
                stat_date    = DateTime.Now,
                stat_type    = (sender as Button).Text.Split('(')[0].Trim(),
                stat_comment = ""
            };

            if ((string)(sender as Button).Tag == "time")
            {
                FComment fComment = FormFactory.Create <FComment>("number", "Amount of time spent:");
                if (fComment.ShowDialog() == DialogResult.OK)
                {
                    statMessage.stat_comment = fComment.textBox1.Text;
                }
            }
            if ((string)(sender as Button).Tag == "string")
            {
                FComment fComment = FormFactory.Create <FComment>("", "Enter Comment:");
                if (fComment.ShowDialog() == DialogResult.OK)
                {
                    statMessage.stat_comment = fComment.textBox1.Text;
                }
            }
            apiStatWrapper.PostStat(statMessage);
            if (BackColor == Color.Blue)
            {
                BackColor = Color.White;
            }
            else if (BackColor == Color.White)
            {
                BackColor = Color.Blue;
            }
            string strCount    = (sender as Button).Text.Split('(')[1].Replace(")", string.Empty);
            int    countButton = 0;

            if (int.TryParse(strCount, out countButton))
            {
                countButton++;
            }
            (sender as Button).Text = $"{statMessage.stat_type}({countButton.ToString()})";
        }
Пример #8
0
        private void CollectStats_Click(object sender, EventArgs e, Form passedForm)
        {
            StatMessage statMessage = new StatMessage();

            statMessage.cpu_name = Environment.MachineName;
            Location loc = new Location();

            foreach (Location mLoc in locations)
            {
                if (mLoc.loc_name.ToLower().Contains(cbLocation.GetItemText(cbLocation.SelectedItem).ToLower()))
                {
                    statMessage.id_loc   = mLoc.id;
                    statMessage.location = cbLocation.GetItemText(cbLocation.SelectedItem).ToLower();
                    loc = mLoc;
                }
            }
            statMessage.year  = cbInputYear.GetItemText(cbInputYear.SelectedItem);
            statMessage.month = cbInputMonth.GetItemText(cbInputMonth.SelectedItem).ToLower();
            foreach (Control c in Controls)
            {
                if (c is TableLayoutPanel)
                {
                    foreach (Control cIn in c.Controls)
                    {
                        if (cIn is TextBox)
                        {
                            if (!cIn.Tag.ToString().ToLower().Contains("string"))
                            {
                                if (statUser.monthly_admin == 1 || cIn.Text.Contains("Not Reported"))
                                {
                                    if (loc.auto_pull_stats.FindIndex(s => s.Contains((String)cIn.Name)) != -1)
                                    {
                                        statMessage.stat_type = (String)cIn.Name;
                                        int countM = apiStatWrapper.GetStatCountForMonth(statMessage);
                                        cIn.Text = countM.ToString();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("Done");
        }
Пример #9
0
        /// <summary>
        /// </summary>
        /// <param name="ch">
        /// </param>
        /// <param name="statsToUpdate">
        /// </param>
        public static void SendBulk(ICharacter ch, Dictionary <int, uint> statsToUpdate)
        {
            if (statsToUpdate.Count == 0)
            {
                return;
            }

            var toPlayfield = new List <int>();

            foreach (KeyValuePair <int, uint> keyValuePair in statsToUpdate)
            {
                if (ch.Stats[keyValuePair.Key].AnnounceToPlayfield)
                {
                    toPlayfield.Add(keyValuePair.Key);
                }
            }

            var stats = new List <GameTuple <CharacterStat, uint> >();

            foreach (KeyValuePair <int, uint> keyValuePair in statsToUpdate)
            {
                if (toPlayfield.Contains(keyValuePair.Key))
                {
                    stats.Add(
                        new GameTuple <CharacterStat, uint>
                    {
                        Value1 = (CharacterStat)keyValuePair.Key,
                        Value2 = keyValuePair.Value
                    });
                }
            }

            /* announce to playfield? */
            if (toPlayfield.Any() == false)
            {
                return;
            }

            var message = new StatMessage {
                Identity = ch.Identity, Stats = stats.ToArray()
            };

            ch.Playfield.AnnounceOthers(message, ch.Identity);
        }
Пример #10
0
        /// <summary>
        /// </summary>
        public void SendChangedStats()
        {
            var message = new StatMessage()
            {
                Identity = this.Identity,
            };

            message.Stats = this.Stats.ChangedAnnouncingStats;
            if (message.Stats.Length > 0)
            {
                this.Playfield.AnnounceOthers(message, this.Identity);
            }

            message.Stats = this.Stats.ChangedStats;
            if (message.Stats.Length > 0)
            {
                this.Playfield.Send(this.Client, message);
            }
        }
Пример #11
0
 public static JsonObject ToJson(StatMessage message)
 {
     return(new JsonObject
     {
         { "stat", new JsonObject
           {
               { "time", JsonValue.CreateStringValue(message.Time.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss' GMT'")) },
               { "lati", JsonValue.CreateNumberValue(message.Latitude) },
               { "long", JsonValue.CreateNumberValue(message.Longitude) },
               { "alti", JsonValue.CreateNumberValue(message.Altitude) },
               { "rxnb", JsonValue.CreateNumberValue(message.Rxnb) },
               { "rxok", JsonValue.CreateNumberValue(message.Rxok) },
               { "rxfw", JsonValue.CreateNumberValue(message.Rxfw) },
               { "ackr", JsonValue.CreateNumberValue(message.Ackr) },
               { "dwnb", JsonValue.CreateNumberValue(message.Dwnb) },
               { "txnb", JsonValue.CreateNumberValue(message.Txnb) }
           } }
     });
 }
Пример #12
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="stat">
        /// </param>
        /// <param name="value">
        /// </param>
        /// <param name="announce">
        /// </param>
        public static void SendDirect(IZoneClient client, int stat, uint value, bool announce)
        {
            var statMessage = new StatMessage
            {
                Identity = client.Character.Identity,
                Stats    =
                    new[]
                {
                    new GameTuple <CharacterStat, uint>
                    {
                        Value1 =
                            (CharacterStat)stat,
                        Value2 = value
                    }
                }
            };

            client.SendCompressed(statMessage);
        }
Пример #13
0
    private void UpdateStat(IMessage message)
    {
        StatMessage updateInfo = message as StatMessage;

        if (updateInfo == null)
        {
            throw new System.Exception("A handler was provided an incorrect IMessage");
        }

        if (stats.ContainsKey(updateInfo.TargetStat))
        {
            stats[updateInfo.TargetStat].AddModifier(updateInfo.Modifier);
        }
        else
        {
            Stat stat = new Stat(0f);
            stat.AddModifier(updateInfo.Modifier);
            stats.Add(updateInfo.TargetStat, stat);
        }
    }
Пример #14
0
        private void DynamicButton_Click(object sender, EventArgs e, Form passedForm)
        {
            string      output      = "";
            StatMessage statMessage = new StatMessage();

            statMessage.cpu_name = Environment.MachineName;
            foreach (Location mLoc in locations)
            {
                if (mLoc.loc_name.ToLower().Contains(cbLocation.GetItemText(cbLocation.SelectedItem).ToLower()))
                {
                    statMessage.id_loc   = mLoc.id;
                    statMessage.location = cbLocation.GetItemText(cbLocation.SelectedItem).ToLower();
                }
            }
            statMessage.year  = cbInputYear.GetItemText(cbInputYear.SelectedItem);
            statMessage.month = cbInputMonth.GetItemText(cbInputMonth.SelectedItem).ToLower();
            foreach (Control c in Controls)
            {
                if (c is TableLayoutPanel)
                {
                    foreach (Control cIn in c.Controls)
                    {
                        if (cIn is TextBox)
                        {
                            bool upload = false;
                            statMessage.stat_type = (String)cIn.Name;
                            statMessage.stat_user = statUser;
                            int countInt = 0;
                            if (cIn.Tag.ToString().ToLower().Contains("string"))
                            {
                                if (!cIn.Text.Contains("Not Reported"))
                                {
                                    statMessage.count        = 0;
                                    statMessage.stat_comment = cIn.Text;
                                    upload = true;
                                }
                            }
                            else
                            {
                                if (int.TryParse(cIn.Text, out countInt))
                                {
                                    statMessage.count = countInt;
                                    upload            = true;
                                }
                                else
                                {
                                    if (cIn.Text != "Not Reported")
                                    {
                                        MessageBox.Show($"Input for {statMessage.stat_type} is not a number and will not be uploaded");
                                    }
                                }
                            }
                            if (upload)
                            {
                                output += $"Stat: {statMessage.stat_type} Result: {apiStatWrapper.SetMonthlyStat(statMessage)}{Environment.NewLine}";
                            }
                        }
                    }
                }
            }
            MessageBox.Show(output);
        }
Пример #15
0
 public bool ApiPostStat(StatMessage statMessage) => apiStatsWrapper.PostStat(statMessage);
Пример #16
0
        public void HandleMessages()
        {
            StreamReader reader = new StreamReader(Client.TcpClient.GetStream());

            while (true)
            {
                string line = null;

                try
                {
                    line = reader.ReadLine().Replace("§", "");
                } catch
                {
                    line = null;
                }

                if (string.IsNullOrEmpty(line))
                {
                    if (Client.TcpClient.Connected)
                    {
                        Client.Disconnect();
                    }
                    return;
                }

                while (line.Contains("  "))
                {
                    line = line.Replace("  ", " ");
                }

                while (line.EndsWith(" "))
                {
                    line = line.Substring(0, line.Length - 1);
                }

                ChatMessage    chatMessage    = new ChatMessage(Client, line);
                CommandMessage commandMessage = new CommandMessage(Client, line);
                StatMessage    statMessage    = new StatMessage(Client, line);

                Client.LastActivity = (int)(DateTime.UtcNow.Subtract(Program.EPOCH_START)).TotalSeconds;

                if (chatMessage.Valid())
                {
                    chatMessage.Handle();
                }
                else if (commandMessage.Valid())
                {
                    commandMessage.Handle();
                }
                else if (statMessage.Valid())
                {
                    statMessage.Handle();
                }
                else
                {
                    // ???
                    Client.Disconnect("§2What was that?");
                    return;
                }
            }
        }
Пример #17
0
 public DataTable ApiGetMonthlyStats(StatMessage statMessage) => apiStatsWrapper.GetMonthlyStats(statMessage);
Пример #18
0
 public string ApiSetMonthlyStat(StatMessage statMessage) => apiStatsWrapper.SetMonthlyStat(statMessage);
Пример #19
0
 public int GetMonthlyStatCountForMonth(StatMessage statMessage) => apiStatsWrapper.GetMonthlyStatCountForMonth(statMessage);
Пример #20
0
 public string GetMonthlyStatComment(StatMessage statMessage) => apiStatsWrapper.GetMonthlyStatComment(statMessage);