Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

SubOps and how .NET devs can use Tracker's database.

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> War in the Pacific: Admiral's Edition >> SubOps and how .NET devs can use Tracker's database. Page: [1]
Login
Message << Older Topic   Newer Topic >>
SubOps and how .NET devs can use Tracker's database. - 9/12/2013 6:53:44 AM   
Knyvet


Posts: 138
Joined: 10/10/2009
Status: offline
I am developing a "SubOps" helper program to help with ASW and sub operations. I want to be able to see patterns over specified periods of time such as heat maps.

Despite Microsoft's best efforts to kill it, I am currently programming in WPF/C# as a hobby. SubOps looks and acts like any other Windows program and SubOps Alpha has a nifty interface for mouse scrolling and zooming the map.

SubOps, however, is garbage without turn info. So even though I can use the scen designer data and parse all of the turns' text reports to pull out sub events for lots of data to analyze and display, I cannot know which side controls a base on a given turn. I also cannot track your sub commander's skill rating as it changes.

The solution is not to pester or mess with the API hooks for the save turn file - a little poking and it became clear to me that the game designers and tracker guys have done a good job locking down access to the turn file and obfuscating to prevent pb email cheating. This is a very good thing and the fewer people who have access to the turn file's guts the better we off we all are in the long run.

So, what is the solution? Tracker's DB has all the info for all the turns and SubOps only needs to read the info, not change it. Also I want SubOps to be open source freeware, heavily commented, and available on gethub so I never want direct access a turn file.

But... (there is always a but), Tracker uses a nifty and well-established Java database and I want to use C#/.NET....... Hmmm. Tracker is frikin' awesome, but I do not play well with Java. I learned it in the early days of Java in graduate school when the swing interface was crap and have not touched it in a decade or so.

The solution was to make Java run within a C# app- the C# code below does just that by using Java to read data from Tracker's database! I am posting it because maybe someone can also use it. It is bare-bones and a bunch more needs to be added and understood to adhere to coding/Java/C# best practices.

PLEASE let me know the following:
1) Tracker and Matrix's forum admin - please post a response and tell me if I should pull this down asap!
2) I can write a detailed step-by-step narrative of what you need to do to access Tracker's db with C#, but is it worth my time considering C# is on the downward trend and the code below should be enough to get someone started in the right direction.
3) Should I make a narrated YouTube vid of SubOps which is currently Alpha but has a few features roughly implemented (e.g., heat mapping, map interface)? I will if people will view it and give me feedback (e.g., interface improvements, features, etc.).

Finally - programming is my hobby. I am not a professional programmer and SubOps is pretty ambitious project. Given my other commitments SubOps may never be done so giving feedback may not be worth your time.

The C# code follows:

// trackerdbAccess
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------

namespace trackerdbAccess
{
    /// .NET System lib is used to display text from trackerdb in a console window.
    using System;

    // IKVM.NET enables running compiled Java code (byte code) directly on Microsoft
    // .NET or Mono. The byte code is converted on the fly to CIL and executed.
    // You can use the Nuget package manager to add IKVM to your .NET project.
    // IKVM.NET is free software, distributed under a permissive free software license.
    using ikvm;

    // Tracker's database is a HyperSQL database.
    // You must use IKVM and the console app to create the HyperSQL lib.
    using org.hsqldb;

    // To connect with SQL databases, the Java Database Connectivity API (JDBC) requires
    // a driver. The JDBC driver provides the connection to the database and implements
    // the protocol for transferring the query and result between client and database.
    // A JDBC driver is used to access Tracker's HyperSQL database.
    // Java libs are automatically available to your project once you add IKVM via Nuget.
    using java;

    class Program
    {
        // Even though I used using declarations above, I use fully qualified domains below for clarity. 
        static void Main(string[] args)
        {
            // Instantiate the database interface as null before the try-catch-final block.
            // As of at least Java 7 Datasource is now the preferred interface, but its not yet available via IKVM. 
            java.sql.Connection conn = null;

            // Instantiate a Result Set object as null to hold the table of data generated by your query.
            // ResultSet also provides the methods used to view your query results.
            java.sql.ResultSet rs = null;
            
            // For pedagogical reasons, I use three variables to provide required information to the database interface.
            string url = @"jdbc:hsqldb:file:c:\Database\trackerdb";    // the interface, driver, HyperSQL database type, database location
            string username = "sa";  // HyperSQL's default admin account.
            string password = "";

            try
            {
                // Register the HyperSQL driver with the DriverManager, a basic service that will manage the driver. 
                // Note that Java apps no longer need to explicitly load JDBC drivers using Class.forName().
                System.Console.WriteLine("Registering HyperSQL driver . . .");
                java.sql.DriverManager.registerDriver(new org.hsqldb.jdbcDriver());

                // Establish a connection to the Tracker database using the driver you registered above with DriverManager.
                System.Console.WriteLine("Establishing connection to database . . .");
                conn = java.sql.DriverManager.getConnection(url, username, password);

                // Create a Statement object that will be used to execute and return the results of your sql query.
                System.Console.WriteLine("Creating SQL query . . .");
                java.sql.Statement st = conn.createStatement();

                // Declare a string variable and assign it your sql query.
                string query = "SELECT NAME FROM Aircraft WHERE ID = 160;";

                // Execute the query and assign the results to your ResultSet object.
                rs = st.executeQuery(query);

                // Advance the cursor within the ResultSet and display the value your query obtained that is in ResultSet row 1.
                // I'm a little confused why I had to advance the cursor and will be reading a lot more about ResultSets.
                // Critical Tip: HyperSQL comes with a great Java utility you can use to view the structure of the Tracker database.
                // Using the utility I know that the aircraft assigned ID 1 is "Anson I".
                rs.next();
                System.Console.WriteLine(rs.getString(1)); 

                // Keep the console window open in debug mode until you can read the result.
                System.Console.WriteLine("Press any key to exit.");
                System.Console.ReadKey();

            }

            // Just a lazy bare minimum exception implementation for step debugging.
            catch (System.Exception ex)
            {
                throw ex;
            }

            // You want to make sure to release resources and close the database if you made a connection.
            finally
            {
                // Release resources allocated to your ResultSet.
                if (rs != null)
                {
                    rs.close();
                    rs = null;
                }

                if (conn != null)
                {
                    //  Release the Connection object's database and JDBC resources
                    //  immediately instead of waiting for them to be automatically released.
                    conn.close();
                    conn = null;
                }
            }
        }
    }
}


< Message edited by Knyvet -- 9/12/2013 6:57:16 AM >
Post #: 1
RE: SubOps and how .NET devs can use Tracker's database. - 9/13/2013 2:39:00 AM   
floydg

 

Posts: 2052
Joined: 6/27/2004
From: Middletown, NJ
Status: offline
I suppose you're free to use whatever is in the Tracker DB. There isn't a whole lot related to sub ops now, but I am working on something now that will add a bit to it.

The schema is mostly straightforward, but is always subject to change. And I need to make a fairly significant one eventually to deal with the exploding DB load time.

Floyd

(in reply to Knyvet)
Post #: 2
RE: SubOps and how .NET devs can use Tracker's database. - 9/13/2013 4:39:40 AM   
Knyvet


Posts: 138
Joined: 10/10/2009
Status: offline
Thanks Floyd

For other devs reference tracker's current tables:





Attachment (1)

(in reply to floydg)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> War in the Pacific: Admiral's Edition >> SubOps and how .NET devs can use Tracker's database. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.680