Author Topic: TNServer.exe "Server.dat"  (Read 3004 times)

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
TNServer.exe "Server.dat"
« on: November 25, 2015, 07:17:15 PM »
When I run TNServer.ext it saves information to "Server.dat"  How would I go about saving and loading it to "Server2.dat" or any other name?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNServer.exe "Server.dat"
« Reply #1 on: November 26, 2015, 07:57:53 AM »
It's one of the parameters when calling TNServerInstance.Start.
If you're running it stand-alone you'll need to modify ServerMain.cs to either add an argument for filename (and pass it to the Start function) or just modify the default value.

Specifically, you can call SaveTo(string fileName) and LoadFrom(string fileName) on the GameServer object
or
SaveTo(string fileName) and Stop(string fileName) on the TNServerInstance object (pass the filename to Start to load from)

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNServer.exe "Server.dat"
« Reply #2 on: November 27, 2015, 03:37:55 AM »
Hi,

Thanks for that.  So, I changed the only value I saw in ServerMain.cs

   public void Start (string serverName, int tcpPort, int udpPort, string lobbyAddress, int lobbyPort, bool useTcp, bool service, string fn = "server2.dat")

but it still runs everything through server.dat. 

I suspect I am missing something else.  Do you have any suggestions?

Do I need to compile this into an .exe after these changes?  Suggestions or starting point how?

I have two separate games running Tnet on the same remote server.  Using the same server.dat is causing quite some conflict.
« Last Edit: November 27, 2015, 03:44:09 AM by voncarp »

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNServer.exe "Server.dat"
« Reply #3 on: November 27, 2015, 06:23:20 AM »
Yes, that is the source file. You need to compile in order for the changes to take effect.

In ServerMain.cs, find the static int Main (string[] args) function and replace it with the following:
  1.         static int Main (string[] args)
  2.         {
  3.                 if (args == null || args.Length == 0)
  4.                 {
  5.                         Console.WriteLine("No arguments specified, assuming default values.");
  6.                         Console.WriteLine("In the future you can specify your own ports like so:\n");
  7.                         Console.WriteLine("   -name \"Your Server\"         <-- Name your server");
  8.                         Console.WriteLine("   -tcp [port]                 <-- TCP port for clients to connect to");
  9.                         Console.WriteLine("   -udp [port]                 <-- UDP port used for communication");
  10.                         Console.WriteLine("   -udpLobby [address] [port]  <-- Start or connect to a UDP lobby");
  11.                         Console.WriteLine("   -tcpLobby [address] [port]  <-- Start or connect to a TCP lobby");
  12.                         Console.WriteLine("   -ip [ip]                    <-- Choose a specific network interface");
  13.                         Console.WriteLine("   -service                    <-- Run it as a service");
  14.             Console.WriteLine("   -filename \"Name\"            <-- Name of file to save to");
  15.                         Console.WriteLine("\nFor example:");
  16.                         Console.WriteLine("  TNServer -name \"My Server\" -tcp 5127 -udp 5128 -udpLobby 5129 -filename server.dat");
  17.  
  18.                         args = new string[] { "-name", "TNet Server", "-tcp", "5127", "-udp", "5128", "-udpLobby", "5129" };
  19.                 }
  20.  
  21.                 string serverName = "TNet Server";
  22.                 int tcpPort = 0;
  23.                 int udpPort = 0;
  24.                 string lobbyAddress = null;
  25.                 int lobbyPort = 0;
  26.                 bool tcpLobby = false;
  27.                 bool service = false;
  28.         string filename = "";
  29.  
  30.                 for (int i = 0; i < args.Length; )
  31.                 {
  32.                         string param = args[i];
  33.                         string val0 = (i + 1 < args.Length) ? args[i + 1] : null;
  34.                         string val1 = (i + 2 < args.Length) ? args[i + 2] : null;
  35.  
  36.                         if (val0 != null && val0.StartsWith("-"))
  37.                         {
  38.                                 val0 = null;
  39.                                 val1 = null;
  40.                         }
  41.                         else if (val1 != null && val1.StartsWith("-"))
  42.                         {
  43.                                 val1 = null;
  44.                         }
  45.  
  46.             if (param == "-name")
  47.             {
  48.                 if (val0 != null) serverName = val0;
  49.             }
  50.             else if (param == "-tcp")
  51.             {
  52.                 if (val0 != null) int.TryParse(val0, out tcpPort);
  53.             }
  54.             else if (param == "-udp")
  55.             {
  56.                 if (val0 != null) int.TryParse(val0, out udpPort);
  57.             }
  58.             else if (param == "-ip")
  59.             {
  60.                 if (val0 != null) UdpProtocol.defaultNetworkInterface = Tools.ResolveAddress(val0);
  61.             }
  62.             else if (param == "-tcpLobby")
  63.             {
  64.                 if (val1 != null)
  65.                 {
  66.                     lobbyAddress = val0;
  67.                     int.TryParse(val1, out lobbyPort);
  68.                 }
  69.                 else int.TryParse(val0, out lobbyPort);
  70.                 tcpLobby = true;
  71.             }
  72.             else if (param == "-udpLobby")
  73.             {
  74.                 if (val1 != null)
  75.                 {
  76.                     lobbyAddress = val0;
  77.                     int.TryParse(val1, out lobbyPort);
  78.                 }
  79.                 else int.TryParse(val0, out lobbyPort);
  80.                 tcpLobby = false;
  81.             }
  82.             else if (param == "-lobby")
  83.             {
  84.                 if (val0 != null) lobbyAddress = val0;
  85.             }
  86.             else if (param == "-service")
  87.             {
  88.                 service = true;
  89.             }
  90.             else if (param == "-filename")
  91.             {
  92.                 filename = val0;
  93.             }
  94.  
  95.                         if (val1 != null) i += 3;
  96.                         else if (val0 != null) i += 2;
  97.                         else ++i;
  98.                 }
  99.  
  100.                 Application app = new Application();
  101.                 app.Start(serverName, tcpPort, udpPort, lobbyAddress, lobbyPort, tcpLobby, service, filename);
  102.                 return 0;
  103.         }
  104.  

This will allow you to specify a filename when launching each server instance. Launch it like so: TNServer.exe -filename "MyUniqueFileName.dat". Add whatever other parameters you need.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNServer.exe "Server.dat"
« Reply #4 on: November 28, 2015, 02:14:35 PM »
 :D Works like a charm.

Thanks!