Author Topic: TNET allias , admin kick and ban  (Read 11116 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #15 on: December 12, 2015, 04:40:17 PM »
Save data files?

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #16 on: December 13, 2015, 11:00:32 AM »
yes save clients .data files on tnserver   

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #17 on: December 14, 2015, 06:09:31 AM »
Post the code you're using then, it would help.

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #18 on: December 16, 2015, 03:27:47 AM »
  1.         // Saving data file
  2.         if (Input.GetKeyDown(KeyCode.X))
  3.         {
  4.             MemoryStream stream = new MemoryStream();
  5.             StreamWriter writer = new StreamWriter(stream);
  6.             writer.Write("Hello world");
  7.             byte[] data = stream.ToArray();
  8.             writer.Close();
  9.             TNManager.SaveFile("testfile3", data);
  10.         }
  11.  
  12.         // Loading data file
  13.         if (Input.GetKeyDown(KeyCode.V))
  14.         {
  15.  
  16.             MemoryStream stream = new MemoryStream(data);
  17.             StreamReader reader = new StreamReader(stream);
  18.             Debug.Log(reader.ReadToEnd());
  19.  
  20.  
  21.         }


[2015.12.16 12:27:54] ERROR: Guest (--------:53835): Unable to save testfile3

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #19 on: December 16, 2015, 10:29:52 PM »
Your stream is empty, so there is nothing to save. Try adding Debug.Log(data.Length); before you call TNManager.SaveFile.

You forgot to call writer.Flush() before calling ToArray(). Consult C#'s documentation for more information.
  1. using UnityEngine;
  2. using TNet;
  3. using System.IO;
  4.  
  5. public class Test : MonoBehaviour
  6. {
  7.         void Update ()
  8.         {
  9.                 if (Input.GetKeyDown(KeyCode.X))
  10.                 {
  11.                         MemoryStream stream = new MemoryStream();
  12.                         StreamWriter writer = new StreamWriter(stream);
  13.                         writer.WriteLine("Hello world");
  14.                         writer.Flush();
  15.                         byte[] data = stream.ToArray();
  16.                         writer.Close();
  17.                         TNManager.SaveFile("testfile3", data);
  18.                 }
  19.  
  20.                 if (Input.GetKeyDown(KeyCode.V))
  21.                 {
  22.                         TNManager.LoadFile("testfile3", delegate(string filename, byte[] data)
  23.                         {
  24.                                 MemoryStream stream = new MemoryStream(data);
  25.                                 StreamReader reader = new StreamReader(stream);
  26.                                 Debug.Log(reader.ReadLine());
  27.                                 reader.Close();
  28.                         });
  29.                 }
  30.         }
  31. }
  32.  

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #20 on: December 17, 2015, 03:25:12 AM »
thanks . all working now good. but how i can save to data files (float , int , bool ) and load it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #21 on: December 17, 2015, 04:05:53 AM »
Use DataNode.
  1. using UnityEngine;
  2. using TNet;
  3. using System.IO;
  4.  
  5. public class Test : MonoBehaviour
  6. {
  7.         void Update ()
  8.         {
  9.                 if (Input.GetKeyDown(KeyCode.X))
  10.                 {
  11.                         DataNode node = new DataNode("Version", 1);
  12.                         node.SetChild("one", "Hello world!");
  13.                         node.SetChild("two", 123f);
  14.                         node.SetChild("three", 12345);
  15.                         node.SetChild("four", true);
  16.  
  17.                         MemoryStream stream = new MemoryStream();
  18.                         StreamWriter writer = new StreamWriter(stream);
  19.                         node.Write(writer);
  20.                         TNManager.SaveFile("testfile3", stream.ToArray());
  21.                         writer.Close();
  22.                 }
  23.  
  24.                 if (Input.GetKeyDown(KeyCode.V))
  25.                 {
  26.                         TNManager.LoadFile("testfile3", delegate(string filename, byte[] data)
  27.                         {
  28.                                 DataNode node = DataNode.Read(data);
  29.  
  30.                                 if (node != null)
  31.                                 {
  32.                                         Debug.Log(node.GetChild<string>("one"));
  33.                                         Debug.Log(node.GetChild<float>("two"));
  34.                                         Debug.Log(node.GetChild<int>("three"));
  35.                                         Debug.Log(node.GetChild<bool>("four"));
  36.                                 }
  37.                                 else Debug.Log("Invalid data: " + (data != null ? data.Length + " bytes" : "none"));
  38.                         });
  39.                 }
  40.         }
  41. }
  42.  
P.S. This saves everything in plain text as you are using a StreamWriter. If you want binary, change it to BinaryWriter instead.
« Last Edit: December 17, 2015, 04:21:53 AM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #22 on: December 17, 2015, 04:21:21 AM »
As a note for TNet 3, it's even easier there:
  1. using UnityEngine;
  2. using TNet;
  3.  
  4. public class Test : MonoBehaviour
  5. {
  6.         void Update ()
  7.         {
  8.                 if (Input.GetKeyDown(KeyCode.X))
  9.                 {
  10.                         DataNode node = new DataNode("Version", 1);
  11.                         node.SetChild("one", "Hello world!");
  12.                         node.SetChild("two", 123f);
  13.                         node.SetChild("three", 12345);
  14.                         node.SetChild("four", true);
  15.                         TNManager.SaveFile("testfile3", node.ToArray(DataNode.SaveType.Text));
  16.                 }
  17.  
  18.                 if (Input.GetKeyDown(KeyCode.V))
  19.                 {
  20.                         TNManager.LoadFile("testfile3", delegate(string filename, byte[] data)
  21.                         {
  22.                                 DataNode node = DataNode.Read(data);
  23.                                 Debug.Log(node.GetChild<string>("one"));
  24.                                 Debug.Log(node.GetChild<float>("two"));
  25.                                 Debug.Log(node.GetChild<int>("three"));
  26.                                 Debug.Log(node.GetChild<bool>("four"));
  27.                         });
  28.                 }
  29.         }
  30. }
  31.  

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #23 on: December 17, 2015, 04:26:02 PM »
can i download tnet 3 from assetstore ? or need buy it from your site again ? :-[ . i am cant find tnet on assetstore  :-[ :-[
« Last Edit: December 17, 2015, 04:34:07 PM by toga94 »

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #24 on: December 17, 2015, 04:29:06 PM »
thanks you . i will try your code tomorrow but today i not have free time. you are the best  ;)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #25 on: December 17, 2015, 10:21:49 PM »
TNet 3 isn't on asset store yet. It's in beta right now. Pro license holders always have access to the repository, and as such -- all the latest code. You can request a beta package by emailing support [at] tasharen.com with your OR# (or if you bought it from tasharen.com -- your email used for the paypal transaction).

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #26 on: December 19, 2015, 01:07:30 AM »
thanks . i will wait update for assetstore ;)  . what need send with mail.