[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bzflag-commits
Subject:    SF.net SVN: bzflag:[22338] trunk/tools/BZStatCollector
From:       JeffM2501 () users ! sourceforge ! net
Date:       2012-01-20 19:04:50
Message-ID: E1RoJla-0005Se-Gk () sfp-svn-5 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 22338
          http://bzflag.svn.sourceforge.net/bzflag/?rev=22338&view=rev
Author:   JeffM2501
Date:     2012-01-20 19:04:50 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
store basic data on servers that are not polled just so we can iterate them int he \
logs

Modified Paths:
--------------
    trunk/tools/BZStatCollector/CollectorCLI/Program.cs
    trunk/tools/BZStatCollector/Connector/BZFSList.cs
    trunk/tools/BZStatCollector/Connector/StatRecords.cs
    trunk/tools/BZStatCollector/DatabaseStore/DBStore.cs
    trunk/tools/BZStatCollector/schema/database.sql

Modified: trunk/tools/BZStatCollector/CollectorCLI/Program.cs
===================================================================
--- trunk/tools/BZStatCollector/CollectorCLI/Program.cs	2012-01-19 23:00:37 UTC (rev \
                22337)
+++ trunk/tools/BZStatCollector/CollectorCLI/Program.cs	2012-01-20 19:04:50 UTC (rev \
22338) @@ -50,24 +50,40 @@
 
             double redoTime = 5*60;
 
+            bool GotList = false;
+
+            List<BZFSList.ServerEntry> serversWithPlayers = new \
List<BZFSList.ServerEntry>(); +            List<BZFSList.ServerEntry> allServers = \
new List<BZFSList.ServerEntry>(); +
             while (!done)
             {
-                if (timer == null || timer.ElapsedMilliseconds >= (redoTime * 1000))
+                double WaitTime = redoTime * 1000;
+
+                if (timer == null || timer.ElapsedMilliseconds >= WaitTime)
                 {
                     BZFSList list = new BZFSList();
-                    list.Update("http://my.bzflag.org/db/?action=LIST");
+                    GotList = list.Update("http://my.bzflag.org/db/?action=LIST");
 
-                  
-                    List<BZFSList.ServerEntry> servers = \
list.ServersWithRealPlayers(BZFSList.ServerEntry.BZFlagProduct, \
BZFSList.ServerEntry.BZFlagVersion); +                    if (GotList)
+                    {
+                        serversWithPlayers = \
list.ServersWithRealPlayers(BZFSList.ServerEntry.BZFlagProduct, \
BZFSList.ServerEntry.BZFlagVersion); +                        allServers = \
list.ServersOfProduct(BZFSList.ServerEntry.BZFlagProduct, \
BZFSList.ServerEntry.BZFlagVersion); +                    }
 
-                    foreach (BZFSList.ServerEntry server in servers)
-                        new DBStore().StoreServerData(server);
+                    if (GotList)
+                    {
+                        foreach (BZFSList.ServerEntry server in allServers)
+                            new DBStore().StoreServerBasicInfo(server);
+                    }
+                   
+                    foreach (BZFSList.ServerEntry server in serversWithPlayers)
+                        new DBStore().StoreServerActivityData(server);
 
                     List<BZConnect> Connectors = new List<BZConnect>();
 
                     int totalPlayers = 0;
                     int totalServersWithPlayers = 0;
-                    foreach (BZConnect con in BZConnect.DoForeach(servers, LogFunc, \
5)) +                    foreach (BZConnect con in \
BZConnect.DoForeach(serversWithPlayers, LogFunc, 5))  {
                         totalServersWithPlayers++;
 
@@ -81,7 +97,6 @@
                         }
                     }
 
-
                     FileInfo file = new FileInfo("results.csv");
                     StreamWriter sw = file.AppendText();
 

Modified: trunk/tools/BZStatCollector/Connector/BZFSList.cs
===================================================================
--- trunk/tools/BZStatCollector/Connector/BZFSList.cs	2012-01-19 23:00:37 UTC (rev \
                22337)
+++ trunk/tools/BZStatCollector/Connector/BZFSList.cs	2012-01-20 19:04:50 UTC (rev \
22338) @@ -134,7 +134,7 @@
 
         public List<ServerEntry> Servers = new List<ServerEntry>();
 
-        public void Update(string url)
+        public bool Update(string url)
         {
             Servers.Clear();
 
@@ -152,12 +152,13 @@
 
                 reader.Close();
                 stream.Close();
+                return true;
             }
             catch (System.Exception ex)
             {
                 Console.WriteLine("Error in list serer update : " + ex.Message);
             }
-
+            return false;
         }
 
         public List<ServerEntry> ServersWithRealPlayers()

Modified: trunk/tools/BZStatCollector/Connector/StatRecords.cs
===================================================================
--- trunk/tools/BZStatCollector/Connector/StatRecords.cs	2012-01-19 23:00:37 UTC (rev \
                22337)
+++ trunk/tools/BZStatCollector/Connector/StatRecords.cs	2012-01-20 19:04:50 UTC (rev \
22338) @@ -40,6 +40,34 @@
                 BadFlagAntidote = (optionsMask & 0x0100) != 0;
                 NoTeamKills = (optionsMask & 0x0400) != 0;
             }
+
+            public override string ToString()
+            {
+                string ret = "";
+                if (SuperFlags)
+                    ret += "SuperFlags,";
+                if (Jumping)
+                    ret += "Jumping,";
+                if (Inertia)
+                    ret += "Inertia,";
+                if (Inertia)
+                    ret += "Inertia,";
+                if (Ricochet)
+                    ret += "Ricochet,";
+                if (BadFlagShakable)
+                    ret += "BadFlagShakable,";
+                if (BadFlagAntidote)
+                    ret += "BadFlagAntidote,";
+                if (HandicapEnabled)
+                    ret += "HandicapEnabled,";
+                if (NoTeamKills)
+                    ret += "NoTeamKills,";
+
+                if (ret.Length > 0)
+                    ret = ret.TrimEnd(",".ToCharArray());
+
+                return ret;
+            }
         }
 
         public enum GameType
@@ -107,6 +135,20 @@
             return GetTeam(IDToTeam(team));
         }
 
+        public string GetTeamList()
+        {
+            string ret = "";
+            foreach (KeyValuePair<TeamColors, TeamInfo> team in Teams)
+            {
+                if (team.Value.MaxSize > 0)
+                    ret += team.Key.ToString() + ",";
+            }
+
+            if (ret.Length > 0)
+                ret = ret.TrimEnd(",".ToCharArray());
+            return ret;
+        }
+
         public class PlayerInfo
         {
             public int PlayerID = 0;

Modified: trunk/tools/BZStatCollector/DatabaseStore/DBStore.cs
===================================================================
--- trunk/tools/BZStatCollector/DatabaseStore/DBStore.cs	2012-01-19 23:00:37 UTC (rev \
                22337)
+++ trunk/tools/BZStatCollector/DatabaseStore/DBStore.cs	2012-01-20 19:04:50 UTC (rev \
22338) @@ -111,12 +111,11 @@
             connection.Dispose();
         }
 
-        public void StoreServerData(BZFSList.ServerEntry server)
+        public void StoreServerActivityData(BZFSList.ServerEntry server)
         {
             MySqlConnection connection = Connect();
             if (connection == null)
                 return;
-
             try
             {
                 string query = String.Format("INSERT INTO server_updates \
(ServerName, Players, Observers, Timestamp) VALUES (@SERVER, @PLAYERS, @OBSERVERS, \
@TIMESTAMP)"); @@ -135,9 +134,66 @@
             {
                 Console.WriteLine("error in StoreServerData " + ex.Message);
             }
-            
         }
 
+        public void StoreServerBasicInfo(BZFSList.ServerEntry server)
+        {
+            MySqlConnection connection = Connect();
+            if (connection == null)
+                return;
+
+            DateTime now = DateTime.Now;
+            string serverName = server.Host + ":" + server.Port.ToString();
+            string query = string.Empty;
+
+            try
+            {
+                query = String.Format("SELECT ID FROM server_names WHERE \
ServerName=@SERVER"); +
+                MySqlCommand command = new MySqlCommand(query, connection);
+                command.Parameters.Add(new MySqlParameter("SERVER", serverName));
+                MySqlDataReader reader = command.ExecuteReader();
+
+                if (reader != null && reader.Read())
+                {
+                    Int64 ID = reader.GetInt64(0);
+
+                    reader.Close();
+                    query = String.Format("UPDATE server_names SET \
Description=@DESCRIPTION, GameType=@GAMETYPE, GameFlags=@FLAGS, Teams=@TEAMS, \
LastUpdate=@TIMESTAMP WHERE ID=@ID"); +
+                    command = new MySqlCommand(query, connection);
+                    command.Parameters.Add(new MySqlParameter("ID", ID));
+                    command.Parameters.Add(new MySqlParameter("DESCRIPTION", \
server.Description)); +                    command.Parameters.Add(new \
MySqlParameter("GAMETYPE", server.GameInfo.ServerGameType.ToString())); +             \
command.Parameters.Add(new MySqlParameter("FLAGS", \
server.GameInfo.Options.ToString())); +                    command.Parameters.Add(new \
MySqlParameter("TEAMS", server.GameInfo.GetTeamList())); +                    \
command.Parameters.Add(new MySqlParameter("TIMESTAMP", DateTime.Now)); +              \
command.ExecuteNonQuery(); +                }
+                else
+                {
+                    reader.Close();
+                    query = String.Format("INSERT INTO server_names (Description, \
GameType, GameFlags, Teams, LastPlayed) VALUES (@DESCRIPTION, @GAMETYPE, @FLAGS, \
@TEAMS, @TIMESTAMP)"); +
+                    command = new MySqlCommand(query, connection);
+                    command.Parameters.Add(new MySqlParameter("DESCRIPTION", \
server.Description)); +                    command.Parameters.Add(new \
MySqlParameter("GAMETYPE", server.GameInfo.ServerGameType.ToString())); +             \
command.Parameters.Add(new MySqlParameter("FLAGS", \
server.GameInfo.Options.ToString())); +                    command.Parameters.Add(new \
MySqlParameter("TEAMS", server.GameInfo.GetTeamList())); +                    \
command.Parameters.Add(new MySqlParameter("TIMESTAMP", DateTime.Now)); +              \
command.ExecuteNonQuery(); +                }
+            }
+            catch (System.Exception ex)
+            {
+                Console.WriteLine("error in StoreServerBasicInfo " + ex.Message);
+                Console.WriteLine(query);
+            }
+
+            connection.Close();
+            connection.Dispose();
+        }
+
         public void StoreTotalData(int players, int servers)
         {
             MySqlConnection connection = Connect();

Modified: trunk/tools/BZStatCollector/schema/database.sql
===================================================================
--- trunk/tools/BZStatCollector/schema/database.sql	2012-01-19 23:00:37 UTC (rev \
                22337)
+++ trunk/tools/BZStatCollector/schema/database.sql	2012-01-20 19:04:50 UTC (rev \
22338) @@ -82,7 +82,28 @@
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
+
 --
+-- Table structure for table `server_names`
+--
+
+DROP TABLE IF EXISTS `server_names`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `server_names` (
+  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `ServerName` text,
+  `Description` text,
+  `GameType` tinytext,
+  `GameFlags` text,
+  `Teams` text,
+  `LastUpdate` datetime DEFAULT NULL,
+  PRIMARY KEY (`ID`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+
+--
 -- Dumping routines for database 'bz_stats'
 --
 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
BZFlag-commits mailing list
BZFlag-commits@lists.SourceForge.net
https://lists.SourceForge.net/lists/listinfo/bzflag-commits
irc: #BZFlag @ irc.freenode.net


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic