Author Topic: TNet: Tasharen Networking Framework  (Read 109912 times)

enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #120 on: January 20, 2013, 08:11:50 AM »
Hi there!

I have a question regarding the standalone server. How is it possible to get events in the standalone server?
The position values are sent with UDP from the client but for security purposes I also want the server to know about it so I can prevent teleport hacks and stuff.

Overall the standalone Server API seems a little thin. For example the CreateChannel method is private, not sure why. Giving the client the ability to create channels seems a little risky unless you really want them to be able to.

So, before I start to rewrite stuff it would be great if you can give me some tips to handle that. It's my first networking project so I'm not that fit when it comes to designing this.

Thanks and greetings from austria!
Thomas

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #121 on: January 20, 2013, 10:02:35 AM »
I would suggest doing teleport hack checks on the client if/when possible. You can still "review" packets on the server, but since TNet's main design revolves around sending RFCs, your best bet will be to create custom packet types for stuff you want checkable by the server, and then add the check logic when the server receives this type of a packet.

In the long run, the more you have on the client, the easier your life will be and the more players your server will be able to support.

enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #122 on: January 20, 2013, 06:25:54 PM »
Thanks I'll keep that in mind.

And how can I setup the events in the server?

Is there something where I can read the received TCP/UPD packets via API?
Or should I rewrite the TNGamerServer.cs?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #123 on: January 20, 2013, 06:46:20 PM »
Rewrite? Nah. But you will want to modify TNet.GameServer.ProcessChannelPacket, adding your packets in there.

enzi

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #124 on: January 21, 2013, 08:39:23 AM »
Hehe, yeah, modifying is what I meant. No need to rewrite solid code. ;)

Can you tell me a little about the overall architecture? What I'm really interested in, is what's happening in SendQuickly and Send with UDP. From my understanding now a UDP packet should be recieved from every client/server that is listening on the UDP port. Is this correct? Or does the packet get sent to the server and the server sends it to the client(s)?

Apart from that, I've everything up and running thanks to your framework. Now it's more of getting lag compensation and all this boring stuff.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #125 on: January 21, 2013, 08:56:12 AM »
SendQuickly will send via UDP if a UDP communication has been proven to be functional. Otherwise it will go through TCP. It's all completely seamless to you as a developer. It's all processed exactly the same as well. The server will send a UDP-arrived packet via UDP as well, whenever possible.

ahgElliot

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #126 on: January 21, 2013, 10:32:42 AM »
Hey there,
Some more woes with getting my game up and running.  In my old networking code I used to just give each their own network view and had the view synchronize my players and it worked as expected.  In TNet I'm finding that if I take my Player class and have it pull from TNBehavior that my players do get connected to the same game/channel (I added in some things to the server to report on this) and they are sharing other networked objects (I have pickups that disappear when one player or the other picks them up). Also, my Player Prefab is created by the TNManager when the player connects to the level and they can control themselves fine.

However, the model for each player is not being created in the networked game.  I only see one player on each instance of the game.  My player prefab is laid out like this:
______________________________
Player (GO)
 |-Stats (component on Player GO)
 |-Equipment/Storage (component on Player GO)
 |->HUD (GO)
 |->Model (GO)
 |->Vision (GO)
______________________________

It's clear that there are 2 players, but the model component doesn't seem to be shared on all clients.

What do you recommend I do here?

Thanks,
Elliot

PS: Are this and this the only available documentation for TNet?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #127 on: January 21, 2013, 10:37:17 AM »
You need to instantiate a new player for each client that joins the channel. Easiest way to do this is to have a script with a Start() function in it that will do a TNManager.Create call with the prefab of your player.

In a script attached to the player prefab you're instantiating, you can check in its Awake() function whether you're the one who created this object by checking TNManager.isThisMyObject.

ahgElliot

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #128 on: January 21, 2013, 10:54:23 AM »
Ok. I think I know what you mean.  I'll try again tonight and see if I have more success.  Thanks for the quick replies.

Zaibach333

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #129 on: January 21, 2013, 04:31:03 PM »
Hi,

I am generating a grid for my turn based strategy game, the host has the grid data and I want to change Instantiate to TNManager.Create but Create doesn't return anything, how would I go about this without a headache?

here's the strip using Instantiate:

  1. //generate grid
  2.   tileActorGrid = new List<List<TileActor>>();
  3.          
  4.   for (int i = 0; i < SessionManager.instance.map.size; i++) {
  5.       List<TileActor> row = new List<TileActor>();
  6.       for (int j = 0; j < SessionManager.instance.map.size; j++) {
  7.           int id = SessionManager.instance.map.grid[i][j].id;
  8.                
  9.           Vector3 pos = new Vector3(-SessionManager.instance.map.size/2 + j ,0,SessionManager.instance.map.size/2 - i);
  10.           Quaternion rot = Quaternion.Euler(new Vector3(0,0,0));
  11.          
  12.           TileActor tile = (TileActor)((GameObject)Instantiate(SessionManager.instance.getPrefabByTileId(id), pos, rot)).GetComponent<TileActor>();
  13.           row.Add(tile);
  14.       }
  15.       tileActorGrid.Add(row);
  16.   }
  17.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #130 on: January 21, 2013, 04:53:54 PM »
I already answered this question above:
Quote
In a script attached to the prefab you're instantiating, you can check in its Awake() function whether you're the one who created this object by checking TNManager.isThisMyObject.

Zaibach333

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #131 on: January 21, 2013, 08:49:24 PM »
Oh, sorry.

I thought I could get a reference to the object immediately after the call ...

what I ended up doing was Instantiate on the host then replace the host grid as they are created via TNManager with Awake() like you said.

Still happens almost immediately.

Thanks.


Smooth P

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #132 on: January 22, 2013, 10:15:21 AM »
Ah, good point about AutoSync. I've fixed it like so:
  1.                                 // Only start the coroutine if we wanted to run periodic updates
  2.                                 if (updatesPerSecond > 0 && TNManager.isConnected)
  3.                                 {
  4.                                         // If we're already in a channel, we can now sync this object
  5.                                         if (TNManager.isInChannel) mCanSync = true;
  6.                                         StartCoroutine(PeriodicSync());
  7.                                 }
  8.                                 else enabled = false;
I'll change it to +=, but any reason you don't want to just rely on automatic OnNetwork* series of functions?

I'm a garage dev who loves NGUI, and just purchased TNet.  I come from a programming background where we rely on type safety and avoid string matches, reflection, and magic bindings like the plague.  So I do all of my event notifications with delegates, which I nearly always bind in Awake().

And I would also like this changed to +=, not for the sake of changes, but because it's the _correct_ thing to do!  :)

Oh, and with TNet I'll be using Enums for all of my RFC identifiers, which is sweet!

(And, yes, typing in Unity has been extremely painful in many ways since the component system doesn't understand interfaces or generics and thus I often have to compromise my design sense and / or create a ton of what should be completely unnecessary boilerplate code, but that's a topic for another day.  And why, oh, why didn't they update the Mono version in 4.0 and am I still relying on my own algebraic classes and dealing with an invariant IEnumerable<T>?  UGGG!).
« Last Edit: January 22, 2013, 02:44:52 PM by Smooth P »

xfinitystudios

  • Guest
Re: TNet: Tasharen Networking Framework
« Reply #133 on: January 22, 2013, 03:55:14 PM »
Hi Aren,

Theoretically .. wouldn't it be possible for me to create a serverside Unity client and connect it to TN and use that server side unity client as a way to handle physics?

For example

[PC Client] >> [TNet] >> [Server Client]
then
[Server Client] >> [TNet] >> [PC Client]

Basically TNet acts as a middle layer between the Server Client and the PC Client. The Server Client will always be the host. Can I get away with this in TNet? I know it's possible with Photon Server.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet: Tasharen Networking Framework
« Reply #134 on: January 22, 2013, 08:56:01 PM »
Yup!

And since the first client to join the channel is always the "host" (authoritative player), your unity's client will essentially do physics on the server.