Author Topic: Possible to make an Instance with TNet?  (Read 3411 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Possible to make an Instance with TNet?
« on: August 25, 2014, 02:20:25 AM »
Hi Guys,

i wanted to make a Game with Dungeon Instances.
Now my Question is, can i archieve Instances with T-net?
Should i do it channels?

If yes, i want to make an dedicated Server with Unity Logic.
How can i build in every custom generated channel a player with the hosting tag, automatically?

Edit: I figured out, how to create a Player when a Channel will be created, but now i need to combine this with an Prefab to put some scripts on it.
On the CreateChannel() function in the GameServer.cs just put this line SendJoinChannel(new TcpPlayer(), channel); after channel is created, correct?

Edit2: Ok, if i create as an Player an Channel, im not host anymore, but my autom. generated player doesnt send data.

I put this on my player prefab:
  1.         void Update () {
  2.         if (TNManager.isHosting)
  3.         {
  4.             tno.SendQuickly(22, Target.All);
  5.         }
  6.         }
  7.  
  8.     [RFC(22)]
  9.     void test()
  10.     {
  11.         Debug.Log("Test");
  12.     }

And normaly it should work, but i doenst.

Do you can tell me, how to generate an automatic "Player" to make the channel authoritative?
« Last Edit: August 25, 2014, 03:29:58 PM by Rexima »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #1 on: August 26, 2014, 03:37:16 AM »
Never send stuff in Update() like that. First, it's framerate-dependent, and second, you're spamming the network with packets. Think about it. if you have 1000 FPS, you are sending 1000 packets per second. Why would you want that?

The first person to enter the channel becomes that channel's owner (host). He's the authoritative player. If he leaves, another person is chosen automatically, inheriting the "host" status. The host is who should be running things like AI logic.

You can make a dedicated server without having to use Unity in it. That's why TNet comes as a tiny executable you can launch. Let the host player do all the logic you'd normally do on the server. It's far, far easier.

To create a player on join, have a look at TNAutoCreate. Create a game object in the scene, add TNAutoCreate to it, and choose your player prefab. Save the scene. Now every player who joins your game will run the TNAutoCreate's logic, spawning their player.

Inside your player, in a script check -- tno.isMine? If so, do your input processing logic. If not, do nothing.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #2 on: August 26, 2014, 03:45:20 AM »
Thanks for the answer, but you didn't understand what i want to do ^^

We need a authoritative channel, we wont that any player has any control of our game.
And we plan to use a MySQL Database for the inventory, items and so one, but this can be made with Custom packets.

So, and i want to use on the server side things like:

  1. if(TNManager.isHosting)
  2. {
  3. tno.sendquickly("PlayerDie", TNManager.GetPlayer(tno.ownerID);
  4. }
(I wrote this as an example, idk if its correct)

So, the Server says, this player will die and not the player self.

Another example, if i want to loot an item, i want that the server put it in my inventory and send me via tno the item to my inventory, to make this game secure from cheaters.

You understand what i mean? Is it possible to chat with you?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #3 on: August 26, 2014, 03:49:09 AM »
Sure, but in doing so you are going to make your server/game logic 100 times more complicated than it should be. Ask yourself if it's worth it for what you're doing. If you're doing a World of Warcraft then I can understand. If you're doing Minecraft or Terraria, then you might want to think about it. I'm guessing you're worrying about hacking and such. I always advise making a game worth hacking first, and only then worrying about hacking.

In any case, SendQuickly is for things like position updates that happen many times per second and each new packet overwrites the state of the previous. If you want to destroy a game object, use TNManager.Destroy instead. Don't inform the player that they should die.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #4 on: August 26, 2014, 03:55:35 AM »
We plan to make something like World of Warcraft, but in small steps.

We made a game before, it was such like a survival game.
There was a server scene, and when you start the server, it creates a gameserver, create a channel and a server prefab was created with TNManger.Create();
The Prefab had the SQL Connection Data, Config Loader etc..

And we build a authoritative gameserver.

Now i want to make the same but for each channel. And i need your help, how to create automatically an gameclient when a channel will be created.

Edit1:
I tried two different things, one with TcpPlayer

  1.                         IPEndPoint ip = TNet.Tools.ResolveEndPoint("127.0.0.1", 27015);
  2.  
  3.                         TcpPlayer p = new TcpPlayer();
  4.                         Player mPlayer = new Player("SERVER");                
  5.                         p.name = mPlayer.name;
  6.                         p.data = mPlayer.data;
  7.                         p.Connect(ip, null);
  8.                         SendJoinChannel(p, channel);

and one with GameClient

  1.                         Player mPlayer = new Player("SERVER");
  2.                         GameClient mClient = new GameClient();
  3.                         mClient.playerName = mPlayer.name;
  4.                         mClient.playerData = mPlayer.data;
  5.                         mClient.Connect(ip, null);
  6.                         mClient.JoinChannel(channelID, levelName, persist, playerLimit, pass);

With TcpPlayer, a Player is in the Channel but it doesnt respond, so i thought it must connect first, but it wont...
And with the GameClient nothing happens.

I tried this here "case Packet.RequestJoinChannel" on the TNGameServer.cs where the
  1. else if (isNew) {
is.
« Last Edit: August 26, 2014, 10:08:32 AM by Rexima »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #5 on: August 27, 2014, 04:39:40 AM »
I don't understand where you're going with your code, and I am pretty sure you don't understand how TNet was meant to work here. TCP player is a class that's used by the TNet's GameServer class. It does a lot inside -- none of which you've handled. Packet processing, for instance. You don't do any, so how can you receive them?

You are approaching TNet with some strange understanding of how you think it should work instead of learning how it does work. I simply can't help you with that. Please start by examining the examples that come with TNet, and more importantly, watch the "how to make a game from scratch" video to have an understanding of how TNet was meant to be used.

To create an authoritative game server, all you need is to have a look at the zipped file that comes with TNet -- the server solution. This solution references all the files in the Server folder, which are the only ones used by the server. The Client section is not used at all, meaning there is no "GameClient". At all.

To add logic to the game server itself, examine that solution file. See what it does inside, and note which files it uses. You can then start looking at the GameServer class -- TNet.GameServer.ProcessPlayerPacket function, to be precise.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #6 on: August 27, 2014, 05:08:31 AM »
Okay, sorry for the misleading informations.

I want to make the GameServer in Unity, not with your .Net zip file.

I tried to follow the TNManager Process, and what i understood was:
- TNManager creates a new Class Player
- TNManager creates a new Class GameClient
- TNManager.Connect() will set the GameClient Name and Data from the Player Name and Data.
  After that it call's GameClient.Connect() and i will connect to the GameServer trough the TcpProtocol and trough the AsyncResult i got an answer if im connected or not.

And i tried the same in the TNGameServer.cs after Line 900
  1. channel.playerLimit = playerLimit;
  2.  
  3. Player mPlayer = new Player("SERVER");
  4.                         GameClient mClient = new GameClient();
  5.                         mClient.playerName = mPlayer.name;
  6.                         mClient.playerData = mPlayer.data;
  7.                         mClient.Connect(ip, null);

If i undestood TNet correctly, i created with this code an "player", or im wrong?

If you wish, that i stop asking, just say it, i will redesign our game idea. :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #7 on: August 28, 2014, 09:50:02 PM »
TNet's server was designed in a specific manner -- clients connect to the server. The server doesn't know anything about client classes, and doesn't use them. You seem to be trying to insert a client into the server, which is like trying to jam a human into a gasoline engine. It just wasn't meant to go there. Humans drive cars powered by engines. Humans don't drive inside the car's engines.

The client needs to be outside your server, not inside it. You can create more than one client easily enough. You can even create a game client right after starting your server, and connect to the same server thus being the first person there, and being the authoritative player.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Possible to make an Instance with TNet?
« Reply #8 on: August 29, 2014, 05:29:44 AM »
Thank you so much! I will try it :)