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

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #15 on: January 16, 2015, 08:30:22 PM »
Alright, so what voncarp's suggesting is that I embed the Network Management object into the scene as a prefab, so when the scene loads the script is there and RFCs can be received without the errors...

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #16 on: January 18, 2015, 02:17:25 AM »
Alright, so what voncarp's suggesting is that I embed the Network Management object into the scene as a prefab, so when the scene loads the script is there and RFCs can be received without the errors...

That's an option.  Much of it depends what your trying to do.  I have a global settings already in scene and request a global setting update when a new player joins.

My iOS project I have several GUI's in game already.  And their prefabs for safety purposes. When I create my player I send what scripts are necessary to the GUI based on the player that's created.  For instance, my inventory.  I only have one inventory GUI that whoever joins will use the same GUI, but their view will be different.  I'll send my scripts to it once a player is created and make calls as necessary.



I modeled my player joining and instantiating based off the example in the multipurpose starter kit.  Which probably isn't the best way to do it for my game, but I'm so far along now I'm stuck with it.

Because all the action is going on, and the new player has  yet to be created thats where I encountered most of my "[TNet] Trying to execute a function 'SetGameMode' on TNObject #1 before it has been created.
UnityEngine.Debug:LogWarning(Object)" errors.

Just guessing, I think the issue your having has something to do with the timing of your tno.sends or the placement of your tno.isMine.  Try preventing your tno.sends until something happens.  And then send.

I would put it in the object that is trying to send:

  1. IEnumerator Start()
  2. {
  3.     while (playerIsNotYetLoaded) yield return null;
  4.     tno.send("whatever");
  5. }

My inventory is built with NGUI :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #18 on: February 12, 2015, 12:59:41 AM »
Thanks for that. I've had put down the project for a little while (well, at least the Networking Stack part of it) and only just recently picked it up again.

I have a potentially dumb question about the player count. If you're hosting and you set a channel up to host 16 players and then the host instance joins that channel, does that click down the limit to 15?

If I bring up my scoreboard (which is polling TNManager.channel.players.Count), it will say 0 until another client joins. Is this correct, or has TNet reserved a slot so only 15 other players can join instead? Why does it say 0 instead of 1 actual player? Does the local server instance not count as a regular player?

What I intend to achieve if I can get away with it, is the host instance is headless and it'll log to a file, telling the person running the server what's going on via Console (Linux-only maybe?), or it'll show a in-game UI server console but not render 3D graphics.

The other question is, will the lobby server show 1 player on server when the said server instance registers with the TCP Lobby Server, or will it just say 0 players?

EDIT: If a client doesn't send the same protocol version as the server, TNet by default throws a warning in the editor. Is it possible to actually have this as a flag, so if the client is, for example, outdated or they're trying to use another game with the lobby server IP, that I can detect and throw whatever at the player (for example "You need to update to play this title"). Or in standalone, does the TNetLobbyClient.error field get updated with the "not correct protocol" error message?
« Last Edit: February 12, 2015, 07:22:30 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 #19 on: February 13, 2015, 09:05:07 AM »
Player limits are handled by the server. All players in the channel count toward this value, host included. So if your limit is 16 and a host joins, you have 15 slots remaining. When checking a list of players on the client side, the list excludes you.

Lobby server will show 1.

I suggest handling custom versioning yourself if you need it. For example in Windward I check what mods the player has active and match it against the mods that the previous player set. If an updated version is detected, the list of mods gets updated (Each mod has its own version number). If the previous player sent that mod-setting RFC with a newer version of the mod, the player gets disconnected with an error message.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #20 on: February 15, 2015, 02:56:22 AM »
Player limits are handled by the server. All players in the channel count toward this value, host included. So if your limit is 16 and a host joins, you have 15 slots remaining. When checking a list of players on the client side, the list excludes you.
Right. Is there any particular reason why the list excludes the player? (I'll just have to add them into the scoreboard at the bottom of the window).

Lobby server will show 1.
Okay, to counter this I could just take the number and subtract one, so servers are "empty" when it's just the server in there so to speak.

I suggest handling custom versioning yourself if you need it. For example in Windward I check what mods the player has active and match it against the mods that the previous player set. If an updated version is detected, the list of mods gets updated (Each mod has its own version number). If the previous player sent that mod-setting RFC with a newer version of the mod, the player gets disconnected with an error message.
Ah, ok. Understandable.

I have a question about playerData and playerDataNode. From what I can see in the code, it's a string I can set. Is playerDataNode like a dictionary of sorts that I could use to store the players weapon loadout? For example: player.playerDataNode['weapSlot1'] = "m4a1", player.playerDataNode['weapSlot2'] = "pistol", etc. This is only on the client side, and can't be edited on the server gathering from what I have read from other topics?

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 #21 on: February 15, 2015, 02:10:52 PM »
There is no particular reason for it... just how I chose to do it early on. It's basically a "list of other players", since you always know that you are present.

playerDataNode is a DataNode, which is much more than a dictionary. It's a tree-like structure. Think of it as an XML tree. Each node can have children. Each of those children can have children of their own, etc.

player.playerDataNode should only be read-only. Only the player who owns it should be able to change its contents. Otherwise you get into hairy situations where one client changes something, then another client does a similar operation at the same time, and then one overwrites the other. Like a thread race condition, only online.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #22 on: February 15, 2015, 04:39:40 PM »
There is no particular reason for it... just how I chose to do it early on. It's basically a "list of other players", since you always know that you are present.

playerDataNode is a DataNode, which is much more than a dictionary. It's a tree-like structure. Think of it as an XML tree. Each node can have children. Each of those children can have children of their own, etc.

player.playerDataNode should only be read-only. Only the player who owns it should be able to change its contents. Otherwise you get into hairy situations where one client changes something, then another client does a similar operation at the same time, and then one overwrites the other. Like a thread race condition, only online.
Alright, so I can use it to store loadout data and other stuff related to the player. Great as this saves me having to compress the load out data into a string and then parse it.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #23 on: February 17, 2015, 08:08:47 PM »
Hmm... Working on a chat script for my shooter, and I need to make a static reference to the TNObject. However it seems the TNBehaviour tno object is not static:
  1. An object reference is required for the non-static field, method, or property 'TNBehaviour.tno.get'
  2.  

To counter this, I make a static TNObject to in the class, but does TNBehaviour have no static TNObject reference?

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 #24 on: February 17, 2015, 10:54:04 PM »
TNObjects are scripts, they shouldn't be static. However an object you have it on can have a static reference you can access. For example in Windward I have a "GameConfig" class that has a "static GameConfig instance;" -- when I need to send something to the config's TNObject, I just do GameConfig.instance.tno.Send(...);

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #25 on: February 18, 2015, 02:32:05 AM »
TNObjects are scripts, they shouldn't be static. However an object you have it on can have a static reference you can access. For example in Windward I have a "GameConfig" class that has a "static GameConfig instance;" -- when I need to send something to the config's TNObject, I just do GameConfig.instance.tno.Send(...);

Ah, that sounds the way it should be done. Thanks for the tip.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #26 on: February 25, 2015, 08:35:15 PM »
With the ping that can be accessed via TNManager.player.ping, is this the current ping or an average? If it's an average, what is the sample rate? How many times a second are we picking up the ping value? I took a look through the code and saw how it does the periodic pings to the server, but not sure how many pings per second it does.

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 #27 on: February 27, 2015, 04:59:40 AM »
It's the result of the last ping.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #28 on: March 05, 2015, 01:36:12 AM »
Alright, that's good. We're now designing our network player logic, and we've started making a NetPlayer class. The major things we need to relay over the network are 3 vectors: one for the root position, one for the movement vector and the aim point (which is for the non-player controlled objects to look at). A quaternion is also used for the rotation of the character. The rest are just for animation control, if we're crouched the animations need to be playing the crouched set, etc.

To sync this across the network, can we use a TNSyncObject script, or do we have to create our own Sync script?

Here's the code that we've prototyped to some extent:

  1. // snip //     
  2.         private Vector3 rootPos;
  3.         private Vector3 moveVec;
  4.         private Vector3 aimPos;
  5.         private Quaternion rootRotation;
  6.        
  7. // snip //
  8.  
  9.         public Vector3 RootPos{
  10.                 get{
  11.                         return rootPos;
  12.                 }
  13.                 set{
  14.                         rootPos = value;
  15.                 }
  16.         }
  17.        
  18.         public Vector3 MoveVec{
  19.                 get{
  20.                         return moveVec;
  21.                 }
  22.                 set{
  23.                         moveVec = value;
  24.                 }
  25.         }
  26.        
  27.         public Vector3 AimPos{
  28.                 get{
  29.                         return aimPos;
  30.                 }
  31.                 set{
  32.                         aimPos = value;
  33.                 }
  34.         }
  35.        
  36.         public Quaternion RootRotation{
  37.                 get{
  38.                         return rootRotation;
  39.                 }
  40.                 set{
  41.                         rootRotation = value;
  42.                 }
  43.         }
  44.  
  45. }
  46.  
For non-player controlled entities, each client would get the values and update things accordingly. On player controlled entities, we'd be sending updates to those values when they change.

If I recall correctly, using Unity's built-in network, there was a function called OnNetworkSync() that was exposed when you attached a object with a network view.
Could you please advise on the best approach in this situation, and if you could provide any snippets of code, that would be helpful. Thanks!

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: TNet: Lag Emulation, Kicks and Bans
« Reply #29 on: March 05, 2015, 07:16:04 PM »
Just took a look at the SyncRigidbody script and saw the Sync RFC and how it's called. There's cached values that are updated every time we broadcast the update to the network (and there's a change?). With that said, we don't broadcast if we're not the player object... Am I mistaken or is that what I'd need to do?