Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - cmifwdll

Pages: 1 ... 16 17 [18] 19
256
TNet 3 Support / Re: TNET allias , admin kick and ban
« on: December 08, 2015, 12:07:38 AM »
The server attempts to read from your documents path + ServerConfig, so on Windows 7-10 you need to place admin.txt in this directory: C:\Users\YOURUSERNAME\Documents\ServerConfig\

If you're on another OS I'm sure you can find it on google.

As far as the content of admin.txt, it can be anything you want it to be. I have this:
admin.txt
  1. password123
  2.  

Connecting to server and logging in as admin: (There are some variables / GUI components you won't have, add them yourself)
  1. string serverAddress;
  2. int serverPort = 5128;
  3.  
  4. void Start ()
  5. {
  6.     // i'm hosting the server on the same PC i'm running the client on
  7.     // otherwise set the IP of your server here
  8.     serverAddress = TNet.Tools.localAddress.ToString();
  9.     TNManager.client.onSetAdmin += OnSetAdmin;
  10. }
  11. // GUI button handler
  12. public void OnClick(string sender)
  13. {
  14.     if (sender == "btnJoinServer")
  15.     {
  16.         // connect to server
  17.         // declare int serverPort elsewhere and set it to your server's port
  18.         Debug.Log("Connecting to " + serverAddress + ":" + serverPort.ToString());
  19.         TNManager.Connect(serverAddress, serverPort);
  20.     }
  21.     else if (sender == "btnVerifyAdmin")
  22.     {
  23.         if (TNManager.isConnected)
  24.             TNManager.SetAdmin("password123");
  25.         else
  26.             Debug.LogError("Connect to the server before calling SetAdmin");
  27.     }
  28. }
  29.  
  30. void OnNetworkConnect (bool result, string message)
  31. {
  32.     if (result)
  33.     {
  34.         Debug.Log("connected to server");
  35.         // Make it possible for this client to use UDP using a random port
  36.         TNManager.StartUDP(Random.Range(10000, 50000));
  37.     }
  38.     else
  39.     {
  40.         Debug.LogError(message);
  41.     }
  42. }
  43.  
  44. void OnSetAdmin(Player admin)
  45. {
  46.     Debug.Log(admin.name + " has logged in as admin");
  47. }
  48.  

That should give you a start at least.

I couldn't find an easy function for kicking / banning, but you can certainly construct the packet yourself by looking at what the server expects (int32: Player ID followed by string: player name or address (if ID is '0'))

So, you might make a helper function like so -
Helper functions for kicking and banning:
  1. void KickPlayer(int PlayerID, string Player)
  2. {
  3.     if ((PlayerID == 0) && (Player == ""))
  4.     {
  5.         Debug.LogError("Must set either PlayerID or Player");
  6.         return;
  7.     }
  8.     Debug.Log("Kicking [" + PlayerID + "](" + Player + ")");
  9.     BinaryWriter packet = TNManager.client.BeginSend(Packet.RequestKick);
  10.     packet.Write(PlayerID);
  11.     packet.Write(Player);
  12.     TNManager.client.EndSend();
  13. }
  14.  
  15. void BanPlayer(int PlayerID, string Player)
  16. {
  17.     if ((PlayerID == 0) && (Player == ""))
  18.     {
  19.         Debug.LogError("Must set either PlayerID or Player");
  20.         return;
  21.     }
  22.     Debug.Log("Banning [" + PlayerID + "](" + Player + ")");
  23.     BinaryWriter packet = TNManager.client.BeginSend(Packet.RequestBan);
  24.     packet.Write(PlayerID);
  25.     packet.Write(Player);
  26.     TNManager.client.EndSend();
  27. }
  28.  

Remember you can only request a kick or ban if you're verified as admin on the server (you've successfully called TNManager.SetAdmin and received a successful response). I'd add some logic to make sure that's always the case.


If you run into further issues please make sure to detail your problem as best you can: what you're trying, what isn't working, how you know it isn't working, etc.

257
TNet 3 Support / Re: TNServer.exe "Server.dat"
« 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.

258
TNet 3 Support / Re: Saving Inventory Server Side / Loading
« on: November 27, 2015, 03:02:29 AM »
The function that writes to the file uses File.WriteAllBytes which overwrites the file (desired in this case).

So it must be something on your end. DataNode.AddChild blindly adds a new child, without checking to see if one with that name already exists. I'd suggest trying AddMissingChild or even SetChild. SetChild will set the value of a specified child, or create a new one if it doesn't exist. Also make sure you're not adding null or empty string values (that's why you're getting blank lines in your output).

If you want to access an existing child, use something like node.GetChild<Type>("NameOfChild"). So if I have an item saved as a DataNode I might access some of its properties like so:
  1. public enum ItemType { Pistol, Shotgun, Sniper };
  2. public class Item
  3. {
  4.         public ItemType type;
  5.         public string name;
  6.         public float damage;
  7. }
  8.  
  9. // set values
  10. node.SetChild("Type", type);
  11. node.SetChild("Name", name);
  12. node.SetChild("Damage", damage);
  13.  
  14. // access values
  15. type = node.GetChild<ItemType>("Type");
  16. name = node.GetChild<string>("Name");
  17. damage = node.GetChild<float>("Damage");
  18.  

Inventory systems can become extremely complex extremely quickly, so put some serious time into planning out exactly how you want it structured and exactly how you're going to use it. It might help to think of DataNode as an XML tree-like datatype.

259
TNet 3 Support / Re: TNServer.exe "Server.dat"
« 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)

260
TNet 3 Support / Re: Deprecated???
« on: November 26, 2015, 07:43:41 AM »
Probably getting ready to transition into its new purpose. Aren made a post about it here [it's the top sticky]: http://www.tasharen.com/forum/index.php?topic=13653.0

Personally I like TNet for its networking (crazy right?). I understand how amazing and versatile the DataNode class is, but I still prefer to handle all my serialization myself. The networking, however, is something I really don't want to handle myself. That's where I think the core of TNet should be: networking; not serialization :)

I'm afraid listing it as an editor extension as opposed to a networking solution will really diminish its greatness.

261
TNet 3 Support / Re: Saving Inventory Server Side / Loading
« on: November 26, 2015, 07:31:29 AM »
So I think I nailed everything you want and followed Aren's advice. I'm not incredibly familiar with the DataNode class and I didn't try compiling / testing this, so hopefully it all works okay :)

  1. public class InventoryManager : TNBehaviour
  2. {
  3.         public int SaveInterval = 60;
  4.        
  5.         void Start()
  6.         {
  7.                 // save it periodically
  8.                 StartCoroutine(SaveInventoryToFile());
  9.         }
  10.        
  11.         void OnNetworkConnect (bool result, string message)
  12.         {
  13.                 if (result)
  14.                 {
  15.                         // when the player connects, load file
  16.                         TNManager.LoadFile("Players/" + TNManager.playerName, OnLoadFile);
  17.                 }
  18.                 else
  19.                 {
  20.                         Debug.LogError(message);
  21.                 }
  22.         }
  23.        
  24.         void OnLoadFile(string filename, byte[] data)
  25.         {
  26.                 if (data.Length == 0)
  27.                 {
  28.                         // if the callback receives no data then it's a new player.
  29.                         // initialize the inventory
  30.                         TNManager.playerDataNode.Add("Item 1");
  31.                         TNManager.playerDataNode.Add("Item 2");
  32.                         TNManager.playerDataNode.Add("Item 3");
  33.                        
  34.                         TNManager.SyncPlayerData();
  35.                 }
  36.                 else
  37.                 {
  38.                         // otherwise, load the data
  39.                         DataNode parsedDataNode = DataNode.Read(data);
  40.                         // setting TNManager.playerData automatically syncs
  41.                         TNManager.playerData = parsedDataNode;
  42.                 }
  43.         }
  44.        
  45.         IEnumerator SaveInventoryToFile()
  46.         {
  47.                 // save it periodically
  48.                 while(true)
  49.                 {
  50.                         try
  51.                         {
  52.                                 // if implicit casting works
  53.                                 //TNManager.SaveFile("Players/" + TNManager.playerName, TNManager.playerData);
  54.                                 // else put it in appropriate type
  55.                                 byte[] buf;
  56.                                 using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  57.                                 {
  58.                                         using (System.IO.StreamWriter bw = new System.IO.StreamWriter(ms))
  59.                                         {
  60.                                                 TNManager.playerDataNode.Write(bw);
  61.                                                 buf = ms.ToArray();
  62.                                         }
  63.                                 }
  64.                                 // and save
  65.                                 TNManager.SaveFile("Players/" + TNManager.playerName, buf);
  66.                         }
  67.                         catch (Exception ex) { Debug.LogError(ex.Message); }
  68.                         yield return new WaitForSeconds(SaveInterval);
  69.                 }
  70.         }
  71. }
  72.  

It saves every minute. You'll have to add saving before disconnect.

The example gets rid of your inventoryItems. The inventory is now TNManager.playerDataNode. If you want to save other stuff in TNManager.playerDataNode you'll need to modify this a bit [make everything above branch off an "Inventory" child].

There's a lot you can do to build upon this example. Hopefully it gives you a start in the right direction.

262
That's a really strange issue. From what you've described the only thing I can think of is you're using tno.SendQuickly for most of your RFCs and UDP is failing (though SendQuickly should fall back to TCP if UDP is unavailable...). TNManager.Create uses TCP so that explains why some actions work for these invisible clients.

I would check to see if your port for UDP is opened (both the server port and the invisible client's port). You can find web-based port scanners online. It's still really strange that it's not falling back to TCP. Maybe you've got some insane packet loss when using UDP?

I'd load up wireshark and inspect packet flow. I'd also set up some breakpoints in your project and step through the important bits.

That's all the help I can provide without more info. Good luck! :) I'll check back periodically for updates.

263
TNet 3 Support / Re: Hosting server not using correct IP Address.
« on: November 24, 2015, 11:58:55 PM »
Your fix assumes bot.whatismyipaddress.com will always return ipv4 over ipv6. Additionally, assumes your ISP will always assign you both an ipv4 and ipv6 address (won't be the case for long).

If you go with the solution I posted you won't have any issues with that. You could even combine the solutions if you'd like.

264
TNet 3 Support / Re: Saved RFC Isn't Working.
« on: November 24, 2015, 04:35:15 AM »
When a player leaves, any networked objects created by that player are destroyed, along with any RFCs residing on those objects.
Additionally, all RFCs are cleared if the channel is not persistent and the last player leaves.

So make sure the RFC you're calling is on an object that won't be destroyed when Player A leaves, and make sure the channel is set to persistent.

Most of the relevant code is in TNChannel.cs.
The part that saves the RFC is in TNGameServer.cs in the ProcessForwardPacket function.

265
What are your launch params for the server?

Example batch script for windows:
  1. @echo off
  2. start "My TNet Server" "TNServer.exe" -name "My TNet Server" -tcp 28001 -udp 28002 -udpLobby 28003
  3.  

And bash for linux:
  1. #!/bin/bash
  2. echo "Starting Server"
  3. mono "TNServer.exe" -name "My TNet Server" -tcp 28001 -udp 28002 -udpLobby 28003
  4. echo "Server has exited"
  5.  

Keep in mind you can't use a port more than once. TcpListener and UdpListener can't share a socket on, say, port 5127 for example. So you'd give 5127 to TcpListener and 5128 to UdpListener.

edit: Make sure you're calling TNManager.StartUDP(int port) on the client after you connect to the server. Good place to do this is the OnNetworkConnect event.
  1. void OnNetworkConnect (bool result, string message)
  2. {
  3.     if (result)
  4.     {
  5.         // Make it possible to use UDP using a random port
  6.         TNManager.StartUDP(Random.Range(10000, 49151));
  7.     }
  8.     else
  9.     {
  10.         Debug.LogError(message);
  11.     }
  12. }
  13.  

266
TNet 3 Support / Re: Hosting server not using correct IP Address.
« on: November 23, 2015, 08:00:43 PM »
Can you go to http://icanhazip.com and tell us the output? Additionally, can you detail your LAN setup? What model is your router? Are you behind a switch / hub, or an additional router? What OS are you building on?

The relevant code:
externalAddress getter: line 253 of TNTools.cs
function GetExternalAddress: line 321 of TNTools.cs (also, check to make sure you aren't setting ipCheckerUrl. Let it use the defaults.)

Might also be a problem with the webclient and parsing:
function ResolveExternalIP: line 344
function ResolveAddress: line 391 (parses what the above function received)

I have a feeling most - if not all - of your issues are caused by something in your LAN setup. Set up some breakpoints on those lines and check if the variables are matching up. Note the first one that doesn't seem right.

edit: oh, I have the same issue :P it's because your external IP is ipv6, I assume. The parsing doesn't account for ipv6 addresses (though TNet should support ipv6). I'll write up a fix after dinner and edit this again. In the meantime, you could try forcing an ipv4 address. On windows: Open Network & Sharing Center -> Change adapter settings -> right click your physical NIC and select Properties -> uncheck the Internet Protocol Version 6 box and click OK -> right click your physical NIC again and select Disable, then Enable.

edit2: In TNTools.cs, in the static bool ResolveExternalIP (string url) function, replace the following:
  1. string[] split1 = text.Split(':');
  2.  
  3. if (split1.Length >= 2)
  4. {
  5.     string[] split2 = split1[1].Trim().Split('<');
  6.     mExternalAddress = ResolveAddress(split2[0]);
  7. }
  8. else mExternalAddress = ResolveAddress(text);
  9.  
With:
  1. mExternalAddress = ResolveAddress(text);
  2.  

I'm not sure what adverse effects this could have with the parsing. I can't think of any IP related string with "<" in it. I checked the webpages and it's just plaintext, too. So no html tags. Hopefully Aren will see this and include it in the next TNet update.

267
TNet 3 Support / Re: TNManager.Ping issues.
« on: November 10, 2015, 05:13:51 AM »
TNManager.Ping uses UDP, so make sure you're sending to your gameservers UDP port.

The TNLobbyClient returns the TCP port by default. You can trace this back to the gameserver in files TNUdpLobbyLink.cs and TNTcpLobbyLink.cs at the top of the ThreadFunction() function where the port argument for constructing mInternal and mExternal is set to the current TCP port.

edit:
You'd need to modify a bit to make the lobby server aware of the gameservers UDP *and* TCP port.
-TNServerList.cs [both the ServerList and Entry classes]
-TNUdpLobbyServer.cs
-TNTcpLobbyServer.cs
-TNUdpLobbyLink.cs
-TNTcpLobbyLink.cs

Should give you a good start. Maybe you can catch Aren's attention and have him include it in the next update :)

268
TNet 3 Support / Re: Channel and host data
« on: November 07, 2015, 07:16:00 PM »
Okay. It's impossible for me to know what you know and what you don't know, so I tried my best at explaining the basics just in case.

It seemed you were unclear on how channels work in TNet, so hopefully I was able to help you with that. I was going to edit my post to include code showing how to store / retrieve a name using channel data but I forgot.

Glad you got it working, though.

269
TNet 3 Support / Re: Channel and host data
« on: November 07, 2015, 02:18:12 PM »
  1. TNGameClient.OnPing onPingCallback;
  2.  
  3. void Start()
  4. {
  5.     onPingCallback = onPingReceived;
  6. }
  7.  
  8. void onPingReceived(IPEndPoint ip, int milliSeconds)
  9. {
  10.     Debug.Log("My ping to " + ip.ToString() + " is " + milliSeconds);
  11. }
  12.  
  13. void SomeFunctionWhereYouCallPing()
  14. {
  15.     TNManager.Ping(blahblah.externalAddress, onPingCallback);
  16. }
  17.  

Try that out. Should work but I didn't test it.
Read more about delegates in C# here: https://msdn.microsoft.com/en-us/library/ms173171.aspx

270
TNet 3 Support / Re: sending navmesh path via rfc
« on: November 07, 2015, 08:00:00 AM »
I wouldn't recommend sending the NavMeshPath at all. Instead, send the positions and have the clients calculate the path. Might run into problems with determinism (client A calculating a different path than client B), so you'd have to design around that. Why not have the host calculate the path AND move the AI / client (according to input)? I think syncing position would be easier, more secure, and you wouldn't have to worry about determinism since only one path exists - the one calculated by the host.

Pages: 1 ... 16 17 [18] 19