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
Connecting to server and logging in as admin: (There are some variables / GUI components you won't have, add them yourself)
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:
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.
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
- password123
Connecting to server and logging in as admin: (There are some variables / GUI components you won't have, add them yourself)
- string serverAddress;
- int serverPort = 5128;
- void Start ()
- {
- // i'm hosting the server on the same PC i'm running the client on
- // otherwise set the IP of your server here
- serverAddress = TNet.Tools.localAddress.ToString();
- TNManager.client.onSetAdmin += OnSetAdmin;
- }
- // GUI button handler
- public void OnClick(string sender)
- {
- if (sender == "btnJoinServer")
- {
- // connect to server
- // declare int serverPort elsewhere and set it to your server's port
- Debug.Log("Connecting to " + serverAddress + ":" + serverPort.ToString());
- TNManager.Connect(serverAddress, serverPort);
- }
- else if (sender == "btnVerifyAdmin")
- {
- if (TNManager.isConnected)
- TNManager.SetAdmin("password123");
- else
- Debug.LogError("Connect to the server before calling SetAdmin");
- }
- }
- void OnNetworkConnect (bool result, string message)
- {
- if (result)
- {
- Debug.Log("connected to server");
- // Make it possible for this client to use UDP using a random port
- TNManager.StartUDP(Random.Range(10000, 50000));
- }
- else
- {
- Debug.LogError(message);
- }
- }
- void OnSetAdmin(Player admin)
- {
- Debug.Log(admin.name + " has logged in as admin");
- }
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:
- void KickPlayer(int PlayerID, string Player)
- {
- if ((PlayerID == 0) && (Player == ""))
- {
- Debug.LogError("Must set either PlayerID or Player");
- return;
- }
- Debug.Log("Kicking [" + PlayerID + "](" + Player + ")");
- BinaryWriter packet = TNManager.client.BeginSend(Packet.RequestKick);
- packet.Write(PlayerID);
- packet.Write(Player);
- TNManager.client.EndSend();
- }
- void BanPlayer(int PlayerID, string Player)
- {
- if ((PlayerID == 0) && (Player == ""))
- {
- Debug.LogError("Must set either PlayerID or Player");
- return;
- }
- Debug.Log("Banning [" + PlayerID + "](" + Player + ")");
- BinaryWriter packet = TNManager.client.BeginSend(Packet.RequestBan);
- packet.Write(PlayerID);
- packet.Write(Player);
- TNManager.client.EndSend();
- }
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.