Author Topic: Custom Server/Channel Creator  (Read 5273 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Custom Server/Channel Creator
« on: February 13, 2014, 11:59:16 AM »
Hi,

im about to think to write a ChannelCreator in C# (not in Unity, in Visual Studio).
But i can't find any function, how to create a Channel.

Why im planing to do this, is to create a standalone server to sync my weather/day and night cycle.
And i planed to write a ban/kick function and combine it with a global ban system with the externel TNet Gameserver.

Is there any possibility?

(Or is it only possible through Unity?)
« Last Edit: February 13, 2014, 02:04:41 PM by Rexima »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #1 on: February 14, 2014, 06:15:12 AM »
TNet's server is not authoritative, and it sounds like you are trying to make it authoritative. The easiest thing you can do is simply start an instance of your game that would connect to the server and do its thing. You could also create a dummy client in Visual Studio that would connect to the server. This would also mean no need to modify the server.

But, if you want to modify the server to give it some authoritative logic, then I would suggest having a look at what happens when you create a channel. Channels can't exist without players in them, and the server can't be a player. So a player has to come from somewhere.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Custom Server/Channel Creator
« Reply #2 on: February 14, 2014, 06:54:18 AM »
Ok so if i understand it correctly, i need to make a special build of my game that works like a "server".

In Detail:
I create a new Scene, where i create a Channel and connect to the game scene.
And if the "Server" connects first its automatic the host.

So, and i can start to send all players the actual game time, weather...
And maybe implement a AntiCheat, Ban System, right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #3 on: February 15, 2014, 02:16:27 AM »
Yes... or you could modify the server to do the weather and anticheat logic inside without having to join any channels. It's just a matter of adding new custom packets, and the server's ability to understand what to do with them.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Custom Server/Channel Creator
« Reply #4 on: February 16, 2014, 08:00:02 AM »
Thank you Aren for the good explanation.

I tried to modify the TNServer, i added the TNGameClient.cs to the project and tried to connect and create a Channel.
Connecting works, but only for 10 seconds. (The standard of your timeout kicker).
But creating a Channel doesnt work.

That's how i try to connect and create a channel:
  1. static void CreateChannel(int port, string name, string level, int maxPlayer, string password)
  2.     {
  3.         try
  4.                 {
  5.             GameClient client =  new GameClient();
  6.  
  7.             IPEndPoint ip = Tools.ResolveEndPoint("127.0.0.1", port);
  8.  
  9.             client.Connect(ip, null);
  10.             client.SetTimeout(60);
  11.  
  12.             client.JoinChannel(-1, level, false, maxPlayer, password);
  13.             //client.BeginSend(Packet.RequestSetChannelData).Write(name);
  14.             //client.EndSend();
  15.         }
  16.         catch (System.Exception ex)
  17.         {
  18.             Console.WriteLine(ex.Message);
  19.         }
  20.     }

Why i plan to do this is, i want to give away the "server logic" to other people.
And if they start the gameserver, it would create a gameserver and automatically a channel with the specific user inputs, and connect to my lobby server.
And the gameserver must be possible to run under Linux (Console) or Windows without a high end graphic card.
And i want to builtin some features like a weather system(send all players only the current ingame time and the current weather) and later a AntiCheat system.

I hope you can help me Aren, or maybe an another guy/women here with some experience with it.





ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #5 on: February 17, 2014, 12:18:59 PM »
You can't do anything after your Connect call. It's a delayed call. You will get OnNetworkConnect notification when it succeeds or fails.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Custom Server/Channel Creator
« Reply #6 on: February 17, 2014, 12:28:07 PM »
Okay, how can i handle the timeout kicker?
And how can i get the OnNetworkConnect notification ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #7 on: February 17, 2014, 01:46:16 PM »
  1. void OnNetworkConnect (bool success, string errMsg)
  2. {
  3.     Debug.Log("Success? " + success + "\n" + errMsg);
  4. }
Timeout shouldn't occur if you do everything properly.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Custom Server/Channel Creator
« Reply #8 on: February 17, 2014, 02:22:50 PM »
I know how to get the notification on Unity thanks.
I want to connect a user over .Net not in Unity.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #9 on: February 18, 2014, 11:00:59 AM »
Oooh... you're doing this in .NET... gotcha.

Timeout is handled by sending periodic messages in Update(). You'd need to do it yourself on your end in something that runs periodically, like the Update function in Unity.

Look inside TNManager.cs, line 856:
  1. void Update () { mClient.ProcessPackets(); }
Be sure to call ProcessPackets() every so often from somewhere.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Custom Server/Channel Creator
« Reply #10 on: February 20, 2014, 02:28:49 AM »
Thank you very much Aren, got it!
Here for all people who plan to start a authoritative server.

  1.  
  2.             TcpProtocol tcpProt = new TcpProtocol();
  3.             IPEndPoint ipC = Tools.ResolveEndPoint("127.0.0.1", tcpPort);
  4.             tcpProt.Connect(ipC, null);
  5.  
  6.             Thread t = new Thread(KeepAlive);
  7.             t.Start();            
  8.  
  9.             Random r = new Random();
  10.             int rID = r.Next(0,999999999);
  11.             bool isNew = true;
  12.             Channel channel = gameServer.CreateChannel(rID, out isNew);
  13.             channel.password = "";
  14.             channel.persistent = false;
  15.             channel.level = "Level";
  16.             channel.playerLimit = 9;
  17. static void KeepAlive()
  18.  
  19.     {
  20.  
  21.         GameClient gCl = new GameClient();
  22.  
  23.  
  24.  
  25.         while (true)
  26.  
  27.         {
  28.  
  29.             gCl.ProcessPackets();
  30.  
  31.             Thread.Sleep(1000);
  32.  
  33.         }
  34.  
  35.     }
  36.  
  37.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Custom Server/Channel Creator
« Reply #11 on: February 20, 2014, 01:02:04 PM »
As a note, this implies that you are processing packets once per second, which will result in very high ping. It's best to sleep for 1 millisecond.