Author Topic: Send CustomPackets to LobbyServer  (Read 1996 times)

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Send CustomPackets to LobbyServer
« on: April 24, 2014, 03:49:50 PM »
How can i send CustomPackets to my LobbyServer?

i tried it, but it doesnt work.

Thats how i try it:

TNGameServer.cs:
  1.     string remoteAddress = "censored";
  2.     int remotePort = 25565;
  3.     TcpProtocol mTcp = new TcpProtocol();
  4.     IPEndPoint mRemoteAddress;
  5. .
  6. .
  7. .
  8. case Packet.RequestPlayerEmail:
  9.             {
  10.                 string playerEmail = reader.ReadString();
  11.  
  12.                 mRemoteAddress = Tools.ResolveEndPoint(remoteAddress, remotePort);
  13.                 mTcp.Connect(mRemoteAddress);
  14.                 mTcp.BeginSend(Packet.RequestPlayerID).Write(playerEmail);
  15.                 mTcp.EndSend();
  16.                 break;
  17.             }
  18. .
  19. .
  20. .
  21.  

And here the Visual Studio Solution without UnityEngine (like your TNserver.zip):

TNTcpLobbyServer.cs
  1. bool ProcessPacket (Buffer buffer, TcpProtocol tc)
  2.         {
  3. .
  4. .
  5. .
  6.             case Packet.RequestPlayerID:
  7.             {
  8.                 string email = reader.ReadString();
  9.  
  10.                
  11.                 mRemoteAddress = Tools.ResolveEndPoint("theGameServerIP", 6192);
  12.                 tc.Connect(mRemoteAddress);
  13.                 tc.BeginSend(Packet.ResponsePlayerID).Write("1");
  14.                 tc.EndSend();  
  15.  
  16.                 break;
  17.             }
  18. .
  19. .
  20. .
  21.  

TNPackets are on both Projects the same. I dont know what i can make better...
« Last Edit: April 24, 2014, 08:34:50 PM by Rexima »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Send CustomPackets to LobbyServer
« Reply #1 on: April 25, 2014, 10:39:18 AM »
Connect() never finishes immediately. It only starts the connection process. You get the result some time later -- can even be seconds later -- by receiving OnNetworkConnect.

Bottom line: you can't send anything until after you receive an OnNetworkConnect response.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: Send CustomPackets to LobbyServer
« Reply #2 on: April 26, 2014, 09:35:32 PM »
Thank you for the answer, helps me a lot :)

Is an custom package more efficient than tno.sendquickly?

Because i need to sync some states from the gameserver like loottable, last spawnposition etc. and i thought, that a custom package is more efficient, is it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Send CustomPackets to LobbyServer
« Reply #3 on: April 27, 2014, 11:14:04 PM »
RFCs are better because you can save them on the server, and when a new player joins they get the RFCs automatically in the same order they were sent. With custom packets you have to do this manually. As I've been working on Windward I have not yet had any need to create custom packets myself.