コード例 #1
0
        internal void SetServerInfo(HistoryServer server = null)
        {
            if (server == null)
            {
                lvInfo.Items.Clear();
                headerServerInfo1.Text = null;
                headerServerInfo2.Text = null;
                lbServerInfo1.Text     = null;
                lbServerInfo2.Text     = null;
                Text = "DayzJournal by rom";
                lbServerInfo2.ForeColor = SystemColors.ControlText;
            }
            else
            {
                if (!string.IsNullOrEmpty(server.Name))
                {
                    Text = string.Format("DayzJournal - {0}", server.Name);
                }
                if (server.Name != null)
                {
                    headerServerInfo1.Text = "online";
                }
                if (server.Players > 0 || server.MaxPlayers > 0)
                {
                    headerServerInfo2.Text = string.Format("{0}/{1}", server.Players, server.MaxPlayers);
                }
                if (server.Ping != 0)
                {
                    lbServerInfo1.Text = string.Format("ping {0} ms, uptime {1}", server.Ping, server.UpTime);
                }
                if (server.GameVersion != null)
                {
                    if (server.GameVersion.Equals("offline?"))
                    {
                        lbServerInfo2.Text = server.GameVersion;
                    }
                    else
                    {
                        lbServerInfo2.Text      = string.Format("{0}{1}", server.GameVersion, server.Hive);
                        lbServerInfo2.ForeColor = Color.ForestGreen;
                    }
                }

                if (server.PlayerList != null && server.PlayerList.Any())
                {
                    foreach (var player in server.PlayerList)
                    {
                        var lvItem = new ListViewItem(string.Format("{0:D2}:{1:D2}:{2:D2}", player.Time.Hours, player.Time.Minutes, player.Time.Seconds));
                        lvItem.SubItems.Add(string.IsNullOrEmpty(player.Name) ? "player connecting..." : player.Name);
                        lvInfo.Items.Add(lvItem);
                    }
                }
                lvInfo.Columns[0].Width = -2;
                lvInfo.Columns[1].Width = -2;
            }
        }
コード例 #2
0
 internal void SetServerInfoCheckInvoked(HistoryServer server = null)
 {
     if (lvInfo.InvokeRequired)
     {
         BeginInvoke(new Action(() => SetServerInfo(server)));
     }
     else
     {
         SetServerInfo(server);
     }
 }
コード例 #3
0
        internal void Read()
        {
            if (string.IsNullOrEmpty(FullName))
            {
                Csv = new List <HistoryServer>();
            }

            if (!File.Exists(FullName))
            {
                using (var sw = File.CreateText(FullName))
                {
                    sw.WriteLine(string.Empty);
                    sw.Close();
                }
            }

            Csv = new List <HistoryServer>();
            using (var tfParser = new TextFieldParser(FullName))
            {
                tfParser.CommentTokens = new[] { "#" };
                tfParser.SetDelimiters(new[] { ";" });
                tfParser.HasFieldsEnclosedInQuotes = false;

                while (!tfParser.EndOfData)
                {
                    var fields = tfParser.ReadFields();
                    var server = new HistoryServer();
                    try
                    {
                        if (fields != null)
                        {
                            server.LastPlayTime = DateTime.Parse(fields[0]);
                        }
                    }
                    catch
                    {
                        server.LastPlayTime = new DateTime();
                    }
                    if (fields != null)
                    {
                        server.AddrIpPort = fields[1];
                        server.PlayerName = fields[2];
                        server.Name       = fields[3];
                    }
                    Csv.Add(server);
                }
            }
        }
コード例 #4
0
        internal void Update(DayZProfile dayzProfile)
        {
            var oldServer = (from s in Csv
                             where s.LastPlayTime == dayzProfile.LastWriteTime
                             select s)
                            .ToList();

            if (oldServer.Any())
            {
                return;
            }

            var server = new HistoryServer
            {
                PlayerName   = dayzProfile.PlayerName,
                AddrIpPort   = dayzProfile.LastMpServer,
                Name         = dayzProfile.LastMpServerName,
                LastPlayTime = dayzProfile.LastWriteTime
            };

            Csv.Add(server);
        }
コード例 #5
0
        private void MasterIpCallback(ReadOnlyCollection <IPEndPoint> endPoints, Exception error)
        {
            HistoryServer server;

            if (error == null && endPoints != null)
            {
                foreach (var endPoint in endPoints)
                {
                    //"0.0.0.0:0" is the last address
                    if (endPoint.Address.ToString() != "0.0.0.0")
                    {
                        var qmServer = ServerQuery.GetServerInstance(Game.DayZ, endPoint);

                        var info = qmServer.GetInfo();
                        if (info != null)
                        {
                            server = new HistoryServer
                            {
                                Ping        = info.Ping,
                                Name        = info.Name,
                                GameVersion = info.GameVersion,
                                Players     = info.Players,
                                MaxPlayers  = info.MaxPlayers
                            };
                            //Keywords	"battleye,privHive,etm2.000000,13:06"
                            var keywords = info.Extra.Keywords;

                            var kWords = keywords.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();

                            server.UpTime = kWords.Last();
                            server.Hive   = kWords.Contains("privHive") ? ", privHive" : ", publHive";
                            server.Hive   = kWords.Contains("no3rd") ? server.Hive + ", 1PP" : server.Hive;

                            var shard = (from k in kWords
                                         where k.Contains("shard")
                                         select k).FirstOrDefault();

                            if (shard != null)
                            {
                                server.Hive += string.Format(", {0}", shard);
                            }

                            var          foo       = 0;
                            Action <int> actionFoo = x => foo++;

                            var getPlayers = qmServer.GetPlayers(actionFoo);
                            if (getPlayers != null)
                            {
                                server.PlayerList = getPlayers.ToList();
                            }

                            SetServerInfoCheckInvoked(server);
                            break;
                        }
                    }
                }
            }
            else
            {
                server = new HistoryServer {
                    GameVersion = "offline?"
                };
                SetServerInfoCheckInvoked(server);
            }
        }