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

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
TNET allias , admin kick and ban
« on: November 28, 2015, 05:26:07 AM »
TNET allias , admin kick and ban . turtorial or example please  ;)

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #1 on: November 29, 2015, 01:58:47 PM »
bump!!!!!

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #2 on: November 29, 2015, 02:23:46 PM »
how i can use tngameserver logics . who have servermain ?

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #3 on: November 29, 2015, 03:36:44 PM »
[2015.11.30 00:35:50] Guest (------------): Connected [1]
[2015.11.30 00:35:52] ERROR:  Guest (------------): Tried to authenticate as admin and failed (password)
[2015.11.30 00:35:52]  Guest (------------): Disconnected [1]

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #4 on: November 30, 2015, 03:09:50 PM »
Have you looked at the TNManager class?

   /// <summary>
   /// Set administrator privileges. Note that failing the password test will cause a disconnect.
   /// </summary>

   static public void SetAdmin (string pass)


static public void CreateChannel (string levelName, bool persistent, int playerLimit, string password)

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #5 on: December 01, 2015, 06:52:55 AM »
already channel created with tnetautojoin . but without password .

i used setadmin or costom packets but server kicked me . you have skype please help me

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 #6 on: December 01, 2015, 08:16:06 AM »
Well, did you actually ADD the administrator to your server? When you authenticate via TNManager.SetAdmin, you pass a password. This password must actually exist in ServerConfig/admin.txt file. Open TNGameServer, line 1494 -- do you see where it parses the admin file?

This is only needed for remote servers. For local servers (ones you start with TNServerInstance.Start) you are automatically marked as an administrator.

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 #7 on: December 01, 2015, 08:18:19 AM »
For the alias, it's just a way to give yourself data that is visible to other players, such as your Steam ID. For example I do this in Windward:
  1. void OnNetworkConnect (bool success, string msg)
  2. {
  3.         if (success)
  4.         {
  5.                 TNManager.SetAlias(Steam.username);
  6.         }
  7. }
You can have several aliases if you like -- in Windward I can have up to 3 different ones that uniquely identify each player.

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #8 on: December 01, 2015, 11:35:49 AM »
i am using tnserver on the rar (with windows 10) . tnmanager.setadmin and costom packets both  giving some eror .  and on windows 10 not saving server data (TNServer -name "My Server" -tcp 5127 -udp 5128 -udpLobby 5129) 

admins.txt  most be like this? >

Nickname password


if(Input.GetKeyDown(KeyCode.A){
TNManager.SetAdmin ("123456");
}


[2015.12.01 20:54:11] Guest  (------------): Connected [1]
[2015.12.01 20:54:15] ERROR: Guest (------------): Tried to authenticate as admin and failed (123456)
[2015.12.01 20:54:15] Guest  (------------): Disconnected [1]

---------------------------------------------------------
The data you are passing in your save packet is completely wrong.

First, you are sending text while the function works with bytes. The length you specify is also 50 bytes, when your text is only 8 bytes long.

Second, you shouldn't be writing that packet yourself. You should be using TNManager.SaveFile.

Use MemoryStream.
Code: [Select]

MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write("Hello world");
byte[] data = stream.ToArray();
writer.Close();
TNManager.SaveFile("testfile3", data);

Then to load it:
Code: [Select]

MemoryStream stream = new MemoryStream(data);
StreamReader reader = new StreamReader(stream);
Debug.Log(reader.ReadToEnd());


--------------------------------------
[2015.12.01 21:57:31] ERROR: Guest (5.250.204.212:49190): Unable to save testfile3



not working nothing

« Last Edit: December 01, 2015, 12:58:42 PM by toga94 »

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #9 on: December 07, 2015, 04:21:51 AM »
bump !!!!!!!!!

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #10 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.

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 #11 on: December 09, 2015, 01:47:10 PM »
Just a note, if you set your TNet.Tools.applicationDirectory name, then it will be:
My Documents/<applicationDirectory>/ServerConfig

For example for Windward I have it set to just that: "Windward".

If you launch with -localPath, it will be "ServerConfig" folder in the same place as the server's executable.

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #12 on: December 10, 2015, 05:01:12 AM »
         if (Input.GetKeyDown(KeyCode.Q))
        {
            TNManager.SetAdmin("password123");
        }
Tried to authenticate as admin and failed (password123)

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #13 on: December 10, 2015, 08:10:01 AM »
If you can tell us your OS you'll receive more specific help.

You need to place admin.txt in your Documents folder in some configuration:
By default (applicationDirectory not set): C:\Users\YOURUSERNAME\Documents\ServerConfig\admin.txt
If applicationDirectory is set: C:\Users\YOURUSERNAME\Documents\<applicationDirectory>\ServerConfig\admin.txt
If you launch with -localPath set: <Wherever the EXE resides>\ServerConfig\admin.txt

Now, all paths containing the following are !!OS-dependent!!: \Users\YOURUSERNAME\Documents.
So you'll need to google "C# My Documents path <YOUR OPERATING SYSTEM>" if you don't know it.

The line of code that determines this is: System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
You can find it by searching "static public string persistentDataPath" in TNTools.cs

If you really need our help, do us a favor and paste the following code in your project and tell us the output:
  1. void Start()
  2. {
  3.         string documentsPath = "";
  4. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_WEBPLAYER || UNITY_WINRT || UNITY_FLASH
  5.                                 documentsPath = UnityEngine.Application.persistentDataPath;
  6. #else
  7.                                 documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
  8. #endif
  9.         Debug.Log("My Documents path is: (" + documentsPath + ")");
  10.         Debug.Log("My Operating System is: (" + SystemInfo.operatingSystem + " / " + Application.platform.ToString() +")");
  11. }
  12.  

toga94

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: TNET allias , admin kick and ban
« Reply #14 on: December 12, 2015, 02:25:08 AM »
thanks , set admin worked now . but save data files still not working