Author Topic: TNet: Lag Emulation, Kicks and Bans  (Read 18026 times)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
TNet: Lag Emulation, Kicks and Bans
« on: December 30, 2014, 10:06:35 PM »
Here comes the list of questions... well, the start anyway...

1. Is there a preferred way to emulate lag on a network connection? I'm working on a shooter and I need to emulate lag on a local area network. Since on a LAN you have sub 50ms pings, lag compensation won't really helping much... well okay, maybe a little bit. What I'm trying to achieve is a emulated lag setup where a host is in Australia and you connect on a poor link from the other side of the world with 300 to 999 ms pings.

The reason I ask is I'm going to start doing lag compensation and I need a laggy setup so I can determine if clients are falling behind the server and if so, pop up a warning or show them the boot.

2. Is there a way to kick and ban clients (players)? Well, for kick I suppose we could refer to it as a forced disconnection since the server host will have the ability to say "Right, no more, you're getting the boot" and the client must obey. Bans could be implemented with the forced disconnections, I would just check the incoming IP against a local blacklist and if it's a match, bam, the client is gone.

I'll update the list as it goes on, but for now, those are my two priority ones.
« Last Edit: December 30, 2014, 11:49:38 PM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #1 on: December 31, 2014, 04:12:13 PM »
1. There is no lag emulation in TNet.
2. Send them a Disconnect packet.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #2 on: December 31, 2014, 10:34:04 PM »
Alright, thanks for that.
Is there a way to wait until TNet has started the server before running commands to connect to it locally, etc?

What I see is that I do the TNServerInstance.Start(...) call and then connect to it. However, that call seems to return immediately, and doesn't wait until the server is up. Therefore my code that tries to connect to itself gets executed straight after the server starts booting, and gets a "No connection could be made due to the host rejecting the connection".

I see that TNServerInstance has isActive and isListening...


I was doing it wrong. Next question:

When you said to send them a disconnection packet, is it possible to use the packet with something like tno.Send(Packet.Disconnect, <insert player reference here>) ? Of course, if I try using "Send" it throws a error, but I see under TNManager.client there's also BeginSend and friends. The issue with that is the server needs to be the one forcing the disconnect, and that command only sends the message to the server unless I'm mistaken. Alternatively, I make a Kick() function that is an RFC, but I can see the odd smartass trying to be clever and avoid the kick by using a hacked version of the assemblies in the built game executable.
« Last Edit: January 01, 2015, 02:50:06 AM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #3 on: January 01, 2015, 07:31:13 PM »
I mean create an RFC that you can trigger, and inside that RFC just TNManager.Disconnect(). So when you want to disconnect someone, just send them that RFC.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #4 on: January 02, 2015, 08:26:24 PM »
I mean create an RFC that you can trigger, and inside that RFC just TNManager.Disconnect(). So when you want to disconnect someone, just send them that RFC.
Alright, that's what I was thinking myself. Just wanted to be sure we're all on the same page. :)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #5 on: January 12, 2015, 01:00:53 AM »
Alright, another issue that I caught:

  1. [TNet] Trying to execute a function 'SetGameMode' on TNObject #1 before it has been created.
  2. UnityEngine.Debug:LogWarning(Object)
  3. TNObject:FindAndExecute(UInt32, String, Object[]) (at Assets/TNet/Client/TNObject.cs:399)
  4. TNManager:OnForwardedPacket(BinaryReader) (at Assets/TNet/Client/TNManager.cs:1089)
  5. TNet.GameClient:ProcessPacket(Buffer, IPEndPoint) (at Assets/TNet/Client/TNGameClient.cs:817)
  6. TNet.GameClient:ProcessPackets() (at Assets/TNet/Client/TNGameClient.cs:747)
  7. TNManager:Update() (at Assets/TNet/Client/TNManager.cs:1113)
  8.  

This error pops up when you go to join a game in progress. When the player has input the IP address of the server they want to connect to, I load a level loading scene which has a script that takes the IP Address, connects to it and handles the channel joining. When the channel is joined, the script spawns two objects:

  • In-game UI: uGUI HUD, Scoreboard, etc.
  • NetworkManagement "Super" GameObject: This handles server and client code. This is TNObject #1

After it spawns them, the script that does the Network join and such kills itself and then those errors occur.

On the host, the host fires them as soon as the client joins inside OnNetworkPlayerJoin(). On the client, the client is still loading the map, which has a lot of objects. I am getting the impression that this is the wrong call to use, because in my case, we're joining the channel and the server is firing the commands to the object that hasn't been spawned yet, hence the error.

Should I instead send a RFC to the host (ie. GetGameConfiguration() ) and let it tell the client what's happening when the client is ready to go?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #6 on: January 12, 2015, 01:27:20 AM »
Don't do anything in OnNetworkPlayerJoin. Each client should be creating their own avatar/manager object after the scene finishes loading and TNManager.isLoadingLevel is finally 'false'.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #7 on: January 12, 2015, 02:40:34 AM »
Don't do anything in OnNetworkPlayerJoin. Each client should be creating their own avatar/manager object after the scene finishes loading and TNManager.isLoadingLevel is finally 'false'.
Alright. I'll try this tomorrow, thanks for the advice!

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #8 on: January 12, 2015, 07:34:20 PM »
Hrm, it seems TNManager.isLoadingLevel doesn't exist.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #9 on: January 13, 2015, 02:46:46 AM »
Hrm, it seems TNManager.isLoadingLevel doesn't exist.

You could try TNManager.isJoiningChannel.

http://www.tasharen.com/forum/index.php?topic=11740.msg54514#msg54514
« Last Edit: January 13, 2015, 02:53:08 AM by voncarp »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #10 on: January 13, 2015, 05:51:43 PM »
Ah yes, that's what I meant, sorry.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #11 on: January 13, 2015, 10:50:28 PM »
Alright, so I tried this:

  1. void Update() {
  2.         // Check if we're actually finished loading level.
  3.         if (TNManager.isInChannel && !TNManager.isJoiningChannel)
  4.         {
  5.             print("[Client] Finishing server connection phrase.");
  6.             FinishUp();
  7.         }
  8. }
  9.  
  10.         void FinishUp() {
  11.         // while (TNManager.isJoiningChannel) yield return null; <- don't mind this, it's leftovers
  12.  
  13.                 // Spawn our persistent prefabs.
  14.  
  15.                 for (int i = 0; i < prefabsToSpawn.Length; i++) {
  16.                         Instantiate(prefabsToSpawn[i]);
  17.                 }
  18.  
  19.         // Destroy the splashscreen object.
  20.                 Destroy (this.gameObject);
  21.         }
  22.  

This basically checks if we're in a channel and we're not joining the channel (as in, the game's loading something). However, it seems that the RFCs still get triggered before that FinishUp function is called to spawn the persistent objects. Maybe I should just make a RFC that asks the server to send it the configuration when it spawns the NetworkManager object and then go from there...

I'm confused.  :o

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #12 on: January 14, 2015, 01:18:25 AM »
Where is the RFC being sent from?  Are you streaming the map in?

I have a huge map with tons of objects too and encountered this issue a number of times early in my project.  You probably want to make that call after the object is instantiated.

If your streaming with Unity Pro send the RFC after AsyncOperation.isDone or if you have another streaming solution your likely going to need some type of event or isFinishedLoading bool before you start sending the RFC.

Another possible solution depends on your setup is to have the object in scene already and just take the network view. That way its already there and you don't have to wait for anything to load.

In-game UI: uGUI HUD, Scoreboard, etc.
NetworkManagement "Super" GameObject: This handles server and client code. This is TNObject #1

Those look like they could always be in scene.  Just take ownership of it.

If (tno.isMine) 

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #13 on: January 14, 2015, 07:07:18 PM »
Where is the RFC being sent from?  Are you streaming the map in?

The RFC is being sent from the "server", which is a client in server mode. When a client-mode client (ie. non-host player) connects, the server fires all the update commands to the client. I think I have it set to OnNetworkPlayerJoin. This would be the issue, because the server is trying to call a RFC on a object that the client doesn't know about yet.

I have a huge map with tons of objects too and encountered this issue a number of times early in my project.  You probably want to make that call after the object is instantiated.

If your streaming with Unity Pro send the RFC after AsyncOperation.isDone or if you have another streaming solution your likely going to need some type of event or isFinishedLoading bool before you start sending the RFC.
I don't do level streaming, my levels aren't open world. They are loaded as a whole (think small maps like Call of Duty, not huge ones seen in Battlefield 3).

Another possible solution depends on your setup is to have the object in scene already and just take the network view. That way its already there and you don't have to wait for anything to load.

In-game UI: uGUI HUD, Scoreboard, etc.
NetworkManagement "Super" GameObject: This handles server and client code. This is TNObject #1

Those look like they could always be in scene.  Just take ownership of it.
I could, but then it has the issue where the UI might be different on a particular map for whatever reason (as in, the prefab didn't get updated on that scene). I'm using prefabs to be on the safe side and UI is not finalized, subject to changes.

What I'll do is when the client connects, I'll broadcast a RequestConfiguration RFC to the channel and the server will respond with the game setup. This might be the antidote to my issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #14 on: January 14, 2015, 10:23:41 PM »
1. All RFCs are guaranteed to be called before OnNetworkJoinChannel.
2. All object creation done via TNManager.Create are guaranteed to be done before RFCs.

You need to use TNManager.Create, not Instantiate.