Author Topic: Stand-alone Server onPlayerDisconnect  (Read 2256 times)

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Stand-alone Server onPlayerDisconnect
« on: September 24, 2016, 08:04:12 PM »
the Player datanode is null when onPlayerDisconnect fires. 

any chance the Player datanode could get sync'd up with TcpPlayer before the onPlayerDisconnect event is called?

temporary fix:
  1. //void RemovePlayer(TcpPlayer p)
  2. //line #610~
  3. #if STANDALONE
  4.         if (p.id != 0) Tools.Log(p.name + " (" + p.address + "): Disconnected [" + p.id + "]");
  5. #endif
  6.  
  7.         //temp_onPlayerDisconnect(p);//sends TcpPlayer instead of Player -- (TcpPlayer)p.datanode is ok with all data
  8.        
  9.         LeaveAllChannels(p);
  10.  
  11.         p.Release();
  12.         p.savePath = null;
  13.         mPlayerList.Remove(p);
  14.  
  15.  
  16.         if (p.udpEndPoint != null)
  17.         {
  18.                 mDictionaryEP.Remove(p.udpEndPoint);
  19.                 p.udpEndPoint = null;
  20.                 p.udpIsUsable = false;
  21.         }
  22.  
  23.         if (p.id != 0)
  24.         {
  25.                 if (mPlayerDict.Remove(p.id))
  26.                 {
  27.                         if (lobbyLink != null) lobbyLink.SendUpdate(this);
  28.                         if (onPlayerDisconnect != null) onPlayerDisconnect(p);//(Player)p.datanode is null at this point
  29.                 }
  30.                 p.id = 0;
  31.         }
  32.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Stand-alone Server onPlayerDisconnect
« Reply #1 on: September 25, 2016, 08:08:28 PM »
You can just move the p.Release() line to the end of that function.
  1.         void RemovePlayer (TcpPlayer p)
  2.         {
  3.                 if (p != null)
  4.                 {
  5.                         SavePlayer(p);
  6. #if STANDALONE
  7.                         if (p.id != 0) Tools.Log(p.name + " (" + p.address + "): Disconnected [" + p.id + "]");
  8. #endif
  9.                         LeaveAllChannels(p);
  10.                         mPlayerList.Remove(p);
  11.  
  12.                         if (p.udpEndPoint != null)
  13.                         {
  14.                                 mDictionaryEP.Remove(p.udpEndPoint);
  15.                                 p.udpEndPoint = null;
  16.                                 p.udpIsUsable = false;
  17.                         }
  18.  
  19.                         if (p.id != 0)
  20.                         {
  21.                                 if (mPlayerDict.Remove(p.id))
  22.                                 {
  23.                                         if (lobbyLink != null) lobbyLink.SendUpdate(this);
  24.                                         if (onPlayerDisconnect != null) onPlayerDisconnect(p);
  25.                                 }
  26.                                 p.id = 0;
  27.                         }
  28.  
  29.                         p.Release();
  30.                         p.savePath = null;
  31.                 }
  32.         }
I'll do it on my end so you will find it like that in the next update.

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Stand-alone Server onPlayerDisconnect
« Reply #2 on: September 25, 2016, 09:25:47 PM »
perfect, thanks.